:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #e9e9ef;
  --text: #1c1c1e;
  --text-2: #6c6c72;
  --text-3: #a1a1a8;
  --separator: rgba(60, 60, 67, 0.18);
  --accent: #1a66e0; /* azul AgneScan */
  --accent-2: #22c3e6; /* celeste AgneScan */
  --accent-soft: rgba(26, 102, 224, 0.12);
  --danger: #e5332a;
  --bar: rgba(242, 242, 247, 0.86);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --segment-active: #ffffff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #f2f2f7;
    --text-2: #98989f;
    --text-3: #636366;
    --separator: rgba(84, 84, 88, 0.6);
    --accent: #3b86f7;
    --accent-soft: rgba(59, 134, 247, 0.18);
    --danger: #ff453a;
    --bar: rgba(10, 10, 10, 0.86);
    --shadow: none;
    --segment-active: #636366;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { opacity: 0.4; cursor: default; }
svg.icon { width: 22px; height: 22px; flex: none; }

/* ---------- Pantallas ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  min-height: calc(var(--safe-top) + 52px);
  background: var(--bar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
  z-index: 2;
}
.bar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 55vw;
}
.bar > :first-child { justify-self: start; }
.bar > :last-child { justify-self: end; }

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px 24px;
}

.text-btn { color: var(--accent); font-size: 17px; padding: 6px 0; display: inline-flex; align-items: center; gap: 2px; }
.text-btn.strong { font-weight: 600; }
.text-btn.back { margin-left: -6px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--accent);
}
.icon-btn.boxed { background: var(--surface); border-radius: var(--radius); width: 52px; height: 50px; box-shadow: var(--shadow); }
.icon-btn.danger { color: var(--danger); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 18px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow);
}
.btn.primary { background: var(--accent); color: #fff; }
.btn:active, .icon-btn:active, .chip:active { transform: scale(0.97); }

.bottom-actions {
  display: flex;
  gap: 10px;
  padding: 10px 16px calc(var(--safe-bottom) + 10px);
  background: var(--bar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
}
.bottom-actions .btn { flex: 1; }

/* ---------- Biblioteca ---------- */

.search {
  width: 100%;
  border: 0;
  border-radius: 10px;
  background: var(--surface-2);
  padding: 9px 12px;
  margin-bottom: 12px;
  font-size: 17px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.doc-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.doc-list:empty { display: none; }
.doc-list li + li { border-top: 0.5px solid var(--separator); }
.doc-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 6px 10px 12px; text-align: left; }
.doc-row .thumb { width: 46px; height: 62px; flex: none; border-radius: 5px; background: var(--surface-2); object-fit: cover; border: 0.5px solid var(--separator); display: grid; place-items: center; color: var(--text-3); }
.doc-row .meta { flex: 1; min-width: 0; }
.doc-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.doc-row .sub { font-size: 14px; color: var(--text-2); }
.doc-row .date { font-size: 12px; color: var(--text-3); }

.empty { text-align: center; padding: 12vh 24px 0; color: var(--text-2); }
.empty h2 { color: var(--text); font-size: 22px; margin: 12px 0 6px; }
.empty-icon { display: inline-grid; place-items: center; width: 84px; height: 84px; border-radius: 22px; background: var(--accent-soft); color: var(--accent); }
.empty-icon svg { width: 44px; height: 44px; }

/* ---------- Nuevo PDF ---------- */

.section-title { margin: 18px 4px 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.02em; color: var(--text-2); }
.section-title:first-child { margin-top: 4px; }
.hint { margin: 6px 4px 0; font-size: 13px; color: var(--text-2); }

.group { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding: 6px 16px; }
.row + .row { border-top: 0.5px solid var(--separator); }
.row select { border: 0; background: none; color: var(--text-2); text-align: right; direction: rtl; max-width: 55%; -webkit-appearance: none; appearance: none; outline: none; }
.row-input { width: 100%; border: 0; background: none; padding: 13px 16px; outline: none; font-size: 17px; }

