/* =========================================================================
   Orario Scolastico — sistema di design
   Palette dati validata (categoriale a 8 slot, stati riservati).
   ========================================================================= */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html, body { height: 100%; }
body { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }

:root {
  color-scheme: light;
  /* superfici e inchiostri */
  --plane:        #f9f9f7;
  --surface:      #fcfcfb;
  --surface-2:    #f3f3f0;
  --surface-3:    #ebebe6;
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --ink-3:        #898781;
  --line:         #e1e0d9;
  --line-2:       #c3c2b7;
  --ring:         rgba(11,11,11,.10);

  /* accento applicativo */
  --accent:       #2a78d6;
  --accent-ink:   #ffffff;
  --accent-soft:  #eaf2fd;
  --accent-line:  #b7d3f6;

  /* stati (riservati, mai usati come colore di serie) */
  --good:     #0ca30c;  --good-soft:     #e8f7e8;
  --warning:  #fab219;  --warning-soft:  #fdf3df;
  --serious:  #ec835a;  --serious-soft:  #fdeee7;
  --critical: #d03b3b;  --critical-soft: #fbeaea;

  /* otto slot categoriali per le aree disciplinari */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --s0: #898781;                      /* neutro: mensa */

  --r-sm: 6px; --r: 9px; --r-lg: 14px;
  --sh-1: 0 1px 2px rgba(11,11,11,.05);
  --sh-2: 0 4px 14px rgba(11,11,11,.08), 0 1px 3px rgba(11,11,11,.06);
  --sh-3: 0 18px 48px rgba(11,11,11,.16), 0 2px 8px rgba(11,11,11,.08);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  --nav-w: 232px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane: #0d0d0d; --surface: #1a1a19; --surface-2: #222220; --surface-3: #2c2c2a;
    --ink: #ffffff; --ink-2: #c3c2b7; --ink-3: #898781;
    --line: #2c2c2a; --line-2: #383835; --ring: rgba(255,255,255,.10);
    --accent: #3987e5; --accent-soft: #16283d; --accent-line: #1c5cab;
    --good-soft:#12280f; --warning-soft:#2e2410; --serious-soft:#2e1d14; --critical-soft:#2e1414;
    --s1:#3987e5; --s2:#d95926; --s3:#199e70; --s4:#c98500;
    --s5:#d55181; --s6:#008300; --s7:#9085e9; --s8:#e66767;
    --sh-1: 0 1px 2px rgba(0,0,0,.4);
    --sh-2: 0 4px 14px rgba(0,0,0,.5), 0 1px 3px rgba(0,0,0,.4);
    --sh-3: 0 18px 48px rgba(0,0,0,.65), 0 2px 8px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d; --surface: #1a1a19; --surface-2: #222220; --surface-3: #2c2c2a;
  --ink: #ffffff; --ink-2: #c3c2b7; --ink-3: #898781;
  --line: #2c2c2a; --line-2: #383835; --ring: rgba(255,255,255,.10);
  --accent: #3987e5; --accent-soft: #16283d; --accent-line: #1c5cab;
  --good-soft:#12280f; --warning-soft:#2e2410; --serious-soft:#2e1d14; --critical-soft:#2e1414;
  --s1:#3987e5; --s2:#d95926; --s3:#199e70; --s4:#c98500;
  --s5:#d55181; --s6:#008300; --s7:#9085e9; --s8:#e66767;
  --sh-1: 0 1px 2px rgba(0,0,0,.4);
  --sh-2: 0 4px 14px rgba(0,0,0,.5), 0 1px 3px rgba(0,0,0,.4);
  --sh-3: 0 18px 48px rgba(0,0,0,.65), 0 2px 8px rgba(0,0,0,.4);
}

