/* PDF Viewer — Highlighter Yellow theme (ported from variants/v4-highlighter-yellow) */

:root {
  --bg: #FFFBE6;
  --surface: #FFFFFF;
  --border: #F0E8B8;
  --text-primary: #1F1B0A;
  --text-secondary: #76705B;
  --primary: #FFE066;
  --primary-strong: #FCD034;
  --secondary: #FF7B5C;
  --hand: 'Caveat', cursive;

  /* legacy aliases — на случай оставшихся ссылок */
  --accent: #FCD034;
  --accent-hover: #F0BE1E;
  --bg-toolbar: var(--surface);
  --bg-body: var(--bg);
  --bg-sidebar: var(--surface);
  --radius: 10px;
  --shadow: 0 1px 0 var(--primary-strong);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === TOOLBAR === */
#toolbarContainer {
  background: var(--surface);
  border-bottom: 3px solid var(--primary);
  box-shadow: 0 1px 0 var(--primary-strong);
  z-index: 100;
  flex-shrink: 0;
}

/* Topbar: brand · file · actions */
#topbar {
  display: flex;
  align-items: center;
  height: 56px;
  padding: 0 18px;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -0.3px; color: var(--text-primary); flex-shrink: 0; }
.logo-mark { width: 32px; height: 32px; object-fit: contain; flex-shrink: 0; display: block; }
.logo .ink { background: linear-gradient(180deg, transparent 28%, var(--primary) 28%, var(--primary) 92%, transparent 92%); padding: 0 4px; }
.file-info { display: flex; align-items: center; gap: 8px; padding: 7px 14px; background: var(--bg); border-radius: 999px; font-size: 13px; max-width: 360px; color: var(--text-primary); }
.file-info[hidden] { display: none; }
.file-info .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-info .size { color: var(--text-secondary); flex-shrink: 0; }
.spacer { flex: 1; }
.top-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: transparent; border-radius: 50%;
  cursor: pointer; color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg); color: var(--text-primary); }
.icon-sun { display: none; }
html.dark .icon-moon { display: none; }
html.dark .icon-sun { display: inline-flex; }

#mainToolbar {
  display: flex;
  align-items: center;
  padding: 8px 18px;
  gap: 6px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toolbar-separator {
  width: 1px;
  height: 26px;
  background: var(--border);
  margin: 0 6px;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  background: transparent;
  border-radius: 12px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s, transform 0.15s;
}
.toolbar-btn:hover { background: var(--bg); color: var(--text-primary); transform: translateY(-2px); }
.toolbar-btn:active { background: var(--border); }
.toolbar-btn:disabled { opacity: 0.35; cursor: default; pointer-events: none; }
.toolbar-btn.active {
  background: var(--primary);
  color: var(--text-primary);
  transform: rotate(-3deg);
  box-shadow: 2px 2px 0 var(--text-primary);
}

/* Page nav + zoom pills */
.page-nav, .zoom-control {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--bg);
  border-radius: 999px;
  font-size: 13px;
}
#pageNumber {
  width: 34px;
  height: 26px;
  text-align: center;
  border: none;
  border-bottom: 1.5px solid var(--text-primary);
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
}
#numPages { color: var(--text-secondary); font-size: 13px; padding-right: 4px; }
.toolbar-btn.sm { width: 28px; height: 28px; border-radius: 8px; }
.toolbar-btn.sm:hover { transform: none; }

/* Scale select (sits inside .zoom-control pill) */
#scaleSelect {
  height: 28px;
  border: none;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  padding: 0 6px;
  background: transparent;
  color: var(--text-primary);
  outline: none;
  cursor: pointer;
}

/* === ANNOTATION TOOLS (inline group in toolbar) === */
#annotationToolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

/* labeled tools (icon + text) */
.anno-btn {
  width: auto !important;
  padding: 7px 12px !important;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
}
.anno-btn span { display: inline; }
.anno-btn svg { flex-shrink: 0; }

/* === SEARCH BAR === */
#searchBar {
  display: flex;
  align-items: center;
  padding: 8px 18px;
  gap: 8px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
#searchBar.hidden { display: none; }
#searchInput {
  flex: 1;
  max-width: 300px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 14px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  outline: none;
}
#searchInput:focus { border-color: var(--primary-strong); }
#searchResultCount { font-size: 12px; color: var(--text-secondary); }

