/* ==========================================================================
   LaboTempo — design system "Moderno & pulito"
   Indaco/teal, superfici chiare, ombre nette, mobile-first, dark mode.
   ========================================================================== */

/* ---- Design tokens (light) ---- */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --surface-hover: #f6f7fb;
  --border: #e3e7ef;
  --border-strong: #cfd6e4;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-bg: #eef2ff;
  --on-primary: #ffffff;
  --accent: #0ea5a4;
  --accent-bg: #e6fbfa;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .08), 0 2px 4px rgba(15, 23, 42, .06);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, .18);

  --fs-xs: .78rem;
  --fs-sm: .875rem;
  --fs-md: 1rem;
  --fs-lg: 1.15rem;
  --fs-xl: 1.5rem;
  --fs-2xl: 1.9rem;

  --touch: 44px;
  --topbar-h: 60px;
  --maxw: 1240px;

  color-scheme: light;
}

/* ---- Dark theme: explicit toggle ---- */
:root[data-theme="dark"] {
  --bg: #0b1020;
  --surface: #151b2e;
  --surface-2: #1c2438;
  --surface-hover: #1c2438;
  --border: #2a3350;
  --border-strong: #3a456a;
  --text: #e8ecf5;
  --muted: #94a3b8;
  --primary: #818cf8;
  --primary-hover: #a5b0ff;
  --primary-bg: #1e2547;
  --on-primary: #0b1020;
  --accent: #2dd4bf;
  --accent-bg: #122e30;
  --success: #4ade80;
  --success-bg: #14331f;
  --warning: #fbbf24;
  --warning-bg: #3a2c10;
  --danger: #f87171;
  --danger-bg: #3a1818;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, .45);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* Follow OS preference only when the user hasn't chosen explicitly. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #0b1020;
    --surface: #151b2e;
    --surface-2: #1c2438;
    --surface-hover: #1c2438;
    --border: #2a3350;
    --border-strong: #3a456a;
    --text: #e8ecf5;
    --muted: #94a3b8;
    --primary: #818cf8;
    --primary-hover: #a5b0ff;
    --primary-bg: #1e2547;
    --on-primary: #0b1020;
    --accent: #2dd4bf;
    --accent-bg: #122e30;
    --success: #4ade80;
    --success-bg: #14331f;
    --warning: #fbbf24;
    --warning-bg: #3a2c10;
    --danger: #f87171;
    --danger-bg: #3a1818;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, .45);
    --shadow-lg: 0 18px 44px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* Clip horizontal overflow so the off-canvas nav drawer (translated off-screen)
   never widens the page or creates a phantom horizontal scrollbar on mobile. */
html, body { overflow-x: hidden; max-width: 100%; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-md);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); font-weight: 400; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---- Icons ---- */
.icon {
  width: 1.15em;
  height: 1.15em;
  display: inline-block;
  vertical-align: -0.18em;
  flex: none;
}

/* ==========================================================================
   App shell: collapsible left sidebar + main column
   ========================================================================== */
.app { display: flex; align-items: flex-start; min-height: 100vh; }