body {
  font-family: var(--sans); background: var(--plane); color: var(--ink);
  font-size: 14px; line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ------------------------------------------------------------- guscio app */
.app { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }

.nav {
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.nav__brand {
  display: flex; align-items: center; gap: 10px; padding: 16px 16px 14px;
  border-bottom: 1px solid var(--line);
}
.nav__mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--s1), var(--s7));
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px;
}
.nav__name { font-weight: 620; letter-spacing: -.01em; font-size: 14px; }
.nav__sub { font-size: 11.5px; color: var(--ink-3); }
.nav__scroll { flex: 1; overflow-y: auto; padding: 12px 10px; }
.nav__group { margin-bottom: 16px; }
.nav__label {
  font-size: 10.5px; font-weight: 650; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-3); padding: 0 8px 6px;
}
.nav__item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 8px; border-radius: var(--r-sm); border: 0; background: none;
  color: var(--ink-2); cursor: pointer; text-align: left; font-size: 13.5px;
  transition: background .12s, color .12s;
}
.nav__item:hover { background: var(--surface-2); color: var(--ink); }
.nav__item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 560; }
.nav__item svg { width: 16px; height: 16px; flex: none; stroke-width: 1.7; }
.nav__count {
  margin-left: auto; font-size: 11px; color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.nav__foot { border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 6px; }

/* ------------------------------------------------------------------ testata */
.main { min-width: 0; display: flex; flex-direction: column; }
.head {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line); padding: 14px 24px;
  display: flex; align-items: center; gap: 14px; min-height: 60px;
}
.head__t { font-size: 17px; font-weight: 640; letter-spacing: -.015em; }
.head__d { font-size: 12.5px; color: var(--ink-3); margin-top: 1px; }
.head__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.page { padding: 22px 24px 60px; }

/* ----------------------------------------------------------------- bottoni */
.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px;
  border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--surface);
  color: var(--ink); font-size: 13px; font-weight: 520; cursor: pointer;
  box-shadow: var(--sh-1); transition: background .12s, border-color .12s, transform .06s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(.5px); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn svg { width: 15px; height: 15px; stroke-width: 1.8; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn--ghost { background: none; border-color: transparent; box-shadow: none; color: var(--ink-2); }
.btn--ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn--danger { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 35%, var(--line)); }
.btn--danger:hover { background: var(--critical-soft); }
.btn--sm { height: 27px; padding: 0 9px; font-size: 12.5px; }
.btn--icon { width: 32px; padding: 0; justify-content: center; }
.btn--icon.btn--sm { width: 27px; }

/* ------------------------------------------------------------------ campi */
.field { display: flex; flex-direction: column; gap: 5px; }
.field__l { font-size: 12px; font-weight: 550; color: var(--ink-2); }
.field__h { font-size: 11.5px; color: var(--ink-3); }
.inp, .sel {
  height: 32px; padding: 0 10px; border-radius: var(--r-sm);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  width: 100%; transition: border-color .12s, box-shadow .12s;
}
.inp:focus, .sel:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.inp--num { text-align: right; font-variant-numeric: tabular-nums; }
.sel { appearance: none; padding-right: 26px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 14px) 14px, calc(100% - 9px) 14px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.switch { display: inline-block; position: relative; width: 34px; height: 20px; flex: none; vertical-align: middle; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3);
  transition: background .16s; pointer-events: none;
}
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: var(--sh-1); transition: transform .16s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------ blocchi */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--sh-1);
}
.card__h {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.card__t { font-size: 13.5px; font-weight: 620; letter-spacing: -.005em; }
.card__d { font-size: 12px; color: var(--ink-3); }
.card__b { padding: 16px; }
.card__b--flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 1180px) { .cols-4 { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .cols-3, .cols-2 { grid-template-columns: 1fr; } }

/* ------------------------------------------------- stat tile (regola dataviz) */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px,1fr)); gap: 12px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 13px 15px 14px; box-shadow: var(--sh-1);
}
.tile__l { font-size: 12px; color: var(--ink-2); font-weight: 520; }
.tile__v { font-size: 27px; font-weight: 640; letter-spacing: -.025em; margin-top: 3px; line-height: 1.1; }
.tile__n { font-size: 11.5px; color: var(--ink-3); margin-top: 3px; }
.tile__d { font-size: 11.5px; font-weight: 560; margin-top: 3px; display: inline-flex; gap: 4px; align-items: center; }
.tile__d--good { color: var(--good); }
.tile__d--bad  { color: var(--critical); }
.hero { font-size: 52px; font-weight: 680; letter-spacing: -.035em; line-height: 1; }

