/* ==========================================================================
   FOLIO — app.css
   A dark, precision document studio.
   ========================================================================== */
:root {
  --bg: #0a0c10;
  --bg-deep: #07090c;
  --panel: #101319;
  --panel-2: #141821;
  --panel-3: #1a1f2a;
  --line: rgba(255, 255, 255, 0.075);
  --line-strong: rgba(255, 255, 255, 0.15);
  --text: #e8ebf1;
  --text-soft: #c3c9d4;
  --muted: #8c94a4;
  --faint: #5b6373;
  --accent: #7c93ff;
  --accent-2: #a78bfa;
  --accent-ink: #0a0c10;
  --accent-soft: rgba(124, 147, 255, 0.14);
  --accent-glow: rgba(124, 147, 255, 0.35);
  --ok: #4bd6a2;
  --warn: #f0b45e;
  --err: #ff6f6f;
  --paper-shadow: 0 22px 60px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.4);
  --radius: 8px;
  --radius-lg: 13px;
  --font: "Segoe UI Variable Text", "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI", Inter, system-ui, sans-serif;
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, ui-monospace, monospace;
  --tb-h: 54px;
  --menubar-h: 32px;
  --status-h: 28px;
  --toolbar-fade: #0e1117;
  --elev-1: #171b23;
  --elev-2: #141821;
}
:root[data-accent="amber"] { --accent: #e9b45c; --accent-2: #f08f6a; --accent-soft: rgba(233, 180, 92, .13); --accent-glow: rgba(233, 180, 92, .3); }
:root[data-accent="teal"] { --accent: #45d5c0; --accent-2: #63b3ff; --accent-soft: rgba(69, 213, 192, .13); --accent-glow: rgba(69, 213, 192, .28); }
:root[data-accent="rose"] { --accent: #f08ea8; --accent-2: #f3b06c; --accent-soft: rgba(240, 142, 168, .13); --accent-glow: rgba(240, 142, 168, .28); }

:root[data-theme="light"] {
  --bg: #eef1f7;
  --bg-deep: #e5e9f1;
  --panel: #f7f8fb;
  --panel-2: #ffffff;
  --panel-3: #eef1f6;
  --line: rgba(15, 23, 42, 0.09);
  --line-strong: rgba(15, 23, 42, 0.18);
  --text: #111827;
  --text-soft: #374151;
  --muted: #6b7280;
  --faint: #9aa3b2;
  --paper-shadow: 0 18px 45px rgba(18, 28, 45, .18), 0 2px 6px rgba(18, 28, 45, .1);
  --accent-ink: #0a0c10;
  --toolbar-fade: #f2f4f9;
  --elev-1: #ffffff;
  --elev-2: #ffffff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

svg.i { flex: none; display: inline-block; vertical-align: middle; }
kbd {
  font-family: var(--mono); font-size: 10px; line-height: 1;
  padding: 3px 5px; border-radius: 4px;
  background: rgba(255,255,255,.06); border: 1px solid var(--line);
  color: var(--muted);
}
.mono { font-family: var(--mono); font-size: 11px; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* ---------- scrollbars ---------- */
* { scrollbar-width: thin; scrollbar-color: rgba(140,148,164,.28) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(140,148,164,.25); border-radius: 8px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(140,148,164,.42); background-clip: padding-box; border: 3px solid transparent; }

/* ==========================================================================
   Menubar
   ========================================================================== */
#menubar {
  height: var(--menubar-h);
  flex: none;
  display: flex; align-items: center; gap: 18px;
  padding: 0 10px 0 12px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--line);
  user-select: none;
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--accent); }
.brand-mark { display: flex; filter: drop-shadow(0 0 8px var(--accent-glow)); }
.brand-name { font-family: var(--font-display); font-size: 13px; font-weight: 800; letter-spacing: .16em; color: var(--text); }
.brand-tag { font-size: 8.5px; letter-spacing: .17em; color: var(--faint); font-weight: 700; margin-left: 1px; border-left: 1px solid var(--line-strong); padding-left: 9px; }
.menus { display: flex; align-items: center; gap: 1px; }
.menu-title {
  background: none; border: 0; height: 24px; padding: 0 9px; border-radius: 5px;
  font-size: 12px; color: var(--text-soft); letter-spacing: .01em;
}
.menu-title:hover { background: rgba(255,255,255,.06); color: var(--text); }
.menubar-right { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.doc-state { font-size: 11px; color: var(--faint); margin-right: 6px; }

.icon-btn {
  width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; border-radius: 7px;
  color: var(--muted); transition: background .12s, color .12s, border-color .12s;
  flex: none;
}
.icon-btn:hover { background: rgba(255,255,255,.06); color: var(--text); }
.icon-btn:active { transform: translateY(.5px); }
.icon-btn.active { background: var(--accent-soft); color: var(--accent); border-color: rgba(124,147,255,.3); }
.icon-btn.disabled, .icon-btn[disabled] { opacity: .3; pointer-events: none; }
.icon-btn.tiny { width: 24px; height: 24px; border-radius: 5px; }
.icon-btn.tight { width: 27px; }
.palette-btn { width: auto; gap: 5px; padding: 0 7px; }
.palette-btn kbd { font-size: 9px; padding: 2px 4px; }

/* ==========================================================================
   Toolbar
   ========================================================================== */
#toolbar {
  height: var(--tb-h); flex: none;
  display: flex; align-items: center; gap: 3px;
  padding: 0 10px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel) 55%, var(--toolbar-fade) 100%);
  border-bottom: 1px solid var(--line);
  z-index: 30;
  overflow: hidden;
}
.tb-group { display: flex; align-items: center; gap: 2px; }
.tb-sep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; flex: none; }
.tb-spacer { flex: 1; min-width: 8px; }
.tool-strip { gap: 1px; padding: 2px; background: rgba(0,0,0,.18); border: 1px solid var(--line); border-radius: 9px; }
.tool-btn {
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; background: transparent; border-radius: 7px; color: var(--muted);
  transition: .13s ease;
}
.tool-btn:hover { color: var(--text); background: rgba(255,255,255,.06); }
.tool-btn.active {
  color: var(--accent); background: var(--accent-soft);
  border-color: rgba(124,147,255,.34);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.02), 0 0 14px -6px var(--accent-glow);
}
.tool-btn.tool-more { width: 24px; color: var(--faint); }
.page-indicator {
  min-width: 76px; height: 30px; padding: 0 10px;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  color: var(--text-soft); font-size: 12px; font-variant-numeric: tabular-nums;
}
.page-indicator:hover { background: rgba(255,255,255,.05); border-color: var(--line); }
.zoom-label {
  min-width: 52px; height: 30px; background: transparent; border: 1px solid transparent;
  border-radius: 6px; font-size: 11.5px; color: var(--text-soft); font-variant-numeric: tabular-nums;
}
.zoom-label:hover { background: rgba(255,255,255,.05); border-color: var(--line); }
.layouts { padding: 2px; background: rgba(0,0,0,.18); border: 1px solid var(--line); border-radius: 8px; }