.switch { -webkit-appearance: none; appearance: none; width: 51px; height: 31px; border-radius: 16px; background: var(--surface-2); position: relative; transition: background 0.2s; flex: none; margin: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25); transition: transform 0.2s; }
.switch:checked { background: #34c759; }
.switch:checked::after { transform: translateX(20px); }

.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px; }
.page-card { position: relative; aspect-ratio: 3 / 4; border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; display: grid; place-items: center; }
.page-card img { width: 100%; height: 100%; object-fit: contain; background: var(--surface-2); }
.page-card .num { position: absolute; left: 6px; bottom: 6px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 13px; font-weight: 600; display: grid; place-items: center; }
.page-card .spinner { width: 26px; height: 26px; }
.add-row { display: flex; gap: 10px; margin-top: 12px; }
.add-row .btn { flex: 1; font-size: 15px; padding: 0 10px; }

/* ---------- Editor de página ---------- */

.screen.dark { background: #000; color: #fff; z-index: 5; --bar: rgba(20, 20, 20, 0.9); --separator: rgba(255, 255, 255, 0.12); --accent: #3b86f7; }
.segmented { display: flex; margin: 10px 16px 0; padding: 2px; border-radius: 9px; background: rgba(118, 118, 128, 0.24); }
.segmented button { flex: 1; padding: 6px 4px; border-radius: 7px; font-size: 14px; font-weight: 500; }
.segmented button.active { background: #636366; color: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); }
.segmented.small { margin: 0; width: 100%; }

.stage { flex: 1; position: relative; display: grid; place-items: center; overflow: hidden; min-height: 0; }
.crop-box { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; }
.crop-box img { display: block; width: 100%; height: 100%; pointer-events: none; }
.crop-box svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.crop-shade { fill: rgba(0, 0, 0, 0.45); }
.crop-edge { fill: rgba(34, 195, 230, 0.14); stroke: #22c3e6; stroke-width: 2.5; stroke-linejoin: round; }
.crop-handle { fill: rgba(255, 255, 255, 0.25); stroke: #fff; stroke-width: 3; }
.preview { max-width: calc(100% - 32px); max-height: calc(100% - 32px); object-fit: contain; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5); background: #fff; }
.stage > .spinner { position: absolute; }

.loupe {
  position: fixed;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  background-repeat: no-repeat;
  background-color: #000;
  pointer-events: none;
  z-index: 10;
}
.loupe::before, .loupe::after { content: ""; position: absolute; background: #22c3e6; }
.loupe::before { left: 50%; top: 35%; bottom: 35%; width: 2px; margin-left: -1px; }
.loupe::after { top: 50%; left: 35%; right: 35%; height: 2px; margin-top: -1px; }

.controls { display: flex; justify-content: center; gap: 10px; padding: 10px 16px 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 18px; background: rgba(118, 118, 128, 0.28); font-size: 14px; font-weight: 500; }
.chip svg { width: 18px; height: 18px; }
.pe-footer { display: flex; justify-content: space-around; padding: 8px 12px calc(var(--safe-bottom) + 8px); }
.pe-footer .icon-btn { color: #fff; }
.pe-footer #peDelete { color: #ff6961; }
.pe-next { padding: 0 16px 10px; margin-top: -4px; }
.pe-next .btn { width: 100%; }

/* ---------- Visor ---------- */

.viewer-pages { display: flex; flex-direction: column; align-items: center; gap: 14px; background: var(--surface-2); }
.viewer-pages img { width: 100%; max-width: 820px; height: auto; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18); }
.viewer-note { text-align: center; color: var(--text-2); padding: 12vh 24px 0; }
.viewer-note .btn { margin-top: 14px; }

/* ---------- Estado ---------- */

.busy { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(0, 0, 0, 0.35); }
.busy-card { min-width: 180px; max-width: 80vw; padding: 22px 24px; border-radius: 16px; background: var(--surface); color: var(--text); text-align: center; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); }
.busy-card p { margin: 12px 0 0; font-size: 15px; }
.spinner { width: 34px; height: 34px; margin: 0 auto; border-radius: 50%; border: 3px solid rgba(128, 128, 128, 0.3); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 90px);
  transform: translateX(-50%);
  z-index: 30;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 20px;
  background: rgba(40, 40, 40, 0.92);
  color: #fff;
  font-size: 15px;
  text-align: center;
}

.file-input { position: fixed; top: -100px; left: 0; width: 1px; height: 1px; opacity: 0; }

/* ---------- Cuenta ---------- */

.screen.sheet { z-index: 6; }
.account-btn { position: relative; }
.account-btn.signed-in::after {
  content: "";
  position: absolute;
  right: 9px;
  bottom: 10px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #34c759;
  border: 2px solid var(--bg);
}
.auth-form { display: flex; flex-direction: column; align-items: stretch; gap: 14px; max-width: 420px; margin: 3vh auto 0; }
.auth-form .empty-icon { align-self: center; }
.auth-intro { margin: 0; text-align: center; color: var(--text-2); }
.segmented.light { margin: 0; }
.segmented.light button.active { background: var(--segment-active); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); }
.row-input + .row-input { border-top: 0.5px solid var(--separator); }
.auth-error { margin: 0; padding: 10px 14px; border-radius: 10px; background: rgba(229, 51, 42, 0.12); color: var(--danger); font-size: 15px; }
.auth-submit { width: 100%; }
.account-email { margin: -8px 0 0; text-align: center; font-size: 19px; font-weight: 600; word-break: break-all; }
.hint.center { text-align: center; }
.danger-text { color: var(--danger); }

/* ---------- Carpetas y nube ---------- */

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: -4px 4px 10px; font-size: 14px; color: var(--text-2); }
.crumbs button { color: var(--accent); font-size: 14px; }
.crumbs .sep { color: var(--text-3); }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; padding: 10px 14px; border-radius: var(--radius); background: var(--accent-soft); font-size: 15px; }
#folderList:not(:empty) { margin-bottom: 12px; }
.folder-thumb { color: var(--accent) !important; background: var(--accent-soft) !important; border: 0 !important; height: 46px !important; }
.folder-thumb svg { width: 26px; height: 26px; }
.doc-row .date.error { color: var(--danger); }
.viewer-thumb { width: min(70%, 360px); height: auto; margin-bottom: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18); background: #fff; }