/* meter: traccia = passo piu' chiaro dello stesso colore */
.meter { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin-top: 9px; }
.meter > i { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width .3s; }
.meter--good > i { background: var(--good); }
.meter--warning > i { background: var(--warning); }
.meter--critical > i { background: var(--critical); }

/* --------------------------------------------------------------- tabelle */
.tw { overflow: auto; max-height: calc(100vh - 250px); }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.t th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2);
  text-align: left; font-weight: 600; font-size: 11.5px; letter-spacing: .02em;
  text-transform: uppercase; color: var(--ink-3); padding: 8px 12px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.t td { padding: 6px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tbody tr:hover td { background: var(--surface-2); }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t .cell-inp {
  height: 27px; width: 100%; min-width: 56px; border: 1px solid transparent;
  background: none; border-radius: var(--r-sm); padding: 0 7px;
}
table.t .cell-inp:hover { border-color: var(--line-2); background: var(--surface); }
table.t .cell-inp:focus { border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); outline: none; }
.rowact { display: flex; gap: 3px; justify-content: flex-end; opacity: 0; transition: opacity .12s; }
table.t tbody tr:hover .rowact, table.t tbody tr:focus-within .rowact { opacity: 1; }

/* ---------------------------------------------------------------- pastiglie */
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 21px; padding: 0 8px;
  border-radius: 999px; font-size: 11.5px; font-weight: 550;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
  white-space: nowrap;
}
.chip__dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.chip--good     { background: var(--good-soft);     color: var(--good);     border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.chip--warning  { background: var(--warning-soft);  color: color-mix(in srgb, var(--warning) 72%, #000); border-color: color-mix(in srgb, var(--warning) 35%, transparent); }
.chip--critical { background: var(--critical-soft); color: var(--critical); border-color: color-mix(in srgb, var(--critical) 30%, transparent); }
.chip--accent   { background: var(--accent-soft);   color: var(--accent);   border-color: var(--accent-line); }
:root[data-theme="dark"] .chip--warning, :root:where(:not([data-theme="light"])) .chip--warning { color: var(--warning); }

/* ---------------------------------------------- elenco stati (icona+etichetta) */
.checks { display: flex; flex-direction: column; }
.check { display: flex; gap: 11px; padding: 11px 16px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.check:last-child { border-bottom: 0; }
.check__i { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.check__t { font-size: 13px; font-weight: 540; }
.check__d { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.check__c { font-size: 10.5px; color: var(--ink-3); font-family: var(--mono); margin-left: auto; padding-top: 2px; }
.i-good { color: var(--good); } .i-warning { color: var(--warning); }
.i-critical { color: var(--critical); } .i-serious { color: var(--serious); }

/* ------------------------------------------------------- griglia dell'orario */
.tt { --cell-h: 46px; overflow: auto; }
.tt__g { display: grid; gap: 3px; min-width: 660px; }
.tt__hd {
  font-size: 11px; font-weight: 620; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-3); padding: 5px 0 7px; text-align: center;
}
.tt__hr {
  font-size: 11px; color: var(--ink-3); display: flex; flex-direction: column;
  justify-content: center; align-items: flex-end; padding-right: 10px;
  font-variant-numeric: tabular-nums; height: var(--cell-h);
}
.tt__hr b { color: var(--ink-2); font-weight: 600; font-size: 12px; }
.tt__c {
  height: var(--cell-h); border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--surface); padding: 5px 8px; overflow: hidden;
  display: flex; flex-direction: column; justify-content: center; gap: 1px;
  position: relative; cursor: grab; transition: box-shadow .1s, transform .1s;
}
.tt__c:hover { box-shadow: var(--sh-2); z-index: 3; }
.tt__c[data-drag="1"] { opacity: .35; cursor: grabbing; }
.tt__c::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--sc, var(--s0)); border-radius: var(--r-sm) 0 0 var(--r-sm); }
.tt__c--v { background: color-mix(in srgb, var(--sc) 9%, var(--surface));
  border-color: color-mix(in srgb, var(--sc) 26%, var(--line)); }
.tt__d { font-size: 12.5px; font-weight: 600; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tt__s { font-size: 11px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tt__c--vuota { background: var(--surface-2); border-style: dashed; cursor: default; }
.tt__c--chiusa { background: repeating-linear-gradient(45deg, transparent, transparent 5px,
  var(--surface-2) 5px, var(--surface-2) 10px); border-style: dashed; cursor: not-allowed; }
.tt__c--mensa { --sc: var(--s0); background: var(--surface-2); }
/* riscontro visivo durante il trascinamento */
.tt__c--ok  { outline: 2px solid var(--good);     outline-offset: -2px; background: var(--good-soft); }
.tt__c--ko  { outline: 2px solid var(--critical); outline-offset: -2px; background: var(--critical-soft); }
.tt__badge { position: absolute; top: 3px; right: 4px;
  pointer-events: none; font-size: 9.5px; font-weight: 700;
  color: var(--ink-3); letter-spacing: .03em; }

.legenda { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 12px 16px; border-top: 1px solid var(--line); }
.legenda span { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-2); }
.legenda i { width: 9px; height: 9px; border-radius: 2.5px; display: block; }

/* ---------------------------------------------- selettore di indisponibilita' */
.picker { display: grid; gap: 3px; }
.picker button {
  height: 26px; border-radius: 5px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 10.5px; color: var(--ink-3);
}
.picker button[aria-pressed="true"] {
  background: var(--critical-soft); border-color: color-mix(in srgb, var(--critical) 40%, transparent);
  color: var(--critical); font-weight: 600;
}
.picker__h { font-size: 10.5px; color: var(--ink-3); text-align: center; padding-bottom: 3px; font-weight: 600; }

/* --------------------------------------------------------------- avanzamento */
.run { display: flex; flex-direction: column; gap: 14px; }
.run__bar { height: 4px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.run__bar > i { display: block; height: 100%; background: var(--accent);
  transition: width .4s; border-radius: 999px; }
.run__bar--ind > i { width: 32% !important; animation: slide 1.5s ease-in-out infinite; }
@keyframes slide { 0%{transform:translateX(-110%)} 100%{transform:translateX(340%)} }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent);
  animation: pulse 1.6s infinite; flex: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* ------------------------------------------------------------------ modale */
.veil { position: fixed; inset: 0; background: rgba(11,11,11,.42); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px; z-index: 100; animation: fade .14s; }
@keyframes fade { from { opacity: 0 } }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--sh-3); width: min(560px, 100%); max-height: 88vh; display: flex;
  flex-direction: column; animation: rise .16s cubic-bezier(.2,.8,.3,1); }
.modal--wide { width: min(940px, 100%); }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.985) } }
.modal__h { padding: 15px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal__t { font-size: 15px; font-weight: 620; letter-spacing: -.01em; }
.modal__b { padding: 18px; overflow: auto; }
.modal__f { padding: 13px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

/* ------------------------------------------------------------------- avvisi */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column;
  gap: 8px; z-index: 200; }
.toast { display: flex; gap: 10px; align-items: flex-start; background: var(--surface);
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--r); box-shadow: var(--sh-2); padding: 11px 14px;
  min-width: 260px; max-width: 400px; animation: rise .18s; }