.btn {
  height: 32px; padding: 0 13px; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: 7px; border: 1px solid var(--line-strong);
  background: var(--panel-3); color: var(--text); font-weight: 600; font-size: 12px;
  transition: background .12s, border-color .12s, transform .06s;
  white-space: nowrap;
}
.btn:hover { background: #232936; border-color: rgba(255,255,255,.22); }
.btn:active { transform: translateY(1px); }
.btn.btn-tall { height: 34px; }
.btn-primary {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent) 100%);
  border-color: transparent; color: var(--accent-ink);
  box-shadow: 0 4px 14px -6px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,.25);
}
.btn-primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn-secondary { background: rgba(255,255,255,.055); border-color: var(--line-strong); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--text-soft); }
.btn-quiet:hover { background: rgba(255,255,255,.06); border-color: var(--line); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: rgba(255,255,255,.06); }
.btn-danger { background: rgba(255,111,111,.14); border-color: rgba(255,111,111,.35); color: #ffb3b3; }
.btn-danger:hover { background: rgba(255,111,111,.2); }
.btn-sm { height: 27px; padding: 0 10px; font-size: 11.5px; }
.btn-lg { height: 40px; padding: 0 17px; font-size: 13px; border-radius: 9px; }
.btn[disabled], .btn.disabled { opacity: .4; pointer-events: none; }
.btn svg { margin-left: -1px; }
.btn-label { letter-spacing: .01em; }

/* ==========================================================================
   Workspace shell
   ========================================================================== */
#workspace { flex: 1; display: flex; min-height: 0; min-width: 0; background: var(--bg); }

#rail {
  width: 62px; flex: none; z-index: 20;
  background: var(--bg-deep);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: stretch;
  padding: 7px 5px; gap: 2px;
  overflow-y: auto; overflow-x: hidden;
}
.rail-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 50px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--faint); font-size: 9px; letter-spacing: .03em;
  position: relative;
}
.rail-btn:hover { color: var(--text-soft); background: rgba(255,255,255,.04); }
.rail-btn.active { color: var(--accent); background: var(--accent-soft); }
.rail-btn.active::before {
  content: ''; position: absolute; left: -5px; top: 12px; bottom: 12px; width: 2px;
  background: var(--accent); border-radius: 2px; box-shadow: 0 0 8px var(--accent-glow);
}