.action-sheet {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 8px calc(var(--safe-bottom) + 8px);
  background: rgba(0, 0, 0, 0.35);
  animation: fade-in 0.15s ease-out;
}
.action-card, .action-cancel { background: var(--surface); color: var(--text); border-radius: 14px; }
.action-card { max-height: 60vh; overflow-y: auto; }
.action-title { margin: 0; padding: 12px 16px; text-align: center; font-size: 13px; color: var(--text-2); border-bottom: 0.5px solid var(--separator); }
.action-item { display: block; width: 100%; padding: 15px 16px; text-align: left; font-size: 17px; color: var(--accent); }
.action-item + .action-item { border-top: 0.5px solid var(--separator); }
.action-item.danger { color: var(--danger); }
.action-item.current { color: var(--text-3); opacity: 1; }
.action-item.current::after { content: " (actual)"; }
.action-cancel { width: 100%; padding: 15px; font-size: 17px; font-weight: 600; color: var(--accent); }
@keyframes fade-in { from { opacity: 0; } }

/* ---------- Barra de progreso e importación ---------- */

.progress-bar { width: 180px; max-width: 60vw; height: 8px; margin: 14px auto 0; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--accent); transition: width 0.2s ease; }
.busy-sub { margin: 8px 0 0; font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }
.busy-sub:empty { display: none; }
.busy-stop { margin-top: 14px; padding: 8px 18px; border: 1px solid var(--border, rgba(128,128,128,.35)); border-radius: 10px; background: transparent; color: var(--text); font: inherit; font-size: 14px; cursor: pointer; }
.busy-stop:hover { background: rgba(128, 128, 128, 0.12); }
.action-item.selected { font-weight: 600; }
.action-item.selected::after { content: " ✓"; color: var(--accent); }

/* ---------- Combinar PDF ---------- */

