/* Delphi Wrapper — design system.
 *
 * A friendly, polished student portal for Tor Vergata students. Wide appeal,
 * not a developer console. Warmth comes from Fraunces (display) and Inter
 * (body); data clarity comes from JetBrains Mono. Tor Vergata green appears
 * sparingly — primary actions, session-active, success states — never as the
 * page's spine.
 *
 * Tension: the data is dense and tabular (matricola, voti, CFU, SSD, IUV, codici)
 * so the mono voice is the data voice; but the surface language is warm and
 * friendly (welcome on riepilogo, not a 4-col stat band). Hairline rules carry
 * structure, not cards-within-cards. Single source of truth: DESIGN.md. */

@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap");

/* ============================== Tokens ============================== */
:root {
  /* Brand */
  --brand:        oklch(0.50 0.137 152);
  --brand-strong: oklch(0.43 0.137 152);
  --brand-text:   oklch(0.46 0.130 152);
  --brand-soft:   oklch(0.94 0.045 152);

  /* Neutrals — light */
  --bg:           oklch(0.985 0.003 90);
  --surface:      oklch(1 0 0);
  --surface-2:    oklch(0.97 0.003 90);
  --ink:          oklch(0.22 0.015 250);
  --ink-2:        oklch(0.45 0.012 250);
  --ink-3:        oklch(0.60 0.010 250);
  --line:         oklch(0.91 0.005 250);
  --line-strong:  oklch(0.82 0.006 250);

  /* Semantic */
  --ok:           oklch(0.50 0.137 152);
  --ok-bg:        oklch(0.94 0.045 152);
  --warn:         oklch(0.62 0.13 65);
  --warn-bg:      oklch(0.96 0.04 80);
  --bad:          oklch(0.52 0.18 27);
  --bad-bg:       oklch(0.96 0.03 27);
  --info:         oklch(0.52 0.12 250);
  --info-bg:      oklch(0.96 0.03 250);

  /* Type */
  --font-display: "Fraunces", ui-serif, Georgia, "Times New Roman", serif;
  --font-sans:    "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --t-2xs: 0.6875rem;
  --t-xs:  0.75rem;
  --t-sm:  0.875rem;
  --t-md:  1rem;
  --t-lg:  1.125rem;
  --t-xl:  1.5rem;
  --t-2xl: 2rem;
  --t-3xl: 3rem;

  /* Spacing */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;
  --sp-9: 96px;

  /* Radius */
  --r-1: 4px; --r-2: 8px; --r-3: 12px; --r-4: 16px; --r-full: 9999px;

  /* Elevation */
  --shadow-1: 0 1px 2px rgba(20, 25, 35, 0.06);
  --shadow-2: 0 6px 24px rgba(20, 25, 35, 0.08), 0 2px 6px rgba(20, 25, 35, 0.05);

  /* Z-index */
  --z-sticky: 10; --z-dropdown: 20; --z-overlay: 30;
  --z-modal: 40; --z-toast: 50; --z-tooltip: 60;

  /* Motion */
  --dur-fast: 120ms;
  --dur: 180ms;
  --dur-slow: 280ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

  --maxw: 880px;
  --sidebar: 240px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-strong: oklch(0.58 0.14 152);
    --brand-text:   oklch(0.74 0.14 152);
    --brand-soft:   oklch(0.28 0.05 152);

    --bg:           oklch(0.16 0.012 250);
    --surface:      oklch(0.20 0.013 250);
    --surface-2:    oklch(0.24 0.013 250);
    --ink:          oklch(0.95 0.005 250);
    --ink-2:        oklch(0.72 0.010 250);
    --ink-3:        oklch(0.58 0.010 250);
    --line:         oklch(0.30 0.010 250);
    --line-strong:  oklch(0.40 0.012 250);

    --ok-bg:        oklch(0.28 0.05 152);
    --warn:         oklch(0.78 0.12 65);
    --warn-bg:      oklch(0.30 0.05 75);
    --bad:          oklch(0.72 0.16 27);
    --bad-bg:       oklch(0.30 0.07 27);
    --info:         oklch(0.72 0.12 250);
    --info-bg:      oklch(0.30 0.05 250);

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-2: 0 6px 24px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand-strong: oklch(0.58 0.14 152);
  --brand-text:   oklch(0.74 0.14 152);
  --brand-soft:   oklch(0.28 0.05 152);

  --bg:           oklch(0.16 0.012 250);
  --surface:      oklch(0.20 0.013 250);
  --surface-2:    oklch(0.24 0.013 250);
  --ink:          oklch(0.95 0.005 250);
  --ink-2:        oklch(0.72 0.010 250);
  --ink-3:        oklch(0.58 0.010 250);
  --line:         oklch(0.30 0.010 250);
  --line-strong:  oklch(0.40 0.012 250);

  --ok-bg:        oklch(0.28 0.05 152);
  --warn:         oklch(0.78 0.12 65);
  --warn-bg:      oklch(0.30 0.05 75);
  --bad:          oklch(0.72 0.16 27);
  --bad-bg:       oklch(0.30 0.07 27);
  --info:         oklch(0.72 0.12 250);
  --info-bg:      oklch(0.30 0.05 250);

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 6px 24px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

/* ============================== Reset ============================== */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  font-size: var(--t-md);
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100dvh;
  font-feature-settings: "cv11", "ss01";
}
h1, h2, h3 { line-height: 1.3; text-wrap: balance; letter-spacing: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-text); text-underline-offset: 2px; }
svg { display: block; }
img { display: block; max-width: 100%; }

