/* JAPT – UI in the style of PDFCraft. All colours and sizes as variables (light/dark). */

:root {
  --font: Inter, "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --radius: 8px;
  --radius-lg: 12px;
  --tabbar-h: 44px;
  --modebar-h: 52px;
  --left-w: 300px;
  --right-w: 340px;
  --rail-w: 48px;
  --focus: 0 0 0 2px var(--bg-surface), 0 0 0 4px var(--accent);
}

:root, [data-theme="light"] {
  color-scheme: light;
  --bg-chrome: #ebebee;
  --bg-surface: #ffffff;
  --bg-canvas: #f0f0f2;
  --bg-hover: #f1f1f4;
  --bg-active: #e6e6ea;
  --bg-input: #ffffff;
  --border: #e1e1e5;
  --border-strong: #c9c9cf;
  --text: #1c1c1f;
  --text-muted: #63636b;
  --accent: #2f62d8;
  --accent-text: #ffffff;
  --accent-soft: #e5edfc;
  --banner: #e3ecfb;
  --danger: #c4262e;
  --success: #23824b;
  --warn-bg: #fff4e0;
  --warn-text: #7a4b00;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .06);
  --shadow-page: 0 1px 3px rgb(0 0 0 / .12), 0 2px 10px rgb(0 0 0 / .08);
  --hl: rgb(255 214 0 / .45);
  --hl-sel: rgb(255 140 0 / .6);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg-chrome: #18181b;
  --bg-surface: #222226;
  --bg-canvas: #141416;
  --bg-hover: #2c2c31;
  --bg-active: #34343a;
  --bg-input: #1b1b1e;
  --border: #33333a;
  --border-strong: #46464e;
  --text: #ececf0;
  --text-muted: #a2a2ab;
  --accent: #6f98ff;
  --accent-text: #0d1220;
  --accent-soft: #24324f;
  --banner: #1f2a42;
  --danger: #ff6b6b;
  --success: #4cc784;
  --warn-bg: #3a2c12;
  --warn-text: #ffcf7a;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 6px 20px rgb(0 0 0 / .35);
  --shadow-page: 0 1px 3px rgb(0 0 0 / .5), 0 2px 12px rgb(0 0 0 / .4);
  --hl: rgb(255 214 0 / .35);
  --hl-sel: rgb(255 140 0 / .55);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg-chrome);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--focus); }
.spacer { flex: 1; }
.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }
.error-text { color: var(--danger); }
.skip-link { position: absolute; left: -999px; top: 4px; z-index: 100; background: var(--bg-surface); padding: 6px 10px; border-radius: 6px; }
.skip-link:focus { left: 8px; }
.icon { display: inline-flex; flex: none; }
.icon svg { display: block; }
kbd { font: 11px/1 var(--font); color: var(--text-muted); border: 1px solid var(--border); border-radius: 4px; padding: 3px 5px; background: var(--bg-surface); }

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---------- Tab bar ---------- */
.brand { display: flex; align-items: center; flex: none; padding: 0 10px 0 6px; user-select: none; }
.brand img { display: block; height: 20px; width: auto; }
.brand-dark, .brand-mark { display: none !important; }
[data-theme="dark"] .brand-light { display: none !important; }
[data-theme="dark"] .brand-dark { display: block !important; }
.tabbar {
  height: var(--tabbar-h); flex: none; display: flex; align-items: center; gap: 4px;
  padding: 0 8px; background: var(--bg-chrome); user-select: none;
}
.tabs { display: flex; align-items: center; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none; height: 100%; padding-top: 6px; }
.tab {
  display: flex; align-items: center; gap: 8px; height: 100%; max-width: 240px; min-width: 120px;
  padding: 0 6px 0 12px; border-radius: 10px 10px 0 0; cursor: pointer; color: var(--text-muted);
  position: relative;
}
.tab:hover { background: var(--bg-hover); }
.tab.active { background: var(--bg-surface); color: var(--text); }
.tab .tab-icon { color: var(--accent); }
.tab-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dirty-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.tab-close { width: 24px; height: 24px; }
.tab-open { display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; margin-left: 4px; }
.tab-open:hover { background: var(--bg-hover); }
.tab-home.active { background: var(--bg-surface); }
.offline-badge { display: inline-flex; align-items: center; gap: 6px; color: var(--success); font-size: 12.5px; padding: 4px 8px; border-radius: 999px; }
.lang-btn { display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 8px; border: 0; border-radius: 8px; background: none; cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.lang-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ---------- Buttons ---------- */
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; flex: none;
  border: 0; border-radius: 8px; background: none; color: var(--text); cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--bg-hover); }