.comb-order { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.comb-order:empty { display: none; }
.comb-order li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; background: var(--accent-soft); }
.comb-num { display: grid; place-items: center; width: 24px; height: 24px; flex: none; border-radius: 50%; background: var(--accent); color: #fff; font-size: 13px; font-weight: 700; }
.comb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.comb-check { display: grid; place-items: center; color: var(--text-3); }
.comb-check b { color: #fff; background: var(--accent); width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; }
.doc-row.selected-row { background: var(--accent-soft); }
.comb-import { width: 100%; }

/* ---------- Organizar páginas ---------- */

.org-hint { margin: 8px 16px 0; }
.org-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 12px; padding: 12px 16px; align-content: start; }
.org-card { position: relative; aspect-ratio: 3 / 4; border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; touch-action: pan-y; }
.org-card.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.org-card.dragging { opacity: 0.6; transform: scale(1.05); box-shadow: 0 6px 20px rgba(0,0,0,0.3); }
.org-thumb { width: 100%; height: 100%; display: grid; place-items: center; background: var(--surface-2); transition: transform 0.2s; }
.org-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.org-num { position: absolute; left: 6px; bottom: 6px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: rgba(0,0,0,0.6); color: #fff; font-size: 13px; font-weight: 600; display: grid; place-items: center; }
.org-check { position: absolute; top: 6px; left: 6px; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; display: none; place-items: center; }
.org-check svg { width: 16px; height: 16px; }
.org-card.selected .org-check { display: grid; }
.org-handle { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; display: grid; place-items: center; color: var(--text-2); background: var(--surface); border-radius: 8px; touch-action: none; cursor: grab; }
.org-handle svg { width: 18px; height: 18px; }
.org-actions { display: flex; justify-content: space-around; gap: 8px; padding: 8px 12px calc(var(--safe-bottom) + 8px); background: var(--bar); border-top: 0.5px solid var(--separator); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); }
.org-action { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 10px; color: var(--accent); font-size: 12px; font-weight: 500; }
.org-action.danger { color: var(--danger); }
.org-action svg { width: 24px; height: 24px; }

/* ---------- Adaptación a computador (edición en pantalla grande) ---------- */

:root { --page: 1040px; --page-wide: 1240px; }

/* Centra el contenido en pantallas anchas; en el teléfono deja 16px de margen. */
.bar,
.scroll,
.bottom-actions,
.org-actions,
.org-hint { padding-inline: max(16px, calc((100% - var(--page)) / 2)); }
.org-grid { padding-inline: max(16px, calc((100% - var(--page-wide)) / 2)); }

@media (min-width: 768px) {
  /* Las miniaturas de páginas (nuevo PDF y organizar) aprovechan el ancho. */
  .page-grid, .org-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }

  /* Menús: diálogo centrado en lugar de hoja que sube desde abajo. */
  .action-sheet { align-items: center; justify-content: center; padding: 24px; }
  .action-card, .action-cancel { width: 420px; max-width: 90vw; }
  .action-card { border-radius: 16px; max-height: 70vh; }

  /* Barra de acciones de organizar: botones agrupados al centro, no estirados. */
  .org-actions { justify-content: center; gap: 28px; }
  .org-action { padding: 6px 18px; }
}

/* Estados al pasar el cursor (solo con ratón). */
@media (hover: hover) {
  .doc-row:hover { background: var(--surface-2); }
  .btn:hover:not(:disabled), .icon-btn:hover:not(:disabled), .chip:hover { filter: brightness(1.06); }
  .org-card:hover { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2); }
  .org-handle:hover { color: var(--accent); }
  .action-item:hover:not(:disabled) { background: var(--surface-2); }
  .text-btn:hover { opacity: 0.6; }
  .crumbs button:hover { text-decoration: underline; }
  .org-action:hover { filter: brightness(1.08); }
}

/* ---------- Anotar / firmar ---------- */

.ann-tools { display: flex; align-items: center; gap: 6px; padding: 8px max(16px, calc((100% - var(--page-wide)) / 2)); overflow-x: auto; background: var(--bar); border-bottom: 0.5px solid var(--separator); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); }
.ann-tool { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 12px; border-radius: 10px; color: var(--text-2); font-size: 11px; font-weight: 500; flex: none; }
.ann-tool svg { width: 22px; height: 22px; }
.ann-tool.active { background: var(--accent-soft); color: var(--accent); }
.ann-tool.danger { color: var(--danger); margin-left: auto; }
.ann-color { width: 38px; height: 38px; flex: none; padding: 0; border: none; border-radius: 10px; background: none; cursor: pointer; }
.ann-color::-webkit-color-swatch { border: 2px solid var(--separator); border-radius: 8px; }
.ann-color::-webkit-color-swatch-wrapper { padding: 2px; }
.ann-hint { margin: 8px max(16px, calc((100% - var(--page-wide)) / 2)) 0; }