/* ============================== A11y ============================== */
.skip-link {
  position: absolute; left: -9999px; top: var(--sp-2); z-index: 100;
  background: var(--surface); color: var(--ink); padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-2); box-shadow: var(--shadow-2);
}
.skip-link:focus { left: var(--sp-3); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: var(--r-1); }

/* ============================== App shell ============================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100dvh;
}

/* Sidebar */
.sidebar {
  position: sticky; top: 0; height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: var(--sp-5) var(--sp-3);
}
.sidebar-head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-3) var(--sp-5);
  margin-bottom: var(--sp-2);
  border-bottom: 1px solid var(--line);
}
.sidebar-logo {
  width: 24px; height: 32px; flex: none;
  background: var(--brand);
  -webkit-mask: url("/static/unilogo.svg") center / contain no-repeat;
          mask: url("/static/unilogo.svg") center / contain no-repeat;
}
.sidebar-title {
  font-family: var(--font-display);
  font-size: var(--t-md);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  line-height: 1.1;
}
.sidebar-tag {
  font-size: var(--t-2xs);
  color: var(--ink-3);
  margin-top: 2px;
  letter-spacing: 0.02em;
}
.sidebar-nav { flex: 1; padding: var(--sp-2) 0; }
.sidebar-group { margin-bottom: var(--sp-4); }
.sidebar-group-label {
  font-size: var(--t-2xs);
  font-weight: 600;
  color: var(--ink-3);
  letter-spacing: 0.04em;
  padding: var(--sp-2) var(--sp-3) var(--sp-1);
}
.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  width: 100%; padding: var(--sp-2) var(--sp-3);
  border: none; background: transparent;
  color: var(--ink-2); font-size: var(--t-sm); font-weight: 500;
  border-radius: var(--r-2); cursor: pointer;
  text-align: left;
  transition: color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.nav-item:hover { color: var(--ink); background: var(--surface-2); }
.nav-item[aria-current="page"] {
  color: var(--ink);
  background: var(--brand-soft);
  font-weight: 600;
}
.nav-item .nav-icon { width: 16px; height: 16px; flex: none; opacity: 0.7; }
.nav-item[aria-current="page"] .nav-icon { opacity: 1; color: var(--brand-text); }

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: var(--sp-3) var(--sp-3) 0;
  display: flex; flex-direction: column; gap: var(--sp-3);
}
.sidebar-actions { display: flex; align-items: center; gap: var(--sp-2); }