.toast--good { border-left-color: var(--good); }
.toast--critical { border-left-color: var(--critical); }
.toast--warning { border-left-color: var(--warning); }
.toast__t { font-size: 13px; font-weight: 560; }
.toast__d { font-size: 12px; color: var(--ink-2); margin-top: 2px; }

/* -------------------------------------------------------------------- vario */
.empty { text-align: center; padding: 52px 24px; color: var(--ink-3); }
.empty svg { width: 34px; height: 34px; margin: 0 auto 12px; opacity: .5; stroke-width: 1.4; }
.empty h3 { font-size: 14.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.empty p { font-size: 13px; max-width: 400px; margin: 0 auto 16px; }
.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px;
  border-radius: var(--r-sm); border: 1px solid var(--line); }
.tabs button { height: 26px; padding: 0 11px; border: 0; background: none; border-radius: 5px;
  font-size: 12.5px; color: var(--ink-2); cursor: pointer; font-weight: 520; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink);
  box-shadow: var(--sh-1); font-weight: 570; }
.muted { color: var(--ink-3); }
.mono { font-family: var(--mono); font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.sep { height: 1px; background: var(--line); margin: 14px 0; }
.skel { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%; animation: sk 1.3s linear infinite; border-radius: var(--r-sm); height: 14px; }
@keyframes sk { to { background-position: -200% 0 } }

@media print {
  .nav, .head__actions, .btn, .legenda { display: none !important; }
  .app { grid-template-columns: 1fr; }
  .head { position: static; border: 0; }
  .tt__c { break-inside: avoid; }
  body { background: #fff; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* =========================================================================
   TABELLONE — quadro generale su un unico foglio A3 orizzontale.
   E' il documento che si appende in sala docenti e che il vicario guarda
   la mattina per trovare chi e' libero: percio' le celle VUOTE devono
   risaltare quanto quelle piene.
   ========================================================================= */
.tab-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 14px; }
.tab-testata { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.tab-testata h2 { font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.tab-testata span { font-size: 12px; color: var(--ink-3); }

table.tab { border-collapse: collapse; table-layout: fixed; width: 100%; min-width: 1050px;
  font-variant-numeric: tabular-nums; }
table.tab th, table.tab td { border: 1px solid var(--line); padding: 0; text-align: center; }
table.tab thead th { background: var(--surface-2); font-size: 9.5px; font-weight: 650;
  color: var(--ink-2); letter-spacing: .02em; height: 17px; }
table.tab thead th.giorno { font-size: 10.5px; text-transform: uppercase; }
table.tab th.nome { width: 118px; text-align: left; padding: 0 6px; font-size: 10.5px;
  font-weight: 550; color: var(--ink); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; background: var(--surface); position: sticky; left: 0; z-index: 2; }
table.tab thead th.nome { background: var(--surface-2); z-index: 3; }
table.tab td { height: 17px; font-size: 9px; font-weight: 600; color: var(--ink-2);
  overflow: hidden; white-space: nowrap; position: relative; letter-spacing: -.02em; }
.marca-sos { position: absolute; top: 1px; right: 1px; width: 4px; height: 4px;
  border-radius: 50%; background: var(--s8); display: block; }
table.tab td.pieno { background: color-mix(in srgb, var(--sc, var(--s1)) 15%, var(--surface));
  color: var(--ink); }
table.tab td.mensa { background: var(--surface-3); color: var(--ink-3); font-weight: 500; }
table.tab td.chiusa { background: repeating-linear-gradient(45deg, transparent, transparent 3px,
  var(--surface-2) 3px, var(--surface-2) 6px); }
table.tab td.buca { background: var(--surface); box-shadow: inset 0 0 0 1px var(--warning); }
table.tab .fine-giorno { border-right: 2px solid var(--line-2); }
table.tab td.tot, table.tab th.tot { width: 30px; font-size: 9.5px; color: var(--ink-3);
  background: var(--surface-2); }

/* -------------------------------------------------------------- stampa A3 */
@media print {
  @page { size: A3 landscape; margin: 8mm; }
  body.stampa-tabellone .nav,
  body.stampa-tabellone .head,
  body.stampa-tabellone .toasts { display: none !important; }
  body.stampa-tabellone .app { grid-template-columns: 1fr; }
  body.stampa-tabellone .page { padding: 0; }
  body.stampa-tabellone .tab-wrap { border: 0; padding: 0; border-radius: 0; overflow: visible; }
  body.stampa-tabellone table.tab { min-width: 0; width: 100%;
    -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body.stampa-tabellone table.tab thead { display: table-header-group; }  /* ripete l'intestazione */
  body.stampa-tabellone table.tab tr { break-inside: avoid; }
  body.stampa-tabellone table.tab th.nome { position: static; width: 104px;
    font-size: calc(var(--riga-f, 8.5px) * .95); }
  body.stampa-tabellone table.tab td { height: var(--riga-h, 15px); font-size: var(--riga-f, 7.5px); }
  body.stampa-tabellone table.tab thead th { height: var(--riga-h, 15px);
    font-size: calc(var(--riga-f, 8px) * .92); }
  body.stampa-tabellone .no-stampa { display: none !important; }
  body.stampa-tabellone .solo-stampa { display: block !important; }
}
.solo-stampa { display: none; }

/* =========================================================================
   GUIDA — pagina di documentazione con indice laterale
   ========================================================================= */
.nav__guida {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
  font-weight: 570; box-shadow: var(--sh-1);
}
.nav__guida:hover { background: color-mix(in srgb, var(--accent) 88%, #000);
  color: var(--accent-ink); }
.nav__guida svg { width: 15px; height: 15px; }

.guida { display: grid; grid-template-columns: 1fr 230px; gap: 34px; align-items: start; }
@media (max-width: 1100px) { .guida { grid-template-columns: 1fr; }
  .guida__idx { position: static !important; order: -1; } }

.guida__idx { position: sticky; top: 78px; font-size: 12.5px; }
.guida__idx b { display: block; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .07em; color: var(--ink-3); margin-bottom: 8px; }
.guida__idx a { display: block; padding: 4px 9px; border-radius: var(--r-sm);
  color: var(--ink-2); border-left: 2px solid transparent; }
.guida__idx a:hover { background: var(--surface-2); color: var(--ink); }
.guida__idx a.att { color: var(--accent); border-left-color: var(--accent);
  background: var(--accent-soft); font-weight: 550; }

.prosa { max-width: 74ch; }
.prosa > section { scroll-margin-top: 82px; padding-bottom: 34px; }
.prosa h2 { font-size: 20px; font-weight: 650; letter-spacing: -.02em; margin: 6px 0 6px;
  padding-top: 8px; }
.prosa h3 { font-size: 15px; font-weight: 620; letter-spacing: -.01em; margin: 24px 0 8px; }
.prosa h4 { font-size: 13.5px; font-weight: 620; margin: 18px 0 6px; color: var(--ink-2); }
.prosa p { margin: 9px 0; color: var(--ink-2); line-height: 1.65; }
.prosa strong { color: var(--ink); font-weight: 600; }
.prosa ul, .prosa ol { margin: 9px 0 9px 20px; color: var(--ink-2); line-height: 1.65; }
.prosa li { margin: 5px 0; }
.prosa li::marker { color: var(--ink-3); }
.prosa code { font-family: var(--mono); font-size: .88em; background: var(--surface-2);
  padding: 1px 5px; border-radius: 4px; color: var(--ink); }
.prosa table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 13px; }
.prosa th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--ink-3); padding: 7px 10px; border-bottom: 1px solid var(--line-2); }
.prosa td { padding: 7px 10px; border-bottom: 1px solid var(--line); color: var(--ink-2);
  vertical-align: top; }
.prosa td:first-child { color: var(--ink); font-weight: 520; white-space: nowrap; }
.prosa hr { border: 0; border-top: 1px solid var(--line); margin: 28px 0; }

.nota { border-left: 3px solid var(--accent); background: var(--accent-soft);
  padding: 12px 15px; border-radius: 0 var(--r) var(--r) 0; margin: 16px 0; }
.nota--att { border-left-color: var(--warning); background: var(--warning-soft); }
.nota--no  { border-left-color: var(--critical); background: var(--critical-soft); }
.nota p { margin: 4px 0; color: var(--ink); }
.nota > b:first-child { display: block; font-size: 12px; text-transform: uppercase;
  letter-spacing: .05em; margin-bottom: 4px; color: var(--ink-2); }
.nota p b { color: var(--ink); font-weight: 650; }

.passi { counter-reset: passo; list-style: none; margin-left: 0 !important; padding: 0; }
.passi > li { counter-increment: passo; position: relative; padding-left: 38px;
  margin: 14px 0; }
.passi > li::before { content: counter(passo); position: absolute; left: 0; top: 0;
  width: 25px; height: 25px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent); font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.passi b { display: block; color: var(--ink); font-weight: 600; margin-bottom: 2px; }

/* =========================================================================
   RESPONSIVE
   Tre soglie: 1200 (desktop pieno) · 900 (tablet) · 600 (telefono).
   La scelta di fondo: sotto i 900px le TABELLE DIVENTANO SCHEDE. Una tabella
   a otto colonne su un telefono si puo' solo far scorrere in orizzontale, ed
   e' il modo piu' rapido per rendere un'applicazione inutilizzabile.
   ========================================================================= */

/* pulsante del menu e velo: esistono solo sotto i 900px */
.menu-btn { display: none; }
.velo-nav { display: none; }

@media (max-width: 1199px) {
  :root { --nav-w: 200px; }
  .page { padding: 18px 16px 60px; }
  .head { padding: 12px 16px; }
}

@media (max-width: 899px) {
  .app { grid-template-columns: 1fr; }

  /* la barra laterale diventa un cassetto scorrevole */
  .nav {
    position: fixed; inset: 0 auto 0 0; width: 268px; z-index: 60;
    transform: translateX(-100%); transition: transform .22s cubic-bezier(.2,.8,.3,1);
    box-shadow: var(--sh-3);
  }
  body.nav-aperta .nav { transform: none; }
  body.nav-aperta { overflow: hidden; }
  .velo-nav {
    display: block; position: fixed; inset: 0; z-index: 55; background: rgba(11,11,11,.45);
    opacity: 0; pointer-events: none; transition: opacity .22s;
  }
  body.nav-aperta .velo-nav { opacity: 1; pointer-events: auto; }
  .menu-btn { display: inline-flex; }
  .nav__item { padding: 10px 10px; font-size: 14.5px; }   /* bersagli piu' grandi */

  .head { gap: 10px; min-height: 56px; flex-wrap: wrap; }
  .head__t { font-size: 16px; }
  .head__d { display: none; }
  .head__actions { width: 100%; margin-left: 0; overflow-x: auto; padding-bottom: 2px; }
  .head__actions::-webkit-scrollbar { display: none; }
  .btn { height: 36px; }            /* 36px: bersaglio tattile decente */
  .btn--sm { height: 32px; }

  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 9px; }
  .tile__v { font-size: 23px; }
  .hero { font-size: 40px; }

  /* ---- le tabelle diventano schede impilate ---- */
  .tw { max-height: none; overflow: visible; }
  table.t { display: block; }
  table.t thead { display: none; }
  table.t tbody, table.t tr, table.t td { display: block; width: 100%; }
  table.t tbody tr {
    border: 1px solid var(--line); border-radius: var(--r); margin: 0 0 10px;
    padding: 4px 2px; background: var(--surface);
  }
  table.t tbody tr:hover td { background: none; }
  table.t td {
    border: 0; border-bottom: 1px solid var(--line); padding: 7px 12px;
    display: flex; align-items: center; gap: 12px; text-align: left !important;
  }
  table.t tbody tr td:last-child { border-bottom: 0; }
  /* l'etichetta viene dall'intestazione di colonna, applicata da JS */
  table.t td::before {
    content: attr(data-l); flex: 0 0 42%; font-size: 11.5px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .02em; color: var(--ink-3);
  }
  table.t td:empty { display: none; }
  table.t td[data-l=""]::before { display: none; }
  table.t .cell-inp { flex: 1; min-width: 0; height: 34px; border-color: var(--line); }
  table.t td > .rowact { opacity: 1; flex: 1; justify-content: flex-start; }
  table.t td > .rowact .btn { height: 32px; }

  /* modali a tutta pagina */
  .veil { padding: 0; align-items: flex-end; }
  .modal, .modal--wide { width: 100%; max-height: 92vh; border-radius: var(--r-lg) var(--r-lg) 0 0; }
  .modal__f { position: sticky; bottom: 0; background: var(--surface); }
  .modal__f .btn { flex: 1; justify-content: center; }

  /* griglia oraria: un giorno alla volta */
  .tt { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tt__g { min-width: 0; }
  .tt { --cell-h: 54px; }
  .guida { grid-template-columns: 1fr; }
  .prosa table { display: block; overflow-x: auto; }
  .prosa td:first-child { white-space: normal; }

  .toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: none; }
  .picker { overflow-x: auto; }
}

@media (max-width: 599px) {
  .page { padding: 14px 12px 56px; }
  .head { padding: 10px 12px; }
  .card__b { padding: 13px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .tile__v { font-size: 20px; }
  .hero { font-size: 34px; }
  table.t td::before { flex-basis: 38%; font-size: 11px; }
  .tabs { width: 100%; }
  .tabs button { flex: 1; }
  .sel, .inp { max-width: none !important; }
}

/* selettore del giorno: compare solo dove serve */
.giorni-sel { display: none; }
@media (max-width: 899px) {
  .giorni-sel { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; }
  .giorni-sel button {
    flex: 1 0 auto; min-width: 62px; height: 34px; border-radius: var(--r-sm);
    border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2);
    font-size: 13px; font-weight: 550; cursor: pointer;
  }
  .giorni-sel button[aria-pressed="true"] {
    background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
  }
}

/* ============================== INSERIMENTO RAPIDO DELLE CATTEDRE ======== */
.rap__testa {
  position: sticky; top: 60px; z-index: 15; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px 16px;
  box-shadow: var(--sh-1); margin-bottom: 16px;
}
.rap__conta { display: flex; align-items: baseline; gap: 7px; }
.rap__conta b { font-size: 26px; font-weight: 650; letter-spacing: -.025em; }
.rap__conta span { font-size: 13px; color: var(--ink-3); }
.rap__conta.ok b { color: var(--good); }
.rap__conta.troppo b { color: var(--critical); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  height: 30px; padding: 0 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2);
  font-size: 12.5px; font-weight: 540; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.chips button:hover { background: var(--surface-2); color: var(--ink); }
.chips button[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}
.chips button i { font-style: normal; opacity: .65; margin-left: 5px; font-size: 11px; }

.rap__griglia { display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); }
.rap__cls { border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); box-shadow: var(--sh-1); }
.rap__cls h4 { display: flex; align-items: center; gap: 8px; margin: 0;
  padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: 13.5px;
  font-weight: 640; }
