/* ═══════════════════════════════════════════════════════════
   GLC Viewer — Professional Design System
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Layout & motion (theme-agnostic) ──────────────────── */
:root {
  --h-top:  52px;
  --h-bar:  48px;
  --w-side: 234px;
  --w-prop: 252px;
  --r-xs:   4px;
  --r-sm:   6px;
  --r-md:   8px;
  --r-lg:   12px;
  --r-xl:   16px;
  --t-fast: 120ms ease;
  --t-mid:  200ms ease;
  --t-slow: 300ms ease;
}

/* ── Dark theme ─────────────────────────────────────────── */
html[data-theme="dark"] {
  --bg-base:    #07091a;
  --bg-raised:  #0b0e1f;
  --bg-surface: #0f1326;
  --bg-hover:   #151a2f;
  --bg-active:  #1a2038;
  --bg-press:   #1f2640;

  --bd-sub:   #141830;
  --bd:       #1e2540;
  --bd-hi:    #2a3560;
  --bd-focus: #4d80f5;

  --acc:      #4d80f5;
  --acc-hi:   #6b97ff;
  --acc-lo:   #3460cc;
  --acc-bg:   #0c1d4a;
  --acc-glow: rgba(77,128,245,.25);

  --tx-0:  #eef1ff;
  --tx-1:  #9aaacf;
  --tx-2:  #4e5a7e;
  --tx-3:  #282e45;

  --ok:   #35c068;
  --warn: #f0a83a;
  --err:  #e04f5e;

  --scrollbar:   #2a3560;
  --scrollbar-h: #3a4870;
  --checker-a:   #111425;
  --checker-b:   #0b0d1a;
  --canvas-bg:   #0a0c18;
}

/* ── Light theme ────────────────────────────────────────── */
html[data-theme="light"] {
  --bg-base:    #f0f2fa;
  --bg-raised:  #ffffff;
  --bg-surface: #f5f6fd;
  --bg-hover:   #eaecf7;
  --bg-active:  #e0e4f4;
  --bg-press:   #d5dbf0;

  --bd-sub:   #e6e8f5;
  --bd:       #d4d8ee;
  --bd-hi:    #b8c0de;
  --bd-focus: #3060e0;

  --acc:      #3060e0;
  --acc-hi:   #4d80f5;
  --acc-lo:   #2048c0;
  --acc-bg:   #e8effd;
  --acc-glow: rgba(48,96,224,.15);

  --tx-0:  #141828;
  --tx-1:  #3a4668;
  --tx-2:  #6874a0;
  --tx-3:  #b8c4d8;

  --ok:   #167a38;
  --warn: #b87010;
  --err:  #c02838;

  --scrollbar:   #c4cce8;
  --scrollbar-h: #a8b2d0;
  --checker-a:   #e4e6f4;
  --checker-b:   #d8dcf0;
  --canvas-bg:   #eceef8;
}

/* ── Smooth theme transition ────────────────────────────── */
html.theme-switching,
html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after {
  transition:
    background-color 220ms ease,
    border-color     200ms ease,
    color            180ms ease,
    box-shadow       220ms ease,
    fill             180ms ease !important;
}

/* ── Base ───────────────────────────────────────────────── */
html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-base);
  color: var(--tx-0);
  font-family: 'Inter', 'Segoe UI Variable', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
svg    { flex-shrink: 0; }

::-webkit-scrollbar            { width: 5px; height: 5px; }
::-webkit-scrollbar-track      { background: transparent; }
::-webkit-scrollbar-thumb      { background: var(--scrollbar);   border-radius: 3px; }
::-webkit-scrollbar-thumb:hover{ background: var(--scrollbar-h); }