#sidebar {
  width: 274px; flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-right: 1px solid var(--line);
}
body:not(.sidebar-open) #sidebar { display: none; }
.side-head {
  height: 40px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 0 14px; border-bottom: 1px solid var(--line);
}
.side-title { font-size: 10.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
#side-panel-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.panel-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; }
.panel-content { padding: 10px 8px 24px; }
.panel-actions { display: flex; align-items: center; gap: 5px; padding: 2px 4px 9px; }
.mini-btn {
  height: 22px; padding: 0 7px; border-radius: 5px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-size: 10.5px; font-weight: 600;
}
.mini-btn:hover { color: var(--text); background: rgba(255,255,255,.05); }
.panel-empty {
  padding: 40px 16px; text-align: center; color: var(--muted); display: flex; flex-direction: column;
  align-items: center; gap: 10px; font-size: 12px;
}
.panel-empty p { margin: 0; }
.panel-error { padding: 18px; color: var(--err); font-size: 12px; }

/* Thumbnails */
.thumb-list { display: flex; flex-direction: column; gap: 8px; padding: 0 4px 8px; }
.thumb {
  position: relative; border-radius: 5px; padding: 5px; cursor: pointer;
  border: 1px solid transparent; background: transparent;
  transition: background .12s, border-color .12s;
}
.thumb:hover { background: rgba(255,255,255,.035); }
.thumb.current { background: rgba(255,255,255,.035); }
.thumb.selected { background: var(--accent-soft); border-color: rgba(124,147,255,.38); }
.thumb.selected.current { border-color: var(--accent); }
.thumb-shot {
  position: relative; width: 100%; background: #fff; border-radius: 2px;
  box-shadow: 0 4px 12px rgba(0,0,0,.35); overflow: hidden; display: flex; align-items: center; justify-content: center;
}
.thumb-shot canvas { width: 100%; height: 100%; object-fit: contain; display: block; opacity: 0; transition: opacity .25s; }
.thumb-shot canvas.ready { opacity: 1; }
.thumb-foot { display: flex; align-items: center; justify-content: space-between; padding: 4px 3px 0; }
.thumb-num { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.thumb.selected .thumb-num { color: var(--accent); font-weight: 700; }
.thumb-meta { font-size: 9px; color: var(--faint); font-family: var(--mono); }
.thumb-grab { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); color: var(--faint); opacity: 0; }
.thumb:hover .thumb-grab { opacity: .8; }
.thumb.dragging { opacity: .35; }
.thumb.drop-before::before, .thumb.drop-after::after {
  content: ''; position: absolute; left: 2px; right: 2px; height: 2px; background: var(--accent);
  border-radius: 2px; box-shadow: 0 0 8px var(--accent-glow);
}
.thumb.drop-before::before { top: -5px; }
.thumb.drop-after::after { bottom: -5px; }

/* ==========================================================================
   Document area
   ========================================================================== */
#docarea { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

#tabstrip {
  height: 37px; flex: none; display: flex; align-items: flex-end; gap: 2px;
  padding: 0 8px; background: var(--bg-deep); border-bottom: 1px solid var(--line);
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
}
#tabstrip::-webkit-scrollbar { display: none; }
.doctab {
  display: flex; align-items: center; gap: 7px; height: 30px; max-width: 220px;
  padding: 0 7px 0 10px; border-radius: 7px 7px 0 0;
  border: 1px solid transparent; border-bottom: 0;
  color: var(--muted); background: transparent; position: relative; user-select: none;
  flex: none;
}
.doctab:hover { color: var(--text-soft); background: rgba(255,255,255,.035); }
.doctab.active {
  color: var(--text); background: var(--panel);
  border-color: var(--line); box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.doctab.active::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: var(--panel);
}
.doctab-name { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doctab-ic { display: flex; color: var(--faint); }
.doctab.active .doctab-ic { color: var(--accent); }
.tab-x {
  width: 17px; height: 17px; border: 0; border-radius: 4px; background: transparent;
  color: var(--faint); display: flex; align-items: center; justify-content: center; padding: 0;
  opacity: 0; flex: none;
}
.doctab:hover .tab-x, .doctab.active .tab-x { opacity: 1; }
.tab-x:hover { background: rgba(255,255,255,.12); color: var(--text); }
.dirty-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--warn); flex: none; }
.tab-add {
  width: 26px; height: 26px; margin-bottom: 2px; border-radius: 6px; border: 1px dashed var(--line-strong);
  background: transparent; color: var(--faint); display: flex; align-items: center; justify-content: center; flex: none;
}
.tab-add:hover { color: var(--accent); border-color: var(--accent); }