.rap__cls h4 span { font-size: 11.5px; font-weight: 500; color: var(--ink-3); }
.rap__riga { display: flex; align-items: center; gap: 10px; padding: 6px 14px;
  border-bottom: 1px solid var(--line); }
.rap__riga:last-child { border-bottom: 0; }
.rap__riga > label { flex: 1; min-width: 0; font-size: 13px; display: flex;
  align-items: baseline; gap: 6px; }
.rap__riga em { font-style: normal; font-size: 11px; color: var(--ink-3);
  font-variant-numeric: tabular-nums; }
.rap__riga input { width: 62px; height: 32px; text-align: right;
  border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 0 8px;
  background: var(--surface); color: var(--ink); font-variant-numeric: tabular-nums; }
.rap__riga input:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.rap__riga input.pieno { border-color: var(--accent); background: var(--accent-soft);
  font-weight: 620; }
.rap__riga button.tutto { height: 28px; padding: 0 8px; font-size: 11.5px;
  border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--r-sm);
  color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.rap__riga button.tutto:hover { background: var(--accent-soft); color: var(--accent);
  border-color: var(--accent-line); }
.rap__cls footer { padding: 9px 14px; border-top: 1px solid var(--line);
  display: flex; gap: 7px; align-items: center; background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg); }

@media (max-width: 899px) {
  .rap__testa { position: static; }
  .rap__griglia { grid-template-columns: 1fr; }
  .rap__riga input { width: 72px; height: 36px; }
}
