/* onlink web, laid out and coloured like the macOS app (system colours, SF fonts).
   Light/dark follow the system. The code palette matches the app's code pane. */
:root {
  color-scheme: light dark;
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --size: 12.5px;

  /* window chrome (NSColor.windowBackgroundColor etc.) */
  --window: #ececec; --toolbar: #ececec; --sidebar: #e6e6e8; --control: #ffffff;
  --sep: #d1d1d1; --text: #1d1d1f; --text2: #6e6e73; --text3: #a1a1a6;
  --accent: #007aff; --chain: #af52de; --star: #f5b800; --warn: #ff9500;
  --row-hover: rgba(0, 0, 0, 0.05); --row-sel: rgba(0, 0, 0, 0.09);
  --search-bg: rgba(118, 118, 128, 0.14); --search-bg-solid: #dcdcde;
  --menu-bg: rgba(246, 246, 246, 0.96); --shadow: 0 10px 34px rgba(0, 0, 0, 0.22), 0 0 0 0.5px rgba(0, 0, 0, 0.18);
  --mark: rgba(255, 196, 0, 0.45);

  /* code pane */
  --bg: #ffffff; --fg: #1f2328; --gutter: #8c959f; --active: rgba(0, 0, 0, 0.035); --sel: #add6ff;
  --hl: rgba(255, 200, 0, 0.22); --match: rgba(255, 200, 0, 0.35); --match-border: #d4a72c;
  --match-sel: rgba(255, 150, 0, 0.45); --selmatch: rgba(173, 214, 255, 0.45);
  --panel: #f6f8fa; --border: #d0d7de; --accent-soft: #007aff22; --err: #d70015;
  --kw: #cf222e; --type: #8250df; --fn: #6639ba; --builtin: #0550ae; --const: #0550ae;
  --num: #0550ae; --str: #0a3069; --comment: #6e7781; --doc: #57606a; --op: #57606a;
  --ins: #116329; --del: #82071e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --window: #2b2b2d; --toolbar: #2b2b2d; --sidebar: #29282c; --control: #1e1f22;
    --sep: #141414; --text: #e5e5e7; --text2: #98989d; --text3: #6c6c70;
    --accent: #0a84ff; --chain: #bf5af2; --star: #ffd60a; --warn: #ff9f0a;
    --row-hover: rgba(255, 255, 255, 0.05); --row-sel: rgba(255, 255, 255, 0.1);
    --search-bg: rgba(118, 118, 128, 0.24); --search-bg-solid: #3a3a3d;
    --menu-bg: rgba(40, 40, 42, 0.97); --shadow: 0 10px 34px rgba(0, 0, 0, 0.5), 0 0 0 0.5px rgba(255, 255, 255, 0.14);
    --mark: rgba(255, 196, 0, 0.32);

    --bg: #1e1f22; --fg: #d4d4d4; --gutter: #5c6370; --active: rgba(255, 255, 255, 0.045); --sel: #264f78;
    --hl: rgba(255, 200, 0, 0.14); --match: rgba(255, 200, 0, 0.25); --match-border: #a08a3c;
    --match-sel: rgba(255, 150, 0, 0.45); --selmatch: rgba(173, 214, 255, 0.15);
    --panel: #26282c; --border: #3a3d42; --accent-soft: #0a84ff33; --err: #ff6961;
    --kw: #ff7b72; --type: #d2a8ff; --fn: #dcbdfb; --builtin: #79c0ff; --const: #79c0ff;
    --num: #79c0ff; --str: #a5d6ff; --comment: #8b949e; --doc: #9aa4ae; --op: #b5bcc4;
    --ins: #7ee787; --del: #ffa198;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { display: flex; flex-direction: column; background: var(--window); color: var(--text); font: 13px/1.3 var(--ui); -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; }
button { cursor: default; }
[hidden] { display: none !important; }
.dim { color: var(--text2); }

/* icons */
.ic { display: inline-flex; width: 16px; height: 16px; flex: none; align-items: center; justify-content: center; }
.ic svg { width: 15px; height: 15px; }
.ic.small svg { width: 11px; height: 11px; }
.c-chain { color: var(--chain); }
.c-star { color: var(--star); }
.c-warn { color: var(--warn); }
.c-dim { color: var(--text2); }

/* ---------------------------------------------------------------- toolbar */
.toolbar { height: 52px; flex: none; display: flex; align-items: center; background: var(--toolbar); border-bottom: 1px solid var(--sep); }
.tb-side { flex: 1 1 0; min-width: 0; display: flex; align-items: center; padding: 0 16px; }
.brand { font: 600 13px var(--ui); color: var(--text2); letter-spacing: -0.01em; }
.tb-center { position: relative; flex: 0 1 680px; min-width: 300px; }
.search { display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 8px; border-radius: 7px; background: var(--search-bg); }
.search:focus-within { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); }
.chain-btn { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 0 2px; font-size: 13px; font-weight: 500; white-space: nowrap; }
.chain-btn svg { color: var(--text2); }
.search-div { width: 1px; height: 14px; background: var(--text3); opacity: 0.6; }
.search-ic { color: var(--text2); flex: none; }
#q { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 13px; }
#q::placeholder { color: var(--text3); }
.busy { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text2); white-space: nowrap; }
.search-clear { border: 0; background: none; padding: 0; color: var(--text3); display: inline-flex; }
.tog { min-width: 20px; height: 18px; padding: 0 3px; border-radius: 4px; border: 1px solid transparent; background: transparent; color: var(--text2); font: 11px var(--mono); }
.tog[aria-pressed="true"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, transparent); border-color: color-mix(in srgb, var(--accent) 70%, transparent); }