.icon-btn.active, .icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.icon-btn:disabled { opacity: .4; cursor: default; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--bg-surface); cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--bg-hover); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.sm { height: 30px; padding: 0 12px; font-size: 13px; }
.btn.lg { height: 44px; padding: 0 22px; font-size: 15px; }
.btn.block { width: 100%; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 8px 16px; font-weight: 500; text-align: left; }

/* ---------- Mode bar ---------- */
.modebar {
  height: var(--modebar-h); flex: none; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; background: var(--bg-surface); border-bottom: 1px solid var(--border);
}
.menu-btn { display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; font-size: 15px; }
.menu-btn:hover { background: var(--bg-hover); }
.modes { display: flex; gap: 2px; margin-left: 12px; height: 100%; }
.mode {
  border: 0; background: none; padding: 0 12px; font-size: 15px; color: var(--text-muted); cursor: pointer;
  position: relative; height: 100%;
}
.mode:hover { color: var(--text); }
.mode.active { color: var(--text); font-weight: 600; }
.mode.active::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 0; height: 2px; border-radius: 2px; background: var(--text); }
.cmd {
  position: relative; display: flex; align-items: center; gap: 8px; width: min(300px, 32vw); height: 36px;
  padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--bg-input); color: var(--text-muted);
}
.cmd:focus-within { border-color: var(--accent); }
.cmd-input { flex: 1; min-width: 0; border: 0; background: none; outline: none; color: var(--text); }
.cmd-input::-webkit-search-cancel-button { display: none; }
.cmd-list {
  position: absolute; top: calc(100% + 6px); right: 0; width: 360px; max-height: 60vh; overflow: auto; z-index: 40;
  list-style: none; margin: 0; padding: 6px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
.cmd-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--text); }
.cmd-item span:not(.icon) { flex: 1; }
.cmd-item.selected, .cmd-item:hover { background: var(--bg-hover); }
.cmd-empty { padding: 10px; color: var(--text-muted); }
.mode-actions { display: flex; gap: 2px; }

/* ---------- Main area ---------- */
.main { flex: 1; min-height: 0; display: flex; background: var(--bg-canvas); }
.left-panel, .right-panel {
  flex: none; display: flex; flex-direction: column; min-height: 0; background: var(--bg-surface);
}
.left-panel { width: var(--left-w); border-right: 1px solid var(--border); overflow: auto; }
.right-panel { width: var(--right-w); border-left: 1px solid var(--border); }
.rail {
  width: var(--rail-w); flex: none; display: flex; flex-direction: column; justify-content: space-between; align-items: center;
  padding: 8px 0; background: var(--bg-surface); border-left: 1px solid var(--border);
}
.rail-top, .rail-bottom { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.page-input { width: 38px; height: 30px; text-align: center; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--bg-input); }
.page-count { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.zoom-label { border: 0; background: none; font-size: 11.5px; color: var(--text-muted); padding: 4px 2px; cursor: pointer; border-radius: 6px; }
.zoom-label:hover { background: var(--bg-hover); color: var(--text); }

.panel-head { display: flex; align-items: center; gap: 6px; padding: 14px 12px 10px 16px; flex: none; }
.panel-head h2 { flex: 1; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.panel-body { flex: 1; min-height: 0; overflow: auto; padding: 4px 16px 20px; }

/* Tool list */
.tool-list { list-style: none; margin: 0; padding: 0 8px; }
.tool-row {
  width: 100%; display: flex; align-items: center; gap: 14px; padding: 10px 8px; border: 0; background: none;
  border-radius: 8px; cursor: pointer; font-size: 15px; text-align: left;
}
.tool-row:hover { background: var(--bg-hover); }
.tool-row span:not(.icon) { flex: 1; }
.tool-row.planned { color: var(--text-muted); }
.tool-icon { color: var(--hue, var(--accent)); }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--bg-active); color: var(--text-muted); font-weight: 500; }

