/* ===== Token ===== */
:root {
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --ink: #17221d;
  --muted: #5b6b63;
  --line: #d9e1dd;
  --brand: #0f5132;
  --brand-ink: #0f5132;
  --brand-soft: #dcefe4;
  --accent: #f2b705;
  --accent-soft: #fff4cc;
  --danger: #b42318;
  --danger-soft: #fde7e4;
  --info: #175cd3;
  --info-soft: #e1ecfe;
  --ok: #067647;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 40, 30, .06), 0 4px 16px rgba(16, 40, 30, .06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1513;
  --surface: #17201c;
  --surface-2: #1f2a25;
  --ink: #e6eeea;
  --muted: #9db0a6;
  --line: #2c3a33;
  --brand: #3ccf8e;
  --brand-ink: #0f5132;
  --brand-soft: #1b3a2c;
  --accent: #f2b705;
  --accent-soft: #3a3110;
  --danger: #ff8a7a;
  --danger-soft: #3d1d19;
  --info: #84adff;
  --info-soft: #1a2a45;
  --ok: #4ade80;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  color-scheme: dark;
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  font-size: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--brand); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); }
h2 { font-size: 1.35rem; margin-top: 1.4em; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
ul, ol { padding-left: 1.3em; margin: 0 0 1em; }
li { margin-bottom: .35em; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip { position: absolute; left: -999px; top: 8px; background: var(--accent); color: #000; padding: 8px 12px; z-index: 99; border-radius: 8px; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ===== Topbar ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: #0f5132;
  color: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-size: 1.25rem; white-space: nowrap; }
.brand svg { width: 32px; height: 32px; }
.brand svg path:last-child { stroke: #0f5132; }
.brand b { color: var(--accent); }
.search { flex: 1; max-width: 560px; margin-left: auto; }
.search input {
  width: 100%; padding: 10px 14px; border-radius: 999px; border: 0;
  background: rgba(255,255,255,.14); color: #fff; font: inherit;
}
.search input::placeholder { color: rgba(255,255,255,.75); }
.search input:focus { background: #fff; color: #111; outline: none; }
.icon-btn { background: rgba(255,255,255,.14); color: #fff; border: 0; border-radius: 999px; width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn svg { width: 20px; height: 20px; }

/* ===== Layout ===== */
.layout { display: flex; flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; }
.sidenav {
  position: sticky; top: 60px; align-self: flex-start;
  width: 220px; flex: none; padding: 20px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.sidenav a, .sidenav .nav-btn {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: 10px;
  color: var(--ink); text-decoration: none; font-weight: 500;
}
.sidenav .nav-btn { border: 0; background: none; font: inherit; font-weight: 500; text-align: left; cursor: pointer; width: 100%; }
.sidenav a:hover, .sidenav .nav-btn:hover { background: var(--surface-2); }
.sidenav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.sidenav .ico { width: 22px; text-align: center; font-size: 1.05rem; }
main { flex: 1; min-width: 0; padding: 24px 24px 48px; }
main:focus { outline: none; }
.footer { border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; padding: 16px 24px 24px; text-align: center; }
.footer p { max-width: 900px; margin: 0 auto; }

/* ===== Components ===== */
.hero {
  background: linear-gradient(135deg, #0f5132 0%, #1a7a4c 100%);
  color: #fff; border-radius: var(--radius); padding: 32px;
  position: relative; overflow: hidden; margin-bottom: 28px;
}
.hero::after {
  content: ""; position: absolute; right: -40px; bottom: -40px; width: 220px; height: 220px;
  background: repeating-linear-gradient(45deg, var(--accent) 0 18px, #1c1c1c 18px 36px);
  opacity: .25; border-radius: 50%;
}
.hero h1 { color: #fff; }
.hero p { max-width: 640px; opacity: .92; font-size: 1.05rem; }
.hero .btn { background: var(--accent); color: #1c1c1c; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; border: 0; cursor: pointer;
  background: var(--brand); color: #fff; font: inherit; font-weight: 600; text-decoration: none;
}
:root[data-theme="dark"] .btn { color: #0b1a13; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.btn.small { padding: 6px 12px; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px;
  color: inherit; text-decoration: none; transition: transform .12s, border-color .12s;
}
a.card:hover { transform: translateY(-2px); border-color: var(--brand); }
.card h3 { margin: 0; }
.card p { margin: 0; color: var(--muted); font-size: .95rem; }
.card .meta { margin-top: auto; padding-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }

.tag {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.tag.brand { background: var(--brand-soft); color: var(--brand); }
.tag.accent { background: var(--accent-soft); color: #7a5a00; }
:root[data-theme="dark"] .tag.accent { color: var(--accent); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.info { background: var(--info-soft); color: var(--info); }

.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.section-head p { color: var(--muted); margin: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 6px 14px; border-radius: 999px; cursor: pointer; font: inherit; font-size: .9rem;
}
.chip[aria-pressed="true"], .chip[aria-current="page"] { background: var(--brand); border-color: var(--brand); color: #fff; }
:root[data-theme="dark"] .chip[aria-pressed="true"], :root[data-theme="dark"] .chip[aria-current="page"] { color: #0b1a13; }
.filters.sub { margin-top: -8px; }
.filters.sub .chip { font-size: .82rem; padding: 4px 12px; }
.filters.grav { align-items: center; padding-top: 10px; border-top: 1px dashed var(--line); }
.filters.grav .chip { font-size: .82rem; padding: 4px 12px; }
.filters-label { font-size: .82rem; font-weight: 700; color: var(--muted); margin-right: 2px; }
.chip-n { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .75rem; text-align: center; }
.chip[aria-current="page"] .chip-n { background: rgba(255,255,255,.25); color: inherit; }
.results-count { margin: -6px 0 12px; }
/* Sottomenu di Esempi nel menu laterale */
.subnav { display: flex; flex-direction: column; gap: 2px; margin: 0 0 4px 34px; padding-left: 10px; border-left: 2px solid var(--line); }
.subnav:empty, .subnav[hidden] { display: none; }
.nav-group { position: relative; }
.subnav-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border: 0; border-radius: 8px; background: none; color: var(--muted);
  display: grid; place-items: center; cursor: pointer;
}
.subnav-toggle[hidden] { display: none; }
.subnav-toggle:hover { background: var(--surface-2); color: var(--ink); }
.subnav-toggle svg { width: 16px; height: 16px; transition: transform .15s ease; }
.subnav-toggle[aria-expanded="true"] svg { transform: rotate(90deg); }
.sidenav .subnav a { padding: 6px 10px; font-size: .88rem; color: var(--muted); justify-content: space-between; gap: 8px; }
.sidenav .subnav a:hover { color: var(--ink); }
.sidenav .subnav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.subnav .count { font-size: .75rem; background: var(--surface-2); border-radius: 999px; padding: 0 7px; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 28px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat b { display: block; font-size: 1.8rem; color: var(--brand); }
.stat span { color: var(--muted); font-size: .9rem; }

/* ===== Article / detail ===== */
.article {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: clamp(18px, 4vw, 36px); box-shadow: var(--shadow); max-width: 900px;
}
.article .lead { font-size: 1.08rem; color: var(--muted); }
.crumbs { font-size: .9rem; color: var(--muted); margin-bottom: 14px; }
.crumbs a { color: var(--muted); }
.article-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.fav-btn { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; color: var(--muted); font: inherit; white-space: nowrap; }
.fav-btn[aria-pressed="true"] { color: #7a5a00; background: var(--accent-soft); border-color: var(--accent); }
:root[data-theme="dark"] .fav-btn[aria-pressed="true"] { color: var(--accent); }

.steps { counter-reset: step; list-style: none; padding: 0; }
.steps li {
  counter-increment: step; position: relative; padding: 14px 16px 14px 60px; margin-bottom: 10px;
  background: var(--surface-2); border-radius: 12px;
}
.steps li::before {
  content: counter(step); position: absolute; left: 14px; top: 12px;
  width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
:root[data-theme="dark"] .steps li::before { color: #0b1a13; }
.steps li b { display: block; margin-bottom: 2px; }

.callout { border-left: 4px solid var(--info); background: var(--info-soft); padding: 12px 16px; border-radius: 8px; margin: 16px 0; }
.callout.warn { border-color: var(--accent); background: var(--accent-soft); }
.callout.danger { border-color: var(--danger); background: var(--danger-soft); }
.callout.ok { border-color: var(--ok); background: var(--brand-soft); }
.callout p:last-child, .callout ul:last-child { margin-bottom: 0; }

table { width: 100%; border-collapse: collapse; margin: 12px 0 18px; font-size: .95rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

.refs { display: flex; flex-wrap: wrap; gap: 6px; }

/* Checklist interattiva */
.checklist { list-style: none; padding: 0; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; }
.checklist li:nth-child(odd) { background: var(--surface-2); }
.checklist input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--brand); flex: none; }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 8px 0 16px; }
.progress > div { height: 100%; background: var(--brand); transition: width .2s; }

/* Form documento */
.doc-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin: 16px 0; }
.doc-form label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; font-weight: 600; }
.doc-form input, .doc-form textarea, .doc-form select {
  font: inherit; font-weight: 400; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
}

/* Segnaletica */
.signs { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 12px 0; }
.sign { border: 1px solid var(--line); border-radius: 12px; padding: 14px; text-align: center; background: var(--surface); }
.sign svg { width: 64px; height: 64px; display: block; margin: 0 auto 8px; }
.sign b { display: block; }
.sign span { font-size: .85rem; color: var(--muted); }

/* Quiz */
.quiz-q { font-size: 1.15rem; font-weight: 600; margin-bottom: 14px; }
.options { display: grid; gap: 10px; }
.option {
  text-align: left; padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; cursor: pointer;
}
.option:hover:not(:disabled) { border-color: var(--brand); }
.option.correct { border-color: var(--ok); background: var(--brand-soft); }
.option.wrong { border-color: var(--danger); background: var(--danger-soft); }
.option:disabled { cursor: default; }
.quiz-bar { display: flex; justify-content: space-between; color: var(--muted); font-size: .9rem; margin-bottom: 8px; }

/* Ricerca */
.result { padding: 14px 0; border-bottom: 1px solid var(--line); }
.result a { font-weight: 600; font-size: 1.05rem; }
.result p { margin: 4px 0 0; color: var(--muted); font-size: .93rem; }
mark { background: var(--accent-soft); color: inherit; padding: 0 2px; border-radius: 3px; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* ===== Stato di autenticazione ===== */
body.booting .auth-only, body.guest .auth-only { display: none !important; }
body.guest .layout { justify-content: center; }
.nav-sep { height: 1px; background: var(--line); margin: 8px 6px; }

.user-chip {
  display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none;
  padding: 4px 12px 4px 4px; border-radius: 999px; background: rgba(255,255,255,.14); flex: none;
}
.user-chip .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #1c1c1c; display: grid; place-items: center; font-weight: 700; }
.user-chip .who { display: flex; flex-direction: column; line-height: 1.1; }
.user-chip .who b { font-size: .88rem; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .who small { font-size: .72rem; opacity: .85; }

.role-badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; vertical-align: middle; }
.role-badge.visualizzatore { background: var(--surface-2); color: var(--muted); }
.role-badge.editore { background: var(--info-soft); color: var(--info); }
.role-badge.supervisor { background: var(--accent-soft); color: #7a5a00; }
:root[data-theme="dark"] .role-badge.supervisor { color: var(--accent); }

/* ===== Login / registrazione ===== */
.auth-wrap { display: flex; justify-content: center; padding: 24px 0; }
.auth-card {
  width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 32px;
}
.auth-card h1 { font-size: 1.6rem; text-align: center; }
.auth-card > .muted { text-align: center; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 12px; }
.auth-logo svg { width: 56px; height: 56px; }
.auth-links { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 18px 0 0; font-size: .92rem; }

/* ===== Form ===== */
.form { display: grid; gap: 14px; margin: 16px 0 0; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .92rem; }
.form label small { font-weight: 400; }
.form input:not([type=checkbox]):not([type=radio]), .form textarea, .form select, .qa-search input {
  font: inherit; font-weight: 400; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); width: 100%;
}
.form input:focus, .form textarea:focus, .form select:focus, .qa-search input:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
.form textarea.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: .88rem; }
label.check { flex-direction: row !important; align-items: flex-start; gap: 8px !important; font-weight: 400 !important; }
label.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--brand); flex: none; }
.form-msg { margin: 0; min-height: 0; font-size: .92rem; }
.form-msg:empty { display: none; }
.form-msg.error { color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: 8px; }
.form-msg.ok { color: var(--ok); background: var(--brand-soft); padding: 10px 12px; border-radius: 8px; }
.btn.block { width: 100%; justify-content: center; }
.btn.light { background: rgba(255,255,255,.16); color: #fff; }
.btn.danger, .btn.ghost.danger { color: var(--danger); border-color: var(--danger-soft); }
.linklike { background: none; border: 0; padding: 0; color: var(--brand); text-decoration: underline; cursor: pointer; font: inherit; }
.linklike.danger { color: var(--danger); }
.refs-pick { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.refs-pick.one-col { grid-template-columns: 1fr; gap: 10px; }
.refs-pick legend { font-weight: 600; font-size: .92rem; padding: 0 6px; }
.sticky-actions { position: sticky; bottom: 0; background: var(--surface); padding: 12px 0; border-top: 1px solid var(--line); }
.article.wide { max-width: 1000px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.panel h2 { margin-top: 0; font-size: 1.1rem; }
.panel.flush { padding: 0; overflow: hidden; }
.table-wrap.panel.flush { overflow-x: auto; }
.grid.two { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); align-items: start; }

/* ===== Tabelle di gestione ===== */
.admin-table { margin: 0; }
.admin-table th, .admin-table td { padding: 12px 14px; vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table select { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.admin-table tr.disabled td { opacity: .55; }
/* Registro accessi */
.log-filters { display: grid; grid-template-columns: 2fr 2fr 1fr 1fr auto; gap: 12px; align-items: end; margin-bottom: 14px; }
.log-filters label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; font-weight: 600; }
.log-filters input, .log-filters select { font: inherit; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.log-table td { vertical-align: top; }
.pager { justify-content: center; margin: 14px 0; }
.stat b.warn-num { color: var(--danger); }
@media (max-width: 860px) {
  .log-filters { grid-template-columns: 1fr 1fr; }
  .log-filters label:first-child, .log-filters label:nth-child(2), .log-filters .row { grid-column: 1 / -1; }
}

/* ===== Domande e risposte ===== */
.qa-search { display: flex; gap: 8px; margin-bottom: 12px; max-width: 640px; }
.qa-list { display: grid; gap: 10px; }
.qa-item {
  display: flex; gap: 16px; padding: 16px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); color: inherit; text-decoration: none; box-shadow: var(--shadow);
}
.qa-item:hover { border-color: var(--brand); }
.qa-item h3 { margin: 0 0 4px; }
.qa-item p { margin: 0 0 6px; color: var(--muted); font-size: .94rem; }
.qa-body { min-width: 0; }
.qa-count { flex: none; width: 70px; text-align: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px 4px; align-self: flex-start; }
.qa-count b { display: block; font-size: 1.3rem; }
.qa-count small { color: var(--muted); font-size: .72rem; }
.qa-count.done { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.question-body { background: var(--surface-2); padding: 16px; border-radius: 12px; margin: 12px 0 8px; }
.answer { border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
.answer-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.callout.ask { margin-top: 28px; }
.big-score { font-size: 2.4rem; font-weight: 700; color: var(--brand); margin: 0; }
.sign-line { border-bottom: 1px solid var(--muted); height: 40px; }
/* Intestazione e piè di pagina dei documenti (logo e nome dell'app) */
.doc-letterhead { display: flex; align-items: center; gap: 12px; padding-bottom: 12px; margin-bottom: 16px; border-bottom: 2px solid var(--brand); }
.doc-letterhead svg { width: 40px; height: 40px; flex: none; }
.doc-letterhead b { display: block; font-size: 1.3rem; color: var(--brand); line-height: 1.1; }
.doc-letterhead b span { color: #b88a00; }
.doc-letterhead small { color: var(--muted); }
.doc-brand-footer { margin-top: 32px; padding-top: 8px; border-top: 1px solid var(--line); font-size: .8rem; color: var(--muted); }
input.cell { width: 100%; border: 0; background: transparent; color: inherit; font: inherit; }
.chip { text-decoration: none; display: inline-block; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #17221d; color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 50;
  transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: #067647; }
.toast.error { background: #b42318; }

/* ===== Mobile ===== */
@media (max-width: 860px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  .brand span { display: none; }
  .layout { flex-direction: column; }
  .user-chip .who { display: none; }
  .user-chip { padding: 4px; }
  .auth-card { padding: 22px; }
  .qa-item { flex-direction: column; gap: 8px; }
  .qa-count { width: auto; display: flex; gap: 6px; align-items: baseline; padding: 4px 10px; }
  .qa-count b { font-size: 1rem; }
  main { padding: 16px 16px 40px; }
  .hero { padding: 22px; }
  .article-head { flex-direction: column; }
}

/* ===== Stampa ===== */
@media print {
  .topbar, .sidenav, .footer, .no-print, .fav-btn, .crumbs, .article-head .btn, .toast { display: none !important; }
  body, .article { background: #fff !important; color: #000 !important; box-shadow: none !important; border: 0 !important; }
  main { padding: 0; }
  .doc-form input, .doc-form textarea { border: 0; border-bottom: 1px solid #999; border-radius: 0; }
  .checklist li { break-inside: avoid; }
  .doc-letterhead { border-bottom-color: #0f5132; }
  .doc-letterhead b { color: #0f5132; }
  .doc-letterhead small, .doc-brand-footer { color: #444; }
  .doc-page .article-head + .row, .doc-page .callout.ask { display: none; }
  .doc-page .tag { display: none; }
}

/* ===== Pittogrammi ===== */
.pitto { display: block; }
.pt-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin-bottom: 22px; }
.pt-fam { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--fam); text-decoration: none; color: var(--ink); transition: transform .12s ease, box-shadow .12s ease; }
.pt-fam:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.pt-fam.on { box-shadow: 0 0 0 2px var(--fam); }
.pt-fam .pitto { width: 52px; height: 52px; flex: none; }
.pt-fam b { display: block; }
.pt-fam .pt-shape { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pt-fam p { margin: 4px 0 0; font-size: .88rem; color: var(--muted); }
.pt-toolbar { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.pt-toolbar .filters { margin-bottom: 8px; }
.pt-search input { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; min-width: 240px; }
.pt-group { margin-bottom: 26px; }
.pt-group[hidden] { display: none; }
.pt-group-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; border-bottom: 3px solid var(--fam); padding-bottom: 6px; margin-bottom: 14px; }
.pt-group-head h2 { margin: 0; }
.pt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.pt-tile { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 14px 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); transition: transform .12s ease, box-shadow .12s ease, border-color .12s; }
.pt-tile[hidden] { display: none; }
.pt-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--brand); }
.pt-tile .pitto { width: 84px; height: 84px; margin-bottom: 6px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.18)); }
.pt-tile b { font-size: .9rem; line-height: 1.25; }
.pt-tile span { font-size: .75rem; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.pt-detail { display: grid; grid-template-columns: minmax(180px, 260px) 1fr; gap: 28px; align-items: start; }
.pt-big { background: #fff; border-radius: var(--radius); padding: 18px; border: 1px solid var(--line); }
.pt-big .pitto { width: 100%; height: auto; filter: drop-shadow(0 4px 8px rgba(0,0,0,.2)); }
.pt-detail h2 { font-size: 1.05rem; margin: 1em 0 .3em; }
.pt-strip { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0 18px; }
.pt-strip a, .scene-signs a { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 96px; text-align: center; font-size: .78rem; color: var(--ink); text-decoration: none; padding: 8px 4px; border-radius: 10px; border: 1px solid transparent; }
.pt-strip a:hover, .scene-signs a:hover { border-color: var(--line); background: var(--surface-2); }
.pt-strip .pitto, .scene-signs .pitto { width: 54px; height: 54px; }
.pt-quiz-sign { display: grid; place-items: center; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 6px 0 16px; }
.pt-quiz-sign .pitto { width: min(200px, 50vw); height: auto; filter: drop-shadow(0 4px 8px rgba(0,0,0,.2)); }
.print-sign { display: none; }

/* Scene illustrate */
.scene { margin: 18px 0 10px; border-radius: var(--radius); overflow: hidden; background: #111; box-shadow: var(--shadow); }
.scene-svg { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; }
.scene figcaption { padding: 8px 14px; font-size: .85rem; color: #d7dcd9; background: #1a1f1d; }
.scene-signs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 4px 0 14px; }
.scene-signs > span { width: 100%; }
.card.has-pitto { position: relative; padding-right: 62px; }
.card-pitto { position: absolute; top: 12px; right: 12px; width: 40px; height: 40px; }
.card-pitto .pitto { width: 100%; height: 100%; }

@media (max-width: 640px) {
  .pt-detail { grid-template-columns: 1fr; }
  .pt-big { max-width: 220px; margin: 0 auto; }
  .pt-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .pt-tile .pitto { width: 66px; height: 66px; }
  .pt-search input { min-width: 0; width: 100%; }
  .pt-search { width: 100%; }
}
@media print {
  body.print-sign-mode main > * { display: none !important; }
  body.print-sign-mode main > .print-sign { display: flex !important; flex-direction: column; align-items: center; justify-content: center; min-height: 90vh; }
  body.print-sign-mode .print-sign .pitto { width: 70%; height: auto; }
  body.print-sign-mode .print-sign p { font: 700 2.4rem/1.2 var(--font); text-align: center; margin-top: 24px; color: #000; }
  .scene { break-inside: avoid; }
}

/* ===== Menu laterale (pannello scuro, come nelle altre app) ===== */
.menu-btn { display: none; flex: none; width: 42px; height: 42px; border: 0; border-radius: 10px; background: rgba(255,255,255,.14); color: #fff; cursor: pointer; place-items: center; }
.menu-btn svg { width: 24px; height: 24px; }
.menu-btn:hover { background: rgba(255,255,255,.24); }
.sidenav {
  --nav-bg: #0c3a25; --nav-ink: #e4f0e9; --nav-muted: #a9c7b7;
  background: var(--nav-bg); color: var(--nav-ink);
  top: 72px; margin: 12px 0 12px 12px; border-radius: 16px;
  max-height: calc(100vh - 84px); overflow-y: auto; scrollbar-width: thin;
  box-shadow: 0 6px 24px rgba(0,0,0,.12);
}
.sidenav a, .sidenav .nav-btn { color: var(--nav-ink); }
.sidenav a:hover, .sidenav .nav-btn:hover { background: rgba(255,255,255,.09); }
.sidenav a.active { background: rgba(242,183,5,.18); color: #ffd34d; box-shadow: inset 3px 0 0 #f2b705; }
.sidenav .nav-sep { background: rgba(255,255,255,.14); }
.sidenav .subnav { border-left-color: rgba(255,255,255,.18); }
.sidenav .subnav a { color: var(--nav-muted); }
.sidenav .subnav a:hover { color: #fff; }
.sidenav .subnav a.active { background: rgba(242,183,5,.18); color: #ffd34d; }
.sidenav .subnav .count { background: rgba(255,255,255,.12); color: var(--nav-muted); }
.sidenav .subnav-toggle { color: var(--nav-muted); }
.sidenav .subnav-toggle:hover { background: rgba(255,255,255,.1); color: #fff; }
.sidenav-head { display: none; }
.nav-backdrop { display: none; }

@media (max-width: 860px) {
  .menu-btn { display: grid; }
  .sidenav {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 60;
    width: min(290px, 84vw); margin: 0; border-radius: 0 18px 18px 0;
    max-height: none; height: 100%; padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
    transform: translateX(-105%); transition: transform .22s ease, visibility .22s; visibility: hidden;
  }
  body.nav-open .sidenav { transform: none; visibility: visible; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .sidenav-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 10px 14px; margin-bottom: 4px; border-bottom: 1px solid rgba(255,255,255,.14); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; font-size: .8rem; color: var(--nav-muted); }
  .nav-close { width: 38px; height: 38px; border: 0; border-radius: 10px; background: rgba(255,255,255,.1); color: #fff; font-size: 1.1rem; cursor: pointer; }
  .sidenav a, .sidenav .nav-btn { padding: 12px 14px; font-size: 1rem; }
  .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.45); }
  .nav-backdrop[hidden] { display: none; }
  body.nav-open { overflow: hidden; }
}
@media (prefers-reduced-motion: reduce) { .sidenav { transition: none; } }
@media print { .menu-btn, .nav-backdrop { display: none !important; } }