.sidebar {
  flex: none;
  width: 240px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 70;
  transition: width .18s ease, transform .22s ease;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  height: var(--topbar-h);
  padding: 0 .6rem 0 1rem;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.sidenav {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  padding: .75rem .6rem;
  overflow-y: auto;
}
.sidenav a {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem .7rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
  font-size: var(--fs-sm);
  white-space: nowrap;
}
.sidenav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidenav a.active { background: var(--primary-bg); color: var(--primary); }
.sidenav a .icon { width: 1.25rem; height: 1.25rem; flex: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* Collapsed sidebar (desktop): icons only, remembered in localStorage */
#sidebar-collapse .icon { transition: transform .18s; transform: rotate(180deg); }
.sidebar-collapsed #sidebar-collapse .icon { transform: rotate(0deg); }
.sidebar-collapsed .sidebar { width: 68px; }
.sidebar-collapsed .brand-text,
.sidebar-collapsed .sidenav a span { display: none; }
.sidebar-collapsed .sidebar-head { padding: 0; justify-content: center; }
.sidebar-collapsed .brand { display: none; }
.sidebar-collapsed .sidenav a { justify-content: center; padding: .65rem; }

/* ==========================================================================
   Topbar (inside main column)
   ========================================================================== */
.topbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  height: var(--topbar-h);
  padding: 0 clamp(.75rem, 2vw, 1.5rem);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-weight: 700;
  font-size: var(--fs-lg);
  letter-spacing: -.02em;
  color: var(--text);
  white-space: nowrap;
  min-width: 0;
}
.brand:hover { text-decoration: none; }
.brand .icon { width: 1.4rem; height: 1.4rem; color: var(--primary); flex: none; }
.brand-text { display: inline; overflow: hidden; text-overflow: ellipsis; }

.search-wrap { position: relative; flex: 1 1 auto; min-width: 0; max-width: 640px; }
.search-field { position: relative; display: flex; align-items: center; }
.search-field .icon {
  position: absolute; left: .8rem; color: var(--muted);
  width: 1.15rem; height: 1.15rem; pointer-events: none;
}
#global-search {
  width: 100%;
  height: var(--touch);
  padding: 0 .9rem 0 2.5rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-md);
}
#global-search::placeholder { color: var(--muted); }
#global-search:focus {
  border-color: var(--primary);
  background: var(--surface);
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-bg);
}