#scroller {
  flex: 1; min-height: 0; overflow: auto; position: relative;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(124,147,255,.055), transparent 60%),
    radial-gradient(900px 500px at 100% 110%, rgba(167,139,250,.04), transparent 60%),
    var(--bg);
}
#scroller::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background-image: radial-gradient(rgba(255,255,255,.055) 1px, transparent 1px);
  background-size: 22px 22px;
  mask-image: radial-gradient(ellipse at center, rgba(0,0,0,.5), transparent 75%);
}
.viewer {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; gap: 30px;
  padding: 34px 40px 120px; min-height: 100%;
}
.viewer.layout-single { justify-content: flex-start; }
.page-slot { position: relative; flex: none; transition: outline-color .15s; }
.page-surface {
  position: relative; background: #fff; overflow: hidden;
  box-shadow: var(--paper-shadow); border-radius: 1px;
  outline: 1px solid rgba(255,255,255,.04);
  transition: outline-color .15s, box-shadow .15s;
}
.page-surface::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.05);
}
.page-slot.selected .page-surface { outline: 2px solid var(--accent); outline-offset: 3px; }
.page-slot.clicked .page-surface { box-shadow: 0 0 0 6px var(--accent-soft), var(--paper-shadow); }
.canvas-wrap { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: #fff; }
.canvas-wrap canvas { display: block; width: 100%; height: 100%; }
.page-slot.needs-render .canvas-wrap { background: linear-gradient(100deg, #f4f5f7 20%, #fff 40%, #f4f5f7 60%); background-size: 200% 100%; animation: shimmer 1.5s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.page-slot.pulse .page-surface { animation: pulseRing .8s ease; }
@keyframes pulseRing { 0% { outline-color: var(--accent); } 100% { outline-color: var(--accent); } }

.page-badge {
  position: absolute; left: -34px; top: 2px; font-size: 10px; color: var(--faint);
  font-family: var(--mono); user-select: none; pointer-events: none;
}
.page-slot.selected .page-badge { color: var(--accent); }
.page-hints, .page-annots, .page-tool-layer { position: absolute; inset: 0; }
.page-hints { pointer-events: none; z-index: 3; }
.page-annots { pointer-events: none; z-index: 4; }
.page-tool-layer { pointer-events: none; z-index: 5; }
body.tool-active .page-tool-layer { pointer-events: auto; }
body[data-tool="text"] .page-tool-layer { cursor: text; }
body[data-tool="image"] .page-tool-layer { cursor: copy; }
body[data-tool="highlight"] .page-tool-layer { cursor: crosshair; }
body[data-tool="ink"] .page-tool-layer { cursor: crosshair; }
body[data-tool="comment"] .page-tool-layer { cursor: pointer; }
body[data-tool="link"] .page-tool-layer { cursor: crosshair; }
body[data-tool="stamp"] .page-tool-layer { cursor: copy; }
body[data-tool="signature"] .page-tool-layer { cursor: crosshair; }
body.tool-active .page-surface { user-select: none; }
body.pan-ready #scroller { cursor: grab; }
#scroller.panning { cursor: grabbing; }
#scroller.panning .page-surface { pointer-events: none; }

.draft-box {
  position: absolute; border: 1.5px dashed var(--accent);
  background: var(--accent-soft); border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.15);
  pointer-events: none;
}
.draft-box.stamp { border-style: solid; }
.draft-other { position: absolute; inset: 0; pointer-events: none; }
.find-hit {
  position: absolute; background: rgba(255, 212, 64, .38); border-radius: 1px;
  mix-blend-mode: multiply; box-shadow: inset 0 0 0 1px rgba(214, 160, 0, .38);
}
.find-hit.active { background: rgba(255, 170, 0, .55); box-shadow: 0 0 0 2px rgba(255,150,0,.45); }
.ann-pin {
  position: absolute; width: 22px; height: 22px; border-radius: 50% 50% 50% 4px;
  background: var(--accent); color: var(--accent-ink); transform: translate(-4px, -100%);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 12px rgba(0,0,0,.35);
  pointer-events: auto; cursor: pointer; font-size: 10px; font-weight: 800;
}
.spread-row { display: flex; align-items: flex-start; gap: 20px; }
.spread-row .page-slot { margin: 0; }

.header-link-map { display: none; }

/* Tool hint */
.tool-hint {
  position: absolute; left: 50%; bottom: 16px; transform: translate(-50%, 8px);
  background: rgba(12, 15, 21, .92); border: 1px solid var(--line-strong);
  color: var(--text-soft); font-size: 11.5px; padding: 6px 12px; border-radius: 999px;
  box-shadow: 0 8px 30px rgba(0,0,0,.4); backdrop-filter: blur(8px);
  opacity: 0; pointer-events: none; transition: .18s; z-index: 12; white-space: nowrap;
}
.tool-hint.on { opacity: 1; transform: translate(-50%, 0); }

/* ==========================================================================
   Empty state
   ========================================================================== */
#viewer:empty { min-height: 0; padding: 0; }
body:not(.no-doc) #empty-state { display: none; }
body.no-doc #scroller { overflow: auto; }
#empty-state {
  position: relative; z-index: 2; display: none;
  padding: 40px 40px 30px; min-height: 100%;
}
body.no-doc #empty-state { display: block; }
.empty-hero { max-width: 760px; margin: 6vh auto 30px; text-align: center; }
.hero-mark { color: var(--accent); display: flex; justify-content: center; margin-bottom: 18px; filter: drop-shadow(0 8px 30px var(--accent-glow)); }
.hero-copy h1 {
  font-family: var(--font-display); font-size: 30px; line-height: 1.15; letter-spacing: -.02em;
  margin: 0 0 10px; font-weight: 600; color: var(--text);
}
.hero-copy h1 em { font-style: normal; color: var(--accent); }
.hero-copy p { margin: 0 auto 22px; max-width: 520px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.hero-actions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.dropzone {
  margin: 26px auto 0; max-width: 520px; display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px dashed var(--line-strong); border-radius: 9px; padding: 12px 16px;
  color: var(--faint); font-size: 11.5px; transition: .15s;
}
body.dragging-file .dropzone, body.dragging-file #scroller { border-color: var(--accent); color: var(--accent); }
.dropzone svg { color: var(--accent); opacity: .7; }
.empty-grid {
  max-width: 950px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr 1.15fr; gap: 12px;
}
.empty-card {
  background: linear-gradient(180deg, rgba(255,255,255,.028), rgba(255,255,255,.012));
  border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-height: 150px;
  display: flex; flex-direction: column;
}
.card-kicker { font-size: 9.5px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); margin-bottom: 9px; }
.empty-card h3 { font-size: 13px; margin: 0 0 6px; color: var(--text); font-weight: 600; letter-spacing: -.005em; }
.empty-card p { margin: 0 0 14px; font-size: 11.5px; line-height: 1.55; color: var(--muted); }
.text-btn {
  margin-top: auto; align-self: flex-start; background: none; border: 0; padding: 0;
  color: var(--text-soft); font-size: 11.5px; font-weight: 600; display: flex; align-items: center; gap: 5px;
}
.text-btn:hover { color: var(--accent); }
.recent-list { display: flex; flex-direction: column; gap: 2px; }
.recent-item {
  display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 6px; border: 0;
  background: transparent; text-align: left; color: var(--text-soft); width: 100%;
}
.recent-item:hover { background: rgba(255,255,255,.05); }
.recent-ic { color: var(--faint); display: flex; }
.recent-name { flex: 1; min-width: 0; font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-meta { font-size: 9.5px; color: var(--faint); font-family: var(--mono); }
.recent-empty { font-size: 11.5px; color: var(--faint); padding: 10px 8px; }
.empty-foot {
  max-width: 950px; margin: 22px auto 0; display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
  justify-content: center; color: var(--faint); font-size: 10.5px;
}
.empty-foot span { display: flex; align-items: center; gap: 4px; }
.offline-badge { margin-left: auto; color: var(--faint); }
.offline-badge i { width: 6px; height: 6px; background: var(--ok); border-radius: 50%; box-shadow: 0 0 6px var(--ok); display: inline-block; }

/* ==========================================================================
   Inspector
   ========================================================================== */
#inspector {
  width: 302px; flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-left: 1px solid var(--line);
}
body:not(.right-open) #inspector { display: none; }
.inspector-head {
  height: 52px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px 0 16px; border-bottom: 1px solid var(--line);
}
.inspector-title { font-size: 12px; font-weight: 650; color: var(--text); }
.inspector-sub { font-size: 10.5px; color: var(--faint); margin-top: 2px; max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inspector-body { flex: 1; overflow-y: auto; padding: 14px 14px 30px; }
#inspector.empty .inspector-body { display: none; }

.insp-section { margin-bottom: 18px; }
.insp-section + .insp-section { border-top: 1px solid var(--line); padding-top: 15px; }
.insp-label { font-size: 9.5px; letter-spacing: .13em; text-transform: uppercase; color: var(--faint); font-weight: 700; margin-bottom: 8px; }
.insp-row { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; font-size: 11.5px; }
.insp-k { color: var(--muted); }
.insp-v { color: var(--text-soft); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 62%; }
.insp-v.mono { font-family: var(--mono); font-size: 10.5px; }
.insp-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.insp-btn {
  height: 26px; padding: 0 9px; display: inline-flex; align-items: center; gap: 5px;
  border-radius: 5px; border: 1px solid var(--line); background: rgba(255,255,255,.03);
  color: var(--text-soft); font-size: 10.5px; font-weight: 600;
}
.insp-btn:hover { background: rgba(255,255,255,.07); color: var(--text); border-color: var(--line-strong); }
.insp-note { font-size: 10.5px; line-height: 1.55; color: var(--faint); font-style: italic; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px; border-radius: 4px;
  font-size: 9.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  background: rgba(255,255,255,.06); color: var(--muted); border: 1px solid var(--line);
}
.badge.ok { color: var(--ok); border-color: rgba(75,214,162,.3); background: rgba(75,214,162,.08); }
.badge.warn { color: var(--warn); border-color: rgba(240,180,94,.3); background: rgba(240,180,94,.08); }
.badge.err { color: var(--err); border-color: rgba(255,111,111,.3); background: rgba(255,111,111,.08); }
.badge.accent { color: var(--accent); border-color: rgba(124,147,255,.32); background: var(--accent-soft); }

/* ==========================================================================
   Status bar
   ========================================================================== */
#statusbar {
  height: var(--status-h); flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; background: var(--bg-deep); border-top: 1px solid var(--line);
  font-size: 10.5px; color: var(--muted); user-select: none;
}
.status-left, .status-right { display: flex; align-items: center; gap: 9px; min-width: 0; }
.status-item { white-space: nowrap; }
.status-dot { width: 3px; height: 3px; border-radius: 50%; background: var(--faint); }
.status-message { color: var(--accent); margin-left: 4px; overflow: hidden; text-overflow: ellipsis; }
.selection-status { color: var(--accent); font-weight: 600; }
.selection-status:empty { display: none; }
.status-right .status-item.local { display: flex; align-items: center; gap: 4px; color: var(--faint); }
.status-right .status-item.local svg { color: var(--ok); }

/* ==========================================================================
   Busy bar
   ========================================================================== */
#busybar {
  position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 300;
  pointer-events: none; opacity: 0; transition: opacity .2s;
}
#busybar.on { opacity: 1; }
.busy-track { height: 100%; background: rgba(124,147,255,.15); overflow: hidden; }
.busy-fill {
  height: 100%; width: 35%; border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent-2), transparent);
  animation: busySlide 1.1s ease-in-out infinite;
}
@keyframes busySlide { 0% { transform: translateX(-100%); } 100% { transform: translateX(320%); } }
.busy-label {
  position: fixed; top: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(12,15,21,.94); border: 1px solid var(--line-strong); border-radius: 999px;
  padding: 5px 12px; font-size: 10.5px; color: var(--text-soft); box-shadow: 0 8px 24px rgba(0,0,0,.4);
  opacity: 0; transition: .2s;
}
#busybar.on .busy-label { opacity: 1; }