/* Tool panel */
.tool-panel { display: flex; flex-direction: column; min-height: 100%; }
.tool-panel .panel-head { padding-left: 8px; }
.tool-panel .panel-body { display: flex; flex-direction: column; gap: 14px; }
.tool-panel h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-top: 6px; }
.tool-panel p { margin: 0; }
.tool-panel hr { border: 0; border-top: 1px solid var(--border); width: 100%; margin: 2px 0; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.row > .field { flex: 1; }
.field > label { font-weight: 500; font-size: 13px; }
.hint { color: var(--text-muted); font-size: 12px; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row.between { justify-content: space-between; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.input {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--bg-input); min-width: 0;
}
.input:focus { border-color: var(--accent); outline: none; }
textarea.input { height: auto; padding: 8px 10px; resize: vertical; }
.input.color { padding: 3px; height: 36px; cursor: pointer; }
.input.preview { font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input, .radio input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; flex: none; }
.radio-group { display: flex; flex-direction: column; gap: 6px; }
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.radio input { margin-top: 2px; }
.radio:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio span { display: flex; flex-direction: column; gap: 2px; }
.radio small { color: var(--text-muted); }
.slider-row { display: flex; align-items: center; gap: 10px; }
.slider { flex: 1; accent-color: var(--accent); }
.slider-row output { min-width: 56px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text-muted); }
.note { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius); background: var(--bg-hover); font-size: 13px; color: var(--text-muted); }
.note .icon { margin-top: 1px; }
.note.warn { background: var(--warn-bg); color: var(--warn-text); }
.note.info .icon { color: var(--accent); }
.result:empty { display: none; }