/* On mobile, hide the desktop sidebar entirely and switch the app to a
 * single column. The hamburger drawer is the navigation surface instead. */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

/* Mobile drawer (slides in from the left, full-height, modal) */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: var(--z-overlay);
  background: oklch(0.16 0.012 250 / 0.5);
  animation: fade-in var(--dur) var(--ease-out) both;
}
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: var(--z-modal);
  width: min(86vw, 320px);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: var(--sp-4) var(--sp-3);
  animation: drawer-in var(--dur) var(--ease-out) both;
  box-shadow: var(--shadow-2);
  /* respect the safe area on phones with notches */
  padding-top: calc(var(--sp-4) + env(safe-area-inset-top));
  padding-bottom: calc(var(--sp-4) + env(safe-area-inset-bottom));
}
.drawer-head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-2) var(--sp-4);
  margin-bottom: var(--sp-2);
  border-bottom: 1px solid var(--line);
}
.drawer-head .sidebar-logo { width: 24px; height: 32px; flex: none; background: var(--brand); -webkit-mask: url("/static/unilogo.svg") center / contain no-repeat; mask: url("/static/unilogo.svg") center / contain no-repeat; }
.drawer-head > div { flex: 1; min-width: 0; }
.drawer-close { margin-left: auto; }
.drawer-nav { flex: 1; overflow-y: auto; padding: var(--sp-2) 0; }
.drawer-foot {
  border-top: 1px solid var(--line);
  padding-top: var(--sp-3);
  display: flex; flex-direction: column; gap: var(--sp-1);
}
.drawer-action {
  justify-content: flex-start;
  width: 100%;
  height: 44px;
  font-weight: 500;
  color: var(--ink-2);
}
.drawer-action:hover { color: var(--ink); background: var(--surface-2); }
@keyframes drawer-in {
  from { transform: translateX(-100%); }
  to   { transform: none; }
}

/* Mobile top bar */
.mobile-top {
  display: none;
  position: sticky; top: 0; z-index: var(--z-sticky);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: var(--sp-3) var(--sp-4);
  align-items: center; gap: var(--sp-3);
}
.mobile-top-logo {
  width: 22px; height: 30px; flex: none;
  background: var(--brand);
  -webkit-mask: url("/static/unilogo.svg") center / contain no-repeat;
          mask: url("/static/unilogo.svg") center / contain no-repeat;
}
.mobile-top-title { font-family: var(--font-display); font-size: var(--t-md); font-weight: 600; flex: 1; }
.mobile-top-actions { display: flex; gap: var(--sp-1); }
@media (max-width: 900px) {
  .mobile-top { display: flex; }
}

/* Main */
.main {
  padding: var(--sp-7) var(--sp-6) var(--sp-9);
  max-width: 100%;
}
.main-inner { max-width: var(--maxw); margin: 0 auto; }
@media (max-width: 720px) {
  .main { padding: var(--sp-5) var(--sp-4) var(--sp-7); }
}
@media (max-width: 900px) {
  /* No tabbar — just the standard bottom padding. */
  .main { padding-bottom: var(--sp-7); }
}

/* ============================== Page header ============================== */
.page-head {
  margin-bottom: var(--sp-6);
}
.page-title {
  font-family: var(--font-display);
  font-size: var(--t-2xl);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.1;
  color: var(--ink);
  font-variation-settings: "opsz" 48;
}
.page-sub {
  margin-top: var(--sp-2);
  color: var(--ink-2);
  font-size: var(--t-md);
  max-width: 60ch;
}
.page-actions {
  display: flex; flex-wrap: wrap; gap: var(--sp-2);
  margin-top: var(--sp-4);
}