/* search results (VS Code-like dropdown) */
.results { position: absolute; top: 36px; left: 0; right: 0; max-height: min(520px, 70vh); overflow: auto; z-index: 20; background: var(--menu-bg); border-radius: 9px; box-shadow: var(--shadow); padding: 4px 0 6px; backdrop-filter: blur(20px); }
.res-summary { padding: 4px 12px 6px; font-size: 11px; color: var(--text2); }
.res-file { display: flex; align-items: center; gap: 5px; padding: 3px 10px; font-size: 12px; }
.res-file:hover { background: var(--row-hover); }
.res-name { font-weight: 600; white-space: nowrap; }
.res-path { flex: 1; min-width: 0; color: var(--text3); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
.res-count { font-size: 10.5px; color: var(--text2); background: var(--search-bg); border-radius: 8px; padding: 0 6px; }
.res-line { display: flex; gap: 8px; padding: 2px 10px 2px 42px; font: 12px var(--mono); white-space: nowrap; overflow: hidden; }
.res-line:hover { background: var(--row-hover); }
.res-line.sel { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.res-ln { color: var(--text3); min-width: 28px; text-align: right; flex: none; }
.hit-text { overflow: hidden; text-overflow: ellipsis; }
.hit-text mark { background: var(--mark); color: inherit; border-radius: 2px; }

/* ---------------------------------------------------------------- split view */
.main { flex: 1; display: flex; min-height: 0; }
.sidebar { width: var(--side-w, 340px); min-width: 220px; max-width: 560px; flex: none; display: flex; flex-direction: column; background: var(--sidebar); min-height: 0; }
.split { width: 1px; flex: none; background: var(--sep); position: relative; cursor: col-resize; }
.split::after { content: ""; position: absolute; inset: 0 -4px; }
.detail { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--control); }

/* sidebar tree */
.tree { flex: 1; overflow: auto; padding: 6px 8px 10px; }
.row { display: flex; align-items: center; gap: 6px; height: 26px; padding-right: 8px; border-radius: 5px; white-space: nowrap; }
.row:hover { background: var(--row-hover); }
.row.sel { background: var(--row-sel); }
.disc { width: 12px; flex: none; display: inline-flex; justify-content: center; color: var(--text2); }
.disc .ic svg { width: 10px; height: 10px; }
.row .title { overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; min-width: 20px; }
.row .subtitle { font-size: 11px; color: var(--text3); overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; min-width: 0; }
.row .retry { margin-left: auto; border: 0; background: none; color: var(--warn); padding: 0; display: inline-flex; }
.row .retry .ic svg { width: 12px; height: 12px; stroke-width: 2; }
.row .spin { margin-left: auto; }
.rename { font-size: 13px; padding: 1px 4px; border: 1px solid var(--accent); border-radius: 3px; background: var(--control); outline: 0; min-width: 0; width: 60%; }
.sidebar-empty { padding: 18px; text-align: center; font-size: 12px; line-height: 1.5; }

/* ---------------------------------------------------------------- tabs */
.tabbar { height: 30px; flex: none; display: flex; overflow-x: auto; overflow-y: hidden; background: var(--window); border-bottom: 1px solid var(--sep); scrollbar-width: none; }
.tabbar::-webkit-scrollbar { display: none; }
.tab { position: relative; display: flex; align-items: center; gap: 6px; padding: 0 10px; flex: none; font-size: 13px; border-right: 1px solid var(--sep); }
.tab.active { background: var(--control); }
.tab.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--accent); }
.tab-addr { font-size: 10.5px; color: var(--text2); }
.tab-close { border: 0; background: none; padding: 2px; color: var(--text2); display: inline-flex; border-radius: 3px; }
.tab-close:hover { background: var(--row-sel); color: var(--text); }