/* Right panel */
.thumbs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 12px; padding-top: 4px; }
.thumb { display: flex; flex-direction: column; align-items: center; gap: 6px; border: 0; background: none; cursor: pointer; padding: 6px; border-radius: 8px; color: var(--text-muted); font-size: 12px; }
.thumb:hover { background: var(--bg-hover); }
.thumb-img { width: 100%; aspect-ratio: 1 / 1.3; display: grid; place-items: center; }
.thumb-img canvas { max-width: 100%; max-height: 100%; box-shadow: var(--shadow-page); background: #fff; }
.thumb.current { color: var(--accent); font-weight: 600; }
.thumb.current canvas { outline: 2px solid var(--accent); outline-offset: 2px; }
.outline { list-style: none; margin: 0; padding: 0 0 0 12px; }
.panel-body > .outline { padding-left: 0; }
.outline-item { border: 0; background: none; padding: 6px 8px; border-radius: 6px; cursor: pointer; text-align: left; width: 100%; }
.outline-item:hover { background: var(--bg-hover); }
.attachment { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; padding: 8px; border-radius: 8px; cursor: pointer; text-align: left; }
.attachment span:not(.icon) { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.attachment:hover { background: var(--bg-hover); }
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 4px 0 18px; font-size: 13px; }
.info-list dt { color: var(--text-muted); }
.info-list dd { margin: 0; word-break: break-word; }

/* ---------- Centre & viewer ---------- */
.center { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.banner-host:empty { display: none; }
.banner { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 16px; background: var(--banner); color: var(--text); flex: none; }
.banner .icon { color: var(--accent); }
.viewer-host { flex: 1; min-height: 0; position: relative; }
.viewer-scroll { position: absolute; inset: 0; overflow: auto; outline: none; }
.viewer-scroll:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.page-column { display: flex; flex-direction: column; align-items: safe center; padding: 20px 24px 40px 76px; width: 100%; }
.pdfViewer.page-column .page {
  margin: 0 0 16px; border: 0; box-shadow: var(--shadow-page); background: #fff; flex: none;
}
.page-loading { position: absolute; inset: 0; background: #fff; }
.pdfViewer .canvasWrapper { position: absolute; inset: 0; }
.viewer-scroll.hand-mode { cursor: grab; }
.viewer-scroll.hand-mode .textLayer { pointer-events: none; }
.viewer-scroll.dragging { cursor: grabbing; user-select: none; }
.textLayer mark.hl { background: var(--hl); color: transparent; border-radius: 2px; padding: 0; margin: 0; }
.textLayer mark.hl.selected { background: var(--hl-sel); }
.textLayer { z-index: 1; }
.annotationLayer { z-index: 2; }
.highlight-fields .annotationLayer :is(input, textarea, select, .buttonWidgetAnnotation.checkBox input) {
  background-color: rgb(47 98 216 / .18) !important; outline: 1px solid rgb(47 98 216 / .7);
}
.floatbar {
  position: absolute; left: 14px; top: 16px; z-index: 5; display: flex; flex-direction: column; gap: 4px; padding: 5px;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.searchbar {
  position: absolute; right: 18px; top: 12px; z-index: 6; display: flex; align-items: center; gap: 6px;
  padding: 6px 6px 6px 12px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.searchbar .input { width: 220px; height: 32px; }
.search-count { font-size: 12px; color: var(--text-muted); min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; }

/* Placeable objects */
.overlay-layer { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.overlay-placing .overlay-layer, .overlay-draw .overlay-layer { pointer-events: auto; cursor: crosshair; }
.overlay-draw .textLayer { pointer-events: none; }
.ov-item { position: absolute; pointer-events: auto; cursor: move; outline: 1px dashed transparent; touch-action: none; }
.ov-item:hover, .ov-item.selected, .ov-item:focus-within { outline-color: var(--accent); }
.ov-text { min-width: 2ch; line-height: 1.2; white-space: pre; outline: none; padding: 0; cursor: text; background: rgb(47 98 216 / .06); }
.ov-image img { width: 100%; height: 100%; display: block; pointer-events: none; }
.ov-check { color: #000; }
.ov-rect { background: rgb(0 0 0 / .72); outline: 1px solid rgb(255 255 255 / .6); }
.ov-rect.selected { outline: 2px solid var(--accent); }
.ov-del {
  position: absolute; top: -12px; right: -12px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--bg-surface); box-shadow: var(--shadow); display: none; color: var(--text);
}
.ov-item:hover .ov-del, .ov-item.selected .ov-del { display: grid; }
.ov-handle { position: absolute; right: -5px; bottom: -5px; width: 10px; height: 10px; border-radius: 2px; background: var(--accent); cursor: nwse-resize; display: none; }
.ov-item.selected .ov-handle, .ov-item:hover .ov-handle { display: block; }
.place-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.place-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-surface); cursor: pointer; font-size: 13px;
}
.place-btn:hover { background: var(--bg-hover); }
.place-btn.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.sig-slot { display: flex; flex-direction: column; gap: 8px; }
.sig-slot .place-btn { flex-direction: row; justify-content: center; }
.sig-preview { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.sig-preview img { flex: 1; min-width: 0; max-height: 60px; object-fit: contain; }
.sig-preview .icon-btn { color: #333; }

/* ---------- Home ---------- */
.home { flex: 1; overflow: auto; background: var(--bg-canvas); }
.home-inner { max-width: 1120px; margin: 0 auto; padding: 36px 28px 60px; display: flex; flex-direction: column; gap: 32px; }
.hero-drop {
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; cursor: pointer;
  padding: 44px 24px; border: 2px dashed var(--border-strong); border-radius: 20px; background: var(--bg-surface);
}
.hero-drop:hover { border-color: var(--accent); }
.hero-drop h1 { font-size: 26px; }
.hero-drop p { margin: 0; color: var(--text-muted); }
.hero-icon { width: 72px; height: 72px; display: block; }
.privacy { display: inline-flex; gap: 6px; align-items: center; color: var(--success) !important; font-size: 13px; }
.home-section h2 { font-size: 18px; margin-bottom: 14px; }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.tile {
  display: flex; align-items: center; gap: 14px; padding: 14px; text-align: left; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-surface);
}
.tile:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.tile-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none; color: var(--hue); background: color-mix(in srgb, var(--hue) 13%, transparent); }
.tile-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.tile-text small { color: var(--text-muted); font-size: 12.5px; line-height: 1.35; }
.tile.planned { opacity: .6; }
.recent { display: flex; flex-wrap: wrap; gap: 8px; }
.recent-item { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-surface); cursor: pointer; }
.recent-item small { color: var(--text-muted); }

/* ---------- Workspaces ---------- */
.workspace { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--bg-canvas); }
.workspace-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--bg-surface); border-bottom: 1px solid var(--border); flex: none; flex-wrap: wrap; }
.workspace-head h2 { font-size: 17px; display: flex; align-items: center; gap: 8px; }
.ws-summary { color: var(--text-muted); font-size: 13px; }
.workspace-body { flex: 1; min-height: 0; overflow: auto; padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 16px; }
.ws-intro { margin: 0; }
.ws-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 240px; padding: 24px;
  border: 2px dashed var(--border-strong); border-radius: 16px; background: var(--bg-surface); color: var(--text-muted); cursor: pointer; text-align: center;
}
.ws-drop p { margin: 0; color: var(--text); font-weight: 500; }
.ws-drop.compact { min-height: 0; flex-direction: row; padding: 14px; }
.ws-drop.compact small { display: none; }
.ws-drop:hover { border-color: var(--accent); }
.ws-options { display: flex; gap: 12px; flex-wrap: wrap; padding: 12px 14px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.ws-options .field { min-width: 160px; flex: 0 1 220px; }
.ws-toolbar { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; padding: 6px 8px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); position: sticky; top: -20px; z-index: 3; }
.ws-toolbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 6px; }
.thumb-size { flex: 0 0 120px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.card-grid:empty { display: none; }
.file-card {
  position: relative; display: flex; flex-direction: column; gap: 8px; padding: 12px; background: var(--bg-surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); cursor: grab;
}
.file-card.error { border-color: var(--danger); }
.file-card.dragging, .page-card.dragging { opacity: .4; }
.file-thumb { height: 170px; display: grid; place-items: center; background: var(--bg-canvas); border-radius: 8px; overflow: hidden; color: var(--text-muted); }
.file-thumb canvas, .file-thumb img { max-width: 100%; max-height: 100%; box-shadow: var(--shadow-page); background: #fff; object-fit: contain; }
.file-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.file-meta strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta small { color: var(--text-muted); }
.file-card .input { height: 32px; font-size: 13px; }
.card-actions { display: flex; gap: 2px; justify-content: flex-end; }
.card-actions .icon-btn { width: 28px; height: 28px; }
.card-badge { position: absolute; top: 8px; left: 8px; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 999px; background: var(--hue, var(--accent)); color: #fff; font-size: 12px; font-weight: 600; display: grid; place-items: center; }
.drop-marker { width: 4px; border-radius: 2px; background: var(--accent); align-self: stretch; justify-self: center; min-height: 120px; }
.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--thumb, 160px), 1fr)); gap: 18px; align-items: start; }
.page-grid .drop-marker { width: 4px; }
.page-card { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 8px; border-radius: var(--radius-lg); border: 2px solid transparent; cursor: pointer; user-select: none; }
.page-card:hover { background: var(--bg-hover); }
.page-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.page-thumb { aspect-ratio: 1 / 1.25; display: grid; place-items: center; overflow: hidden; }
.page-thumb .rot { max-width: 100%; max-height: 100%; display: grid; place-items: center; transition: transform .15s; width: 100%; height: 100%; }
.page-thumb img, .blank-page { max-width: 86%; max-height: 86%; box-shadow: var(--shadow-page); background: #fff; min-width: 40px; min-height: 40px; }
.blank-page { width: 70%; }
.page-card-foot { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-muted); }
.page-card-foot > span { flex: 1; text-align: center; padding-left: 60px; }
.src-tag { background: var(--bg-active); border-radius: 4px; padding: 0 5px; }
.page-card .card-actions { opacity: 0; }
.page-card:hover .card-actions, .page-card:focus-within .card-actions, .page-card.selected .card-actions { opacity: 1; }