/* ── Focus ring ─────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--bd-focus);
  outline-offset: 2px;
}

/* ════════════════════  TOPBAR  ════════════════════ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--h-top);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--bd-sub);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  z-index: 200;
  gap: 12px;
}

html[data-theme="light"] .topbar { box-shadow: 0 1px 6px rgba(0,0,0,.08); }
html[data-theme="light"] .toolbar { box-shadow: 0 -1px 6px rgba(0,0,0,.06); }

/* Brand */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.brand-icon  { width: 28px; height: 28px; }
.brand-name  { font-size: 13px; font-weight: 700; color: var(--tx-0); letter-spacing: .2px; }

/* Topbar buttons */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-sep {
  width: 1px; height: 20px;
  background: var(--bd);
  margin: 0 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: 32px;
  border-radius: var(--r-sm);
  border: 1px solid var(--bd);
  background: var(--bg-surface);
  color: var(--tx-1);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform 80ms ease;
}
.btn svg { width: 14px; height: 14px; }
.btn:hover  { background: var(--bg-hover); border-color: var(--bd-hi); color: var(--tx-0); }
.btn:active { transform: scale(.97); background: var(--bg-press); }

.btn-primary {
  background: var(--acc);
  border-color: var(--acc);
  color: #fff;
}
.btn-primary:hover  { background: var(--acc-hi); border-color: var(--acc-hi); color: #fff; }
.btn-primary:active { background: var(--acc-lo); }

.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover  { background: var(--bg-hover); border-color: var(--bd); color: var(--tx-0); }
.btn-ghost:active { background: var(--bg-press); }

/* ════════════════════  WORKSPACE  ════════════════════ */
.workspace {
  position: fixed;
  top: var(--h-top);
  bottom: var(--h-bar);
  left: 0; right: 0;
  display: flex;
  overflow: hidden;
}

/* ════════════════════  SIDEBAR  ════════════════════ */
.sidebar {
  width: var(--w-side);
  min-width: var(--w-side);
  background: var(--bg-raised);
  border-right: 1px solid var(--bd-sub);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--bd-sub);
  flex-shrink: 0;
}
.sidebar-footer svg  { width: 16px; height: 16px; flex-shrink: 0; }
.sidebar-footer span {
  font-size: 11px;
  font-weight: 600;
  color: var(--tx-2);
  text-transform: uppercase;
  letter-spacing: .8px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 38px;
  border-bottom: 1px solid var(--bd-sub);
  flex-shrink: 0;
}
.sidebar-count { font-size: 11px; font-weight: 600; color: var(--tx-2); text-transform: uppercase; letter-spacing: .6px; }

.icon-btn {
  width: 28px; height: 28px;
  border-radius: var(--r-sm);
  border: none;
  background: transparent;
  color: var(--tx-2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
}
.icon-btn svg { width: 14px; height: 14px; }
.icon-btn:hover { background: var(--bg-hover); color: var(--tx-0); }

.thumb-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.thumb-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

/* Thumbnail card */
.thumb-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--r-sm);
  overflow: hidden;
  cursor: pointer;
  border: 1.5px solid transparent;
  background: var(--bg-surface);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}
.thumb-item:hover {
  border-color: var(--bd-hi);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
}
.thumb-item.active {
  border-color: var(--acc);
  box-shadow: 0 0 0 1px var(--acc), 0 4px 16px var(--acc-glow);
}
.thumb-item img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.thumb-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,.75) 0%, transparent 55%);
  opacity: 0;
  transition: opacity var(--t-fast);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 5px;
}
.thumb-item:hover .thumb-overlay { opacity: 1; }
.thumb-label {
  color: #fff;
  font-size: 9.5px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.thumb-remove {
  position: absolute;
  top: 4px; right: 4px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,.55);
  border: none;
  color: #fff;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--t-fast), background var(--t-fast);
  line-height: 1;
  backdrop-filter: blur(4px);
}
.thumb-item:hover .thumb-remove { opacity: 1; }
.thumb-remove:hover { background: var(--err); }

