/* Tirocini Formativi — stile mobile first, tema chiaro e scuro. Il colore dell'ente arriva in --brand. */

:root {
  --brand: #1f6f78;
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #eef2f3;
  --text: #17262b;
  --muted: #5d6f75;
  --border: #d9e1e3;
  --ok-bg: #e5f4ea; --ok-fg: #1d6b3a;
  --warn-bg: #fdf3dc; --warn-fg: #7a5600;
  --err-bg: #fbe7e6; --err-fg: #9b2620;
  --info-bg: #e6eef8; --info-fg: #24508a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 32, 38, .06), 0 4px 16px rgba(16, 32, 38, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1719; --surface: #172225; --surface-2: #1e2c30; --text: #e5eef0; --muted: #94a8ad; --border: #2b3c41;
    --ok-bg: #173826; --ok-fg: #8fdcaa; --warn-bg: #3a2f12; --warn-fg: #f1cf7c; --err-bg: #3d1c1a; --err-fg: #f3a29c;
    --info-bg: #1b2b40; --info-fg: #9cc0f0; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1719; --surface: #172225; --surface-2: #1e2c30; --text: #e5eef0; --muted: #94a8ad; --border: #2b3c41;
  --ok-bg: #173826; --ok-fg: #8fdcaa; --warn-bg: #3a2f12; --warn-fg: #f1cf7c; --err-bg: #3d1c1a; --err-fg: #f3a29c;
  --info-bg: #1b2b40; --info-fg: #9cc0f0; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); }
:root[data-theme="dark"] a, :root:not([data-theme="light"]) a { text-underline-offset: 2px; }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0 0 .4rem; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
p { margin: 0 0 .75rem; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 6px; }
code.wrap { word-break: break-all; display: inline-block; }
code[data-copy] { cursor: copy; }
code.copied { outline: 2px solid var(--brand); }
img { max-width: 100%; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .875rem; display: block; margin-top: .25rem; }
.mt { margin-top: 1rem; }
.nowrap { white-space: nowrap; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* Layout applicazione */
.app { min-height: 100vh; }
.side {
  position: fixed; inset: 0 auto 0 0; width: 280px; max-width: 86vw; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; transform: translateX(-100%); transition: transform .2s ease; z-index: 30; overflow-y: auto;
}
.menu-open .side { transform: none; }
.side-backdrop { display: none; }
.menu-open .side-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 20; }
.main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: .5rem; padding: .6rem 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.crumb { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: .25rem; }
.lang { font-size: .8rem; font-weight: 600; color: var(--muted); text-decoration: none; padding: .3rem .45rem; border-radius: 6px; }
.lang.on { color: var(--text); background: var(--surface-2); }
.page { padding: 16px; max-width: 1080px; margin: 0 auto; }
@media (min-width: 960px) {
  .side { transform: none; }
  .app { padding-left: 280px; }
  .topbar .menu-btn, .menu-open .side-backdrop { display: none; }
  .page { padding: 24px 32px; }
}

.brand { display: flex; align-items: center; gap: .65rem; padding: 1rem; text-decoration: none; color: var(--text); font-weight: 700; line-height: 1.2; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: .78rem; }
.brand-mark { flex: none; width: 36px; height: 36px; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; }
.brand-logo { flex: none; width: 40px; height: 40px; object-fit: contain; border-radius: 8px; background: #fff; }
.role-switch { padding: 0 1rem .75rem; }
.role-switch label { font-size: .75rem; color: var(--muted); display: block; margin-bottom: .2rem; }
.nav { display: flex; flex-direction: column; padding: .25rem .5rem; gap: 2px; flex: 1; }
.nav a { display: flex; align-items: center; gap: .65rem; padding: .6rem .75rem; border-radius: 10px; color: var(--text); text-decoration: none; min-height: 44px; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--text); font-weight: 600; }
.nav .ico { width: 1.25rem; text-align: center; color: var(--brand); }
.nav .badge { margin-left: auto; background: var(--brand); color: #fff; border-radius: 999px; font-size: .75rem; padding: 0 .5rem; min-width: 1.5rem; text-align: center; }
.nav-label { font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: .9rem .75rem .3rem; }
.side-bottom { display: flex; align-items: center; gap: .5rem; padding: .75rem 1rem; border-top: 1px solid var(--border); }
.me { display: flex; align-items: center; gap: .6rem; flex: 1; min-width: 0; color: var(--text); text-decoration: none; line-height: 1.25; }
.me small { display: block; color: var(--muted); font-size: .75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { flex: none; width: 36px; height: 36px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; color: var(--brand); }
.icon-btn { background: none; border: 0; color: var(--text); font-size: 1.15rem; min-width: 40px; min-height: 40px; border-radius: 10px; cursor: pointer; display: inline-grid; place-items: center; text-decoration: none; }
.icon-btn:hover { background: var(--surface-2); }

/* Pagine pubbliche */
.auth-body { min-height: 100vh; }
.auth-wrap { max-width: 560px; margin: 0 auto; padding: 16px; }
.auth-wrap.single { max-width: 760px; }
.auth-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.auth-top .brand { padding: .5rem 0 1rem; }
.auth-card { padding: 20px; }
.auth-foot { text-align: center; color: var(--muted); font-size: .875rem; margin-top: 1rem; }

/* Componenti */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.flash { padding: .7rem .9rem; border-radius: 10px; margin: 0 0 1rem; background: var(--info-bg); color: var(--info-fg); }
.flash.ok { background: var(--ok-bg); color: var(--ok-fg); }
.flash.warn { background: var(--warn-bg); color: var(--warn-fg); }
.flash.err { background: var(--err-bg); color: var(--err-fg); }
.pill { display: inline-block; font-size: .78rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; vertical-align: middle; }
.pill.green { background: var(--ok-bg); color: var(--ok-fg); }
.pill.amber { background: var(--warn-bg); color: var(--warn-fg); }
.pill.red { background: var(--err-bg); color: var(--err-fg); }
.pill.blue { background: var(--info-bg); color: var(--info-fg); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .55rem 1rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--err-fg); border-color: color-mix(in srgb, var(--err-fg) 40%, transparent); }
.btn.small { min-height: 34px; padding: .3rem .7rem; font-size: .875rem; }
.btn.block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }

.field { margin-bottom: .9rem; min-width: 0; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: .6rem .7rem; min-height: 44px;
}
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; flex: none; margin: .15rem 0 0; accent-color: var(--brand); }
input[type="color"] { padding: .2rem; height: 44px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
input:disabled { background: var(--surface-2); color: var(--muted); }
textarea { min-height: 8rem; resize: vertical; }
.code-input { font-size: 1.4rem; letter-spacing: .2em; text-align: center; font-family: ui-monospace, Consolas, monospace; }
.fields { display: grid; grid-template-columns: 1fr; gap: 0 1rem; }
.fields .full, .fields h3 { grid-column: 1 / -1; }
@media (min-width: 640px) { .fields { grid-template-columns: 1fr 1fr; } }
.consent { display: flex; gap: .6rem; align-items: flex-start; margin: .5rem 0 .9rem; font-weight: 400; cursor: pointer; }
.checks { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; }
.inline-form .field { flex: 1 1 200px; margin-bottom: 0; }
.inline-form .consent { margin: 0 0 .7rem; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filters input, .filters select { flex: 1 1 160px; width: auto; }
.inline-label { display: flex; align-items: center; gap: .35rem; font-size: .875rem; color: var(--muted); flex: 1 1 180px; }

.tabs { display: flex; gap: .25rem; overflow-x: auto; margin: .5rem 0 1rem; border-bottom: 1px solid var(--border); }
.tabs a { padding: .6rem .9rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 600; }
.tabs a.active { color: var(--text); border-color: var(--brand); }
.tabs .tab-action { margin-left: auto; color: var(--brand); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table.compact td { padding: .35rem .5rem; }
.diff small { word-break: break-word; font-family: ui-monospace, Consolas, monospace; font-size: .75rem; }

.kv { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: .35rem 1rem; margin: 0 0 1rem; }
.kv dt { color: var(--muted); font-size: .875rem; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.request-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; }
.request-head h2 { margin: 0; }
.decision { border-top: 1px solid var(--border); padding-top: .9rem; display: grid; gap: 0 1rem; }
@media (min-width: 640px) { .decision { grid-template-columns: 1fr 2fr; } .decision .actions { grid-column: 1 / -1; } }

.list { display: grid; gap: 0; }
details.user summary, .ente-row { display: flex; align-items: center; gap: .75rem; cursor: pointer; list-style: none; text-decoration: none; color: var(--text); }
details.user summary::-webkit-details-marker { display: none; }
.user-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.user-main small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.user-body { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 1rem; }
details.card > summary { cursor: pointer; }
.roles, .plain, .edit-list, .codes, .todo { list-style: none; margin: 0 0 1rem; padding: 0; }
.roles li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .45rem 0; border-bottom: 1px solid var(--border); }
.roles li small { display: block; }
.plain li { padding: .25rem 0; }
.edit-list li { padding: .6rem 0; border-bottom: 1px solid var(--border); }
.add-form { margin-top: .5rem; }
.codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; }
.codes code { display: block; text-align: center; padding: .4rem; font-size: 1rem; }
.plain-steps { padding-left: 1.2rem; }

.todo li a { display: flex; align-items: center; gap: .75rem; padding: .75rem .25rem; border-bottom: 1px solid var(--border); color: var(--text); text-decoration: none; min-height: 48px; }
.todo li:last-child a { border-bottom: 0; }
.todo .go { margin-left: auto; color: var(--muted); font-size: 1.3rem; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.amber { background: #d99a00; }
.dot.red { background: #d0453c; }

.steps { list-style: none; padding: 0; margin: 0; counter-reset: s; }
.steps li a { display: flex; gap: .75rem; align-items: center; padding: .6rem 0; color: var(--text); text-decoration: none; border-bottom: 1px solid var(--border); }
.steps li small { display: block; color: var(--muted); }
.step-check { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; font-weight: 700; }
.steps li.done .step-check { background: var(--brand); border-color: var(--brand); color: #fff; }
.steps li.done b { color: var(--muted); }

.meter { height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: .4rem 0 .6rem; }
.meter span { display: block; height: 100%; background: var(--brand); }
.meter span.amber { background: #d99a00; }
.meter span.red { background: #d0453c; }

.legal { max-width: 70ch; }
.legal.scroll { max-height: 50vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; padding: 1rem; margin-bottom: 1rem; }
.qr { background: #fff; display: inline-block; padding: 8px; border-radius: 10px; margin: .5rem 0 1rem; }
.qr svg { display: block; max-width: 100%; height: auto; }
.logo-preview { max-height: 80px; background: #fff; padding: 6px; border-radius: 8px; border: 1px solid var(--border); }
.bell { position: relative; font-size: 1rem; }
.bell .badge { position: absolute; top: 2px; right: 0; background: var(--brand); color: #fff; border-radius: 999px; font-size: .65rem; line-height: 1.4; padding: 0 .35rem; font-weight: 700; }
.flash.small { padding: .4rem .7rem; font-size: .875rem; margin-bottom: .5rem; }
.m0 { margin: 0; }
.periods { list-style: none; margin: .5rem 0 0; padding: 0; }
.periods li a { display: grid; grid-template-columns: 1fr auto; gap: .2rem .75rem; align-items: center; padding: .6rem 0; border-top: 1px solid var(--border); color: var(--text); text-decoration: none; }
.periods .period-dates { grid-column: 1 / -1; font-size: .8rem; color: var(--muted); }
.periods .period-main small { color: var(--muted); }
@media (min-width: 640px) {
  .periods li a { grid-template-columns: 200px 1fr auto; }
  .periods .period-dates { grid-column: auto; font-size: .875rem; }
}
/* Timbratura */
.card.highlight { border-color: var(--brand); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 25%, transparent); }
.status-card .big { font-size: 1.15rem; font-weight: 700; margin: 0 0 .25rem; }
.status-card.in { border-left: 6px solid var(--brand); }
.scanner .video-wrap { position: relative; border-radius: 12px; overflow: hidden; background: #000; margin-bottom: .75rem; aspect-ratio: 1 / 1; max-width: 480px; margin-inline: auto; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; inset: 18%; border: 3px solid rgba(255, 255, 255, .85); border-radius: 16px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .25); }
.big-btn { min-height: 56px; font-size: 1.1rem; }
.block-link { display: block; text-decoration: none; }
.month-nav { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; }

/* Chiosco (tablet in reparto) */
body.kiosk { background: #fff; color: #111; min-height: 100vh; }
.kiosk-main { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 3vh 4vw; gap: 2vh; text-align: center; }
.kiosk-main header { width: 100%; display: flex; align-items: center; gap: 1rem; text-align: left; }
.kiosk-main header img { height: 64px; }
.kiosk-main header div { flex: 1; }
.kiosk-main h1 { font-size: clamp(1.5rem, 4vw, 2.6rem); margin: 0; }
.kiosk-main header p { margin: 0; color: #555; font-size: 1.1rem; }
.kiosk-clock { font-size: clamp(1.5rem, 4vw, 2.6rem); font-weight: 700; font-variant-numeric: tabular-nums; }
.kiosk-qr { width: min(70vh, 86vw); aspect-ratio: 1 / 1; }
.kiosk-qr svg { width: 100%; height: 100%; }
.kiosk-hint { font-size: 1.2rem; color: #333; margin: 0; }
.kiosk-bar { width: min(70vh, 86vw); height: 8px; background: #eee; border-radius: 99px; overflow: hidden; }
.kiosk-bar span { display: block; height: 100%; background: var(--brand); transition: width .25s linear; }
.kiosk-status { color: #b42318; font-weight: 600; min-height: 1.5em; }
.kiosk-off { max-width: 560px; margin: 15vh auto; padding: 16px; text-align: center; }

/* Foglio QR da stampare */
.print-sheet { background: #fff; color: #111; }
.print-sheet .no-print { padding: 16px; }
.sheet { max-width: 680px; margin: 0 auto; padding: 24px; text-align: center; }
.sheet h1 { font-size: 2.2rem; margin: .3rem 0; }
.sheet-ente, .sheet-presidio { color: #555; margin: 0; }
.sheet-qr svg { width: 100%; max-width: 460px; height: auto; margin: 1.5rem auto; display: block; }
.sheet-validita { font-weight: 600; }
@media print {
  .no-print { display: none !important; }
  .sheet { padding: 0; }
}

/* Valutazione UEB */
.ueb-bar { position: sticky; top: 64px; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .6rem 1rem; }
.crit { border: 0; border-top: 1px solid var(--border); padding: .8rem 0 .4rem; margin: 0; }
.crit legend { padding: 0; margin-bottom: .55rem; font-size: .95rem; }
.scale { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .35rem; }
.scale label { position: relative; }
.scale input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.scale span { display: grid; place-items: center; min-height: 48px; border: 1px solid var(--border); border-radius: 10px; font-weight: 700; font-size: 1.1rem; background: var(--surface); }
.scale .nv span { font-size: .85rem; color: var(--muted); }
.scale input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }
.scale .nv input:checked + span { background: var(--surface-2); color: var(--text); border-color: var(--text); }
.scale input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.voce { border-top: 1px solid var(--border); padding: .7rem 0; }
.voce-head { margin: 0 0 .4rem; font-size: .92rem; }
.criterio { padding: .3rem 0 .3rem .5rem; }
.criterio.off summary { color: var(--muted); text-decoration: line-through; }
.criterio summary { cursor: pointer; font-size: .92rem; }
.ueb-summary { display: grid; gap: 1rem; align-items: center; }
@media (min-width: 720px) { .ueb-summary { grid-template-columns: 220px 1fr; } }
.big-number { font-size: 2.6rem; font-weight: 800; margin: 0; line-height: 1.1; }
.radar { width: 100%; max-width: 420px; display: block; margin: 0 auto; }
.radar-grid { fill: none; stroke: var(--border); stroke-width: 1; }
.radar-label { font-size: 13px; fill: var(--muted); }
.radar-a { fill: rgba(217, 154, 0, .18); stroke: #d99a00; stroke-width: 2; }
.radar-b { fill: color-mix(in srgb, var(--brand) 22%, transparent); stroke: var(--brand); stroke-width: 2; }
.legend { text-align: center; font-size: .85rem; color: var(--muted); }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin: 0 .3rem 0 .8rem; }
.legend .sw.a { background: #d99a00; }
.legend .sw.b { background: var(--brand); }
.table tr.sub td { color: var(--muted); font-size: .88rem; }
.crit-list { list-style: none; padding: 0; margin: 0; }
.crit-list li { display: flex; gap: .7rem; align-items: flex-start; padding: .45rem 0; border-bottom: 1px solid var(--border); }
.crit-list .score { flex: none; width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; font-weight: 700; background: var(--brand); color: #fff; }
.crit-list .score.nv { background: var(--surface-2); color: var(--muted); font-size: .75rem; }
.score-pill { font-weight: 700; padding: .15rem .5rem; border-radius: 8px; }
.score-pill.ok { background: var(--ok-bg); color: var(--ok-fg); }
.score-pill.ko { background: var(--err-bg); color: var(--err-fg); }
.small { font-size: .85rem; }

.pager { display: flex; gap: .75rem; align-items: center; justify-content: center; margin: 1rem 0; }

/* Accesso di supporto del super admin: sempre visibile */
.support-bar { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between;
  padding: .55rem 1rem; background: #b3261e; color: #fff; font-weight: 600; font-size: .9rem; }
.support-bar .btn { background: #fff; color: #b3261e; border-color: #fff; }