/* ---------- Dialogs, menus, toasts ---------- */
.modal {
  width: min(460px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 16px;
  background: var(--bg-surface); color: var(--text); box-shadow: var(--shadow);
}
.modal.wide { width: min(680px, calc(100vw - 32px)); }
.modal::backdrop { background: rgb(0 0 0 / .35); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 4px 20px; }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 10px 20px 4px; }
.modal-body p { margin: 0 0 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px 18px; }
.about-head { display: flex; gap: 14px; align-items: center; }
.about-head div { display: flex; flex-direction: column; }
.bullets { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.popup-menu {
  position: fixed; z-index: 50; min-width: 240px; padding: 6px; background: var(--bg-surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; text-align: left; }
.menu-item span:not(.icon) { flex: 1; }
.menu-item:hover, .menu-item:focus-visible { background: var(--bg-hover); box-shadow: none; }
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: 12px; max-width: min(560px, 90vw);
  background: #26262b; color: #fff; box-shadow: var(--shadow); pointer-events: auto; animation: toast-in .2s ease-out;
}
[data-theme="dark"] .toast { background: #3a3a42; }
.toast.success .icon { color: #4cc784; }
.toast.error .icon { color: #ff7b7b; }
.toast.leaving { opacity: 0; transition: opacity .3s; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
.busy { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; background: rgb(0 0 0 / .25); }
.busy-card { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 24px 28px; min-width: 280px; background: var(--bg-surface); border-radius: 16px; box-shadow: var(--shadow); }
.busy-card p { margin: 0; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--bg-active); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { width: 100%; height: 4px; border-radius: 2px; background: var(--bg-active); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.dropzone-overlay { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 18%, transparent); border: 3px dashed var(--accent); pointer-events: none; }
.dropzone-overlay > div { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 28px 36px; border-radius: 16px; background: var(--bg-surface); box-shadow: var(--shadow); color: var(--accent); }
.dropzone-overlay p { margin: 0; color: var(--text); font-weight: 600; }
.print-frame { position: fixed; width: 0; height: 0; border: 0; visibility: hidden; }

/* Signature dialog */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; background: var(--bg-active); align-self: flex-start; }
.seg-btn { border: 0; background: none; padding: 6px 16px; border-radius: 999px; cursor: pointer; }
.seg-btn.active { background: var(--bg-surface); box-shadow: 0 1px 2px rgb(0 0 0 / .15); font-weight: 600; }
.sig-pane { display: flex; flex-direction: column; gap: 10px; }
.sig-canvas { width: 100%; aspect-ratio: 3 / 1; border: 1px solid var(--border-strong); border-radius: 12px; background: #fff; touch-action: none; cursor: crosshair; }
.sig-typed-preview { height: 110px; display: grid; place-items: center; border: 1px solid var(--border-strong); border-radius: 12px; background: #fff; font-size: 48px; overflow: hidden; white-space: nowrap; }
.sig-typed-preview.placeholder { color: #bbb !important; }
.sig-upload-preview { min-height: 110px; display: grid; place-items: center; border: 1px dashed var(--border-strong); border-radius: 12px; background: #fff; padding: 8px; }
.sig-upload-preview img { max-width: 100%; max-height: 160px; }
.color-dots { display: flex; gap: 8px; }
.dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--bg-surface); background: var(--c); box-shadow: 0 0 0 1px var(--border-strong); cursor: pointer; }
.dot.active { box-shadow: 0 0 0 2px var(--accent); }

/* ---------- Narrow screens ---------- */
@media (max-width: 1100px) {
  :root { --left-w: 260px; --right-w: 280px; }
  .offline-badge span:not(.icon) { display: none; }
}
@media (max-width: 860px) {
  .modes { display: none; }
  .main[data-view="doc"] .right-panel { position: absolute; right: var(--rail-w); top: calc(var(--tabbar-h) + var(--modebar-h)); bottom: 0; z-index: 20; box-shadow: var(--shadow); }
  .main[data-view="doc"] .left-panel { position: absolute; left: 0; top: calc(var(--tabbar-h) + var(--modebar-h)); bottom: 0; z-index: 20; box-shadow: var(--shadow); }
  .cmd { width: 180px; }
  .cmd kbd { display: none; }
  .page-column { padding-left: 64px; padding-right: 12px; }
  .tab { min-width: 90px; }
  .brand .brand-logo { display: none !important; }
  .brand .brand-mark { display: block !important; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media print { .app { display: none; } }