/* PDF page badge */
.thumb-pdf-badge {
  position: absolute;
  top: 4px; left: 4px;
  background: rgba(77,128,245,.85);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .3px;
  padding: 2px 5px;
  border-radius: 4px;
  line-height: 1.4;
  pointer-events: none;
}

/* Drop hint */
.drop-hint {
  display: none;
  text-align: center;
  padding: 24px 16px 16px;
  color: var(--tx-2);
}
.drop-hint.visible { display: block; }
.drop-hint svg { width: 52px; height: 52px; margin-bottom: 12px; }
.drop-hint p {
  font-size: 12px;
  font-weight: 500;
  color: var(--tx-1);
  margin-bottom: 4px;
}
.drop-hint span { font-size: 11px; color: var(--tx-2); }

/* ════════════════════  CANVAS  ════════════════════ */
.canvas-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-base);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Subtle checkerboard pattern when an image is loaded */
.canvas-area.has-image {
  background-color: var(--canvas-bg);
  background-image:
    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-a) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-a) 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0px;
}

/* Empty state */
.empty-state {
  text-align: center;
  color: var(--tx-2);
  pointer-events: none;
  user-select: none;
  padding: 20px;
}
.empty-icon {
  width: 88px; height: 88px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--bd);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}
.empty-icon svg { width: 52px; height: 52px; color: var(--tx-2); }
.empty-state h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--tx-1);
  margin-bottom: 8px;
}
.empty-state p {
  font-size: 13px;
  color: var(--tx-2);
  line-height: 1.7;
  margin-bottom: 20px;
}
.empty-hints {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}
.hint-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--bd);
  background: var(--bg-surface);
  font-size: 11px;
  color: var(--tx-2);
}
.hint-chip kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-hover);
  border: 1px solid var(--bd-hi);
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
  color: var(--tx-1);
}

/* Image wrapper */
.img-wrapper {
  position: absolute;
  top: 50%; left: 50%;
  transform-origin: center;
  cursor: grab;
  user-select: none;
  will-change: transform;
  line-height: 0;
  transition: opacity .15s ease;
}
.img-wrapper.dragging { cursor: grabbing; }
.img-wrapper.loading  { opacity: .3; }

#main-img {
  max-width: none;
  max-height: none;
  display: block;
  pointer-events: none;
  image-rendering: auto;
}

/* Image loader */
.img-loader {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.img-loader.active { display: flex; }

.spinner {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 2.5px solid var(--bd-hi);
  border-top-color: var(--acc);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Zoom badge */
.zoom-badge {
  position: absolute;
  bottom: 52px; right: 10px;
  background: var(--bg-raised);
  border: 1px solid var(--bd);
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
  color: var(--tx-0);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .3px;
  padding: 4px 10px;
  border-radius: 20px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--t-mid), transform var(--t-mid);
}
.zoom-badge.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Canvas corner controls */
.canvas-controls {
  position: absolute;
  bottom: 10px; right: 10px;
  display: flex;
  gap: 3px;
}
.canvas-ctrl-btn {
  width: 30px; height: 30px;
  border-radius: var(--r-sm);
  border: 1px solid var(--bd);
  background: var(--bg-raised);
  color: var(--tx-1);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
.canvas-ctrl-btn svg        { width: 14px; height: 14px; }
.canvas-ctrl-label          { font-size: 10px; font-weight: 700; font-family: monospace; letter-spacing: .5px; }
.canvas-ctrl-btn:hover  { background: var(--bg-hover); border-color: var(--bd-hi); color: var(--tx-0); }
.canvas-ctrl-btn:active { background: var(--bg-press); }
.canvas-ctrl-btn.active { border-color: var(--acc); color: var(--acc); background: var(--acc-bg); }

/* ════════════════════  PROPERTIES  ════════════════════ */
.props-panel {
  width: var(--w-prop);
  min-width: var(--w-prop);
  background: var(--bg-raised);
  border-left: 1px solid var(--bd-sub);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 14px;
  height: 38px;
  border-bottom: 1px solid var(--bd-sub);
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--tx-2);
}
.panel-header svg { width: 13px; height: 13px; }

.props-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}

