/* ================================================================
   theme-neuralpha.css — load AFTER css/app.css.
   The editor is fully CSS-variable driven, so matching the NeurAlpha
   platform theme is just a re-definition of the palette variables +
   amber accent, with light/dark switched via [data-theme] on <html>.
   Default = light (the platform's default). js/theme.js sets the
   attribute from the shared `na_theme` cookie.
   NOTE: light values mirror the NeurAlpha tokens (--bg #f5f5f5,
   --card #fff, text #1a1a2e, amber #D97706). Reconcile exact tokens
   with the live platform during integration if they differ.
   ================================================================ */

:root,
html[data-theme="light"] {
  --bg-app:       #f5f5f5;
  --bg-bar:       #ffffff;
  --bg-panel:     #ffffff;
  --bg-card:      #ffffff;
  --bg-hover:     #ececec;
  --bg-active:    rgba(217,119,6,0.10);

  --accent:       #F59E0B;            /* NeurAlpha amber — unified light + dark */
  --accent-2:     #D97706;
  --accent-light: #FBBF24;
  --accent-glow:  rgba(245,158,11,0.25);
  --accent-text:  #b45309;

  /* Fonts (apply to both modes via :root inheritance) */
  --font:       'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-head:  'Outfit', 'DM Sans', -apple-system, sans-serif;

  /* PDF canvas surface — light mode */
  --pdf-surface: #e9e9ee;
  --pdf-grid:    #dadae1;
  --pdf-glow:    rgba(245,158,11,0.05);

  --text-primary:   #1a1a2e;
  --text-secondary: #555a66;
  --text-muted:     #9aa0aa;

  --border:         #e3e3e6;
  --border-subtle:  #eeeef1;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 14px rgba(0,0,0,.10);
  --shadow-lg: 0 8px 28px rgba(0,0,0,.14);
  --shadow-xl: 0 16px 50px rgba(0,0,0,.18);
}

html[data-theme="dark"] {
  --bg-app:       #0d1117;
  --bg-bar:       #161b22;
  --bg-panel:     #1c2333;
  --bg-card:      #21262d;
  --bg-hover:     #30363d;
  --bg-active:    rgba(245,158,11,.12);

  --accent:       #f59e0b;            /* amber stays the brand in dark too */
  --accent-2:     #d97706;
  --accent-light: #fbbf24;
  --accent-glow:  rgba(245,158,11,.28);
  --accent-text:  #fbbf24;

  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #484f58;

  --border:         #30363d;
  --border-subtle:  #21262d;

  /* PDF canvas surface — dark mode */
  --pdf-surface: #2d2d35;
  --pdf-grid:    #333341;
  --pdf-glow:    rgba(245,158,11,0.04);

  --shadow-sm: 0 1px 4px rgba(0,0,0,.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,.5);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.6);
  --shadow-xl: 0 16px 64px rgba(0,0,0,.7);
}

/* Theme toggle — mounted by theme.js INSIDE the editor header button row
   (.header-actions), so it participates in flex layout (no fixed/overlap). */
#na-theme-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-card); color: var(--text-primary);
  font: 600 12px var(--font); cursor: pointer; flex-shrink: 0;
}
#na-theme-toggle:hover { background: var(--bg-hover); border-color: var(--accent); }

/* [pdf-fix] Format buttons (B/I/U + alignment) — previously unstyled native
   buttons (dark-mode tofu, clipped glyphs, no active state). */