/* ============================== Section ============================== */
.section { margin-bottom: var(--sp-7); }
.section:last-child { margin-bottom: 0; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--sp-4); margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--line);
}
.section-title {
  font-family: var(--font-sans);
  font-size: var(--t-md);
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0;
}
.section-meta { color: var(--ink-3); font-size: var(--t-sm); }
.section + .section { margin-top: var(--sp-6); }

/* ============================== Buttons ============================== */
.btn {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: 0 var(--sp-4); height: 40px;
  border: 1px solid transparent; border-radius: var(--r-2);
  font-family: var(--font-sans); font-size: var(--t-sm); font-weight: 500; line-height: 1;
  cursor: pointer; background: transparent; color: var(--ink);
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
  text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(0.985); }
.btn-primary { background: var(--brand); color: white; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { color: var(--ink-2); background: transparent; }
.btn-ghost:hover { color: var(--ink); background: var(--surface-2); }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn-sm { height: 32px; padding: 0 var(--sp-3); font-size: var(--t-xs); }
.btn-icon { width: 40px; height: 40px; padding: 0; justify-content: center; }
.btn-icon.btn-sm { width: 32px; height: 32px; }

/* ============================== Inputs ============================== */
.field { display: block; margin-bottom: var(--sp-4); }
.field-label {
  display: block; font-size: var(--t-sm); font-weight: 500;
  color: var(--ink-2); margin-bottom: var(--sp-2);
}
.field-hint { font-size: var(--t-xs); color: var(--ink-3); margin-top: var(--sp-2); }
.field-error { font-size: var(--t-xs); color: var(--bad); margin-top: var(--sp-2); }

.input, .select, .textarea {
  width: 100%; height: 44px; padding: 0 var(--sp-3);
  font-family: var(--font-sans); font-size: var(--t-md);
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r-2);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.input.mono, .mono-input { font-family: var(--font-mono); font-size: var(--t-sm); letter-spacing: 0; }
.input::placeholder { color: var(--ink-3); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px oklch(0.50 0.137 152 / 0.20);
}
.input.has-error, .select.has-error { border-color: var(--bad); }

/* ============================== Filter bar ============================== */
.filterbar {
  display: flex; flex-wrap: wrap; gap: var(--sp-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  padding: var(--sp-3);
  margin-bottom: var(--sp-4);
  align-items: center;
}
.filterbar .input, .filterbar .select { height: 38px; flex: 1; min-width: 140px; }
.filterbar .input.input-sm { flex: 0 0 110px; min-width: 0; }
.filterbar .filterbar-spacer { flex: 1; }
@media (max-width: 640px) {
  .filterbar .input, .filterbar .select { flex: 1 0 100%; }
  .filterbar .input.input-sm { flex: 1 0 100%; }
}

/* ============================== Tables ============================== */
.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  background: var(--surface);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-sm);
  color: var(--ink);
}
table.data th {
  text-align: left;
  font-family: var(--font-sans);
  font-size: var(--t-xs);
  font-weight: 600;
  color: var(--ink-2);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  position: sticky; top: 0;
}
table.data td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background var(--dur-fast) var(--ease-out); }
table.data tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: var(--ink-2); }
td.mono, th.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.row-cell-name { display: flex; flex-direction: column; gap: 2px; }
.row-cell-name strong { font-weight: 600; color: var(--ink); }
.row-cell-name .row-cell-sub { color: var(--ink-3); font-size: var(--t-xs); font-family: var(--font-mono); }

/* ============================== Status & badges ============================== */
.tag {
  display: inline-flex; align-items: center;
  padding: 2px var(--sp-2); border-radius: var(--r-1);
  font-family: var(--font-sans); font-size: var(--t-xs); font-weight: 600;
  line-height: 1.4; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2);
  border: 1px solid transparent;
}
.tag-ok { background: var(--ok-bg); color: var(--ok); }
.tag-warn { background: var(--warn-bg); color: var(--warn); }
.tag-bad { background: var(--bad-bg); color: var(--bad); }
.tag-info { background: var(--info-bg); color: var(--info); }
.tag-muted { background: var(--surface-2); color: var(--ink-2); }