.no-props {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 28px 16px;
  color: var(--tx-2);
}
.no-props svg { width: 28px; height: 28px; opacity: .5; }
.no-props p  { font-size: 12px; }

/* Props section label */
.prop-section {
  padding: 8px 14px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--tx-3);
}
.prop-section:first-child { padding-top: 4px; }

/* Props row */
.prop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 14px;
  transition: background var(--t-fast);
}
.prop-row:hover { background: var(--bg-hover); }
.prop-key {
  font-size: 12px;
  color: var(--tx-2);
  flex-shrink: 0;
}
.prop-val {
  font-size: 12px;
  color: var(--tx-1);
  text-align: right;
  word-break: break-all;
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Color swatch */
.color-swatch {
  width: 14px; height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,.12);
  display: inline-block;
  flex-shrink: 0;
}

/* ════════════════════  TOOLBAR  ════════════════════ */
.toolbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--h-bar);
  background: var(--bg-raised);
  border-top: 1px solid var(--bd-sub);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 2px;
  z-index: 200;
}

.tbar-group { display: flex; align-items: center; gap: 1px; }
.tbar-sep {
  width: 1px; height: 22px;
  background: var(--bd);
  margin: 0 6px;
  flex-shrink: 0;
}

.tbar-btn {
  width: 34px; height: 34px;
  border-radius: var(--r-sm);
  border: none;
  background: transparent;
  color: var(--tx-2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast), transform 80ms ease;
  flex-shrink: 0;
}
.tbar-btn svg { width: 16px; height: 16px; }
.tbar-btn:hover    { background: var(--bg-hover); color: var(--tx-0); }
.tbar-btn:active   { transform: scale(.93); background: var(--bg-press); }
.tbar-btn:disabled { opacity: .25; pointer-events: none; }
.tbar-btn.active   { background: var(--acc-bg); color: var(--acc); }

.img-index {
  min-width: 54px;
  text-align: center;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--tx-2);
  font-variant-numeric: tabular-nums;
}

/* Status bar */
.tbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
  overflow: hidden;
}
.status-item {
  font-size: 11.5px;
  color: var(--tx-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.status-item:first-child { color: var(--tx-1); font-weight: 500; max-width: 200px; }
.status-dot {
  width: 3px; height: 3px;
  border-radius: 50%;
  background: var(--tx-3);
  flex-shrink: 0;
}

/* ════════════════════  DOCUMENT VIEWER  ════════════════════ */
.doc-viewer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  z-index: 2;
}

.doc-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  height: 40px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--bd);
  flex-shrink: 0;
  gap: 8px;
}

.doc-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: none;
}
.doc-tabs::-webkit-scrollbar { display: none; }

.doc-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 12px;
  height: 28px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--tx-2);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.doc-tab:hover  { background: var(--bg-hover); color: var(--tx-1); }
.doc-tab.active {
  background: var(--acc-bg);
  border-color: var(--acc);
  color: var(--acc);
}

.doc-toolbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.doc-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 10px;
  height: 28px;
  border-radius: var(--r-sm);
  border: 1px solid var(--bd);
  background: var(--bg-surface);
  color: var(--tx-2);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.doc-action-btn svg { width: 13px; height: 13px; }
.doc-action-btn:hover { background: var(--bg-hover); color: var(--tx-0); border-color: var(--bd-hi); }

.doc-scroll {
  flex: 1;
  overflow: auto;
  padding: 32px 40px;
  display: flex;
  justify-content: center;
}

