:root { --sky: #DCE9FF; --navy: #20324D; --ink: #202020; --blue: #174A86; --gutter: #EAF0FA; --line-no: #52627A; }
* { box-sizing: border-box; }
html { margin: 0; min-height: 100%; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif; font-size: 13px; color: var(--ink); background: var(--sky); min-width: 850px; min-height: 100vh; height: auto; overflow-x: hidden; overflow-y: auto; }
#app { display: flex; flex-direction: column; min-height: 100vh; height: auto; }
#windows { position: fixed; inset: 0; pointer-events: none; z-index: 100; }

/* ---- menubar ---- */
#menubar { display: flex; background: #f0f0f0; border-bottom: 1px solid #c8c8c8; position: relative; z-index: 9500; user-select: none; }
.fn-top { position: relative; padding: 4px 11px; cursor: default; }
.fn-top:hover, .fn-top.active { background: #cce4f7; }
.fn-menu { display: none; position: absolute; left: 0; top: 100%; min-width: 270px; background: #fff; border: 1px solid #b8b8b8; box-shadow: 2px 3px 8px rgba(0,0,0,.25); padding: 3px 0; z-index: 9600; }
.fn-menu.open { display: block; }
.fn-mi { display: flex; justify-content: space-between; gap: 24px; padding: 4px 22px 4px 18px; position: relative; white-space: nowrap; cursor: default; }
.fn-mi:hover { background: #cce4f7; }
.fn-mi-accel { color: #666; }
.fn-sep { height: 1px; background: #ddd; margin: 4px 0; }
.fn-mi .fn-menu { left: 100%; top: -4px; }
.fn-mi.has-sub:hover > .fn-menu { display: block; }

/* ---- header / toolbar ---- */
.header { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--sky); }
.app-title { font-size: 24px; font-weight: 700; color: var(--navy); }
.status { color: var(--navy); }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 4px 12px; background: var(--sky); }
.timer-label { font-weight: 700; color: var(--navy); font-size: 13px; }

/* ---- dark control panels ---- */
.panel-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 4px 11px; background: var(--navy); color: #fff; }
.row-label { display: inline-block; width: 128px; font-size: 12px; color: #fff; }
.white { color: #fff; }

/* ---- buttons / inputs ---- */
.btn { font: inherit; font-size: 12px; padding: 3px 11px; border: 1px solid #adadad; border-radius: 2px; background: linear-gradient(#f6f6f6, #e2e2e2); color: #111; cursor: pointer; }
.btn:hover:not(:disabled) { background: linear-gradient(#e9f4fd, #cfe6f8); border-color: #3c7fb1; }
.btn:active:not(:disabled) { background: #bcd9f0; }
.btn:disabled { color: #8a8a8a; cursor: default; background: #f0f0f0; }
.btn.default { border-color: #0078d7; box-shadow: inset 0 0 0 1px #0078d7; }
.combo, .fn-input { font: inherit; font-size: 12px; padding: 3px 5px; border: 1px solid #8a8a8a; background: #fff; color: #111; border-radius: 2px; }
.fn-input:focus, .combo:focus { outline: 2px solid #4a90d9; outline-offset: -1px; }

/* ---- editor ---- */
.editor-frame { flex: none; min-height: 660px; display: flex; flex-direction: column; padding: 8px 12px 12px; background: #fff; }
.fold-controls { display: flex; gap: 8px; padding-bottom: 6px; }
.editor-host { flex: none; height: 620px; min-height: 620px; background: #fff; border: 1px solid #c8c8c8; }
.ed-wrap { display: flex; height: 100%; min-height: 620px; --ed-size: 15px; --ed-lh: 23px; background: #fff; }
.ed-gutter { width: 132px; flex: none; background: #fff; border-right: 1px solid #e2e2e2; position: relative; overflow: hidden; user-select: none; }
.ed-main { flex: 1; position: relative; background: #fff; min-width: 0; }
.ed-mirror, .ed-text { position: absolute; top: 0; left: 0; margin: 0; padding: 12px; border: 0; font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif; font-size: var(--ed-size); line-height: var(--ed-lh); letter-spacing: normal; word-spacing: normal; tab-size: 4; white-space: pre-wrap; overflow-wrap: break-word; word-break: normal; }
.ed-mirror { height: 100%; overflow: hidden; color: transparent; pointer-events: none; }
.ed-mirror .ml { min-height: var(--ed-lh); }
.ed-text { width: 100%; height: 100%; resize: none; outline: none; background: #fff; color: #202020; caret-color: #202020; overflow: auto; }
.ed-wrap.nowrap .ed-mirror, .ed-wrap.nowrap .ed-text { white-space: pre; overflow-wrap: normal; }
.ed-wrap.readonly .ed-text { cursor: default; }
.m-note { background: #DCEBFF; text-decoration: underline; text-decoration-color: var(--blue); }
.m-hl { background: #FFF1A8; }
.m-find { background: #FFE58A; }
.g-num, .g-fold, .g-sec { position: absolute; transform: translateY(-50%); line-height: 1; white-space: nowrap; }
.g-num { right: 10px; font-size: 12px; color: var(--line-no); }
.g-fold { left: 5px; width: 16px; text-align: center; font-size: 17px; font-weight: 700; color: var(--blue); }
.g-sec { left: 29px; font-size: 12px; font-weight: 700; color: var(--blue); }

.footer { display: flex; gap: 16px; padding: 6px 10px; background: var(--navy); color: #fff; }

/* ---- modal dialogs ---- */
.fn-overlay { position: fixed; inset: 0; background: rgba(20, 30, 48, .38); display: flex; align-items: center; justify-content: center; }
.fn-dialog { background: #f3f3f3; border: 1px solid #6d7b91; box-shadow: 0 10px 40px rgba(0,0,0,.4); width: min(520px, 94vw); border-radius: 3px; }
.fn-dlg-title { background: #fff; padding: 7px 12px; font-size: 12px; border-bottom: 1px solid #ddd; color: #333; }
.fn-dlg-body { display: flex; gap: 14px; padding: 18px 18px 10px; align-items: flex-start; }
.fn-dlg-icon { font-size: 26px; line-height: 1; }
.fn-dlg-msg { white-space: pre-wrap; line-height: 1.45; flex: 1; user-select: text; }
.fn-dlg-msg.block { padding: 16px 18px 8px; flex: none; }
.fn-dialog > .fn-input { margin: 4px 18px 6px; width: calc(100% - 36px) !important; }
.fn-dlg-buttons { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 14px; background: #e9e9e9; margin-top: 10px; }
.fn-recovery { display: block; width: calc(100% - 36px); margin: 4px 18px; font: 600 14px/1.5 Consolas, "Courier New", monospace; padding: 8px; border: 1px solid #888; resize: none; letter-spacing: .5px; word-break: break-all; }
.fn-colorpick { width: 120px; height: 70px; border: 0; padding: 0; background: none; }

/* ---- Toplevel-style windows ---- */
.fn-win { position: absolute; pointer-events: auto; display: flex; flex-direction: column; background: #f0f0f0; border: 1px solid #5b6b85; box-shadow: 0 8px 30px rgba(0,0,0,.35); resize: none; overflow: hidden; border-radius: 3px; }
.fn-win-title { flex: none; display: flex; align-items: center; justify-content: space-between; background: #fff; border-bottom: 1px solid #d4d4d4; padding: 0 0 0 10px; height: 30px; cursor: move; user-select: none; touch-action: none; font-size: 12px; }
.fn-win-x { width: 44px; height: 30px; border: 0; background: transparent; cursor: pointer; font-size: 13px; }
.fn-win-x:hover { background: #e81123; color: #fff; }
.fn-win-resize { position: absolute; right: 0; bottom: 0; width: 28px; height: 28px; z-index: 50; cursor: nwse-resize; touch-action: none; user-select: none; pointer-events: auto; border-radius: 3px 0 2px 0; background: linear-gradient(135deg, transparent 0 48%, #7b8797 49% 53%, transparent 54% 63%, #7b8797 64% 68%, transparent 69% 78%, #7b8797 79% 83%, transparent 84%); }
.fn-win-resize:hover { background-color: rgba(0,120,215,.10); }
.fn-win-body { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.fn-win-body.col { overflow: hidden; }
.win-heading { font-size: 21px; font-weight: 700; padding: 10px 12px; }
.win-heading.small { font-size: 13px; padding: 10px 12px 6px; }
.row-pad { display: flex; align-items: center; gap: 8px; padding: 8px 12px; flex: none; flex-wrap: wrap; }
.row-pad.right { justify-content: flex-end; }
.pad { padding: 4px 12px; flex: none; }
.pad.scroll, .scroll { overflow: auto; flex: 1; min-height: 0; }
.grow { flex: 1; min-height: 0; }
.spacer { flex: 1; }
.small-text { font-size: 12px; }
.muted { color: #777; }
.status-line { padding: 4px 12px 10px; flex: none; }
.form-grid { display: grid; grid-template-columns: auto 1fr; gap: 8px 10px; align-items: center; padding: 14px; }
.form-grid input { width: 100%; }

/* ---- listbox ---- */
.fn-listbox { background: #fff; border: 1px solid #8a8a8a; margin: 0 12px 8px; overflow: auto; outline: none; min-height: 60px; }
.fn-lb-item { padding: 2px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12.5px; cursor: default; user-select: none; }
.fn-lb-item.sel { background: #0078d7; color: #fff; }
.fn-listbox:not(:focus) .fn-lb-item.sel { background: #9ec3ea; color: #000; }

/* ---- text views ---- */
.detail-view, .mono-view { margin: 0 12px 10px; padding: 8px 10px; border: 1px solid #8a8a8a; background: #fff; font: 13px/1.5 "Segoe UI", system-ui, sans-serif; resize: none; flex: none; }
.detail-view.grow { flex: 1; }
.mono-view { font: 12.5px/1.45 Consolas, "Courier New", monospace; word-break: break-all; margin-top: 0; }
/* Memory Bank session viewer must expand to fill the available window body. */
.mono-view.grow { flex: 1 1 auto; min-height: 0; height: 0; width: calc(100% - 24px); }

/* ---- annotations ---- */
.annot-form { display: flex; flex-direction: column; gap: 2px; }
.annot-label { font-size: 12px; font-weight: 700; margin: 6px 0 1px; }
.annot-form textarea, .annot-form input { width: 100%; }
.swatch { display: inline-block; border: 1px inset #999; height: 20px; width: 40px; }

/* ---- calendar ---- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-head { text-align: center; font-weight: 700; font-size: 12px; color: var(--navy); padding: 2px 0; }
.cal-day { height: 40px; border: 1px solid #c3c9d4; background: #fff; border-radius: 2px; cursor: pointer; font: inherit; position: relative; }
.cal-day:hover { background: #e6f1fc; }
.cal-day.today { border-color: var(--blue); font-weight: 700; }
.cal-day.sel { background: #0078d7; color: #fff; }
.cal-dots { position: absolute; bottom: 1px; left: 0; right: 0; font-size: 9px; line-height: 1; }
.cal-box { background: #fff; border: 1px solid #c3c9d4; padding: 6px 8px; max-height: 90px; overflow: auto; font-size: 12.5px; }

.single-instance { margin: 80px auto; max-width: 520px; padding: 24px; background: #fff; border: 1px solid #889; font-size: 15px; line-height: 1.5; }

/* Responsive P2P pairing drawer */
#p2p-panel{position:fixed;right:12px;bottom:12px;z-index:99999;width:min(440px,calc(100vw - 24px));max-height:65vh;overflow:auto;background:#192840;color:#fff;border:1px solid #71809a;border-radius:12px;box-shadow:0 8px 35px #0007;font:14px system-ui}#p2p-panel summary{padding:12px;cursor:pointer;font-weight:700}#p2p-panel .p2p-body{padding:12px}#p2p-panel textarea{width:100%;box-sizing:border-box;margin:5px 0 10px;min-height:55px;background:#fff;color:#111;border-radius:5px}#p2p-panel button{padding:8px;margin:3px;border-radius:6px;cursor:pointer;background:#dce9fa;color:#10213a;border:0}#p2p-panel label{display:block}#p2p-panel a{color:#9cd5ff}#p2p-panel .p2p-actions{display:flex;flex-wrap:wrap}#p2p-panel p{line-height:1.45}@media(max-width:600px){#p2p-panel{bottom:4px;right:4px;width:calc(100vw - 8px);max-height:60vh}}