.voto {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 2px var(--sp-2); border-radius: var(--r-1);
  font-family: var(--font-mono); font-size: var(--t-xs); font-weight: 600;
  font-variant-numeric: tabular-nums; min-width: 36px;
  background: var(--surface-2); color: var(--ink);
}
.voto.lode { background: var(--ok); color: white; }
.voto.idoneo, .voto.partial { background: var(--ink); color: var(--surface); }
.voto.fail { background: var(--bad-bg); color: var(--bad); }

/* ============================== Cards (sparing) ============================== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  padding: var(--sp-5);
}

/* Anagrafica head card */
.profile-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  padding: var(--sp-5);
  display: flex; gap: var(--sp-5); align-items: center; flex-wrap: wrap;
}
.profile-photo {
  width: 96px; height: 128px; object-fit: cover; flex: none;
  border-radius: var(--r-2);
  background: var(--surface-2);
}
.profile-body { flex: 1; min-width: 200px; }
.profile-name {
  font-family: var(--font-display);
  font-size: var(--t-2xl);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.1;
  color: var(--ink);
  font-variation-settings: "opsz" 48;
  margin-bottom: var(--sp-2);
}
.profile-meta { display: flex; flex-wrap: wrap; gap: var(--sp-3); color: var(--ink-2); font-size: var(--t-sm); align-items: center; }
.profile-meta .meta-key { color: var(--ink-3); }

/* ============================== Riepilogo hero ============================== */
.greeting {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--sp-5); flex-wrap: wrap;
  padding-bottom: var(--sp-5);
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--sp-6);
}
.greeting-text { flex: 1; min-width: 220px; }
.greeting-eyebrow {
  font-size: var(--t-sm); color: var(--ink-3); margin-bottom: var(--sp-2);
}
.greeting-name {
  font-family: var(--font-display);
  font-size: var(--t-3xl);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--ink);
  font-variation-settings: "opsz" 144;
}
.greeting-name em { font-style: italic; font-weight: 400; }
.greeting-sub { color: var(--ink-2); margin-top: var(--sp-2); font-size: var(--t-md); }
.greeting-stat {
  display: flex; flex-direction: column; align-items: flex-end; gap: 2px;
  padding: var(--sp-3) var(--sp-5);
  background: var(--brand-soft);
  border-radius: var(--r-3);
  min-width: 180px;
}
.greeting-stat-label {
  font-size: var(--t-2xs); color: var(--ink-2); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.greeting-stat-value {
  font-family: var(--font-display);
  font-size: var(--t-3xl); font-weight: 600;
  letter-spacing: -0.02em; line-height: 1;
  color: var(--brand-text); font-variation-settings: "opsz" 144;
  font-variant-numeric: tabular-nums;
}
.greeting-stat-value .lode-suffix { font-size: 0.5em; color: var(--ok); margin-left: var(--sp-1); }

/* Inline stats list (no grid) */
.stat-line {
  display: flex; flex-wrap: wrap; gap: var(--sp-5);
  padding: var(--sp-4) 0;
  border-bottom: 1px solid var(--line);
}
.stat-line > div { display: flex; flex-direction: column; gap: 2px; }
.stat-line .k { font-size: var(--t-xs); color: var(--ink-3); font-weight: 500; }
.stat-line .v { font-family: var(--font-mono); font-size: var(--t-md); color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-line .v.strong { font-weight: 600; color: var(--brand-text); }

/* Recent exams (mini list) */
.recent-list { display: flex; flex-direction: column; }
.recent-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--line);
}
.recent-row:last-child { border-bottom: none; }
.recent-row .recent-date { color: var(--ink-3); font-size: var(--t-xs); font-family: var(--font-mono); min-width: 80px; }
.recent-row .recent-name { flex: 1; }
.recent-row .recent-name strong { display: block; color: var(--ink); font-weight: 500; }
.recent-row .recent-name .recent-cfu { color: var(--ink-3); font-size: var(--t-xs); margin-left: var(--sp-2); }
.recent-row .recent-voto { min-width: 56px; text-align: right; }