/* === SIDEBAR === */
#sidebarContainer {
  width: 200px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}
#sidebarContainer.hidden { display: none; }

#thumbnailView {
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.thumbnail-item {
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 2px 2px 0 var(--border);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.thumbnail-item:hover { border-color: var(--primary-strong); }
.thumbnail-item.active {
  border-color: var(--text-primary);
  box-shadow: 3px 3px 0 var(--primary);
}
.thumbnail-item canvas { display: block; width: 100%; }
.thumbnail-label {
  text-align: center;
  font-family: var(--hand);
  font-size: 15px;
  color: var(--text-secondary);
  padding: 2px 0;
}

/* === VIEWER === */
#viewerContainer {
  overflow: auto;
  background: var(--bg);
}

#viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 0;
  gap: 12px;
}

.page-wrapper {
  background: white;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.04);
  border-radius: 2px;
  position: relative;
}

.pdf-canvas {
  display: block;
}

.anno-overlay {
  pointer-events: none;
}

/* === OCR TEXT LAYER === */
/* Transparent, selectable text positioned over a scanned page so it becomes
   selectable / copyable / searchable (Ctrl+F). Sits below the annotation overlay. */
.ocr-text-layer {
  position: absolute;
  overflow: hidden;
  line-height: 1;
  z-index: 2;
  pointer-events: auto;
  user-select: text;
  -webkit-user-select: text;
}
.ocr-text-layer span {
  position: absolute;
  color: transparent;
  white-space: pre;
  transform-origin: 0 0;
  cursor: text;
}
.ocr-text-layer span::selection { background: rgba(252, 208, 52, 0.45); }
.ocr-text-layer span::-moz-selection { background: rgba(252, 208, 52, 0.45); }

/* === MIRO-STYLE STICKERS === */
/* Rendered from native PDF annotations (Text / FreeText / Square subtypes).
   Default opacity is low so they don't obstruct reading. Hover wakes them up. */