.ann-pages { display: flex; flex-direction: column; align-items: center; gap: 16px; background: var(--surface-2); padding-block: 16px; }
.ann-page { position: relative; width: 100%; max-width: 820px; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18); container-type: size; touch-action: pan-y; }
.ann-page img { display: block; width: 100%; height: 100%; pointer-events: none; }
.ann-layer { position: absolute; inset: 0; }
.ann-item { position: absolute; }
.ann-item.selected { outline: 2px dashed var(--accent); outline-offset: 2px; }
.ann-text { white-space: pre; line-height: 1.15; transform: translateY(-2%); pointer-events: auto; }
.ann-redact, .ann-highlight { pointer-events: auto; }
.ann-highlight { mix-blend-mode: multiply; opacity: 0.35; }
.ann-draw { pointer-events: none; }
.ann-draw svg { width: 100%; height: 100%; overflow: visible; }
.ann-draw.selected { outline: 2px dashed var(--accent); }

@media (min-width: 768px) {
  .ann-tools { justify-content: center; }
  .ann-tool:hover { background: var(--surface-2); }
}

/* Paleta de colores e imagen de firma en Anotar */
.ann-sep { width: 1px; align-self: stretch; margin: 4px 4px; background: var(--separator); flex: none; }
.ann-palette { display: flex; align-items: center; gap: 5px; flex: none; }
.ann-chip { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; flex: none; padding: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15); }
.ann-chip.active { border-color: var(--text); }
.ann-image { pointer-events: auto; }
.ann-image img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }

/* Timbre (sello con datos y folio) en Anotar */
.ann-stamp { border: 2px solid; border-radius: 3px; background: rgba(255, 255, 255, 0.85); display: flex; flex-direction: column; justify-content: center; padding: 1% 2.5%; overflow: hidden; pointer-events: auto; box-sizing: border-box; line-height: 1.2; }
.ann-stamp-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ann-stamp-line.head { font-weight: 700; }

/* Firma a mano alzada: seleccionable/movible por su recuadro */
.ann-draw { pointer-events: auto; }
.ann-draw svg { pointer-events: none; }
.ann-chip[style*="#ffffff"], .ann-chip[style*="rgb(255, 255, 255)"] { box-shadow: inset 0 0 0 1px var(--separator); }

/* Anotar: barra de herramientas a la izquierda en computador */
.ann-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
@media (min-width: 768px) {
  .ann-body { flex-direction: row; }
  .ann-side { width: 230px; flex: none; display: flex; flex-direction: column; border-right: 0.5px solid var(--separator); overflow-y: auto; background: var(--bar); }
  .ann-side .ann-tools { flex-direction: column; align-items: stretch; overflow: visible; padding: 10px; gap: 4px; border-bottom: none; justify-content: flex-start; }
  .ann-side .ann-tool { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 11px 14px; font-size: 15px; border-radius: 10px; }
  .ann-side .ann-tool.danger { margin-left: 0; }
  .ann-side .ann-sep { width: auto; height: 1px; align-self: stretch; margin: 6px 10px; }
  .ann-side .ann-palette { flex-wrap: wrap; padding: 6px 12px; gap: 8px; }
  .ann-hint { margin: 4px 14px 12px; }
  .ann-pages { flex: 1; min-width: 0; }
}

/* Control de tamaño de letra en Anotar */
.ann-sizes { display: flex; align-items: center; gap: 2px; flex: none; }
.ann-size { width: 34px; height: 38px; display: grid; place-items: center; border-radius: 8px; color: var(--text-2); line-height: 1; }
.ann-size.active { background: var(--accent-soft); color: var(--accent); }
@media (hover: hover) { .ann-size:hover { background: var(--surface-2); } }
@media (min-width: 768px) {
  .ann-side .ann-sizes { padding: 4px 12px; justify-content: flex-start; }
}