.prop-fmt-btn{
  display:inline-flex; align-items:center; justify-content:center;
  min-width:32px; height:30px; padding:4px 10px;
  background:var(--bg-card); color:var(--text-primary);
  border:1px solid var(--border); border-radius:var(--radius-sm);
  font:600 13px var(--font); line-height:1; cursor:pointer;
  transition:background .15s, border-color .15s, color .15s;
}
.prop-fmt-btn svg{ width:15px; height:15px; display:block; stroke:currentColor; stroke-width:2; fill:none; }
.prop-fmt-btn:hover{ background:var(--bg-hover); border-color:var(--accent); }
.prop-fmt-btn.active{ background:var(--accent); border-color:var(--accent); color:#1a1a2e; }

/* [pdf-fix] Properties-panel labels use a <div class="props-label"> (NOT a
   <label>), so the .props-section label rule never matched them — style here
   so they stay legible in both themes. */
.props-label{ display:block; font-size:11px; color:var(--text-secondary); margin:10px 0 4px; }
.props-label:first-child{ margin-top:0; }

/* Headings + logo use the display font */
h1,h2,h3,.logo-text{ font-family:var(--font-head); }

/* [feature] OCR badge + language selector on scanned pages */
.ocr-badge{ position:absolute; top:8px; right:8px; z-index:4; display:flex; align-items:center; gap:6px; pointer-events:auto; }
.ocr-badge-tag{ font:700 10px var(--font); letter-spacing:.04em; color:#1a1a2e; background:#F59E0B; border-radius:4px; padding:2px 7px; box-shadow:var(--shadow-sm); }
.ocr-badge-tag.ocr-badge-pro{ background:rgba(245,158,11,0.18); color:var(--accent-text); border:1px solid var(--accent); }
.ocr-lang{ font:600 11px var(--font); height:22px; border:1px solid var(--border); border-radius:4px; background:var(--bg-card); color:var(--text-primary); cursor:pointer; }

/* [feature] Viewport indicator — lives INSIDE the active page's Pages-panel
   thumbnail (see js/pages-viewport.js). pointer-events only on the rect so
   thumbnail click-to-switch still works; clipped within the thumb by the
   wrap's overflow:hidden. */
.thumb-canvas-wrap{ position: relative; }
#pages-vp-rect{ position:absolute; box-sizing:border-box; border:1.5px solid #F59E0B; background:rgba(245,158,11,0.12); cursor:grab; pointer-events:auto; z-index:3; display:none; }
#pages-vp-rect:active{ cursor:grabbing; }

/* [fix] Non-blocking in-app confirm modal (replaces native confirm()). */
.app-modal-overlay{ position:fixed; inset:0; z-index:10000; display:none; align-items:center; justify-content:center; background:rgba(0,0,0,.45); }
.app-modal-overlay.visible{ display:flex; }
.app-modal{ background:var(--bg-card); color:var(--text-primary); border:1px solid var(--border); border-radius:var(--radius-md,8px); box-shadow:var(--shadow-xl); min-width:300px; max-width:90vw; padding:20px 22px; font-family:var(--font); }
.app-modal-msg{ margin-bottom:18px; font-size:15px; line-height:1.4; }
.app-modal-actions{ display:flex; justify-content:flex-end; gap:10px; }
.app-modal-btn{ height:34px; padding:0 16px; border:1px solid var(--border); border-radius:var(--radius-sm,6px); background:var(--bg-card); color:var(--text-primary); font:600 13px var(--font); cursor:pointer; transition:background .15s,border-color .15s; }
.app-modal-btn:hover{ background:var(--bg-hover); border-color:var(--accent); }
.app-modal-btn.primary{ background:var(--accent); border-color:var(--accent); color:#1a1a2e; }
.app-modal-btn.danger{ background:#dc2626; border-color:#dc2626; color:#fff; }
.app-modal-btn.danger:hover{ background:#b91c1c; border-color:#b91c1c; }

/* [retype] Serif/Sans toggle floating above the retype editable. */
.retype-font-toggle{ position:absolute; z-index:60; display:flex; gap:2px; padding:2px;
  background:var(--bg-card); border:1px solid var(--border); border-radius:6px; box-shadow:var(--shadow-md); }
.retype-font-toggle button{ height:22px; padding:0 9px; border:1px solid transparent; border-radius:4px;
  background:transparent; color:var(--text-primary); font-size:12px; font-weight:600; line-height:1; cursor:pointer; }
.retype-font-toggle button:hover{ background:var(--bg-hover); }
.retype-font-toggle button.active{ background:var(--accent); border-color:var(--accent); color:#1a1a2e; }

/* Extract (split-out) bar in the Pages panel + per-thumbnail selection */
#extract-bar{ display:flex; align-items:center; gap:6px; flex-wrap:wrap; padding:8px;
  border-bottom:1px solid var(--border); }
#extract-bar #extract-range{ flex:1 1 90px; min-width:70px; height:28px; padding:0 8px;
  border:1px solid var(--border); border-radius:5px; background:var(--bg-card); color:var(--text-primary); font-size:12px; }
#extract-bar button{ height:28px; padding:0 10px; border-radius:5px; font-size:12px; font-weight:600; cursor:pointer; border:1px solid var(--border); }
#extract-bar .btn-primary{ background:var(--accent); border-color:var(--accent); color:#1a1a2e; }
#extract-bar .btn-outline{ background:transparent; color:var(--text-primary); }
#extract-bar #extract-count{ flex-basis:100%; font-size:11px; color:var(--text-secondary); }
.thumb-item{ position:relative; }
.thumb-item .thumb-select{ position:absolute; top:6px; left:6px; z-index:6; width:16px; height:16px; cursor:pointer; accent-color:var(--accent); }
.thumb-item.selected{ outline:2px solid var(--accent); outline-offset:1px; border-radius:4px; }

/* Find & Replace panel (extends the search panel into stacked rows) */
#search-panel{ flex-direction:column; align-items:stretch; gap:6px; }
#search-panel .fr-row{ display:flex; align-items:center; gap:6px; }
#search-panel .fr-row #search-input,
#search-panel .fr-row #fr-replace{ flex:1 1 auto; min-width:120px; }
#search-panel #fr-replace{ height:30px; padding:0 10px; border:1px solid var(--border); border-radius:6px; background:var(--bg-card); color:var(--text-primary); font-size:13px; }
#search-panel .fr-opts{ gap:14px; padding:0 2px; }
#search-panel .fr-opts label{ display:inline-flex; align-items:center; gap:5px; font-size:12px; color:var(--text-secondary); cursor:pointer; }
#search-panel .fr-opts input[type=checkbox]{ accent-color:var(--accent); cursor:pointer; }

/* Page Overlays — dialogs + Layers-panel doc-overlay section */
.ov-modal-overlay{ position:fixed; inset:0; z-index:10001; display:flex; align-items:center; justify-content:center; background:rgba(0,0,0,.45); }
.ov-modal{ background:var(--bg-card); color:var(--text-primary); border:1px solid var(--border); border-radius:var(--radius-md,8px); box-shadow:var(--shadow-xl); width:420px; max-width:92vw; max-height:88vh; overflow:auto; padding:18px 20px; font-family:var(--font); }
.ov-modal-title{ font:700 15px var(--font-head,var(--font)); margin-bottom:12px; }
.ov-modal-body{ display:flex; flex-direction:column; gap:8px; }
.ov-f{ display:flex; align-items:center; justify-content:space-between; gap:10px; font-size:12px; color:var(--text-secondary); }
.ov-f input[type=text], .ov-f input[type=number], .ov-f select{ flex:1 1 60%; height:28px; padding:0 8px; border:1px solid var(--border); border-radius:5px; background:var(--bg-app); color:var(--text-primary); font-size:12px; }
.ov-f input[type=color]{ width:34px; height:26px; padding:0; border:1px solid var(--border); border-radius:5px; background:var(--bg-card); }
.ov-f input[type=range]{ flex:1 1 60%; accent-color:var(--accent); }
.ov-help{ font-size:11px; color:var(--text-secondary); background:var(--bg-app); border:1px solid var(--border-subtle); border-radius:5px; padding:5px 8px; }
.ov-grid3{ display:grid; grid-template-columns:1fr 1fr 1fr; gap:6px; font-size:10px; color:var(--text-secondary); }
.ov-grid3 input{ width:100%; height:26px; margin-top:2px; padding:0 6px; border:1px solid var(--border); border-radius:5px; background:var(--bg-app); color:var(--text-primary); font-size:11px; }
.ov-modal-actions{ display:flex; justify-content:flex-end; gap:10px; margin-top:16px; }
#overlay-list{ padding:6px 6px 0; }
#overlay-list .overlay-hdr{ font:700 10px var(--font); letter-spacing:.04em; text-transform:uppercase; color:var(--text-muted); padding:2px 4px 6px; }
.overlay-row{ display:flex; align-items:center; gap:5px; padding:5px 6px; margin-bottom:4px; border:1px solid var(--accent); border-radius:6px; background:var(--bg-active); }
.overlay-row.off{ opacity:.55; border-color:var(--border-subtle); background:var(--bg-card); }
.overlay-name{ flex:1 1 auto; font-size:12px; color:var(--text-primary); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.overlay-scope{ flex:none; font-size:10px; color:var(--text-secondary); }

/* Layers panel (non-destructive layer system) */
#layers-bar{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; padding:8px; border-bottom:1px solid var(--border); }
#layers-bar #btn-show-original{ height:28px; padding:0 12px; border-radius:5px; font-size:12px; font-weight:600;
  cursor:pointer; border:1px solid var(--border); background:transparent; color:var(--text-primary); }
#layers-bar #btn-show-original.active{ background:var(--accent); border-color:var(--accent); color:#1a1a2e; }
#layers-bar #layers-count{ font-size:11px; color:var(--text-secondary); }
#layer-list{ padding:6px; }
.layer-row{ display:flex; align-items:center; gap:5px; padding:5px 6px; margin-bottom:4px; border:1px solid var(--border-subtle);
  border-radius:6px; background:var(--bg-card); cursor:grab; }
.layer-row.drop-target{ border-color:var(--accent); box-shadow:0 0 0 1px var(--accent) inset; }
.layer-row.hidden{ opacity:.5; }
.layer-row.locked{ background:var(--bg-hover); }
.layer-btn{ flex:none; width:24px; height:24px; padding:0; border:1px solid var(--border); border-radius:5px;
  background:var(--bg-card); color:var(--text-secondary); font:600 12px var(--font); line-height:1; cursor:pointer; }
.layer-btn.on{ background:var(--accent); border-color:var(--accent); color:#1a1a2e; }
.layer-btn.danger:hover{ background:#dc2626; border-color:#dc2626; color:#fff; }
.layer-name{ flex:1 1 60px; min-width:40px; height:24px; padding:0 6px; border:1px solid transparent; border-radius:5px;
  background:transparent; color:var(--text-primary); font-size:12px; }
.layer-name:focus{ border-color:var(--border); background:var(--bg-app); outline:none; }
.layer-opacity{ flex:0 0 56px; width:56px; accent-color:var(--accent); cursor:pointer; }

/* Region (Rect/Lasso) + Eraser (Brush/Lasso) gesture-mode toggles — shown only
   while their tool is active (body.marquee-active / body.eraser-active). */
.mode-toggle{ display:none; align-items:center; gap:2px; margin-left:4px; padding:2px;
  background:var(--bg-card); border:1px solid var(--border); border-radius:6px; }
body.marquee-active #region-mode-toggle,
body.eraser-active  #eraser-mode-toggle,
body.redact-active  #redact-bar,
body.form-active    #form-type-toggle,
body.link-active    #link-mode-toggle{ display:inline-flex; }
/* Bookmarks panel rows (mirror the layer-row look) */
.bm-add-bar{ display:flex; gap:6px; margin:4px 0 8px; }
.bookmark-row{ display:flex; align-items:center; gap:4px; padding:4px 5px; margin-bottom:4px;
  border:1px solid var(--border-subtle); border-radius:6px; background:var(--bg-card); }
.bookmark-title{ flex:1 1 auto; min-width:0; height:24px; padding:0 6px; border:1px solid var(--border);
  border-radius:4px; background:var(--bg-input,transparent); color:var(--text); font-size:12px; }
.bookmark-page{ width:46px; height:24px; padding:0 4px; border:1px solid var(--border); border-radius:4px;
  background:var(--bg-input,transparent); color:var(--text); font-size:12px; text-align:center; }
#form-type-toggle{ flex-wrap:wrap; gap:3px; }
#form-type-toggle #btn-flatten-forms{ background:transparent; }
#form-type-toggle #btn-flatten-forms.active{ background:#dc2626; border-color:#dc2626; color:#fff; }
#redact-bar{ flex-wrap:wrap; gap:4px; }
#redact-bar #redact-color{ width:26px; height:24px; padding:0; border:1px solid var(--border); border-radius:4px; background:var(--bg-card); cursor:pointer; }
#redact-bar #redact-label{ width:120px; height:24px; padding:0 6px; border:1px solid var(--border); border-radius:4px; background:var(--bg-card); color:var(--text-primary); font-size:11px; }
#redact-bar .redact-apply{ background:#dc2626; border-color:#dc2626; color:#fff; }
#redact-bar .redact-apply:hover{ background:#b91c1c; border-color:#b91c1c; }
.mode-toggle .mode-btn{ height:24px; padding:0 9px; border:1px solid transparent; border-radius:4px;
  background:transparent; color:var(--text-primary); font-size:11px; font-weight:600; line-height:1; cursor:pointer; }
.mode-toggle .mode-btn:hover{ background:var(--bg-hover); }
.mode-toggle .mode-btn.active{ background:var(--accent); border-color:var(--accent); color:#1a1a2e; }

/* Erase & Rewrite "not editable" notification (outlined/raster text) */
.er-notify{ position:absolute; z-index:70; display:flex; align-items:center; gap:8px;
  max-width:320px; padding:7px 9px; background:var(--bg-card); color:var(--text-primary);
  border:1px solid var(--border); border-left:3px solid var(--accent); border-radius:7px;
  box-shadow:var(--shadow-md); font-size:12px; line-height:1.25; }
.er-notify-msg{ flex:1; }
.er-notify-btn{ flex:none; height:24px; padding:0 10px; border:1px solid var(--accent);
  border-radius:5px; background:var(--accent); color:#1a1a2e; font-size:12px; font-weight:600;
  white-space:nowrap; cursor:pointer; }
.er-notify-btn:hover{ background:var(--accent-light); border-color:var(--accent-light); }
.er-notify-x{ flex:none; width:18px; height:18px; padding:0; border:none; border-radius:4px;
  background:transparent; color:var(--text-secondary); font-size:15px; line-height:1; cursor:pointer; }
.er-notify-x:hover{ background:var(--bg-hover); color:var(--text-primary); }
