/* Velasolo — foglio di stile
   Palette definita una sola volta su :root, ridefinita nei blocchi tema. */

:root {
  --bg: #0D1016;
  --panel: #151A21;
  --panel-2: #1A202A;
  --line: #262D38;
  --text: #E6EAF0;
  --muted: #8B96A5;
  --accent: #D8A657;
  --accent-ink: #1A1206;
  --mark: #000000;
  --mark-line: #E5534B;
  --ok: #4FB477;
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="light"] {
  --bg: #F5F0E8;
  --panel: #FFFFFF;
  --panel-2: #FAF6F0;
  --line: #DED8CE;
  --text: #1A1D22;
  --muted: #6A7280;
  --accent: #8A5A00;
  --accent-ink: #FFFFFF;
  --mark: #000000;
  --mark-line: #C4342B;
  --ok: #2E7D4F;
  --shadow: 0 8px 28px rgba(0, 0, 0, .12);
}

@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #F5F0E8;
    --panel: #FFFFFF;
    --panel-2: #FAF6F0;
    --line: #DED8CE;
    --text: #1A1D22;
    --muted: #6A7280;
    --accent: #8A5A00;
    --accent-ink: #FFFFFF;
    --mark-line: #C4342B;
    --ok: #2E7D4F;
    --shadow: 0 8px 28px rgba(0, 0, 0, .12);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- barra superiore ---------- */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar-start { display: flex; align-items: center; gap: 10px; }

/* Il marchio e' il comando per tornare alla pagina iniziale. */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font: inherit;
  font-weight: 600;
  letter-spacing: .2px;
  color: var(--text);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 4px 8px;
  margin-inline-start: -8px;
  cursor: pointer;
}

.brand:hover, .brand:focus-visible { border-color: var(--line); }

/* La freccia compare solo dentro una sezione: nella pagina iniziale
   non c'e' nessun posto da cui tornare. */
.back .arrow { font-size: 17px; line-height: 1; }
:root[dir="rtl"] .back .arrow,
[dir="rtl"] .back .arrow { display: inline-block; transform: scaleX(-1); }

.brand-mark {
  width: 34px;
  height: 14px;
  background: var(--mark);
  border: 1px solid var(--line);
  border-radius: 2px;
  display: inline-block;
}

:root[data-theme="light"] .brand-mark,
:root[data-theme="auto"] .brand-mark { border-color: transparent; }

.brand-name { font-size: 15px; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- controlli ---------- */

.btn {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 14px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, opacity .12s ease;
}

.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}

.btn-wide { width: 100%; margin-top: 10px; }
.btn-quiet { color: var(--muted); }

.select, .input {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
}

.select-wide { width: 100%; }
.input { flex: 1 1 auto; min-width: 0; }

/* ---------- menù ---------- */

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 34px;
  padding: 0;
  font: inherit;
  font-size: 18px;
  line-height: 1;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.icon-btn:hover, .icon-btn:focus-visible { border-color: var(--accent); }

.bars { display: flex; flex-direction: column; gap: 3px; width: 16px; }
.bars i { display: block; height: 2px; background: currentColor; border-radius: 1px; }

.menu-wrap { position: relative; }

.menu {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  z-index: 40;
  min-width: 232px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.menu-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 2px 6px 6px;
}

.menu-sep { height: 1px; background: var(--line); margin: 6px 0; }

.menu-item {
  font: inherit;
  text-align: start;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 7px;
  padding: 8px 10px;
  cursor: pointer;
}

.menu-item:hover, .menu-item:focus-visible { background: var(--panel-2); }

.menu-foot { font-size: 11px; color: var(--muted); padding: 2px 6px; }

.menu-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
}

.menu-check:hover { background: var(--panel-2); }
.menu-check input { accent-color: var(--accent); flex: 0 0 auto; }
.menu-check input:disabled { cursor: not-allowed; }
.menu-check:has(input:disabled) { cursor: default; opacity: .75; }

.menu-note {
  margin: 0;
  padding: 0 10px 4px;
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
}

.menu-note:empty { display: none; }

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 2px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.seg-btn {
  font: inherit;
  font-size: 12.5px;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 6px 4px;
  cursor: pointer;
}

.seg-btn[aria-checked="true"] {
  color: var(--accent-ink);
  background: var(--accent);
  font-weight: 600;
}

/* ---------- sezione di lettura ---------- */

.reader {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 40px 28px 72px;
}

.reader-inner { max-width: 62ch; margin: 0 auto; }

.reader h1 {
  margin: 0 0 22px;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -.01em;
}

.reader h3 {
  margin: 26px 0 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.reader .q { margin: 26px 0 6px; font-weight: 600; font-size: 15.5px; }
.reader p { margin: 0 0 11px; line-height: 1.65; }
.reader p:last-child { margin-bottom: 0; }

.todo-note {
  margin-top: 26px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

/* ---------- striscia privacy ---------- */

.privacy-strip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}

.privacy-strip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  flex: 0 0 auto;
}