.sticker {
  position: absolute;
  min-width: 168px;
  min-height: 86px;
  padding: 14px 16px 10px;
  font-family: 'Caveat', cursive;
  font-size: 18px;
  line-height: 1.32;
  color: #1F1B0A;
  cursor: grab;
  opacity: 0.4;
  transition: opacity 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
  box-shadow: 2px 3px 8px rgba(0, 0, 0, 0.08);
  z-index: 5;
  border-radius: 2px;
  transform: rotate(var(--rot, 0deg));
  user-select: none;
  pointer-events: auto;
  background: #FFE066;
}
.sticker::after {
  /* tape-like translucent strip at top — Post-it feel */
  content: '';
  position: absolute;
  top: -7px;
  left: calc(50% - 22px);
  width: 44px;
  height: 14px;
  background: rgba(0, 0, 0, 0.06);
  transform: rotate(-2deg);
}
.sticker:hover {
  opacity: 1;
  transform: rotate(0deg) scale(1.05);
  box-shadow: 6px 12px 26px rgba(0, 0, 0, 0.18);
  z-index: 10;
}
.sticker.dragging {
  opacity: 1 !important;
  transform: rotate(0deg) scale(1.04);
  cursor: grabbing;
  box-shadow: 8px 16px 32px rgba(0, 0, 0, 0.22);
  z-index: 20;
}
.sticker.yellow { background: #FFE066; }
.sticker.pink   { background: #FFC8DA; }
.sticker.blue   { background: #B8D8FF; }
.sticker.green  { background: #BFEDC4; }

.sticker-content {
  white-space: pre-wrap;
  word-break: break-word;
}
.sticker-meta {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  opacity: 0.55;
  margin-top: 6px;
  font-weight: 500;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

/* User-created sticker has delete button + two modes:
   - default = read (contenteditable=false, just hover/drag)
   - .editing = edit (dashed outline, text cursor, placeholder when empty)
   Double-click .sticker-content enters edit; Enter / Esc / blur exits. */
.sticker .sticker-content {
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 1.2em;
  cursor: default;
  outline: none;
}
.sticker.editing .sticker-content {
  cursor: text;
  outline: 1px dashed rgba(0, 0, 0, 0.30);
  outline-offset: 2px;
}
.sticker.editing .sticker-content:empty::before {
  content: 'Type a note…';
  opacity: 0.45;
  font-style: italic;
}

.sticker-delete {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 0;
  background: #1F1B0A;
  color: #FFE066;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.15s, transform 0.15s;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.sticker:hover .sticker-delete {
  opacity: 1;
  transform: scale(1);
}
.sticker.dragging .sticker-delete {
  opacity: 0;
  pointer-events: none;
}
.sticker-delete:hover {
  background: #C8431F;
  color: white;
}

/* Sticker tool — toolbar wrap with color swatch popover */
.anno-tool-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.anno-tool-wrap .toolbar-btn.active {
  background: #FFE066;
  color: #1F1B0A;
}

.sticker-swatches {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 100;
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
  gap: 6px;
  box-shadow: 4px 6px 18px rgba(0, 0, 0, 0.15);
}

/* OCR language picker popover */
.ocr-popover {
  display: none;
  flex-direction: column;
  gap: 8px;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 100;
  width: 230px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 4px 6px 18px rgba(0, 0, 0, 0.15);
}
.anno-tool-wrap.active .ocr-popover { display: flex; }
.ocr-popover label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.ocr-popover select {
  width: 100%;
  padding: 7px 9px;
  font: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.ocr-popover .ocr-run {
  padding: 8px 14px;
  font-weight: 700;
  font-size: 13px;
  color: #1F1B0A;
  background: var(--primary);
  border: 0;
  border-radius: 999px;
  box-shadow: 2px 2px 0 var(--primary-strong);
  cursor: pointer;
  transition: transform 0.12s;
}
.ocr-popover .ocr-run:hover { transform: translateY(-1px); }
.anno-tool-wrap.active .sticker-swatches {
  display: flex;
}
.sticker-swatch,
.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  box-shadow: 2px 2px 0 var(--text-primary);
  transition: transform 0.12s;
  outline: none;
}
.sticker-swatch:hover,
.color-swatch:hover {
  transform: scale(1.15);
}
.sticker-swatch.selected,
.color-swatch.selected {
  border-color: #1F1B0A;
  box-shadow: 0 0 0 2px white, 0 0 0 4px #1F1B0A;
}
.sticker-swatch.yellow { background: #FFE066; }
.sticker-swatch.pink   { background: #FFC8DA; }
.sticker-swatch.blue   { background: #B8D8FF; }
.sticker-swatch.green  { background: #BFEDC4; }

/* === WELCOME SCREEN === */
#welcomeScreen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background: var(--bg);
  z-index: 10;
}
#welcomeScreen.hidden { display: none; }

.welcome-content {
  text-align: center;
  max-width: 400px;
}
.welcome-content h2 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.4px;
  margin: 20px 0 8px;
  color: var(--text-primary);
}
.welcome-content p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* === BUTTONS === */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 22px;
  background: var(--text-primary);
  color: var(--primary);
  border: none;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.15s;
}
.btn-primary:hover { transform: translateY(-1px); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--bg); }

.btn-sm { padding: 5px 14px; font-size: 12px; }

/* === DROP ZONE === */
#dropZone {
  position: absolute;
  inset: 0;
  background: rgba(255, 224, 102, 0.14);
  border: 3px dashed var(--primary-strong);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  margin: 12px;
}
#dropZone.hidden { display: none; }
.drop-zone-content { text-align: center; }
.drop-zone-content p {
  margin-top: 12px;
  font-size: 16px;
  color: var(--text-primary);
  font-weight: 600;
}

/* === MODALS === */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(31, 27, 10, 0.45); }
.modal-content {
  position: relative;
  background: white;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px; }

/* Properties table */
#propertiesTable { width: 100%; border-collapse: collapse; }
#propertiesTable td {
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--bg);
}
#propertiesTable td:first-child {
  font-weight: 600;
  width: 140px;
  color: var(--text-secondary);
}

/* Sign canvas */
#signCanvas {
  width: 100%;
  height: 150px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: crosshair;
}
.sign-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  justify-content: flex-end;
}

/* === OCR PROGRESS === */
#ocrProgress {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
}
#ocrProgress.hidden { display: none; }
.ocr-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 18px;
  box-shadow: 4px 6px 18px rgba(0, 0, 0, 0.12);
  font-size: 13px;
}
.progress-track {
  width: 160px;
  height: 7px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary-strong);
  border-radius: 4px;
  transition: width 0.3s;
}