/* Visor con lector de PDF nativo (computador) */
.viewer-embed { width: 100%; flex: 1; min-height: 85vh; border: 0; background: #fff; border-radius: 4px; }

/* Panel de firmas guardadas */
.firmas-card { width: 420px; max-width: 92vw; }
.firmas-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; padding: 12px; max-height: 50vh; overflow-y: auto; }
.firma-item { position: relative; aspect-ratio: 3 / 2; border-radius: 8px; background: #fff; border: 0.5px solid var(--separator); overflow: hidden; }
.firma-item img { width: 100%; height: 100%; object-fit: contain; cursor: pointer; }
.firma-del { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: rgba(0,0,0,0.55); color: #fff; }
.firma-del svg { width: 16px; height: 16px; }

/* El visor aprovecha todo el ancho (imágenes centradas, embed a ancho completo) */
.viewer-pages { padding-inline: 16px; }

/* ---------- Biblioteca estilo panel (dashboard) ---------- */

/* Tonos propios de la biblioteca; en modo oscuro, azul noche como el diseño. */
#library {
  --lib-bg: var(--bg);
  --lib-side: var(--surface);
  --lib-card: var(--surface);
  --lib-card-2: var(--surface-2);
  --lib-line: var(--separator);
}
@media (prefers-color-scheme: dark) {
  #library {
    --lib-bg: #0b0f19;
    --lib-side: #0f1522;
    --lib-card: #131a29;
    --lib-card-2: #1a2235;
    --lib-line: rgba(148, 163, 184, 0.16);
    --separator: rgba(148, 163, 184, 0.16);
    --surface: #131a29;
    --surface-2: #1a2235;
    --bar: rgba(11, 15, 25, 0.88);
  }
}
#library { background: var(--lib-bg); }

.lib-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.lib-side { display: none; }

/* Barra superior con buscador */
.lib-topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.search-wrap {
  flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 12px; min-height: 42px;
  border-radius: 10px; background: var(--lib-card-2); color: var(--text-3); border: 0.5px solid var(--lib-line);
}
.search-wrap svg { width: 18px; height: 18px; }
.search-wrap .search { margin: 0; padding: 9px 0; background: none; border-radius: 0; font-size: 16px; color: var(--text); }
.search-wrap:focus-within { border-color: var(--accent); }
.top-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 14px; border-radius: 10px;
  background: var(--lib-card); border: 0.5px solid var(--lib-line); font-size: 14px; font-weight: 600; white-space: nowrap;
}
.top-btn svg { width: 18px; height: 18px; color: var(--accent); }

/* Encabezado */
.lib-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.lib-head h2 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.lib-count { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--lib-card-2); color: var(--text-2); }
.lib-lead { margin: 4px 0 18px; font-size: 14px; color: var(--text-2); }
.section-row { display: flex; align-items: center; justify-content: space-between; margin: 20px 2px 10px; }
.section-title { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-2); }
.section-count { font-size: 12px; color: var(--accent); font-weight: 600; }

/* Tarjetas de carpeta */
.folder-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.folder-grid:empty { display: none; }
.folder-card {
  display: flex; flex-direction: column; gap: 4px; width: 100%; height: 100%; padding: 14px; text-align: left; cursor: pointer;
  border-radius: 14px; background: var(--lib-card); border: 0.5px solid var(--lib-line); box-shadow: var(--shadow);
}
.fc-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 8px; }
.fc-icon {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 11px;
  color: var(--fc); background: color-mix(in srgb, var(--fc) 18%, transparent);
}
.fc-icon svg { width: 22px; height: 22px; fill: currentColor; fill-opacity: 0.25; }
.fc-more { width: 32px; height: 32px; margin: -6px -8px 0 0; color: var(--text-3); }
.fc-name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-sub { font-size: 13px; color: var(--text-2); }
.fc-foot { margin-top: auto; padding-top: 10px; font-size: 12px; color: var(--text-3); }