/* ============================== Tasse timeline ============================== */
.tasse-anno { margin-bottom: var(--sp-6); }
.tasse-anno-head {
  display: flex; align-items: baseline; gap: var(--sp-3);
  padding-bottom: var(--sp-3); margin-bottom: var(--sp-3);
  border-bottom: 2px solid var(--ink);
}
.tasse-anno-title {
  font-family: var(--font-display);
  font-size: var(--t-xl); font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  font-variation-settings: "opsz" 24;
}
.tasse-anno-meta { color: var(--ink-3); font-size: var(--t-sm); }
.tasse-anno-total {
  margin-left: auto;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--t-sm); color: var(--ink);
}

.rata-list { display: flex; flex-direction: column; }
.rata {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: var(--sp-3) var(--sp-4);
  align-items: center;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line);
}
.rata:last-child { border-bottom: none; }
.rata .rata-num { font-weight: 600; color: var(--ink); }
.rata .rata-meta { color: var(--ink-2); font-size: var(--t-sm); }
.rata .rata-importo {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  color: var(--ink); font-size: var(--t-md); font-weight: 500;
  text-align: right;
}
.rata .rata-status { display: flex; align-items: center; gap: var(--sp-2); }
.bollettino-detail {
  grid-column: 1 / -1;
  padding: var(--sp-3) var(--sp-4) var(--sp-2);
  background: var(--surface-2);
  border-radius: var(--r-2);
  margin: var(--sp-2) 0 var(--sp-1);
  font-size: var(--t-sm);
  display: flex; flex-wrap: wrap; gap: var(--sp-3) var(--sp-5);
  color: var(--ink-2);
}
.bollettino-detail .bollettino-iuv { font-family: var(--font-mono); font-size: var(--t-xs); color: var(--ink-3); }
.bollettino-detail .bollettino-voice { color: var(--ink-2); }
.bollettino-detail .bollettino-voice strong { color: var(--ink); font-weight: 500; }

@media (max-width: 640px) {
  .rata { grid-template-columns: 1fr auto; row-gap: var(--sp-2); }
  .rata .rata-meta { grid-column: 1 / -1; }
  .rata .rata-status { grid-column: 1 / -1; justify-content: flex-end; }
}

/* ============================== List rows (servizi, certificati) ============================== */
.list-rows {
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  overflow: hidden;
}
.list-row {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--line);
  transition: background var(--dur-fast) var(--ease-out);
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--surface-2); }
.list-row .list-icon {
  width: 36px; height: 36px; flex: none;
  background: var(--brand-soft);
  color: var(--brand-text);
  border-radius: var(--r-2);
  display: grid; place-items: center;
}
.list-row .list-icon svg { width: 18px; height: 18px; }
.list-row .list-body { flex: 1; min-width: 0; }
.list-row .list-title { font-weight: 600; color: var(--ink); margin-bottom: 2px; }
.list-row .list-sub { color: var(--ink-3); font-size: var(--t-sm); }
.list-row .list-action { flex: none; }

/* Code block (inline, not card-with-stripe) */
.code-value {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  font-family: var(--font-mono);
  font-size: var(--t-sm);
  font-variant-numeric: tabular-nums;
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface-2);
  border-radius: var(--r-2);
  color: var(--ink);
  letter-spacing: 0;
  word-break: break-all;
  max-width: 100%;
}
.code-value.is-link { color: var(--brand-text); }
.code-value.is-link:hover { background: var(--brand-soft); }
.code-row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.code-label { font-size: var(--t-xs); color: var(--ink-3); }