.banner { display: flex; align-items: center; gap: 8px; padding: 5px 10px; font-size: 12.5px; background: color-mix(in srgb, var(--warn) 15%, transparent); white-space: nowrap; overflow: hidden; }

/* ---------------------------------------------------------------- code pane */
.editor-wrap { flex: 1; position: relative; min-height: 0; }
.code { position: absolute; inset: 0; }
.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: var(--control); }
.empty-title { font-size: 22px; font-weight: 600; }
.empty-keys { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; font: 12.5px var(--mono); color: var(--text2); white-space: pre; }

/* ---------------------------------------------------------------- status bar */
.statusbar { height: 22px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 10px; font-size: 11px; color: var(--text2); border-top: 1px solid var(--sep); background: var(--control); }
/* Long paths lose their start, not their file name (the app truncates at the head). */
#status-left { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
#status-left > span, .res-path > span { direction: ltr; unicode-bidi: isolate; }
#status-left.notice { color: var(--text); direction: ltr; }
.status-right { display: flex; gap: 12px; white-space: nowrap; }
.status-right span:first-child { user-select: text; }

/* ---------------------------------------------------------------- menus and sheets */
.menu { position: fixed; z-index: 50; min-width: 180px; max-height: 70vh; overflow: auto; padding: 5px; background: var(--menu-bg); border-radius: 8px; box-shadow: var(--shadow); backdrop-filter: blur(20px); font-size: 13px; }
.menu-item { display: flex; align-items: center; gap: 4px; padding: 3px 10px 3px 4px; border-radius: 4px; white-space: nowrap; }
.menu-item:hover { background: var(--accent); color: #fff; }
.menu-check { width: 16px; display: inline-flex; justify-content: center; }
.menu-sep { height: 1px; margin: 5px 8px; background: var(--sep); }
.sheet { position: fixed; inset: 0; z-index: 40; display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; background: rgba(0, 0, 0, 0.18); outline: 0; }
.pick { width: min(600px, 92vw); max-height: 64vh; display: flex; flex-direction: column; background: var(--menu-bg); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; backdrop-filter: blur(20px); }
.pick-title { padding: 10px 14px 6px; font-size: 12px; font-weight: 600; color: var(--text2); }
.pick-input { margin: 0 10px 8px; padding: 7px 10px; border-radius: 6px; border: 0; outline: 0; background: var(--search-bg); font-size: 14px; }
.pick-list { overflow: auto; padding: 0 6px 6px; }
.pick-item { padding: 5px 8px; border-radius: 5px; }
.pick-item.sel { background: var(--accent); color: #fff; }
.pick-item.sel .pick-sub, .pick-item.sel .pick-detail { color: rgba(255, 255, 255, 0.8); }
.pick-main { display: flex; gap: 8px; align-items: baseline; white-space: nowrap; overflow: hidden; }
.pick-name { font-weight: 500; }
.pick-sub { font-size: 11px; color: var(--text2); overflow: hidden; text-overflow: ellipsis; }
.pick-detail { font: 11.5px var(--mono); color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

/* spinner */
.spin { display: inline-block; width: 11px; height: 11px; flex: none; border-radius: 50%; border: 1.6px solid var(--text3); border-right-color: transparent; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* CodeMirror find panel */
.ol-find { display: flex; align-items: center; gap: 6px; padding: 6px 10px; font: 12px var(--ui); color: var(--fg); background: var(--panel); }
.ol-field { display: flex; align-items: center; gap: 2px; width: 340px; max-width: 60vw; padding: 0 3px 0 0; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; }
.ol-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.ol-field input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--fg); font: 12px var(--mono); padding: 4px 8px; }
.ol-field input::placeholder { color: var(--gutter); font-family: var(--ui); }
.ol-find.ol-none .ol-field { border-color: var(--err); }
.ol-tog, .ol-btn { display: inline-flex; align-items: center; justify-content: center; height: 20px; min-width: 22px; padding: 0 4px; border: 1px solid transparent; border-radius: 4px; background: transparent; color: var(--gutter); font: 11px var(--mono); }
.ol-tog:hover, .ol-btn:hover { background: var(--active); color: var(--fg); }
.ol-tog[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.ol-btn { height: 24px; min-width: 24px; }
.ol-count { min-width: 64px; color: var(--gutter); font-variant-numeric: tabular-nums; }
.ol-find.ol-none .ol-count { color: var(--err); }