/* ==========================================================================
   Menus
   ========================================================================== */
.menu {
  position: fixed; z-index: 400; min-width: 218px; padding: 5px;
  background: var(--elev-1); border: 1px solid rgba(255,255,255,.13); border-radius: 9px;
  box-shadow: 0 18px 50px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.4);
  animation: menuIn .1s ease;
}
:root[data-theme="light"] .menu { background: #fff; }
:root[data-theme="light"] .tool-strip,
:root[data-theme="light"] .layouts { background: rgba(15, 23, 42, .05); }
:root[data-theme="light"] .icon-btn:hover,
:root[data-theme="light"] .tool-btn:hover,
:root[data-theme="light"] .page-indicator:hover,
:root[data-theme="light"] .zoom-label:hover { background: rgba(15, 23, 42, .06); }
:root[data-theme="light"] .toast-close:hover { background: rgba(15, 23, 42, .07); }
:root[data-theme="light"] kbd { background: rgba(15, 23, 42, .05); }
@keyframes menuIn { from { opacity: 0; transform: translateY(-3px) scale(.99); } }
.menu-item {
  width: 100%; display: flex; align-items: center; gap: 8px; height: 28px;
  padding: 0 8px; border: 0; background: transparent; border-radius: 5px;
  color: var(--text-soft); font-size: 11.5px; text-align: left;
}
.menu-item:hover { background: var(--accent-soft); color: var(--text); }
.menu-item.danger { color: #ff9d9d; }
.menu-item.danger:hover { background: rgba(255,111,111,.12); }
.menu-item.disabled { opacity: .35; pointer-events: none; }
.menu-ic { width: 17px; display: flex; color: var(--muted); }
.menu-item:hover .menu-ic { color: var(--accent); }
.menu-label { flex: 1; }
.menu-shortcut { font-family: var(--mono); font-size: 9.5px; color: var(--faint); }
.menu-check { color: var(--accent); display: flex; }
.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }
.menu-heading { font-size: 9px; letter-spacing: .12em; text-transform: uppercase; color: var(--faint); padding: 6px 8px 3px; font-weight: 700; }

/* ==========================================================================
   Dialogs
   ========================================================================== */
#dialog-layer { position: relative; z-index: 500; }
.dialog-backdrop {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(4, 6, 10, .62); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  opacity: 0; transition: opacity .15s; padding: 24px; z-index: 500;
}
.dialog-backdrop.in { opacity: 1; }
.dialog-backdrop.closing { opacity: 0; }
.dialog {
  background: var(--elev-2); border: 1px solid rgba(255,255,255,.12); border-radius: var(--radius-lg);
  box-shadow: 0 30px 90px rgba(0,0,0,.62), 0 2px 10px rgba(0,0,0,.4);
  max-width: calc(100vw - 40px); max-height: calc(100vh - 60px);
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateY(8px) scale(.985); opacity: 0;
  transition: transform .18s cubic-bezier(.2,.9,.3,1), opacity .15s;
}
.dialog-backdrop.in .dialog { transform: none; opacity: 1; }
.dialog-head { display: flex; align-items: flex-start; gap: 10px; padding: 18px 16px 0 18px; }
.dialog-icon {
  width: 32px; height: 32px; border-radius: 8px; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; flex: none;
}
.dialog-titles { flex: 1; min-width: 0; }
.dialog-title { font-family: var(--font-display); font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.dialog-sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; line-height: 1.45; }
.dialog-x { margin: -4px -4px 0 0; flex: none; }
.dialog-body { padding: 16px 18px 6px; overflow-y: auto; min-height: 0; }
.dialog-body p { margin: 0 0 10px; line-height: 1.55; font-size: 12.5px; color: var(--text-soft); }
.dialog-text { color: var(--text-soft); }
.dialog-intro { font-size: 12px; color: var(--muted); line-height: 1.55; margin-bottom: 14px; }
.dialog-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 7px;
  padding: 12px 18px 16px; flex-wrap: wrap;
}
.dialog-error {
  flex: 1; min-width: 120px; font-size: 11px; color: var(--err); display: none;
}
.dialog-error.on { display: block; }
.dialog-backdrop.closing .dialog { transform: translateY(5px) scale(.99); opacity: 0; }
body.modal-open { overflow: hidden; }