/* Lista de documentos */
#library .doc-list { background: none; border-radius: 0; overflow: visible; display: flex; flex-direction: column; gap: 8px; }
#library .doc-list li + li { border-top: 0; }
#library .doc-row {
  cursor: pointer; border-radius: 14px; background: var(--lib-card); border: 0.5px solid var(--lib-line);
  padding: 10px 8px 10px 12px; box-shadow: var(--shadow);
}
.pdf-thumb { position: relative; color: var(--accent) !important; background: var(--accent-soft) !important; border: 0 !important; }
.pdf-thumb b { position: absolute; bottom: 6px; font-size: 9px; font-weight: 800; color: #fff; background: var(--accent); padding: 1px 4px; border-radius: 3px; }
.pdf-thumb svg { margin-top: -10px; }
.name-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.name-line .name { min-width: 0; }
.tag { flex: none; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.tag.warn { color: #f5a524; background: rgba(245, 165, 36, 0.14); }
.row-actions { display: flex; align-items: center; flex: none; }
.row-actions .icon-btn { width: 38px; height: 38px; color: var(--text-2); }
.row-actions .icon-btn svg { width: 19px; height: 19px; }
.row-btn { display: none; }
.desk-only { display: none !important; }

/* Zona para soltar archivos */
.drop-zone {
  display: none; flex-direction: column; align-items: center; gap: 4px; margin-top: 16px; padding: 26px 16px; cursor: pointer;
  border: 1.5px dashed var(--lib-line); border-radius: 14px; color: var(--text-2); text-align: center;
}
.drop-zone svg { width: 30px; height: 30px; color: var(--text-3); margin-bottom: 4px; }
.drop-zone strong { color: var(--text); font-size: 15px; }
.drop-zone small { font-size: 12px; color: var(--text-3); }
#library.dragging .drop-zone { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
#library.dragging .drop-zone svg { color: var(--accent); }

/* Teléfono: más compacto (el título ya está en la barra y el + tiene «Nueva carpeta»). */
@media (max-width: 767px) {
  .top-btn, .lib-lead, .fc-foot { display: none; }
  .lib-head h2 { font-size: 20px; }
  .lib-head { margin-bottom: 4px; }
  .folder-card { padding: 12px; }
  .fc-top { margin-bottom: 4px; }
  .fc-icon { width: 36px; height: 36px; }
  .name-line { flex-wrap: wrap; gap: 2px 8px; }
}

@media (min-width: 768px) {
  .lib-body { flex-direction: row; }
  #library > .bar, #library .bottom-actions { display: none; }

  /* Menú lateral */
  .lib-side {
    display: flex; flex-direction: column; width: 264px; flex: none; min-height: 0;
    background: var(--lib-side); border-right: 0.5px solid var(--lib-line);
  }
  .side-brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px 14px; }
  .side-logo { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--accent); color: #fff; flex: none; }
  .side-logo svg { width: 22px; height: 22px; }
  .side-brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
  .side-brand-text strong { font-size: 16px; }
  .side-brand-text small { font-size: 12px; color: var(--text-3); }
  .cloud-badge { margin-left: auto; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; color: #30a46c; background: rgba(48, 164, 108, 0.15); }

  .side-nav { flex: 1; overflow-y: auto; padding: 4px 12px 12px; display: flex; flex-direction: column; gap: 2px; }
  .side-scan {
    display: flex; align-items: center; justify-content: center; gap: 10px; margin: 2px 0 14px; min-height: 46px; border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #22c3e6)); color: #fff; font-weight: 700; font-size: 15px;
    box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
  }
  .side-heading { display: flex; align-items: center; justify-content: space-between; margin: 14px 8px 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); }
  .side-heading-btn { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; color: var(--text-3); }
  .side-heading-btn svg { width: 16px; height: 16px; }
  .side-item {
    display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 10px; border-radius: 9px;
    font-size: 14px; color: var(--text-2); text-align: left;
  }
  .side-item svg { width: 19px; height: 19px; color: var(--text-3); }
  .side-item.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
  .side-item.active svg { color: var(--accent); }
  .side-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .side-count { font-size: 12px; color: var(--text-3); }
  .side-item.active .side-count { color: var(--accent); font-weight: 700; }
  .side-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dot); flex: none; margin: 0 5px; }
  .side-empty { margin: 4px 10px; font-size: 13px; color: var(--text-3); }

  .side-foot { border-top: 0.5px solid var(--lib-line); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
  .storage-box { padding: 12px; border-radius: 12px; background: var(--lib-card-2); }
  .storage-row { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--text-2); }
  .storage-row strong { color: var(--text); }
  .storage-row.small { font-size: 11px; color: var(--text-3); }
  .storage-bar { height: 6px; margin: 8px 0 6px; border-radius: 999px; background: var(--lib-line); overflow: hidden; }
  .storage-bar span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
  .side-profile { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: 12px; text-align: left; }
  .side-profile > svg { width: 18px; height: 18px; color: var(--text-3); flex: none; }
  .avatar {
    display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; flex: none; font-size: 14px; font-weight: 700; color: #fff;
    background: linear-gradient(135deg, #1d6fe8, #22c3e6);
  }
  .avatar.guest { background: var(--lib-card-2); color: var(--text-2); }
  .avatar svg { width: 20px; height: 20px; }
  .profile-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
  .profile-meta strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-transform: capitalize; }
  .profile-meta small { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Contenido principal */
  .lib-body .lib-main { flex: 1; padding: 22px 32px 40px; }
  .lib-head h2 { font-size: 26px; }
  .folder-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
  .folder-card { min-height: 150px; padding: 16px; }
  #library .doc-row { padding: 12px 14px; gap: 14px; }
  .row-btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; margin-right: 4px; border-radius: 9px;
    background: var(--lib-card-2); border: 0.5px solid var(--lib-line); font-size: 13px; font-weight: 600; color: var(--text);
  }
  .row-btn svg { width: 15px; height: 15px; }
  .desk-only { display: inline-grid !important; }
  .drop-zone { display: flex; }
}