.search-results {
  position: absolute;
  top: calc(var(--touch) + 6px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: min(60vh, 460px);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 60;
  padding: .35rem;
}
.search-item {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .45rem .55rem;
  border-radius: var(--radius-sm);
  min-height: var(--touch);
}
.search-item:hover { background: var(--surface-hover); }
.search-item .pill { flex: none; }
.search-item .si-text {
  flex: 1 1 auto;
  min-width: 0;          /* allow the text column to shrink and ellipsize */
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  overflow: hidden;
}
.search-item .si-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-item .si-meta {
  color: var(--muted);
  font-size: var(--fs-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-item .si-pay { flex: none; padding: 0 .55rem; }
.search-section-label {
  padding: .5rem .65rem .25rem;
  font-size: var(--fs-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 600;
}

.topbar-actions { display: flex; align-items: center; gap: .4rem; margin-left: auto; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch);
  height: var(--touch);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn .icon { width: 1.3rem; height: 1.3rem; }
.icon-btn--danger { color: var(--danger); }
.icon-btn--danger:hover { background: var(--danger-bg); color: var(--danger); }
.card-actions { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.card-actions-main { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.session-dates { list-style: none; margin: .4rem 0 0; padding: 0; columns: 2; font-size: var(--fs-sm); color: var(--muted); }

/* Hamburger lives in the topbar on mobile only; sidebar collapse is desktop-only */
#nav-toggle { display: none; }

/* Theme toggle shows the icon of the theme you'd switch TO */
#theme-toggle .icon-moon { display: inline-block; }
#theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] #theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] #theme-toggle .icon-sun { display: inline-block; }

.logout-form { display: inline-flex; align-items: center; gap: .35rem; }
.username { display: inline-flex; align-items: center; gap: .35rem; font-size: var(--fs-sm); color: var(--muted); white-space: nowrap; }
.username .icon { width: 1.05rem; height: 1.05rem; }

/* Mobile nav drawer (hidden on desktop) */
.nav-scrim { display: none; }

/* ==========================================================================
   Layout
   ========================================================================== */
/* width:100% so it fills the flex .main column; auto margins alone would make a
   flex child shrink-to-fit (collapsing the layout on mobile). */
.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: clamp(1rem, 3vw, 1.75rem); }

h1 { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -.02em; margin: 0 0 1rem; }
h2 { font-size: var(--fs-lg); font-weight: 600; letter-spacing: -.01em; margin: 1.4rem 0 .7rem; }
h3 { font-size: var(--fs-md); font-weight: 600; margin: 1rem 0 .5rem; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.page-head h1, .page-head h2 { margin: 0; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 1.25rem; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: var(--touch);
  padding: 0 1.1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .04s, box-shadow .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn .icon { width: 1.1rem; height: 1.1rem; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); background: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-small { min-height: 36px; padding: 0 .7rem; font-size: var(--fs-xs); }
.btn-lg { min-height: 54px; padding: 0 1.5rem; font-size: var(--fs-md); }
.btn-block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.inline { display: inline; }

/* ==========================================================================
   Cards & stats
   ========================================================================== */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin: 0 0 1.25rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow-sm);
}
section.card { margin-bottom: 1.25rem; }
/* The live-refresh payments wrapper is a bare <div><section> — same rhythm. */
#rate-section { margin-bottom: 1.25rem; }

.stat {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  overflow: hidden;
}
.stat-icon {
  position: absolute;
  top: 1rem; right: 1rem;
  width: 2.2rem; height: 2.2rem;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--muted);
}
.stat-icon .icon { width: 1.3rem; height: 1.3rem; }
.stat-number { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: var(--fs-sm); }
.stat-ok { border-top: 3px solid var(--success); }
.stat-ok .stat-icon { background: var(--success-bg); color: var(--success); }
.stat-pending { border-top: 3px solid var(--warning); }
.stat-pending .stat-icon { background: var(--warning-bg); color: var(--warning); }
.stat-overdue { border-top: 3px solid var(--danger); }
.stat-overdue .stat-icon { background: var(--danger-bg); color: var(--danger); }
.stat-accent { border-top: 3px solid var(--accent); }
.stat-accent .stat-icon { background: var(--accent-bg); color: var(--accent); }

/* ==========================================================================
   Pills / badges
   ========================================================================== */
.pill {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .6rem;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
}
.pill .icon { width: .95rem; height: .95rem; }
.pill--ok, .pill--pagata { background: var(--success-bg); color: var(--success); }
.pill--scaduta { background: var(--danger-bg); color: var(--danger); }
.pill--parziale, .pill--da_pagare { background: var(--warning-bg); color: var(--warning); }
.pill--esonerata { background: var(--surface-2); color: var(--muted); }
/* Easter egg: "Nemico di LABO" — dark, ominous, slightly menacing. */
.pill--nemico { background: #1b1320; color: #ff5470; border: 1px solid #ff547066; font-weight: 700; }
.pill--nemico .icon { color: #ff5470; }

/* Macro-area colour markers */
.area-dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; vertical-align: middle; flex: none; }
.area-dots { display: inline-flex; gap: .25rem; align-items: center; }
.area-pill { background: transparent; border: 1px solid; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .15rem .55rem;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
}

/* ==========================================================================
   Tables (responsive: stack to cards under md)
   ========================================================================== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
th, td { text-align: left; padding: .7rem .8rem; border-bottom: 1px solid var(--border); }
th {
  background: var(--surface-2);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
}
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--surface-hover); }
tbody tr:last-child td { border-bottom: none; }
td a { font-weight: 600; }

/* Area accent: solid 4px left edge per row (custom prop set inline on the tr).
   border-left on <tr> is unreliable with border-collapse, so paint the first
   cell; a transparent border on every row keeps columns aligned. */
tbody td:first-child { border-left: 4px solid transparent; padding-left: calc(.8rem - 4px); }
tbody tr.area-accent > td:first-child { border-left-color: var(--area-color); }

/* ==========================================================================
   Definition lists
   ========================================================================== */
dl { display: grid; grid-template-columns: minmax(7rem, auto) 1fr; gap: .45rem 1rem; margin: 0; }
dt { font-weight: 600; color: var(--muted); font-size: var(--fs-sm); }
dd { margin: 0; }

.enrollment-row { padding: .6rem 0; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; }
.enrollment-row:last-child { border-bottom: none; }
.enrollment-row.inactive { opacity: .55; }

/* ==========================================================================
   Forms
   ========================================================================== */
.filters {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
  align-items: center;
  margin: 0 0 1.25rem;
  padding: .9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.filters input, .filters select { min-height: var(--touch); flex: 1 1 160px; }

/* Collapsible filter drawer inside .filters: keeps the fold clean, opens on
   demand (or automatically when filters are active — the template adds
   [open]). The summary is styled as a button; the native marker is hidden. */
.filters-collapse { width: 100%; }
.filters-collapse > summary { list-style: none; display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; user-select: none; }
.filters-collapse > summary::-webkit-details-marker { display: none; }
.filters-collapse > summary .badge { background: var(--primary); color: var(--on-primary); }
.filters-collapse[open] > summary { margin-bottom: .6rem; }
.filters-body { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.filters-body input, .filters-body select { min-height: var(--touch); flex: 1 1 160px; }

.form-grid { display: grid; grid-template-columns: 1fr; gap: 1.1rem; margin-top: .5rem; }
.settings-card { display: block; text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s; }
.settings-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.settings-card strong { display: block; margin-top: .4rem; }
.settings-card .settings-card-icon .icon { width: 1.6rem; height: 1.6rem; color: var(--primary); }
.settings-card p { margin: .2rem 0 0; }
fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem 1.2rem;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  margin: 0;
}
legend { padding: 0 .5rem; font-weight: 600; color: var(--text); font-size: var(--fs-sm); }
label { display: block; margin-bottom: .85rem; font-size: var(--fs-sm); font-weight: 500; color: var(--muted); }
label:last-child { margin-bottom: 0; }
label.check { display: flex; align-items: center; gap: .55rem; font-weight: 500; }

input, select, textarea {
  width: 100%;
  min-height: var(--touch);
  margin-top: .3rem;
  padding: .5rem .75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: var(--fs-md);
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}
input[type=checkbox], input[type=radio] { width: auto; min-height: auto; margin-top: 0; accent-color: var(--primary); width: 1.1rem; height: 1.1rem; }
textarea { min-height: 88px; resize: vertical; }
label.check input { margin-top: 0; }

.form-actions { grid-column: 1 / -1; display: flex; gap: .6rem; flex-wrap: wrap; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
@media (max-width: 479px) { .row-2 { grid-template-columns: 1fr; } }
.teacher-pick { margin: .2rem 0 .6rem; max-height: 180px; overflow-y: auto; }
.teacher-pick label.check { margin-bottom: .4rem; }

/* ==========================================================================
   Alerts
   ========================================================================== */
.alert { display: flex; align-items: center; gap: .5rem; padding: .75rem 1rem; border-radius: var(--radius); margin: 0 0 1rem; font-size: var(--fs-sm); }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); display: block; }
.alert-info { background: var(--primary-bg); color: var(--primary); }
.alert .icon { width: 1.2rem; height: 1.2rem; }

.empty { color: var(--muted); padding: 1.5rem; text-align: center; }

/* On phones, buttons carrying a .btn-label shrink to icon-only (the title
   attribute keeps them discoverable; touch target stays >= --touch). */
@media (max-width: 767px) {
  .btn .btn-label { display: none; }
  /* Icon-only buttons stretch to fill the action row edge to edge; the
     primary (btn-lg) takes double width and a taller, bigger icon. */
  .page-head .actions { width: 100%; }
  .page-head .actions .btn:has(.btn-label) { flex: 1 1 0; }
  .page-head .actions .btn-lg:has(.btn-label) { flex: 2 1 0; min-height: 58px; }
  .btn-lg .icon { width: 1.5rem; height: 1.5rem; }
}

/* Collapsible secondary sections (anagrafica, portale, reminder): summary
   reads like a section heading; chevron rotates when open. */
.section-collapse { margin-bottom: 1rem; }
.section-collapse > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: .5rem;
  font-weight: 700; font-size: var(--fs-lg);
  min-height: var(--touch);
}
.section-collapse > summary::-webkit-details-marker { display: none; }
.section-collapse > summary::after { content: "▸"; margin-left: auto; color: var(--muted); transition: transform .15s; }
.section-collapse[open] > summary::after { transform: rotate(90deg); }
.section-collapse[open] > summary { margin-bottom: .8rem; }

/* ==========================================================================
   Login
   ========================================================================== */
.login-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  padding: 1.25rem;
  background:
    radial-gradient(1200px 500px at 50% -10%, var(--primary-bg), transparent),
    var(--bg);
}
.login-card {
  background: var(--surface);
  padding: 2.25rem 2rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 380px;
}
.login-card .brand { font-size: var(--fs-xl); justify-content: center; margin-bottom: .25rem; }
.login-card .brand .icon { width: 1.8rem; height: 1.8rem; }
.login-card h1 { text-align: center; }
.login-card p.muted { text-align: center; margin-top: 0; }

/* ==========================================================================
   Quick-pay modal / bottom-sheet
   ========================================================================== */
#quick-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 1rem 1rem;
  z-index: 100;
}
#quick-overlay.open { display: flex; }
.quick-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.3rem;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  /* Long panels (e.g. new course) scroll inside, never past the viewport. */
  max-height: 84vh;
  overflow-y: auto;
}
.quick-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.1rem; }
.quick-head strong { font-size: var(--fs-lg); }
.method-buttons { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; margin-top: .3rem; }
.method-opt {
  display: flex; align-items: center; justify-content: center; gap: .3rem;
  min-height: var(--touch);
  padding: .5rem;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin: 0;
  font-weight: 600;
  color: var(--muted);
  text-transform: capitalize;
}
.method-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.method-opt:has(input:checked) { border-color: var(--primary); background: var(--primary-bg); color: var(--primary); }