/* The "paper" page */
.doc-page {
  width: 100%;
  max-width: 900px;
  background: #fff;
  color: #111;
  border-radius: var(--r-md);
  box-shadow: 0 4px 32px rgba(0,0,0,.4);
  padding: 48px 56px;
  font-family: 'Calibri', 'Segoe UI', Georgia, serif;
  font-size: 14px;
  line-height: 1.7;
  min-height: 400px;
}

/* ── Word content styles ── */
.doc-page h1 { font-size: 24px; font-weight: 700; margin: 0 0 16px; color: #1a1a2e; }
.doc-page h2 { font-size: 20px; font-weight: 600; margin: 20px 0 12px; color: #1a1a2e; }
.doc-page h3 { font-size: 16px; font-weight: 600; margin: 16px 0 8px; }
.doc-page p  { margin: 0 0 10px; }
.doc-page ul, .doc-page ol { margin: 0 0 10px 24px; }
.doc-page li { margin-bottom: 4px; }
.doc-page strong { font-weight: 700; }
.doc-page em     { font-style: italic; }
.doc-page a      { color: #2d5be0; }
.doc-page img    { max-width: 100%; height: auto; border-radius: 4px; }

/* ── Excel / CSV table styles ── */
.doc-page.excel-view {
  padding: 0;
  overflow: hidden;
  font-family: 'Calibri', 'Segoe UI', sans-serif;
}

.excel-table-wrap {
  overflow: auto;
  max-height: 100%;
  padding: 24px;
}

.doc-page table {
  border-collapse: collapse;
  font-size: 12.5px;
  width: 100%;
  min-width: max-content;
}
.doc-page th {
  background: #e8eaf6;
  color: #222;
  font-weight: 600;
  padding: 6px 12px;
  border: 1px solid #c5c8e0;
  text-align: left;
  white-space: nowrap;
}
.doc-page td {
  padding: 5px 12px;
  border: 1px solid #dde0ee;
  color: #222;
  white-space: nowrap;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-page tr:nth-child(even) td { background: #f4f5fb; }
.doc-page tr:hover td { background: #eaecf8; }

/* ── Document thumbnail in sidebar ── */
.thumb-doc-icon {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg-surface);
  padding: 8px;
}
.thumb-doc-icon svg  { width: 36px; height: 36px; }
.thumb-doc-icon span {
  font-size: 9px;
  font-weight: 600;
  color: var(--tx-2);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  width: 100%;
  text-align: center;
}

.thumb-type-badge {
  position: absolute;
  top: 4px; left: 4px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .3px;
  padding: 2px 5px;
  border-radius: 4px;
  line-height: 1.4;
  pointer-events: none;
}
.thumb-type-badge.excel { background: rgba(33,115,70,.85); color: #fff; }
.thumb-type-badge.word  { background: rgba(43,87,154,.85);  color: #fff; }
.thumb-type-badge.pdf   { background: rgba(77,128,245,.85); color: #fff; }

/* ════════════════════  LIGHTBOX  ════════════════════ */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(2,3,10,.94);
  backdrop-filter: blur(12px);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: lb-in .2s ease;
}
@keyframes lb-in { from { opacity:0 } to { opacity:1 } }

.lb-close {
  position: absolute;
  top: 16px; right: 16px;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.07);
  color: var(--tx-1);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
  z-index: 1;
}
.lb-close svg { width: 14px; height: 14px; }
.lb-close:hover { background: rgba(255,255,255,.15); color: #fff; }

.lb-nav {
  position: absolute;
  top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(255,255,255,.06);
  color: var(--tx-1);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
  z-index: 1;
  user-select: none;
}
.lb-nav svg { width: 18px; height: 18px; }
.lb-nav:hover { background: rgba(255,255,255,.14); color: #fff; }
.lb-nav-prev { left: 20px; }
.lb-nav-next { right: 20px; }

.lightbox img {
  max-width: calc(100vw - 120px);
  max-height: calc(100vh - 80px);
  object-fit: contain;
  border-radius: var(--r-md);
  box-shadow: 0 24px 64px rgba(0,0,0,.7);
  display: block;
  transform-origin: center center;
}
.lightbox img.zoomed { cursor: grab; }
.lightbox img.zoomed:active { cursor: grabbing; }

.lb-caption {
  position: absolute;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.08);
  color: var(--tx-1);
  font-size: 12px;
  padding: 5px 14px;
  border-radius: 20px;
  white-space: nowrap;
  pointer-events: none;
}

/* ════════════════════  DRAG OVER  ════════════════════ */
body.drag-over::after {
  content: 'Drop to load images';
  position: fixed;
  inset: 0;
  border: 2px dashed var(--acc);
  border-radius: var(--r-lg);
  background: rgba(77,128,245,.06);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--acc);
  pointer-events: none;
  animation: drag-pulse .8s ease infinite alternate;
}
@keyframes drag-pulse { from { opacity:.5 } to { opacity:1 } }

/* ════════════════════  TOASTS  ════════════════════ */
.toast-container {
  position: fixed;
  bottom: calc(var(--h-bar) + 10px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.toast {
  background: var(--bg-surface);
  border: 1px solid var(--bd-hi);
  color: var(--tx-0);
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 16px;
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  animation: toast-in .18s ease, toast-out .25s ease 1.9s forwards;
  white-space: nowrap;
}
.toast.success { border-color: var(--ok);  color: var(--ok); }
.toast.error   { border-color: var(--err); color: var(--err); }
@keyframes toast-in  { from { opacity:0; transform:translateY(6px) } to { opacity:1; transform:translateY(0) } }
@keyframes toast-out { to   { opacity:0; transform:translateY(-4px) } }

/* ════════════════════  SIDEBAR BACKDROP (mobile overlay)  ════════════════════ */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 140;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sidebar-backdrop.visible { display: block; }

/* Mobile hamburger button — hidden on desktop */
.btn-mobile-menu { display: none !important; }

/* Hint chip visibility helpers */
.hint-mobile { display: none; }

/* ════════════════════  RESPONSIVE  ════════════════════ */

/* Large tablet */
@media (max-width: 1024px) {
  :root { --w-prop: 210px; }
}

/* Tablet: hide properties panel */
@media (max-width: 860px) {
  .props-panel { display: none; }
}

/* Tablet ≤768px: sidebar becomes a slide-in overlay panel */
@media (max-width: 768px) {
  .btn-mobile-menu { display: inline-flex !important; }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--h-top);
    bottom: var(--h-bar);
    z-index: 150;
    width: 260px;
    min-width: unset;
    transform: translateX(-100%);
    transition: transform var(--t-mid), box-shadow var(--t-mid);
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 6px 0 40px rgba(0,0,0,.55);
  }

  .doc-scroll { padding: 16px 12px; }
  .doc-page   { padding: 28px 24px; }
}

/* Medium phones ≤600px: icon-only topbar, touch-friendly toolbar */
@media (max-width: 600px) {
  .brand-name  { display: none; }
  .btn-label   { display: none; }
  .tbar-status { display: none; }

  /* Switch hint chips for mobile context */
  .hint-desktop { display: none; }
  .hint-mobile  { display: inline-flex; }

  /* Horizontally scrollable toolbar — all buttons stay, user swipes to reach them */
  .toolbar {
    overflow-x: auto;
    overflow-y: hidden;
    justify-content: flex-start;
    padding: 0 6px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .toolbar::-webkit-scrollbar { display: none; }

  .tbar-group { flex-shrink: 0; }
  .tbar-sep   { flex-shrink: 0; margin: 0 5px; }

  /* Larger touch targets */
  .tbar-btn {
    width: 40px; height: 40px;
    flex-shrink: 0;
  }
  .tbar-btn svg { width: 18px; height: 18px; }

  .img-index { min-width: 42px; font-size: 11px; }

  /* Canvas controls bigger for finger tap */
  .canvas-ctrl-btn { width: 36px; height: 36px; }
  .canvas-ctrl-btn svg { width: 16px; height: 16px; }
}

/* Small phones ≤480px */
@media (max-width: 480px) {
  .topbar { padding: 0 8px; gap: 4px; }
  .topbar-sep { display: none; }

  /* Sidebar can take more width on tiny screens */
  .sidebar { width: min(280px, 86vw); }

  /* Compact document page */
  .doc-page { padding: 18px 14px; font-size: 13px; }

  /* Lightbox nav arrows closer to edges */
  .lb-nav-prev { left: 6px; }
  .lb-nav-next { right: 6px; }
  .lightbox img { max-width: calc(100vw - 80px); }
}

/* ════════════════════  OCR MODAL  ════════════════════ */
.ocr-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: lb-in .18s ease;
}

.ocr-dialog {
  background: var(--bg-raised);
  border: 1px solid var(--bd);
  border-radius: var(--r-xl);
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
  width: 100%;
  max-width: 620px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Head ── */
.ocr-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--bd-sub);
  flex-shrink: 0;
}
.ocr-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
  color: var(--tx-0);
  flex-shrink: 0;
}
.ocr-title svg { color: var(--acc); }
.ocr-ai-badge {
  padding: 1px 6px;
  background: linear-gradient(135deg, #4d80f5 0%, #8b5cf6 100%);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .5px;
  border-radius: 20px;
}
.ocr-head-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
.ocr-lang-label {
  font-size: 11px;
  color: var(--tx-2);
  white-space: nowrap;
}
.ocr-lang-sel {
  height: 28px;
  padding: 0 6px;
  border-radius: var(--r-sm);
  border: 1px solid var(--bd);
  background: var(--bg-surface);
  color: var(--tx-1);
  font-size: 11.5px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  max-width: 160px;
}
.ocr-lang-sel:focus { border-color: var(--bd-focus); }
.ocr-icon-btn {
  width: 28px; height: 28px;
  border-radius: var(--r-sm);
  border: 1px solid var(--bd);
  background: var(--bg-surface);
  color: var(--tx-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.ocr-icon-btn:hover { background: var(--bg-hover); color: var(--tx-0); border-color: var(--bd-hi); }

/* ── Body ── */
.ocr-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 160px;
}
.ocr-loading {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 36px 24px;
  color: var(--tx-2);
}
#ocr-status-msg {
  font-size: 12.5px;
  color: var(--tx-1);
  margin: 0;
}
.ocr-prog-bar {
  width: 100%;
  max-width: 260px;
  height: 4px;
  background: var(--bg-active);
  border-radius: 2px;
  overflow: hidden;
}
.ocr-prog-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--acc), var(--acc-hi));
  border-radius: 2px;
  transition: width .25s ease;
}
.ocr-prog-pct {
  font-size: 11px;
  color: var(--tx-2);
  font-variant-numeric: tabular-nums;
}
.ocr-textarea {
  flex: 1;
  padding: 14px 16px;
  background: var(--bg-base);
  border: none;
  border-top: 1px solid var(--bd-sub);
  color: var(--tx-0);
  font-size: 13px;
  font-family: 'Consolas', 'Fira Code', 'Courier New', monospace;
  line-height: 1.75;
  resize: none;
  outline: none;
  min-height: 180px;
  overflow-y: auto;
}
.ocr-textarea::placeholder { color: var(--tx-3); }

/* ── Footer ── */
.ocr-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 14px;
  border-top: 1px solid var(--bd-sub);
  background: var(--bg-surface);
  flex-shrink: 0;
}
.ocr-meta {
  font-size: 11.5px;
  color: var(--tx-2);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ocr-foot-btns { display: flex; gap: 6px; flex-shrink: 0; }
.ocr-act-btn {
  padding: 0 12px;
  height: 28px;
  border-radius: var(--r-sm);
  border: 1px solid var(--bd);
  background: var(--bg-raised);
  color: var(--tx-1);
  font-size: 11.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.ocr-act-btn:hover { background: var(--bg-hover); color: var(--tx-0); border-color: var(--bd-hi); }
.ocr-act-primary {
  background: var(--acc);
  border-color: var(--acc);
  color: #fff;
}
.ocr-act-primary:hover { background: var(--acc-hi); border-color: var(--acc-hi); }

/* ── Mobile adjustments for OCR modal ── */
@media (max-width: 560px) {
  .ocr-head { flex-wrap: wrap; gap: 6px; }
  .ocr-head-right { width: 100%; margin-left: 0; }
  .ocr-lang-sel { flex: 1; max-width: none; }
  .ocr-foot { flex-direction: column; align-items: stretch; gap: 8px; }
  .ocr-foot-btns { width: 100%; }
  .ocr-act-btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; }
}

/* ════════════════════  LOAD FROM URL MODAL  ════════════════════ */
.url-dialog { max-width: 560px; }
.url-textarea {
  min-height: 180px;
  font-family: 'Consolas', 'Fira Code', 'Courier New', monospace;
  font-size: 12.5px;
  white-space: pre;
}

/* ════════════════════  CROP TOOL  ════════════════════ */
.crop-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  cursor: crosshair;
}

.crop-select {
  position: absolute;
  box-shadow: 0 0 0 9999px rgba(2, 3, 10, .68);
  border: 1.5px dashed #fff;
  cursor: move;
  touch-action: none;
}

/* Rule-of-thirds guide lines */
.crop-select::before, .crop-select::after {
  content: '';
  position: absolute;
  background: rgba(255,255,255,.35);
  pointer-events: none;
}
.crop-select::before { left: 33.333%; width: 33.334%; top: 0; height: 100%; border-left: 1px solid rgba(255,255,255,.35); border-right: 1px solid rgba(255,255,255,.35); background: none; }
.crop-select::after   { top: 33.333%; height: 33.334%; left: 0; width: 100%; border-top: 1px solid rgba(255,255,255,.35); border-bottom: 1px solid rgba(255,255,255,.35); background: none; }

.crop-handle {
  position: absolute;
  background: var(--acc);
  border: 1.5px solid #fff;
  border-radius: 2px;
  z-index: 1;
  touch-action: none;
}
/* Corner handles */
.crop-h-nw, .crop-h-ne, .crop-h-sw, .crop-h-se { width: 12px; height: 12px; }
.crop-h-nw { top: -6px;  left: -6px;  cursor: nwse-resize; }
.crop-h-se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.crop-h-ne { top: -6px;  right: -6px; cursor: nesw-resize; }
.crop-h-sw { bottom: -6px; left: -6px;  cursor: nesw-resize; }
/* Edge handles */
.crop-h-n, .crop-h-s { left: 50%; width: 12px; height: 10px; margin-left: -6px; cursor: ns-resize; }
.crop-h-n { top: -5px; }
.crop-h-s { bottom: -5px; }
.crop-h-e, .crop-h-w { top: 50%; width: 10px; height: 12px; margin-top: -6px; cursor: ew-resize; }
.crop-h-e { right: -5px; }
.crop-h-w { left: -5px; }

.crop-actions {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 2;
}
.crop-act-btn {
  padding: 0 16px;
  height: 34px;
  border-radius: var(--r-sm);
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(15,19,38,.85);
  backdrop-filter: blur(6px);
  color: #eef1ff;
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.35);
  transition: background 120ms ease, border-color 120ms ease;
}
.crop-act-btn:hover { background: rgba(30,37,64,.9); border-color: rgba(255,255,255,.3); }
.crop-act-primary { background: var(--acc); border-color: var(--acc); color: #fff; }
.crop-act-primary:hover { background: var(--acc-hi); border-color: var(--acc-hi); }