@media (hover: hover) {
  .side-item:hover:not(.active), .side-profile:hover, .side-heading-btn:hover { background: var(--lib-card-2); color: var(--text); }
  .folder-card:hover { border-color: color-mix(in srgb, var(--fc) 55%, transparent); transform: translateY(-1px); }
  .folder-card { transition: transform 0.12s, border-color 0.12s; }
  #library .doc-row:hover { background: var(--lib-card-2); }
  .row-btn:hover { border-color: var(--accent); }
  .drop-zone:hover { border-color: var(--accent); color: var(--accent); }
  .top-btn:hover { border-color: var(--accent); }
  .side-scan:hover { filter: brightness(1.07); }
}


/* ---------- Favoritos ---------- */
.star-btn svg, .fav-btn svg, .fav-star svg { transition: transform 0.15s; }
.star-btn.on, .fav-btn.on { color: #f5a524 !important; }
.star-btn.on svg, .fav-btn.on svg, .fav-star svg { fill: currentColor; }
.row-actions .star-btn:not(.on) { color: var(--text-3); }
.star-btn:active svg, .fav-btn:active svg { transform: scale(1.25); }

.fav-list {
  list-style: none; margin: 0; padding: 2px 2px 6px; display: grid; gap: 10px;
  grid-auto-flow: column; grid-auto-columns: minmax(220px, 78%); overflow-x: auto; scroll-snap-type: x mandatory;
}
.fav-list:empty { display: none; }
.fav-list li { scroll-snap-align: start; }
.fav-chip {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; text-align: left;
  border-radius: 14px; background: var(--lib-card); border: 0.5px solid var(--lib-line); box-shadow: var(--shadow);
}
.fav-thumb {
  width: 38px; height: 48px; flex: none; border-radius: 6px; object-fit: cover; display: grid; place-items: center;
  color: var(--accent); background: var(--accent-soft);
}
.fav-thumb svg { width: 20px; height: 20px; }
.fav-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.fav-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-meta small { font-size: 12px; color: var(--text-3); }
.fav-star { color: #f5a524; flex: none; }
.fav-star svg { width: 18px; height: 18px; }

@media (min-width: 768px) {
  .fav-list { grid-auto-flow: row; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); grid-auto-columns: auto; overflow: visible; }
}
@media (hover: hover) {
  .fav-chip:hover { border-color: #f5a524; }
  .row-actions .star-btn:hover { color: #f5a524; }
}

/* ---------- Marca AgneScan ---------- */
@media (min-width: 768px) {
  img.side-logo { width: 42px; height: 42px; padding: 0; background: none; border-radius: 0; object-fit: contain; }
}
.wordmark { display: inline-flex; font-weight: 800; letter-spacing: 0.03em; font-size: 17px !important; }
.wordmark span:first-child { color: #13398a; }
.wordmark span:last-child {
  background: linear-gradient(90deg, #1d8fe8, #22c3e6); -webkit-background-clip: text; background-clip: text; color: transparent;
}
@media (prefers-color-scheme: dark) {
  .wordmark span:first-child { color: #dbe7ff; }
}

/* ---------- Ajustes del resultado (brillo, contraste…) ---------- */
.adjust-bar { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 10px; }
.adjust-bar .chip.active { background: var(--accent); color: #fff; }
.adjust-panel { display: grid; gap: 4px; margin: 10px auto 0; max-width: 520px; width: 100%; }
.adjust-row { display: grid; grid-template-columns: 84px 1fr 40px; align-items: center; gap: 10px; font-size: 14px; color: #fff; }
.adjust-row output { text-align: right; font-variant-numeric: tabular-nums; color: rgba(255, 255, 255, 0.7); font-size: 13px; }
.adjust-row input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }
#filterControls { flex-direction: column; align-items: stretch; }
#filterControls .segmented { align-self: center; }