/* ==========================================================================
   Toasts
   ========================================================================== */
#toast-area {
  /* Raised above the FAB (56px + margins) so toasts never cover it. */
  position: fixed;
  bottom: calc(1.75rem + 56px + env(safe-area-inset-bottom, 0px));
  right: 1rem; left: auto;
  display: flex; flex-direction: column; gap: .6rem;
  z-index: 200; max-width: min(92vw, 440px);
}

/* ==========================================================================
   Floating action button (nuovo interessato)
   ========================================================================== */
.fab {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  z-index: 90; /* above sidebar (70), below #quick-overlay (100) and toasts (200) */
  width: 56px; height: 56px;
  border: none; border-radius: 50%;
  background: var(--primary); color: var(--on-primary);
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.fab .icon { width: 1.5rem; height: 1.5rem; }
.fab:hover { background: var(--primary-hover); }
.fab:active { transform: scale(.96); }
.toast {
  display: flex; align-items: center; gap: 1rem;
  padding: .9rem 1.1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  color: #fff;
  font-size: var(--fs-sm);
}
.toast .icon { width: 1.3rem; height: 1.3rem; flex: none; }
.toast-success { background: var(--success); }
.toast-info { background: var(--primary); }
.toast .btn { color: #fff; border-color: rgba(255, 255, 255, .55); background: rgba(255, 255, 255, .12); }
.toast .btn:hover { background: rgba(255, 255, 255, .22); }

/* HTMX loading affordance */
.htmx-request.btn { opacity: .7; pointer-events: none; }

/* ==========================================================================
   Calendar
   ========================================================================== */
.cal-week {
  display: grid;
  grid-template-columns: repeat(6, 1fr);  /* Mon–Sat by default; Sunday hidden */
  gap: .6rem;
}
.cal-week.show-sunday { grid-template-columns: repeat(7, 1fr); }
.cal-week:not(.show-sunday) .cal-sunday { display: none; }
.cal-day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-height: 120px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.cal-today { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-bg); }
.cal-day-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: .5rem .6rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.cal-dow { font-weight: 700; text-transform: uppercase; font-size: var(--fs-xs); letter-spacing: .04em; }
.cal-date { color: var(--muted); font-size: var(--fs-xs); }
.cal-day-body { padding: .45rem; display: flex; flex-direction: column; gap: .45rem; }
.cal-empty { color: var(--border-strong); text-align: center; margin: .4rem 0; }

.cal-lesson {
  border: 1px solid var(--border);
  /* Solid area colour as the card's left edge; primary when no area. */
  border-left: 4px solid var(--area-color, var(--primary));
  border-radius: var(--radius-sm);
  padding: .45rem .55rem;
  background: var(--surface);
  font-size: var(--fs-sm);
}
/* Lesson just rescheduled (?evidenzia=<id>): pulse on landing, then keep a
   visible ring so it stays findable at a glance. */
.cal-highlight { outline: 2px solid var(--primary); outline-offset: 1px; animation: cal-pulse 1.1s ease-out 3; }
@keyframes cal-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--primary) 55%, transparent); }
  100% { box-shadow: 0 0 0 14px transparent; }
}
.cal-lesson .cal-time { font-weight: 700; font-size: var(--fs-xs); color: var(--muted); }
.cal-lesson .cal-student { font-weight: 600; display: block; }
.cal-lesson .cal-meta { color: var(--muted); font-size: var(--fs-xs); }
.cal-lesson .cal-status { margin-top: .35rem; }
/* Status speaks through backgrounds/pills; the left edge stays area-coloured. */
.cal-svolta { background: var(--success-bg); }
.cal-annullata { opacity: .7; }
.cal-annullata .cal-student { text-decoration: line-through; }
.cal-conflict { box-shadow: 0 0 0 2px var(--danger); }
.cal-session { border-left-width: 5px; border-left-style: double; }
.cal-session--planned { border: 1px dashed var(--border); border-left: 4px dashed var(--area-color, var(--primary)); opacity: .72; background: transparent; }
.cal-session .cal-student { font-weight: 700; }
.cal-roster { list-style: none; margin: .3rem 0; padding-left: .4rem; display: flex; flex-direction: column; gap: .15rem; font-size: var(--fs-xs); }
.cal-roster li { display: flex; gap: .3rem; align-items: center; }
.cal-status .btn { margin-top: .3rem; }
.quick-panel--wide { max-width: 560px; }
.cal-actions { margin-top: .5rem; padding-top: .5rem; border-top: 1px dashed var(--border); display: flex; flex-direction: column; gap: .4rem; }
.cal-status-btns { display: flex; flex-wrap: wrap; gap: .3rem; }
.cal-actions label { margin-bottom: .35rem; font-size: var(--fs-xs); }
.cal-move summary { display: inline-flex; margin-bottom: .3rem; }
.cal-move form { display: flex; flex-direction: column; gap: .2rem; }
[x-cloak] { display: none !important; }

