:root {
  /* Blu istituzionale Galbusera (dal logo) */
  --navy: #000094;
  --navy-2: #2433B5;
  --accent: #000094;
  --accent-soft: #E8EAFB;
  --req: #C8102E;
  --bg: #F4F5F8;
  --card: #FFFFFF;
  --text: #171B3A;
  --muted: #5B6170;
  --line: #DFE2E8;
  --ok: #157347;
  --ok-soft: #E6F4EC;
  --warn: #9A6700;
  --warn-soft: #FFF6E0;
  --err: #B42318;
  --err-soft: #FDECEA;
  --info-soft: #EBEDFC;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--navy-2); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .8rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, Consolas, monospace; }

/* ---------- Topbar ---------- */
.topbar { background: #fff; color: var(--text); border-bottom: 4px solid var(--navy); box-shadow: 0 1px 6px rgba(0, 0, 80, .06); }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 14px; white-space: nowrap; }
.brand .logo { height: 46px; width: auto; display: block; }
.brand small { display: block; padding-left: 14px; border-left: 1px solid var(--line); font-size: .85rem; font-weight: 600; color: var(--navy); line-height: 1.25; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .875rem; color: var(--muted); text-align: right; }
.topbar button.link { color: var(--navy); }
@media (max-width: 520px) { .brand .logo { height: 36px; } .brand small { font-size: .75rem; padding-left: 10px; white-space: normal; max-width: 110px; } }

/* ---------- Layout ---------- */
.wrap { max-width: 720px; margin: 0 auto; padding: 24px 16px 64px; }
.wrap.wide { max-width: 1200px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px; }
.card.tight { padding: 16px; }
.hero { margin: 8px 0 20px; }
.hero .eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; color: var(--accent); font-weight: 700; }
.hero h1 { font-size: 1.9rem; margin: 4px 0; }
.hero .when { color: var(--muted); }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 640px) { .grid2, .grid3 { grid-template-columns: 1fr; } .card { padding: 18px; } .hero h1 { font-size: 1.5rem; } }

/* ---------- Form ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field > span, .field-label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
label.field > span em, .field-label em { color: var(--req); font-style: normal; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=time], input[type=search], select, textarea {
  width: 100%; font: inherit; color: inherit; background: #fff; border: 1px solid #C8CDD7; border-radius: 8px; padding: 11px 12px; min-height: 46px;
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, .choice:focus-within { outline: 3px solid rgba(0, 0, 148, .22); outline-offset: 1px; border-color: var(--navy-2); }
input[readonly] { background: #F2F3F6; color: var(--muted); }
.hint { font-size: .82rem; color: var(--muted); margin-top: 4px; }

.choices { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.choice { position: relative; display: flex; align-items: center; gap: 10px; border: 1.5px solid #C8CDD7; border-radius: 10px; padding: 12px 14px; cursor: pointer; background: #fff; min-height: 50px; }
.choice input { accent-color: var(--navy); width: 18px; height: 18px; margin: 0; }
.choice:has(input:checked) { border-color: var(--navy); background: var(--info-soft); }
.choice .t { font-weight: 600; }

.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: 6px 0; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--navy); flex: none; }

.stepper { display: inline-flex; border: 1px solid #C8CDD7; border-radius: 10px; overflow: hidden; }
.stepper button { border: 0; background: #fff; padding: 10px 18px; font: inherit; font-weight: 600; cursor: pointer; min-width: 52px; min-height: 46px; }
.stepper button[aria-pressed=true] { background: var(--navy); color: #fff; }
.stepper button + button { border-left: 1px solid #C8CDD7; }

.family { border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin: 14px 0 0; background: #FBFBFC; }
.family h3 { display: flex; align-items: center; gap: 8px; }
.family h3 .n { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--navy); color: #fff; font-size: .85rem; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600; border-radius: 9px; padding: 10px 18px; min-height: 44px; cursor: pointer; border: 1.5px solid transparent; text-decoration: none; white-space: nowrap; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-ghost { background: #fff; color: var(--navy); border-color: #C8CDD7; }
.btn-ghost:hover { border-color: var(--navy); }
.btn-danger { background: #fff; color: var(--err); border-color: #E7B4AF; }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: .875rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--navy-2); text-decoration: underline; cursor: pointer; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Alerts / badges ---------- */
.alert { border-radius: 10px; padding: 12px 14px; margin: 0 0 14px; border-left: 4px solid; font-size: .95rem; }
.alert-info { background: var(--info-soft); border-color: var(--navy-2); }
.alert-warn { background: var(--warn-soft); border-color: #E0A100; }
.alert-err { background: var(--err-soft); border-color: var(--err); color: #7A1A12; }
.alert-ok { background: var(--ok-soft); border-color: var(--ok); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.b-pending { background: var(--warn-soft); color: var(--warn); }
.b-approved { background: var(--ok-soft); color: var(--ok); }
.b-rejected { background: var(--err-soft); color: var(--err); }
.b-cancelled { background: #EEF0F3; color: var(--muted); }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-weight: 600; }
@media (max-width: 520px) { dl.kv { grid-template-columns: 1fr; gap: 0; } dl.kv dd { margin-bottom: 8px; } }

.slot-big { display: flex; gap: 16px; align-items: center; background: var(--ok-soft); border-radius: 10px; padding: 16px; margin: 12px 0; }
.slot-big .time { font-size: 1.6rem; font-weight: 800; color: var(--ok); }

/* ---------- Tabelle (backoffice) ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tabs button { background: none; border: 0; font: inherit; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; font-weight: 600; }
.tabs button[aria-selected=true] { color: var(--navy); border-color: var(--accent); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; min-height: 40px; padding: 8px 10px; }
.toolbar input[type=search] { min-width: 240px; }
.table-wrap { overflow-x: auto; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
table.data { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.data th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #F8F9FB; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 10px 12px; border-bottom: 1px solid #EEF0F3; vertical-align: top; }
table.data tr.main { cursor: pointer; }
table.data tr.main:hover td { background: #FAFBFC; }
table.data tr.detail td { background: #FAFBFC; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data select { min-height: 34px; padding: 4px 8px; width: auto; font-size: .875rem; }
.fam-chip { display: inline-block; background: #EEF0F3; border-radius: 6px; padding: 1px 8px; margin: 2px 4px 2px 0; font-size: .82rem; }
.allergy { color: var(--err); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.stat .value { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: #EEF0F3; border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--navy); border-radius: 99px; }
.bar.over > i { background: var(--err); }

dialog { border: 0; border-radius: var(--radius); padding: 24px; max-width: 520px; width: calc(100% - 32px); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(16, 24, 40, .45); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 1000; max-width: calc(100% - 32px); }
.toast.err { background: var(--err); }

.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 20px; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