/* ============================== Definition list ============================== */
.dl { display: grid; grid-template-columns: minmax(140px, max-content) 1fr; gap: var(--sp-3) var(--sp-5); margin: 0; }
.dl dt { color: var(--ink-2); font-size: var(--t-sm); }
.dl dd { color: var(--ink); font-size: var(--t-sm); font-family: var(--font-mono); font-variant-numeric: tabular-nums; margin: 0; }
@media (max-width: 600px) {
  .dl { grid-template-columns: 1fr; gap: var(--sp-1) 0; }
  .dl dt { margin-top: var(--sp-3); }
  .dl dt:first-child { margin-top: 0; }
}

/* ============================== Empty ============================== */
.empty {
  padding: var(--sp-6) 0;
  color: var(--ink-2);
  max-width: 50ch;
}
.empty-title { font-weight: 600; color: var(--ink); margin-bottom: var(--sp-1); }
.empty-hint { font-size: var(--t-sm); color: var(--ink-3); }

/* ============================== Loading ============================== */
.skeleton {
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  background: var(--surface);
  overflow: hidden;
}
.skel-row {
  height: 56px; border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
.skel-row:last-child { border-bottom: none; }
.skel-block {
  height: 80px; border-radius: var(--r-3);
  background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  margin-bottom: var(--sp-3);
}

/* ============================== Toast ============================== */
.toast-region {
  position: fixed; right: var(--sp-5); bottom: var(--sp-5);
  z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--sp-2);
  max-width: calc(100vw - 2 * var(--sp-5));
}
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-2);
  font-size: var(--t-sm);
  color: var(--ink);
  min-width: 260px;
  animation: toast-in var(--dur) var(--ease-out) both;
}
.toast .toast-icon { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.toast.ok .toast-icon { color: var(--ok); }
.toast.bad .toast-icon { color: var(--bad); }
.toast.info .toast-icon { color: var(--info); }
.toast .toast-close { margin-left: auto; background: none; border: none; color: var(--ink-3); cursor: pointer; padding: 2px; }
.toast .toast-close:hover { color: var(--ink); }
@media (max-width: 900px) {
  .toast-region { left: var(--sp-4); right: var(--sp-4); bottom: 80px; }
  .toast { min-width: 0; }
}

/* ============================== Login ============================== */
.login-page {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: var(--sp-6) var(--sp-4);
  background: var(--bg);
}
.login-wrap { max-width: 360px; width: 100%; text-align: center; }
.login-logo {
  width: 44px; height: 60px;
  background: var(--brand);
  -webkit-mask: url("/static/unilogo.svg") center / contain no-repeat;
          mask: url("/static/unilogo.svg") center / contain no-repeat;
  margin: 0 auto var(--sp-5);
}
.login-eyebrow {
  font-family: var(--font-display);
  font-size: var(--t-sm); color: var(--ink-3);
  font-style: italic; font-weight: 400; margin-bottom: var(--sp-3);
}
.login-title {
  font-family: var(--font-display);
  font-size: var(--t-2xl);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.1;
  color: var(--ink);
  font-variation-settings: "opsz" 48;
  margin-bottom: var(--sp-2);
}
.login-sub {
  color: var(--ink-2);
  font-size: var(--t-md);
  margin-bottom: var(--sp-7);
}
.login-form { text-align: left; }
.login-foot {
  margin-top: var(--sp-6);
  font-size: var(--t-xs);
  color: var(--ink-3);
  line-height: 1.5;
}
.login-foot a { color: var(--ink-2); text-decoration: underline; text-underline-offset: 2px; }

/* ============================== Theme toggle ============================== */
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; }
}

/* ============================== Animations ============================== */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}
@keyframes row-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}
.fade-in { animation: fade-in var(--dur) var(--ease-out) both; }
.row-in { animation: row-in var(--dur) var(--ease-out) both; }

/* ============================== Utilities ============================== */
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.flex-row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.gap-2 { gap: var(--sp-2); }
.text-end { text-align: right; }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); }
.mt-6 { margin-top: var(--sp-6); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }

/* ============================== Mobile polish (< 720px) ============================== */
@media (max-width: 720px) {
  /* Page title: 32 -> 26, keeps balance, never overflows */
  .page-title { font-size: 1.625rem; }
  .page-head { margin-bottom: var(--sp-5); }

  /* Greeting: stack vertically, smaller type, full width stat */
  .greeting { flex-direction: column; align-items: flex-start; }
  .greeting-name { font-size: 2.25rem; }
  .greeting-stat { width: 100%; align-items: flex-start; min-width: 0; }
  .greeting-stat-value { font-size: 2.5rem; }

  /* Stat line: 2 columns of 3, no more overflow */
  .stat-line {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: var(--sp-4);
    row-gap: var(--sp-4);
  }
  .stat-line > div { min-width: 0; }

  /* Recent esami rows: tighter, allow wrap */
  .recent-row { flex-wrap: wrap; row-gap: var(--sp-1); }
  .recent-row .recent-date { min-width: 0; flex: 0 0 100%; }
  .recent-row .recent-name { flex: 1 0 calc(100% - 60px); }
  .recent-row .recent-voto { min-width: 0; }

  /* Tables: switch to card list at narrow width. The table is still
     rendered in JS so the dataTable() helper doesn't need a separate
     code path; we just restyle cells as stacked cards on mobile. */
  .table-wrap {
    border: none; border-radius: 0; background: transparent;
  }
  table.data, table.data thead, table.data tbody, table.data tr, table.data td { display: block; }
  table.data thead { display: none; }
  table.data { width: 100%; }
  table.data tr {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-3);
    padding: var(--sp-3) var(--sp-4);
    margin-bottom: var(--sp-3);
  }
  table.data td {
    border-bottom: 1px solid var(--line);
    padding: var(--sp-2) 0;
    display: flex; justify-content: space-between; align-items: baseline;
    gap: var(--sp-3);
  }
  table.data td:last-child { border-bottom: none; padding-bottom: 0; }
  table.data td::before {
    content: attr(data-label);
    font-size: var(--t-xs); color: var(--ink-3); font-weight: 500;
    flex: 0 0 auto;
    text-transform: none; letter-spacing: 0;
  }
  table.data td.num, table.data td.mono { text-align: right; font-family: inherit; font-variant-numeric: tabular-nums; }

  /* Page actions stack under the title on mobile */
  .page-head { flex-direction: column; align-items: flex-start; }
  .page-actions { width: 100%; }

  /* Section head: stack */
  .section-head { flex-direction: column; align-items: flex-start; gap: var(--sp-2); }

  /* Greeting eyebrow: drop, the h1 carries it */
  /* (no rule needed — we already removed page-eyebrow) */

  /* Tasse: keep the timeline readable on small screens */
  .tasse-anno-title { font-size: var(--t-lg); }

  /* Filter bar: full-width controls stacked */
  .filterbar { padding: var(--sp-2); }
  .filterbar .input,
  .filterbar .select { flex: 1 0 100%; }
  .filterbar .input.input-sm { flex: 1 0 100%; }
  .filterbar .btn { width: 100%; }

  /* Anagrafica head card */
  .profile-photo { width: 72px; height: 96px; }
  .profile-name { font-size: var(--t-xl); }
  .profile-meta { font-size: var(--t-xs); }

  /* Rata: force single-column on very narrow screens */
  .rata { grid-template-columns: 1fr auto; row-gap: var(--sp-2); }
  .rata .rata-meta { grid-column: 1 / -1; }
  .rata .rata-status { grid-column: 1 / -1; justify-content: flex-start; }
}

/* Very small screens: get even more compact */
@media (max-width: 380px) {
  .greeting-name { font-size: 2rem; }
  .page-title { font-size: 1.5rem; }
}

/* ============================== Reduced motion ============================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .skel-row, .skel-block { animation: none; }
}