/* === NOTIFICATION BAR === */
#notificationBar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  background: var(--primary);
  border-bottom: 1px solid var(--primary-strong);
  font-size: 13px;
  color: var(--text-primary);
}
#notificationBar.hidden { display: none; }
#notificationText { flex: 1; }

.sidebar-title {
  font-family: var(--hand);
  font-size: 18px;
  color: var(--text-secondary);
  padding: 14px 16px 2px;
}

/* === RIGHT INSPECTOR PANEL (#toolPanel) === */
#toolPanel {
  width: 232px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.tp-head {
  font-family: var(--hand);
  font-size: 20px;
  color: var(--text-secondary);
  padding: 14px 16px 4px;
}
.tp-body {
  flex: 1;
  overflow-y: auto;
  padding: 6px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.tp-active {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
}
.tp-group { display: flex; flex-direction: column; gap: 8px; }
.tp-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.tp-label b { color: var(--text-primary); }
.tp-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.tp-swatch {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer; padding: 0;
  box-shadow: 2px 2px 0 var(--text-primary);
  transition: transform 0.12s;
}
.tp-swatch:hover { transform: scale(1.15); }
.tp-swatch.selected { border-color: #1F1B0A; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px #1F1B0A; }
.tp-range { width: 100%; accent-color: var(--primary-strong); cursor: pointer; }
.tp-select {
  width: 100%; padding: 7px 9px; font: inherit; font-size: 13px;
  color: var(--text-primary); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}

/* Rate us — pinned to the bottom */
.tp-rate {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: 14px 16px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.tp-rate-text { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.tp-stars { display: flex; flex-direction: row-reverse; gap: 3px; }
.tp-stars input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.tp-stars label {
  cursor: pointer; font-size: 26px; line-height: 1;
  color: var(--border);
  transition: color 0.12s, transform 0.12s;
}
.tp-stars label:hover,
.tp-stars label:hover ~ label { color: var(--primary-strong); transform: scale(1.12); }

@media (max-width: 900px) { #toolPanel { display: none; } }

/* === EMPTY STATE — пока документ не загружен, ведём к загрузке файла === */
/* всё в тулбаре приглушено и некликабельно, кроме переключателя темы;
   активны остаются welcome-кнопка «Choose PDF File» и drag-drop (они вне тулбара). */
body.no-doc #mainToolbar,
body.no-doc #toolPanel .tp-body,
body.no-doc .top-actions > :not(#themeToggle) {
  opacity: 0.4;
  filter: grayscale(0.6);
  pointer-events: none;
  user-select: none;
}

/* === DARK THEME (toggle via html.dark; tokens from variants/v4b) === */
html.dark {
  --bg: #14110A;
  --surface: #221E14;
  --border: #3A3320;
  --text-primary: #F2EAD0;
  --text-secondary: #A89E80;
  --accent: #FCD034;
  --accent-hover: #FFE066;
}
/* keep yellow chips readable on dark chrome */
html.dark .btn-primary { background: var(--primary); color: #14110A; }
html.dark .toolbar-btn.active,
html.dark .anno-tool-wrap .toolbar-btn.active {
  color: #14110A;
  box-shadow: 2px 2px 0 var(--primary-strong);
}
html.dark .thumbnail-item.active { box-shadow: 3px 3px 0 var(--primary-strong); }
html.dark .modal-content { background: var(--surface); }
/* logo highlight: in dark, make the band translucent so the light text stays readable (v4b) */
html.dark .logo .ink {
  background: linear-gradient(180deg, transparent 28%, rgba(255, 224, 102, 0.32) 28%, rgba(255, 224, 102, 0.32) 92%, transparent 92%);
}
html.dark .sticker-swatches { background: var(--surface); }
/* PDF page stays white (document), but soften its glow on dark */
html.dark .page-wrapper { box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5), 0 4px 12px rgba(0, 0, 0, 0.4); }

/* === RESPONSIVE === */
@media (max-width: 768px) {
  /* --- Topbar: let the file pill yield, keep actions visible --- */
  #topbar { padding: 0 12px; gap: 10px; }
  .file-info { min-width: 0; flex: 1 1 auto; max-width: none; padding: 6px 12px; }
  .file-info .name { min-width: 0; }
  .top-actions { gap: 4px; flex-shrink: 0; }

  /* --- Main toolbar: ONE horizontally-scrollable row (no vertical stacking) --- */
  #mainToolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px 10px;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #mainToolbar::-webkit-scrollbar { display: none; }
  #annotationToolbar { flex-wrap: nowrap; padding: 0; gap: 2px; }
  #mainToolbar > *, #annotationToolbar > * { flex: 0 0 auto; }
  #mainToolbar .spacer { flex: 0 0 8px; }

  /* icon-only tools, ≥40px touch targets */
  .anno-btn span { display: none; }
  .anno-btn { width: 40px !important; height: 40px; padding: 0 !important; gap: 0; }
  .toolbar-btn { width: 40px; height: 40px; }
  .toolbar-separator { height: 24px; margin: 0 2px; }

  /* page-nav + zoom pills compact */
  .page-nav, .zoom-control { padding: 3px 6px; gap: 2px; flex: 0 0 auto; }
  #scaleSelect { max-width: 96px; padding: 0 4px; }
  #pageNumber { width: 32px; }
  .toolbar-btn.sm { width: 32px; height: 32px; }

  /* --- Sidebar (Pages): overlay instead of crushing the page area --- */
  #sidebarContainer {
    position: absolute; left: 0; top: 0; bottom: 0;
    width: min(72vw, 260px); z-index: 60;
    box-shadow: 6px 0 20px rgba(31, 27, 10, 0.18);
  }

  /* --- Viewer: tighten gutters so the fitted page uses the width --- */
  #viewer { padding: 14px 0; gap: 8px; }
  .page-wrapper { max-width: 100%; box-shadow: 0 6px 18px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.06); }
  .pdf-canvas { max-width: 100%; height: auto; }

  /* --- Welcome --- */
  #welcomeScreen { padding: 24px 20px; }
  .welcome-content { max-width: 100%; }
  .welcome-content svg { width: 64px; height: 64px; }
  .welcome-content h2 { font-size: 22px; margin: 16px 0 8px; }
  .welcome-content p { font-size: 13px; margin-bottom: 20px; }
  .welcome-content .btn-primary { padding: 12px 24px; font-size: 15px; }

  /* --- Modals: near-full-width bottom-sheet feel --- */
  .modal { padding: 16px; align-items: flex-end; }
  .modal-content { width: 100%; max-width: none; max-height: 85vh; border-radius: 16px; }
  .sign-actions { flex-wrap: wrap; }
  .sign-actions .btn-secondary, .sign-actions .btn-primary { flex: 1; justify-content: center; min-height: 40px; }

  /* --- Notification bar --- */
  #notificationBar { padding: 8px 14px; font-size: 12px; flex-wrap: wrap; }
  #notificationText { flex: 1 1 100%; }

  /* --- OCR progress pill --- */
  #ocrProgress { left: 12px; right: 12px; transform: none; }

  /* --- Touch overlays: bigger sticker targets, no sticky :hover --- */
  .sticker { opacity: 0.9; min-width: 150px; min-height: 80px; }
  .sticker:hover { transform: rotate(0deg) scale(1); }
  .sticker-delete { width: 30px; height: 30px; top: -12px; right: -12px; opacity: 1; transform: none; }
}

@media (max-width: 480px) {
  #topbar { padding: 0 10px; gap: 8px; height: 54px; }
  .logo .ink { display: none; }          /* keep the logo icon, drop the wordmark */
  .logo { gap: 0; }
  #topbar .spacer { display: none; }
  .file-info { display: none; }            /* file name secondary on a phone — free space for actions */
  .icon-btn { width: 40px; height: 40px; }
  .btn-primary { padding: 9px 14px; font-size: 13px; }
  #viewer { padding: 10px 0; }
  .welcome-content h2 { font-size: 20px; }
}

/* Very narrow: collapse "Save" to a round icon button (the word is a bare text node) */
@media (max-width: 380px) {
  #download.btn-primary { font-size: 0; padding: 0; width: 40px; height: 40px; border-radius: 50%; }
  #download.btn-primary svg { font-size: initial; }
}