.form-grid { display: flex; flex-direction: column; gap: 12px; }
.form-grid.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid.cols-2 .field-wide { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 10.5px; font-weight: 600; letter-spacing: .02em; color: var(--muted); }
.field-hint { font-size: 10.5px; color: var(--faint); line-height: 1.45; }
.input {
  height: 34px; padding: 0 10px; border-radius: 6px;
  background: var(--bg-deep); border: 1px solid var(--line-strong); color: var(--text);
  font-size: 12.5px; width: 100%; transition: border-color .12s, box-shadow .12s;
}
:root[data-theme="light"] .input { background: #fff; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { height: auto; min-height: 90px; padding: 9px 10px; resize: vertical; line-height: 1.5; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 14px) 14px, calc(100% - 9px) 14px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
input[type="color"] { width: 42px; height: 34px; padding: 3px; border-radius: 6px; border: 1px solid var(--line-strong); background: var(--bg-deep); }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row .input { flex: 1; font-family: var(--mono); font-size: 11px; text-transform: uppercase; }
.range-row { display: flex; align-items: center; gap: 10px; height: 34px; }
.range-row input[type=range] { flex: 1; accent-color: var(--accent); }
.range-row output { min-width: 44px; text-align: right; font-family: var(--mono); font-size: 11px; color: var(--text-soft); }
.check-row { display: flex; align-items: flex-start; gap: 8px; font-size: 12px; color: var(--text-soft); cursor: pointer; padding: 2px 0; }
.check-row input { accent-color: var(--accent); margin-top: 2px; }
.file-input { height: auto; padding: 7px 8px; font-size: 11px; }
.pill-row { display: flex; gap: 5px; flex-wrap: wrap; }
.pill {
  height: 27px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-size: 11px; font-weight: 600;
}
.pill:hover { color: var(--text); border-color: var(--line-strong); }
.pill.on { background: var(--accent-soft); border-color: rgba(124,147,255,.4); color: var(--accent); }

/* ==========================================================================
   Toast
   ========================================================================== */
#toasts {
  position: fixed; right: 16px; bottom: 42px; z-index: 600;
  display: flex; flex-direction: column; gap: 7px; align-items: flex-end; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 9px; min-height: 38px; max-width: 420px;
  padding: 8px 9px 8px 12px; border-radius: 9px;
  background: rgba(20, 24, 33, .96); border: 1px solid var(--line-strong);
  color: var(--text-soft); font-size: 11.5px; box-shadow: 0 12px 40px rgba(0,0,0,.5);
  pointer-events: auto; animation: toastIn .2s cubic-bezier(.2,.9,.3,1);
  backdrop-filter: blur(10px);
}
:root[data-theme="light"] .toast { background: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.toast.out { opacity: 0; transform: translateY(5px); transition: .2s; }
.toast-icon { display: flex; }
.toast-success .toast-icon { color: var(--ok); }
.toast-error .toast-icon { color: var(--err); }
.toast-warn .toast-icon { color: var(--warn); }
.toast-info .toast-icon { color: var(--accent); }
.toast-text { flex: 1; line-height: 1.4; }
.toast-close { background: none; border: 0; color: var(--faint); width: 20px; height: 20px; border-radius: 4px; display: flex; align-items: center; justify-content: center; }
.toast-close:hover { background: rgba(255,255,255,.08); color: var(--text); }

/* ==========================================================================
   Command palette
   ========================================================================== */
.palette-backdrop {
  position: fixed; inset: 0; z-index: 450; background: rgba(4,6,10,.5); backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center; padding-top: 14vh;
  animation: fadeIn .12s;
}
@keyframes fadeIn { from { opacity: 0; } }
.palette-backdrop.closing { opacity: 0; transition: opacity .12s; }
.palette {
  width: min(640px, calc(100vw - 40px)); background: var(--elev-1);
  border: 1px solid rgba(255,255,255,.14); border-radius: 12px;
  box-shadow: 0 40px 100px rgba(0,0,0,.65);
  overflow: hidden; animation: paletteIn .16s cubic-bezier(.2,.9,.3,1);
}
:root[data-theme="light"] .palette { background: #fff; }
@keyframes paletteIn { from { transform: translateY(-8px) scale(.99); opacity: .4; } }
.palette-search { display: flex; align-items: center; gap: 10px; padding: 13px 14px; border-bottom: 1px solid var(--line); color: var(--muted); }
.palette-input { flex: 1; background: none; border: 0; outline: none; font-size: 14px; color: var(--text); }
.palette-input::placeholder { color: var(--faint); }
.palette-list { max-height: 340px; overflow-y: auto; padding: 6px; }
.palette-item {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border: 0; border-radius: 6px; background: transparent; color: var(--text-soft); text-align: left;
}
.palette-item.sel { background: var(--accent-soft); color: var(--text); }
.palette-ic { width: 20px; display: flex; color: var(--muted); }
.palette-item.sel .palette-ic { color: var(--accent); }
.palette-label { flex: 1; font-size: 12.5px; }
.palette-hint { font-size: 10px; color: var(--faint); }
.palette-key { font-family: var(--mono); font-size: 9.5px; color: var(--faint); background: rgba(255,255,255,.05); border: 1px solid var(--line); padding: 2px 5px; border-radius: 4px; }
.palette-empty { padding: 24px; text-align: center; color: var(--faint); font-size: 12px; }
.palette-foot { display: flex; align-items: center; gap: 16px; padding: 8px 14px; border-top: 1px solid var(--line); color: var(--faint); font-size: 10px; }
.palette-foot span { display: flex; align-items: center; gap: 4px; }
.palette-foot span:last-child { margin-left: auto; }

/* ==========================================================================
   Generic panel widgets used by features
   ========================================================================== */
.section-title { font-size: 9.5px; letter-spacing: .13em; text-transform: uppercase; color: var(--faint); font-weight: 700; margin: 14px 2px 7px; }
.section-title:first-child { margin-top: 2px; }
.field-row { display: flex; gap: 6px; align-items: center; }
.field-row .input { flex: 1; }
.list-row {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 6px;
  border: 1px solid transparent; color: var(--text-soft); font-size: 11.5px; width: 100%;
  background: transparent; text-align: left;
}
.list-row:hover { background: rgba(255,255,255,.045); }
.list-row.sel { background: var(--accent-soft); border-color: rgba(124,147,255,.25); }
.row-main { flex: 1; min-width: 0; }
.row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 9.5px; color: var(--faint); margin-top: 2px; }
.icon-mini { width: 24px; height: 24px; border-radius: 5px; border: 0; background: transparent; color: var(--faint); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.icon-mini:hover { background: rgba(255,255,255,.08); color: var(--text); }
.panel-note { padding: 9px 10px; border-radius: 7px; background: rgba(124,147,255,.06); border: 1px solid rgba(124,147,255,.14); font-size: 10.5px; line-height: 1.5; color: var(--muted); margin: 8px 2px; }
.panel-note.warn { background: rgba(240,180,94,.06); border-color: rgba(240,180,94,.2); }
.panel-note.error { background: rgba(255,111,111,.06); border-color: rgba(255,111,111,.2); }
.tag { font-size: 9px; padding: 1px 5px; border-radius: 4px; background: rgba(255,255,255,.07); color: var(--muted); font-weight: 600; letter-spacing: .03em; }
.tag.ok { background: rgba(75,214,162,.1); color: var(--ok); }
.tag.warn { background: rgba(240,180,94,.1); color: var(--warn); }
.tag.err { background: rgba(255,111,111,.1); color: var(--err); }
.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.stat-box { background: rgba(255,255,255,.03); border: 1px solid var(--line); border-radius: 7px; padding: 8px 9px; }
.stat-k { font-size: 8.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); font-weight: 700; }
.stat-v { font-size: 14px; font-weight: 650; color: var(--text); margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat-v small { font-size: 9px; color: var(--faint); font-weight: 500; }

/* ==========================================================================
   Print
   ========================================================================== */
@media print {
  body > * { display: none !important; }
  #print-root { display: block !important; }
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1700px) {
  .palette-btn kbd { display: none; }
}
@media (max-width: 1320px) {
  .brand-tag { display: none; }
  #inspector { width: 278px; }
  .tb-group .btn-label { display: none; }
  .btn.btn-tall { padding: 0 9px; }
}
@media (max-width: 1160px) {
  #sidebar { width: 238px; }
  #rail { width: 54px; }
  .tool-btn { width: 29px; }
  .empty-grid { grid-template-columns: 1fr 1fr; }
  .recent-card { grid-column: 1 / -1; }
}
@media (max-width: 980px) {
  #inspector { display: none; }
  .tool-strip .tool-btn:nth-child(n+7) { display: none; }
  .tb-group.zoom .icon-btn.tight { display: none; }
}
@media (max-width: 800px) {
  #sidebar { display: none; }
  #rail { display: none; }
}
/* File drop affordance */
body.dragging-file::after {
  content: 'Drop to open in Folio';
  position: fixed; inset: 10px; z-index: 900; pointer-events: none;
  border: 2px dashed var(--accent); border-radius: 16px;
  background: rgba(10, 12, 16, .78);
  color: var(--accent); font-family: var(--font-display); font-size: 18px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(6px); box-shadow: inset 0 0 80px var(--accent-soft);
}