.strip-tag {
  flex: 0 0 auto;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .04em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.strip-tag-strong {
  border-color: color-mix(in srgb, var(--ok) 45%, transparent);
  color: var(--ok);
}

/* ---------- impianto ---------- */

.layout {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.sidebar {
  flex: 0 0 300px;
  overflow-y: auto;
  background: var(--panel);
  border-inline-end: 1px solid var(--line);
  padding: 14px;
}

.viewer {
  flex: 1 1 auto;
  overflow-y: auto;
  position: relative;
  padding: 20px;
}

/* ---------- pannelli ---------- */

.panel {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-head .panel-title { margin-bottom: 8px; }

.head-tools { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }

.mini {
  font: inherit;
  font-size: 15px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  width: 26px;
  height: 24px;
  cursor: pointer;
}

.mini:hover:not(:disabled), .mini:focus-visible { color: var(--text); border-color: var(--line); }
.mini:disabled { opacity: .3; cursor: default; }

.badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 20px;
  padding: 1px 9px;
}

.badge-quiet {
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
}

.badge-ok {
  color: #FFFFFF;
  background: var(--ok);
  border-color: var(--ok);
}

.hint, .warn {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 10px;
}

.warn {
  border-inline-start: 2px solid var(--accent);
  padding-inline-start: 9px;
}

.muted { color: var(--muted); }

.doc-info { font-size: 13px; word-break: break-word; }
.doc-info strong { color: var(--text); font-weight: 600; }

.row { display: flex; gap: 8px; }

.field { display: block; font-size: 12px; color: var(--muted); }
.field span { display: block; margin-bottom: 5px; }

.checks { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }

.group-title {
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.checks .group-title:first-child { margin-top: 0; }

.hint-tight { margin: 6px 0 0; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.check input { accent-color: var(--accent); }
.check .count { margin-left: auto; font-size: 11px; color: var(--muted); }

label.check { margin-top: 8px; }

.range-row { margin-top: 10px; align-items: center; }
.range-row .dash { color: var(--muted); }
.input.num { width: 100%; min-width: 0; text-align: center; padding: 6px 4px; }

/* ---------- barra dell'ingrandimento ---------- */

.zoombar {
  position: sticky;
  bottom: 14px;
  margin: 0 auto;
  width: max-content;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 5;
}

.zb {
  font: inherit;
  font-size: 15px;
  line-height: 1;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 999px;
  min-width: 32px;
  height: 30px;
  cursor: pointer;
}

.zb:hover:not(:disabled) { background: var(--panel-2); }
.zb:disabled { opacity: .35; cursor: default; }

.zb-level {
  font-size: 12.5px;
  font-weight: 600;
  min-width: 58px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.input.area {
  width: 100%;
  resize: vertical;
  min-height: 78px;
  font-size: 13px;
  line-height: 1.5;
  margin-top: 4px;
}

.term-results {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.term-results li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12.5px;
}

.term-results .tr-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.term-results .tr-n { flex: 0 0 auto; color: var(--muted); font-variant-numeric: tabular-nums; }

/* un termine che non compare da nessuna parte e' un avviso, non un dato */
.term-results li.zero .tr-name { color: var(--muted); }
.term-results li.zero .tr-n { color: var(--mark-line); }

/* ---------- elenco marcature ---------- */

.mark-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
}

.mark-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.mark-list li:last-child { border-bottom: 0; }
.mark-list .m-page { color: var(--muted); flex: 0 0 auto; }
.mark-list .m-label { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mark-list .m-del {
  flex: 0 0 auto;
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 4px;
}

.mark-list .m-del:hover { color: var(--mark-line); }

/* ---------- zona di rilascio ---------- */

.dropzone {
  position: absolute;
  inset: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--line);
  border-radius: 14px;
  text-align: center;
  padding: 24px;
}

.dropzone.hot { border-color: var(--accent); background: rgba(216, 166, 87, .06); }
.dropzone-inner { max-width: 380px; }

.dz-mark {
  width: 120px;
  height: 26px;
  background: var(--mark);
  border-radius: 3px;
  margin: 0 auto 18px;
}

.dz-title { font-size: 19px; margin: 0 0 8px; font-weight: 600; }
.dz-sub { font-size: 13px; color: var(--muted); margin: 0; }

/* ---------- pagine ---------- */

.pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.page-wrap {
  position: relative;
  box-shadow: var(--shadow);
  background: #FFFFFF;
  line-height: 0;
}

.page-wrap canvas { display: block; }

.page-num {
  position: absolute;
  top: -9px;
  inset-inline-start: -9px;
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 11px;
  padding: 1px 7px;
  line-height: 1.6;
  z-index: 3;
}

.mark-layer {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  z-index: 2;
}

.mark-box {
  position: absolute;
  background: var(--mark);
  outline: 1px solid var(--mark-line);
  outline-offset: -1px;
}

.mark-box.manual { outline-style: dashed; }

.mark-box .x {
  position: absolute;
  top: -9px;
  inset-inline-end: -9px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--mark-line);
  color: #fff;
  border: 0;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  padding: 0;
  opacity: 0;
  transition: opacity .12s ease;
}

.mark-box:hover .x { opacity: 1; }

.drawing {
  position: absolute;
  background: rgba(0, 0, 0, .55);
  outline: 1px dashed var(--mark-line);
}

/* ---------- velo di attesa ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.overlay-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px 28px;
  text-align: center;
  min-width: 280px;
  box-shadow: var(--shadow);
}

.overlay-box p { margin: 12px 0; font-size: 13px; }

.spinner {
  width: 26px;
  height: 26px;
  margin: 0 auto;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.progress {
  height: 4px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .2s ease;
}

[hidden] { display: none !important; }

/* ---------- schermi stretti ---------- */

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { flex: 0 0 auto; max-height: 45vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .topbar { flex-wrap: wrap; }
}