/* Month grid */
.cal-month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-mhead { background: var(--surface-2); padding: .4rem; text-align: center; font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; color: var(--muted); }
.cal-mcell { background: var(--surface); min-height: 92px; padding: .3rem; display: flex; flex-direction: column; gap: 2px; }
.cal-mcell.cal-other { background: var(--surface-2); opacity: .55; }
.cal-mcell.cal-today { box-shadow: inset 0 0 0 2px var(--primary); }
.cal-mdate { font-size: var(--fs-xs); color: var(--muted); font-weight: 600; }
.cal-mitem { font-size: var(--fs-xs); padding: 1px 4px; border-radius: 4px; background: var(--primary-bg); color: var(--primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-mitem:hover { text-decoration: none; filter: brightness(.96); }
.cal-mitem.cal-svolta { background: var(--success-bg); color: var(--success); }
.cal-mitem.cal-annullata { background: var(--danger-bg); color: var(--danger); text-decoration: line-through; }
.cal-mitem.cal-conflict { box-shadow: 0 0 0 1.5px var(--danger); }
.cal-mitem .area-dot { width: .45rem; height: .45rem; margin-right: .2rem; }
@media (max-width: 700px) {
  .cal-mcell { min-height: 64px; }
  .cal-mitem { font-size: 10px; }
}

/* Calendar on tablet/phone: stack the days vertically */
@media (max-width: 900px) {
  .cal-week, .cal-week.show-sunday { grid-template-columns: 1fr; }
  .cal-day { min-height: auto; }
  .cal-day-body:empty::after { content: ""; }
}

/* ==========================================================================
   Responsive — tablet & up
   ========================================================================== */
@media (min-width: 768px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 1024px) {
  .container { padding: 1.75rem 2rem; }
  /* Side-by-side sections only when there's room for two full tables; below
     this they stack vertically so each table keeps its full width. */
  .grid-2 { grid-template-columns: 1fr 1fr; }
}

/* ==========================================================================
   Responsive — below lg: the sidebar becomes an off-canvas drawer
   ========================================================================== */
@media (max-width: 1023px) {
  #nav-toggle { display: inline-flex; }
  #sidebar-collapse { display: none; }

  /* Drawer is always full (labels visible) even if collapsed on desktop */
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    height: 100%;
    width: min(82vw, 280px);
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar-collapsed .sidebar { width: min(82vw, 280px); }
  .sidebar-collapsed .brand,
  .sidebar-collapsed .brand-text,
  .sidebar-collapsed .sidenav a span { display: revert; }
  .sidebar-collapsed .sidebar-head { padding: 0 .6rem 0 1rem; justify-content: space-between; }
  .sidebar-collapsed .sidenav a { justify-content: flex-start; padding: .65rem .7rem; }

  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .nav-scrim {
    display: block;
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, .45);
    z-index: 65;
  }
  .username { display: none; }
}

/* ==========================================================================
   Responsive — phones: stack tables into cards
   ========================================================================== */
@media (max-width: 767px) {
  table, thead, tbody, th, td, tr { display: block; }
  table {
    border: none;
    background: transparent;
    box-shadow: none;
    overflow: visible;
  }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tbody tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: .35rem .9rem;
    margin-bottom: .75rem;
  }
  tbody tr:hover { background: var(--surface); }
  /* Card mode: the area accent moves from the first cell to the card edge
     (border-left on a display:block row IS reliable here). */
  tbody td:first-child { border-left: none; padding-left: 0; }
  tbody tr.area-accent { border-left: 4px solid var(--area-color); }
  td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: .5rem 0;
    border-bottom: 1px solid var(--border);
    text-align: right;
  }
  tr td:last-child { border-bottom: none; }
  td::before {
    content: attr(data-label);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    font-weight: 600;
    text-align: left;
    flex: none;
  }
  td:empty { display: none; }
  /* Inline forms inside table cells (course list edit) stay usable */
  td form, td input, td select { width: auto; }

  /* Quick-pay becomes a bottom-sheet */
  #quick-overlay { align-items: flex-end; padding: 0; }
  .quick-panel {
    max-width: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 1.1rem 1.1rem calc(1.1rem + env(safe-area-inset-bottom));
    animation: sheet-up .22s ease;
  }
  .quick-panel::before {
    content: "";
    display: block;
    width: 40px; height: 4px;
    background: var(--border-strong);
    border-radius: 999px;
    margin: -.4rem auto .8rem;
  }
  #toast-area { left: 1rem; right: 1rem; max-width: none; }
  h1 { font-size: var(--fs-lg); }
}

@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

@media (max-width: 479px) {
  body { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
