/* Software29 Control Hub — design system, layout e componenti condivisi. */

/* --- Colori del marchio ------------------------------------------------------
   I tre valori del logo Software29. SONO STIMATI dal logo: se il brand book dice
   altro, si correggono QUI e basta — tutto il resto sotto ne deriva.
       navy    #123a5b   il blu scuro della scritta
       azzurro #3e87c1   il tratto chiaro della w e i pallini
       giallo  #fbb615   il giallo dei contorni
   ---------------------------------------------------------------------------- */
:root {
    color-scheme: light;
    --bg: #f5f6fa;
    --surface: #fff;
    --surface-2: #f8f9fc;
    --surface-3: #eff2f7;
    /* Sidebar: il navy del marchio, un gradino piu' scuro perche' il logo ci si stacchi. */
    --sidebar: #0e2f4a;
    --sidebar-2: #143c5e;
    --border: #e4e8ef;
    --border-strong: #d5dbe5;
    --text: #171b26;
    --muted: #6c7280;
    --muted-2: #98a0ae;
    /* Azzurro del marchio scurito quanto basta: il bianco sopra fa 5.2:1 (AA). */
    --accent: #1f6fb8;
    --accent-strong: #185792;
    --accent-soft: #e8f1fa;
    --on-accent: #fff;
    --success: #16875c;
    --success-bg: #eaf8f2;
    /* Famiglia del giallo del marchio: il giallo puro su bianco non si legge, questo
       ne e' la versione testo (5.4:1 sul proprio fondo). */
    --warning: #8a5b00;
    --warning-bg: #fff4dc;
    --danger: #ca3d4d;
    --danger-strong: #a92c3b;
    --danger-bg: #fff0f1;
    --info: #1f6fb8;
    --info-bg: #edf4fb;
    /* Serie dei grafici: ordine fisso, mai ciclato. Verificato con lo strumento della
       skill dataviz su fondo bianco — banda di luminosita', soglia di croma,
       separazione CVD (peggior coppia adiacente ΔE 9.1, soglia 8) e visione normale
       (ΔE 19.6, soglia 15) passano. Tre tinte stanno sotto 3:1 di contrasto sul
       bianco: per questo ogni grafico porta legenda con i valori e nota sotto —
       il colore non e' mai l'unico modo di leggere il dato. */
    --cat-0: #2a78d6;
    --cat-1: #eb6834;
    --cat-2: #1baf7a;
    --cat-3: #eda100;
    --cat-4: #e87ba4;
    --cat-other: #c2c7d2;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(18, 24, 40, .04);
    --shadow: 0 8px 28px rgba(24, 31, 52, .07);
    --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.55 var(--font); -webkit-tap-highlight-color: transparent; }
/* Mentre il foglio del menu e' aperto la pagina sotto non scorre. */
body.no-scroll { overflow: hidden; }
button, input, select, textarea { font: inherit; }
a { color: var(--accent); text-decoration: none; transition: color .16s ease, background .16s ease, border-color .16s ease, transform .16s ease; }
a:hover { color: var(--accent-strong); }
:focus-visible { outline: 3px solid rgba(31,111,184, .25); outline-offset: 2px; }
::selection { background: #d5e6f6; }
code { padding: .15rem .42rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); color: #4a5060; font: .86em var(--mono); word-break: break-all; }
pre.api-code { margin: 14px 0; padding: 18px; overflow: auto; border: 1px solid #dfe2eb; border-radius: 10px; background: #111827; color: #e5e7eb; font: .78rem/1.65 var(--mono); }
pre.api-code code { padding: 0; border: 0; background: transparent; color: inherit; word-break: normal; }

/* Brand */
.brand { display: inline-flex; align-items: center; gap: .72rem; color: inherit; min-width: 0; }
.brand:hover { color: inherit; }
.brand-mark { position: relative; display: inline-flex; align-items: end; justify-content: center; gap: 2px; width: 34px; height: 34px; padding: 8px; flex: none; overflow: hidden; border-radius: 10px; background: linear-gradient(145deg, #3e8fd6, #1a5f9f); box-shadow: 0 7px 18px rgba(31,111,184,.28); }
.brand-mark span { width: 4px; border-radius: 3px; background: #fff; }
.brand-mark span:nth-child(1) { height: 8px; opacity: .7; }
.brand-mark span:nth-child(2) { height: 13px; }
.brand-mark span:nth-child(3) { height: 17px; opacity: .85; }
/* Logo in assets/brand/ (vedi brand_mark() in src/Hub/helpers.php). Il riquadro chiaro
   non e' decorazione: il marchio ha elementi navy, e la sidebar e' navy — senza, meta'
   del segno sparirebbe nello sfondo. Su fondo bianco il riquadro non si vede. */
.brand-logo { display: inline-grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: 9px; background: #fff; }
.brand-logo img { width: 28px; height: 28px; object-fit: contain; }
.brand-copy { display: flex; flex-direction: column; min-width: 0; line-height: 1.12; }
.brand-copy strong { font-size: .91rem; letter-spacing: -.01em; }
.brand-copy small { margin-top: .23rem; color: var(--muted-2); font-size: .68rem; letter-spacing: .075em; text-transform: uppercase; }

/* App shell */
.shell { display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: 100vh; transition: grid-template-columns .2s ease; }
.sidebar { position: sticky; z-index: 30; top: 0; display: flex; flex-direction: column; height: 100vh; min-width: 0; overflow: hidden auto; background: var(--sidebar); color: #e8ebf3; border-right: 1px solid rgba(255,255,255,.06); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; min-height: 72px; padding: 0 14px 0 18px; border-bottom: 1px solid rgba(255,255,255,.07); }
.sidebar-toggle { color: #7f899d; }
.sidebar-toggle:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-toggle svg { transition: transform .2s ease; }
.nav { flex: 1; padding: 16px 10px 22px; }
.nav-group { margin: 20px 10px 7px; color: #687389; font-size: .66rem; font-weight: 700; letter-spacing: .095em; text-transform: uppercase; white-space: nowrap; }
.nav-group:first-child { margin-top: 2px; }
.nav-item { position: relative; display: flex; align-items: center; min-height: 41px; gap: 11px; margin: 2px 0; padding: 0 10px; border-radius: 9px; color: #aeb6c7; font-size: .86rem; font-weight: 520; white-space: nowrap; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.055); }
.nav-item.is-active { color: #fff; background: linear-gradient(90deg, rgba(31,111,184,.28), rgba(31,111,184,.12)); box-shadow: inset 0 0 0 1px rgba(78,154,224,.18); }
.nav-item.is-active::before { content: ""; position: absolute; left: -10px; width: 3px; height: 21px; border-radius: 0 3px 3px 0; background: #4e9ae0; box-shadow: 0 0 12px #4e9ae0; }
.nav-icon { display: grid; place-items: center; width: 19px; height: 19px; flex: none; }
.nav-icon svg, .icon-btn svg, .global-search svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.nav-icon svg path[d^="M4 13"] { fill: currentColor; stroke: none; }
.sidebar-profile { display: flex; align-items: center; gap: 10px; min-height: 72px; margin-top: auto; padding: 13px 14px; border-top: 1px solid rgba(255,255,255,.07); background: rgba(255,255,255,.015); }
.avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: 10px; background: linear-gradient(145deg, #e8f1fa, #cfe2f4); color: var(--accent-strong); font-size: .76rem; font-weight: 800; }
.profile-copy { display: flex; flex: 1; min-width: 0; flex-direction: column; line-height: 1.2; }
.profile-copy strong { overflow: hidden; color: #eef1f7; font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.profile-copy small { margin-top: 4px; color: #778297; font-size: .67rem; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 8px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.logout { color: #7f899c; }
.logout:hover { background: rgba(202,61,77,.14); color: #ff8997; }
.workspace { min-width: 0; }
.app-header { position: sticky; z-index: 20; top: 0; display: flex; align-items: center; gap: 12px; height: 72px; padding: 0 28px; border-bottom: 1px solid rgba(220,223,232,.85); background: rgba(255,255,255,.88); backdrop-filter: blur(14px); }
.breadcrumb { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--muted-2); font-size: .79rem; white-space: nowrap; }
.breadcrumb a { color: var(--muted); }
.breadcrumb strong { overflow: hidden; color: var(--text); font-weight: 600; text-overflow: ellipsis; }
.global-search { position: relative; display: flex; align-items: center; width: min(390px, 35vw); height: 38px; margin-left: auto; padding: 0 52px 0 37px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--muted-2); text-align: left; cursor: pointer; }
.global-search svg { position: absolute; left: 12px; width: 17px; height: 17px; color: var(--muted-2); }
.global-search:hover { border-color: #c3d7ea; background: #fff; color: var(--text); }
.global-search kbd { position: absolute; right: 9px; padding: 2px 6px; border: 1px solid var(--border-strong); border-radius: 5px; background: #fff; color: var(--muted-2); font: .67rem var(--font); }
.global-search > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-action { border: 1px solid var(--border); background: #fff; }
.header-avatar { display: none; }
.notification-wrap { position: relative; }
.notification-dot { position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; border: 2px solid #fff; border-radius: 50%; background: var(--danger); }
.notification-panel { position: absolute; z-index: 40; top: calc(100% + 10px); right: 0; width: min(360px, calc(100vw - 24px)); overflow: hidden; border: 1px solid var(--border); border-radius: 13px; background: #fff; box-shadow: 0 18px 50px rgba(21,27,47,.16); }
.notification-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 15px; border-bottom: 1px solid var(--border); }
.notification-head strong { font-size: .82rem; }.notification-head span { color: var(--muted); font-size: .66rem; }
.notification-item { display: grid; grid-template-columns: auto 1fr; gap: 9px; padding: 12px 15px; border-bottom: 1px solid var(--border); color: var(--text); font-size: .73rem; }
.notification-item:hover { background: var(--surface-2); color: var(--text); }
.notification-level { align-self: start; padding: 2px 5px; border-radius: 5px; background: var(--warning-bg); color: var(--warning); font-size: .55rem; font-weight: 800; text-transform: uppercase; }
.notification-item.is-critical .notification-level { background: var(--danger-bg); color: var(--danger); }
.notification-all { display: block; padding: 11px 15px; background: var(--surface-2); font-size: .7rem; font-weight: 650; text-align: center; }
.notification-empty { display: flex; flex-direction: column; align-items: center; padding: 28px 16px; color: var(--muted); font-size: .72rem; }.notification-empty strong { color: var(--text); }
.command-palette { width: min(620px, calc(100vw - 28px)); max-height: min(620px, 80vh); padding: 0; overflow: hidden; border: 1px solid var(--border); border-radius: 15px; background: #fff; box-shadow: 0 26px 80px rgba(10,15,30,.24); }
.command-palette::backdrop { background: rgba(8,12,22,.45); backdrop-filter: blur(3px); }
.command-head { display: flex; align-items: center; gap: 11px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.command-head svg { width: 19px; height: 19px; fill: none; stroke: var(--muted); stroke-width: 1.8; }
.command-head input { flex: 1; min-width: 0; border: 0; outline: 0; color: var(--text); font-size: .92rem; }
.command-head kbd, .command-list kbd, .command-search-action kbd { padding: 2px 5px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface-2); color: var(--muted-2); font: .62rem var(--font); }
.command-body { max-height: 460px; overflow-y: auto; padding: 10px; }
.command-label { padding: 4px 8px 7px; color: var(--muted-2); font-size: .61rem; font-weight: 750; letter-spacing: .07em; text-transform: uppercase; }
.command-list a, .command-search-action button { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 7px 10px; border: 0; border-radius: 9px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.command-list a:hover, .command-search-action button:hover { background: var(--accent-soft); color: var(--accent-strong); }
.command-list a > span:nth-child(2) { display: flex; flex-direction: column; }.command-list strong { font-size: .77rem; }.command-list small { color: var(--muted); font-size: .62rem; }
.command-search-action { margin-top: 5px; padding-top: 5px; border-top: 1px solid var(--border); }
.sidebar-scrim, .tabbar { display: none; }
/* La maniglia esiste solo quando la sidebar diventa un foglio che sale dal basso. */
.sheet-handle { display: none; }

/* Installazione sulla schermata Home: app.js la mostra solo quando e' davvero possibile. */
.sidebar-install { margin: 6px 10px 0; }
.install-btn { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 8px 11px; border: 1px dashed rgba(255,255,255,.22); border-radius: 10px; background: rgba(255,255,255,.04); color: #dfe4ee; text-align: left; cursor: pointer; }
.install-btn:hover { border-color: rgba(78,154,224,.55); background: rgba(31,111,184,.18); color: #fff; }
.install-btn > span:last-child { display: flex; flex-direction: column; line-height: 1.2; }
.install-btn strong { font-size: .8rem; }
.install-btn small { margin-top: 3px; color: #8b95a9; font-size: .66rem; }
.install-hint { margin: 0; padding: 11px 12px; border: 1px dashed rgba(255,255,255,.2); border-radius: 10px; background: rgba(255,255,255,.04); color: #97a1b4; font-size: .7rem; line-height: 1.45; }
.install-hint strong { display: block; margin-bottom: 3px; color: #dfe4ee; font-size: .78rem; }
.is-collapsed .sidebar-install { display: none; }
.content { width: 100%; max-width: 1660px; margin: 0 auto; padding: 30px 32px 64px; }
.is-collapsed.shell { grid-template-columns: 72px minmax(0, 1fr); }
.is-collapsed .sidebar-head { justify-content: center; padding: 0; }
.is-collapsed .brand-copy, .is-collapsed .nav-group, .is-collapsed .nav-label, .is-collapsed .profile-copy, .is-collapsed .sidebar-profile .logout { display: none; }
.is-collapsed .sidebar-toggle { position: absolute; top: 76px; right: 5px; width: 22px; height: 22px; padding: 5px; border: 1px solid rgba(255,255,255,.12); background: var(--sidebar-2); }
.is-collapsed .sidebar-toggle svg { transform: rotate(180deg); }
.is-collapsed .nav { padding-inline: 10px; }
.is-collapsed .nav-item { justify-content: center; padding: 0; }
.is-collapsed .nav-item.is-active::before { left: -10px; }
.is-collapsed .sidebar-profile { justify-content: center; padding-inline: 0; }

/* Typography and page structure */
h1, h2, h3 { color: var(--text); line-height: 1.25; }
h1 { margin: 0 0 6px; font-size: clamp(1.55rem, 2vw, 2rem); letter-spacing: -.035em; }
h2 { margin: 30px 0 12px; font-size: 1.05rem; letter-spacing: -.018em; }
h3 { margin: 20px 0 9px; font-size: .91rem; }
.content > h1 + .muted, .page-lead { max-width: 850px; margin: 0 0 26px; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 6px; color: var(--accent); font-size: .7rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 22px; margin-bottom: 26px; }
.page-heading p:not(.eyebrow) { max-width: 690px; margin: 0; color: var(--muted); }
.page-actions { display: flex; gap: 8px; flex: none; }
.range-picker { display: inline-flex; padding: 3px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.range-option { min-height: 31px; padding: 5px 9px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: .7rem; font-weight: 650; cursor: pointer; }
.range-option:hover { color: var(--text); background: var(--surface-2); }
.range-option.is-active { background: var(--accent-soft); color: var(--accent-strong); }
.snapshot-meta { display: flex; align-items: center; gap: 5px; width: fit-content; margin: -15px 0 22px; color: var(--muted); font-size: .7rem; }
.snapshot-meta time { color: var(--text); font-weight: 600; }
.snapshot-meta.is-stale { color: var(--warning); }
.snapshot-meta .sync-warning, .chart-note .sync-warning { color: var(--warning); font-weight: 600; }

/* Barra della sincronizzazione all'ingresso.
   Sta in alto, sopra al contenuto e sotto l'intestazione: deve farsi vedere senza
   coprire niente e senza spostare la pagina sotto di se' quando sparisce, motivo per cui
   e' `sticky` e non un riquadro nel flusso. */
.sync-bar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px; padding: 9px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); color: var(--muted); font-size: .76rem; font-weight: 600; }
.sync-bar.is-done { background: var(--success-bg); color: var(--success); }
.sync-bar.is-error { background: var(--danger-bg); color: var(--danger-strong); }
.sync-spinner { flex: none; width: 14px; height: 14px; border: 2px solid var(--surface-3); border-top-color: var(--accent); border-radius: 50%; animation: sync-spin .7s linear infinite; }
.sync-bar.is-done .sync-spinner, .sync-bar.is-error .sync-spinner { display: none; }
.sync-reload { padding: 4px 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.sync-reload:hover { background: var(--surface-3); }
@keyframes sync-spin { to { transform: rotate(360deg); } }
/* Col movimento ridotto il cerchio resta fermo: a dire «sto lavorando» basta il testo,
   ed e' il testo che porta davvero l'informazione. */
@media (prefers-reduced-motion: reduce) { .sync-spinner { animation: none; } }

/* Pannelli del cruscotto caricati a parte (vedi templates/dashboard.php).
   Lo scheletro ha un'altezza MINIMA di proposito: senza, l'arrivo di ogni riquadro
   spingerebbe in basso quelli sotto e il primo clic finirebbe su un bersaglio che nel
   frattempo si e' spostato. Meglio un po' di spazio vuoto che un layout che salta. */
.panel-slot:not(:empty) { display: block; }
.skeleton { display: flex; flex-direction: column; gap: 12px; min-height: 148px; margin-bottom: 26px; padding: 22px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.sk-bar { height: 13px; border-radius: 7px; background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%); background-size: 400% 100%; animation: sk-shimmer 1.4s ease infinite; }
.sk-title { width: 42%; height: 19px; }
.sk-short { width: 64%; }
@keyframes sk-shimmer { from { background-position: 100% 50%; } to { background-position: 0 50%; } }
/* Con il movimento ridotto lo scheletro resta, fermo: e' comunque l'indicazione che
   li' arrivera' qualcosa. E' l'animazione a essere superflua, non il segnaposto. */
@media (prefers-reduced-motion: reduce) { .sk-bar { animation: none; } }
.active-filter { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 0 0 18px; padding: 10px 13px; border: 1px solid #c9dff2; border-radius: 9px; background: var(--accent-soft); color: var(--accent-strong); font-size: .76rem; font-weight: 650; }
.filter-card { margin-bottom: 18px; padding: 15px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin: 30px 0 12px; }
.section-head h2 { margin: 0; }
.section-head p { margin: 3px 0 0; color: var(--muted); font-size: .81rem; }
.section-link { font-size: .8rem; font-weight: 650; }

/* Cards, KPIs, summaries */
.card { padding: 22px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.card:hover { border-color: var(--border-strong); }
.card-foot { margin: 18px -22px -22px; padding: 13px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); font-size: .79rem; font-weight: 600; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0; padding: 0; list-style: none; }
.hub-kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stat { position: relative; min-width: 0; padding: 20px; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease; }
a.stat { display: block; color: inherit; }
a.stat:hover { transform: translateY(-2px); border-color: #bcd6ee; box-shadow: var(--shadow); color: inherit; }
.stat::after { content: ""; position: absolute; top: 0; right: 0; width: 68px; height: 68px; background: radial-gradient(circle at top right, rgba(31,111,184,.09), transparent 68%); }
.stat.warn::after { background: radial-gradient(circle at top right, rgba(202,61,77,.12), transparent 68%); }
.stat .label { color: var(--muted); font-size: .72rem; font-weight: 650; letter-spacing: .025em; }
.stat .value { margin-top: 10px; color: var(--text); font-size: clamp(1.55rem, 2.4vw, 2.05rem); font-weight: 735; line-height: 1; letter-spacing: -.045em; font-variant-numeric: tabular-nums; }
.stat .value.small { font-size: 1.14rem; letter-spacing: -.02em; }
.stat .sub { margin-top: 10px; color: var(--muted); font-size: .76rem; line-height: 1.35; }
.stat.warn .value { color: var(--danger); }
.stat-arrow { position: absolute; right: 17px; bottom: 17px; color: var(--muted-2); font-size: 1.05rem; }
.control-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(300px, .75fr); gap: 14px; align-items: start; }
.grid-2, .grid-auto { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }
.panel { min-width: 0; }
.panel > h2, .panel > h3 { margin-top: 0; }
.panel .card { height: 100%; }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.panel-title h2, .panel-title h3 { margin: 0; }
.panel-kicker { display: block; margin-bottom: 4px; color: var(--muted); font-size: .71rem; }
.quick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.quick-action { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-size: .79rem; font-weight: 650; }
.quick-action:hover { border-color: #bcd6ee; background: var(--accent-soft); color: var(--accent-strong); }
.quick-icon { display: grid; place-items: center; width: 29px; height: 29px; border-radius: 8px; background: var(--surface-3); color: var(--accent); font-size: 1rem; }
.quick-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.api-guide-grid { margin-top: 8px; }
.api-endpoint-card p { color: var(--muted); }
.api-endpoint { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.api-method { padding: 4px 8px; border-radius: 6px; background: var(--accent); color: #fff; font: 750 .66rem var(--mono); letter-spacing: .04em; }
.api-warning { margin: 14px 0 0; }
.api-checklist, .api-steps { margin: 0; padding: 0; list-style: none; }
.api-checklist li { position: relative; padding: 10px 0 10px 27px; border-bottom: 1px solid var(--border); color: var(--text); font-size: .8rem; }
.api-checklist li:last-child { border-bottom: 0; }
.api-checklist li::before { position: absolute; left: 0; top: 10px; display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; font-size: .65rem; font-weight: 800; }
.api-checklist.allowed li::before { content: "✓"; background: var(--success-bg); color: var(--success); }
.api-checklist.forbidden li::before { content: "×"; background: var(--danger-bg); color: var(--danger); }
.api-steps { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 22px; }
.api-steps li { display: grid; grid-template-columns: 30px 1fr; gap: 11px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.api-steps li > span { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-strong); font-weight: 800; }
.api-steps strong { font-size: .81rem; }.api-steps p { margin: 3px 0 0; color: var(--muted); font-size: .75rem; }
.tenant-secret code { user-select: all; }.tenant-secret dl.detail { margin-top: 10px; }

/* Alerts and situation */
.alert { margin: 0 0 18px; padding: 13px 15px; border: 1px solid transparent; border-radius: 10px; font-size: .82rem; font-weight: 520; }
.alert.ok { border-color: #cceade; background: var(--success-bg); color: var(--success); }
.alert.error { border-color: #f3d4d8; background: var(--danger-bg); color: var(--danger-strong); }
.alert.warn { border-color: #eddfb4; background: var(--warning-bg); color: var(--warning); }
.alert.warn code { border-color: #e5d5a8; background: #fff9e9; color: inherit; }
.situation { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.sit { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; min-height: 54px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.sit-level { padding: 4px 7px; border-radius: 6px; background: var(--surface-3); color: var(--muted); font-size: .61rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.sit-text { min-width: 0; font-size: .8rem; }
.sit-go { font-size: .75rem; font-weight: 700; }
.sit.critico { border-color: #f2d4d8; background: var(--danger-bg); }
.sit.critico .sit-level { background: #fbdde1; color: var(--danger-strong); }
.sit.attenzione { border-color: #eddfb4; background: var(--warning-bg); }
.sit.attenzione .sit-level { background: #f7e7b6; color: var(--warning); }
.all-clear { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid #cfe9df; border-radius: 10px; background: var(--success-bg); color: var(--success); font-weight: 600; }
.all-clear-icon { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--success); color: #fff; }

/* Compact data */
.mini-list, .facts, .num-grid, .mini-strip, .legend { margin: 0; padding: 0; list-style: none; }
.mini-list li { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.mini-list li:last-child { border-bottom: 0; }
.mini-name { flex: 1; min-width: 0; color: var(--text); font-size: .82rem; font-weight: 650; }
.mini-val { color: var(--muted); font-size: .74rem; text-align: right; white-space: nowrap; }
.sep { opacity: .45; }
.facts li { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--border); color: var(--muted); font-size: .8rem; }
.facts li:last-child { border-bottom: 0; }
.facts .n { max-width: 66%; color: var(--text); font-weight: 650; text-align: right; }
.num-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 10px; }
.num { display: flex; flex-direction: column; gap: 5px; }
.num .v { color: var(--text); font-size: 1.42rem; font-weight: 720; line-height: 1; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.num .k { color: var(--muted); font-size: .62rem; font-weight: 650; letter-spacing: .045em; text-transform: uppercase; }
.num.ok .v { color: var(--success); }
.num.bad .v { color: var(--danger); }
.rule { margin: 17px 0; border: 0; border-top: 1px solid var(--border); }
.mini-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mini-strip li { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 12px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.mini-strip strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.mini-strip .warn-link { grid-column: 1 / -1; }
.warn-link { color: var(--danger); font-weight: 650; }
.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: #e7a732; box-shadow: 0 0 0 3px rgba(231,167,50,.12); vertical-align: middle; }
.status-dot.ok { background: #22a678; box-shadow: 0 0 0 3px rgba(34,166,120,.12); }
.status-dot.err { background: #df4b5b; box-shadow: 0 0 0 3px rgba(223,75,91,.12); }

/* Tables */
.table-wrap { position: relative; max-width: 100%; margin: 10px 0 24px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); scrollbar-width: thin; }
.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 18px 0 -1px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; background: var(--surface); }
.table-toolbar + .table-wrap { margin-top: 0; border-radius: 0 0 var(--radius) var(--radius); }
.table-search { flex: 0 1 300px; }
.table-search input { width: 100%; height: 34px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); outline: 0; }
.table-search input:focus { border-color: #7fb0dd; background: #fff; box-shadow: 0 0 0 3px rgba(31,111,184,.09); }
.table-count { color: var(--muted); font-size: .7rem; font-weight: 650; }
table.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .8rem; }
table.table th, table.table td { min-height: 48px; padding: 12px 15px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.table thead th { position: sticky; z-index: 2; top: 0; background: #fafbfc; color: var(--muted); font-size: .66rem; font-weight: 750; letter-spacing: .055em; text-transform: uppercase; }
table.table thead th.is-sortable { cursor: pointer; user-select: none; }
table.table thead th.is-sortable::after { content: "↕"; margin-left: 7px; color: var(--muted-2); font-size: .7rem; }
table.table thead th[aria-sort="ascending"]::after { content: "↑"; color: var(--accent); }
table.table thead th[aria-sort="descending"]::after { content: "↓"; color: var(--accent); }
table.table tbody tr { transition: background .14s ease; }
table.table tbody tr:hover { background: #f7fafd; }
table.table tbody tr:last-child td { border-bottom: 0; }
table.table td a { color: var(--text); font-weight: 650; }
table.table td a:hover { color: var(--accent); }
table.table td[colspan] { height: 100px; text-align: center; white-space: normal; }

/* Storico del tenant: una riga per fatto, la tinta dice se e' buono o no. */
.timeline { margin: 0; padding: 0; list-style: none; }
.tl { position: relative; display: grid; grid-template-columns: 124px 82px 1fr; align-items: baseline; gap: 12px; padding: 12px 0 12px 16px; border-bottom: 1px solid var(--border); }
.tl:last-child { border-bottom: 0; }
.tl::before { content: ""; position: absolute; top: 18px; left: 0; width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); }
.tl.tone-ok::before { background: var(--success); }
.tl.tone-bad::before { background: var(--danger); }
.tl.tone-warn::before { background: #d79a16; }
/* Il filo che unisce i pallini: e' cio' che rende «una fila» invece di un elenco. */
.tl::after { content: ""; position: absolute; top: 25px; bottom: -12px; left: 3px; width: 1px; background: var(--border); }
.tl:last-child::after { display: none; }
.tl-when { color: var(--muted); font-size: .74rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tl-kind { padding: 2px 7px; border-radius: 5px; background: var(--surface-3); color: var(--muted); font-size: .6rem; font-weight: 800; letter-spacing: .05em; text-align: center; text-transform: uppercase; }
.tl-body { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
.tl-body strong { font-size: .84rem; font-weight: 650; }
.tl-body small { color: var(--muted); font-size: .74rem; }
@media (max-width: 680px) {
    .tl { grid-template-columns: 1fr auto; gap: 4px 10px; }
    .tl-body { grid-column: 1 / -1; }
    .tl-kind { justify-self: end; }
}

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .68rem; font-weight: 700; line-height: 1.2; }
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .65; }
.badge.active, .badge.processed, .badge.ok { border-color: #cfe9df; background: var(--success-bg); color: var(--success); }
.badge.suspended, .badge.failed, .badge.ko, .badge.invalid { border-color: #f2d5d9; background: var(--danger-bg); color: var(--danger); }
.badge.cancelled, .badge.revoked { border-color: #f2d5d9; background: var(--danger-bg); color: var(--danger); }
.badge.received, .badge.warning, .badge.past_due, .badge.trialing { border-color: #eddfb4; background: var(--warning-bg); color: var(--warning); }

/* Forms and buttons */
form.stack { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; max-width: 820px; }
form.stack > p, form.stack > h3, form.stack > .btn-row { grid-column: 1 / -1; }
.wizard-steps { grid-column: 1 / -1; display: flex; gap: 5px; overflow-x: auto; padding: 4px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.wizard-steps button { display: inline-flex; align-items: center; gap: 7px; min-height: 34px; padding: 5px 9px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: .69rem; font-weight: 650; white-space: nowrap; cursor: pointer; }
.wizard-steps button span { display: grid; place-items: center; width: 19px; height: 19px; border: 1px solid var(--border-strong); border-radius: 50%; background: #fff; font-size: .62rem; }
.wizard-steps button.is-active { background: var(--accent-soft); color: var(--accent-strong); }
.wizard-steps button.is-active span, .wizard-steps button.is-done span { border-color: var(--accent); background: var(--accent); color: #fff; }
.wizard-panel { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; padding: 6px 0; }
.wizard-panel > h3, .wizard-panel > p, .wizard-panel > .btn-row { grid-column: 1 / -1; }
.wizard-panel[hidden] { display: none; }
.wizard-actions { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 8px; padding-top: 14px; border-top: 1px solid var(--border); }
label { display: block; color: #343947; font-size: .77rem; font-weight: 650; }
.field, label .field { display: block; width: 100%; min-height: 42px; margin-top: 6px; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface); color: var(--text); outline: 0; transition: border-color .16s ease, box-shadow .16s ease, background .16s ease; }
.field:hover { border-color: #c6cad5; }
.field:focus { border-color: #7fb0dd; box-shadow: 0 0 0 4px rgba(31,111,184,.09); }
.field::placeholder { color: #a4aab5; }
.btn { display: inline-flex; min-height: 39px; align-items: center; justify-content: center; padding: 8px 14px; border: 1px solid var(--accent); border-radius: 9px; background: var(--accent); box-shadow: 0 1px 2px rgba(23,87,143,.18); color: #fff; font-weight: 680; cursor: pointer; }
.btn:hover { border-color: var(--accent-strong); background: var(--accent-strong); color: #fff; transform: translateY(-1px); }
.btn.secondary { border-color: var(--border-strong); background: var(--surface); box-shadow: var(--shadow-sm); color: var(--text); }
.btn.secondary:hover { border-color: #c0cddb; background: var(--surface-2); color: var(--accent); }
.btn.danger { border-color: var(--danger); background: var(--danger); }
.btn.danger:hover { border-color: var(--danger-strong); background: var(--danger-strong); }
.btn-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.search-form { display: flex; max-width: 760px; align-items: flex-end; flex-wrap: wrap; gap: 10px; }
.search-form > .field { flex: 1 1 260px; margin: 0; }
.search-form label.inline { flex: 1 1 180px; color: var(--muted); }
.search-form .btn { flex: none; }

/* Detail, charts and legends */
dl.detail { display: grid; grid-template-columns: minmax(120px, 180px) 1fr; gap: 0; margin: 0; }
dl.detail dt, dl.detail dd { min-height: 43px; padding: 10px 0; border-bottom: 1px solid var(--border); }
dl.detail dt:last-of-type, dl.detail dd:last-of-type { border-bottom: 0; }
dl.detail dt { color: var(--muted); font-size: .75rem; font-weight: 600; }
dl.detail dd { margin: 0; color: var(--text); font-weight: 520; }
.chart-box { position: relative; height: 220px; margin: 2px 0 14px; }
/* Le serie giornaliere hanno bisogno di piu' respiro in verticale delle torte. */
.chart-panel .chart-box { height: 260px; }
/* La nota sotto al grafico dice COSA copre quel grafico: senza, un totale parziale si
   legge come totale. Non e' decorazione, e' parte del dato. */
.chart-note { margin: 6px 0 0; color: var(--muted); font-size: .74rem; line-height: 1.45; }
.chart-note.is-warning { color: var(--warning); font-weight: 560; }
.sankey-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }
.sankey-card { min-width: 0; overflow: hidden; }
.sankey-description { margin: -7px 0 14px; color: var(--muted); font-size: .76rem; }
.sankey-scroll { width: 100%; overflow-x: auto; }
.sankey-chart { display: block; width: 100%; min-width: 520px; height: auto; }
.sankey-flow { opacity: .28; transition: opacity .18s ease; }
.sankey-flow:hover { opacity: .52; }
.sankey-chart a:focus .sankey-flow, .sankey-chart a:hover .sankey-flow { opacity: .58; }
.sankey-source rect { fill: var(--surface-2); stroke: var(--border); }
.sankey-source circle.flow-0 { fill: var(--cat-0); }.sankey-source circle.flow-1 { fill: var(--cat-1); }.sankey-source circle.flow-2 { fill: var(--cat-2); }.sankey-source circle.flow-3 { fill: var(--cat-3); }.sankey-source circle.flow-4 { fill: var(--cat-4); }
.sankey-flow.flow-0 { fill: var(--cat-0); }.sankey-flow.flow-1 { fill: var(--cat-1); }.sankey-flow.flow-2 { fill: var(--cat-2); }.sankey-flow.flow-3 { fill: var(--cat-3); }.sankey-flow.flow-4 { fill: var(--cat-4); }
.sankey-label { fill: var(--text); font: 650 12px var(--font); }
.sankey-value { fill: var(--muted); font: 10px var(--font); }
.sankey-target rect { fill: var(--accent-soft); stroke: #c9dff2; }
.sankey-target-label { fill: var(--accent-strong); font: 650 11px var(--font); text-transform: uppercase; }
.sankey-target-value { fill: var(--text); font: 730 16px var(--font); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.legend li { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .74rem; }
.legend strong { color: var(--text); }
.legend .key { width: 8px; height: 8px; flex: none; border-radius: 3px; }
.legend.column { flex-direction: column; align-items: stretch; }
.legend.column li { justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); }
.key-0 { background: var(--cat-0); }.key-1 { background: var(--cat-1); }.key-2 { background: var(--cat-2); }.key-3 { background: var(--cat-3); }.key-4 { background: var(--cat-4); }.key-other { background: var(--cat-other); }
.key-success { background: var(--success); }.key-warning { background: var(--warning); }.key-danger { background: var(--danger); }.key-muted { background: var(--cat-other); }
.back { margin-top: 28px; font-size: .8rem; }
.detail-heading { align-items: center; }
.detail-heading > .badge { flex: none; padding: 6px 11px; }
.detail-tabs { position: sticky; z-index: 8; top: 72px; display: flex; gap: 4px; margin: 0 0 26px; padding: 5px; overflow-x: auto; border: 1px solid var(--border); border-radius: 11px; background: rgba(255,255,255,.92); backdrop-filter: blur(10px); }
.detail-tabs a { padding: 7px 11px; border-radius: 7px; color: var(--muted); font-size: .75rem; font-weight: 650; white-space: nowrap; }
.detail-tabs a:hover, .detail-tabs a.is-active { background: var(--accent-soft); color: var(--accent-strong); }
.detail-tabs span { margin-left: 4px; color: var(--muted-2); }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

/* Authentication */
.topbar { display: flex; align-items: center; height: 72px; padding: 0 24px; border-bottom: 1px solid var(--border); background: var(--surface); }
.auth-wrap { display: grid; min-height: calc(100vh - 72px); place-items: start center; padding: 8vh 18px 50px; background: radial-gradient(circle at 50% 0, #e4eff8, transparent 34%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; padding: 32px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: 0 20px 60px rgba(26,32,56,.09); }
.auth-card h1 { font-size: 1.55rem; }
.auth-card form.stack { display: flex; max-width: none; flex-direction: column; gap: 17px; }
.auth-card .btn { width: 100%; }
.auth-card .resend { margin-top: 11px; }
.auth-card .resend-note { margin: 14px 0 0; font-size: .76rem; line-height: 1.45; }
/* Il campo del codice: sei cifre da leggere a colpo d'occhio, non un input qualsiasi. */
.auth-card input[autocomplete="one-time-code"] { font: 600 1.35rem/1.2 var(--mono); letter-spacing: .32em; text-align: center; }

/* Responsive */
@media (max-width: 1180px) {
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .hub-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .content { padding-inline: 24px; }
}
/* --- Da qui in giu' si usa con il telefono in mano ---------------------------------
   Sotto i 920px la sidebar sparisce e la navigazione scende dove arriva il pollice:
   una tab bar fissa in fondo per le destinazioni quotidiane, e un foglio che sale dal
   basso per tutto il resto. Niente piu' bersagli nell'angolo in alto a sinistra. */
@media (max-width: 920px) {
    .shell, .is-collapsed.shell { display: block; }

    /* Menu completo: foglio dal basso, perche' dal basso lo si apre. */
    .sidebar {
        position: fixed; z-index: 40; top: auto; right: 0; bottom: 0; left: 0;
        width: auto; height: auto; max-height: min(78vh, 640px);
        padding-bottom: env(safe-area-inset-bottom);
        border-right: 0; border-radius: 20px 20px 0 0;
        transform: translateY(102%);
        /* visibility, non solo transform: un foglio spinto fuori schermo resterebbe
           comunque raggiungibile col tasto Tab e continuerebbe a intercettare i tap
           sopra la tab bar. Il ritardo la spegne a fine animazione, non prima. */
        visibility: hidden;
        transition: transform .26s cubic-bezier(.32, .72, 0, 1), visibility 0s linear .26s;
        overscroll-behavior: contain; box-shadow: 0 -18px 50px rgba(9, 15, 28, .38);
    }
    .mobile-nav-open .sidebar { transform: translateY(0); visibility: visible; transition-delay: 0s; }
    .sheet-handle { display: block; flex: none; width: 38px; height: 4px; margin: 9px auto 0; border-radius: 3px; background: rgba(255,255,255,.22); }
    .sidebar-head { min-height: 58px; }
    .sidebar .brand-copy, .sidebar .nav-label, .sidebar .profile-copy, .sidebar .sidebar-profile .logout { display: flex; }
    .sidebar .nav-group { display: block; }
    .sidebar .sidebar-toggle { display: none; }
    .sidebar .nav { padding-bottom: 12px; }
    .sidebar .nav-item { justify-content: flex-start; min-height: 48px; padding: 0 12px; font-size: .92rem; }
    .sidebar .nav-item.is-active::before { display: none; }
    .sidebar .sidebar-profile { position: sticky; bottom: 0; justify-content: flex-start; padding-inline: 14px; background: var(--sidebar); }
    .sidebar-scrim { position: fixed; z-index: 36; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(4,8,16,.5); cursor: pointer; }
    .mobile-nav-open .sidebar-scrim { display: block; }

    /* Header: ricerca e menu sono scesi in fondo, qui resta lo spazio per dire dove sei. */
    .app-header { height: calc(60px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 16px 0; }
    .breadcrumb { display: flex; flex: 1; }
    .breadcrumb a, .breadcrumb span { display: none; }
    .breadcrumb strong { font-size: 1rem; font-weight: 680; letter-spacing: -.02em; }
    .global-search { display: none; }
    .header-avatar { display: inline-grid; }
    .detail-tabs { top: calc(60px + env(safe-area-inset-top)); }

    /* Tab bar: sopra la barra home dell'iPhone, non sotto. */
    .tabbar {
        position: fixed; z-index: 30; right: 0; bottom: 0; left: 0;
        display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px;
        padding: 5px max(4px, env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
        border-top: 1px solid var(--border);
        background: rgba(255,255,255,.93); backdrop-filter: blur(14px);
    }
    .tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 54px; padding: 6px 2px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-size: .63rem; font-weight: 650; cursor: pointer; }
    .tab .nav-icon { width: 22px; height: 22px; }
    .tab:active { background: var(--surface-3); }
    .tab.is-active, .mobile-nav-open .tab[data-mobile-menu] { background: var(--accent-soft); color: var(--accent-strong); }

    /* Lo spazio che si mangia la tab bar: senza, l'ultima riga resta sempre coperta. */
    .content { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }

    /* Sotto i 16px iOS ingrandisce la pagina appena il fuoco entra in un campo. */
    .field, .table-search input, .command-head input { font-size: 16px; }

    /* Palette ancorata in alto: in fondo la coprirebbe la tastiera. */
    .command-palette { top: 6vh; bottom: auto; width: calc(100vw - 20px); max-height: 74vh; margin: 0 auto; }
    .command-body { max-height: 52vh; }
    .command-list a, .command-search-action button { min-height: 52px; }

    /* Login e 2FA: stessa cura per tacca e barra home, qui non c'e' la tab bar. */
    .topbar { height: calc(60px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 16px 0; }
    .auth-wrap { min-height: calc(100vh - 60px - env(safe-area-inset-top)); padding: 5vh 16px calc(40px + env(safe-area-inset-bottom)); }
    .auth-card { padding: 24px; }

    .table-wrap { overscroll-behavior-x: contain; }
    .control-grid { grid-template-columns: 1fr; }
    .sankey-grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
    .content { padding: 22px max(15px, env(safe-area-inset-right)) calc(86px + env(safe-area-inset-bottom)) max(15px, env(safe-area-inset-left)); }
    .app-header { padding-inline: 13px; }
    .page-heading { align-items: flex-start; flex-direction: column; margin-bottom: 22px; }
    .page-actions { width: 100%; overflow-x: auto; }
    .page-actions .btn { flex: 1; white-space: nowrap; }
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
    .hub-kpis { grid-template-columns: 1fr 1fr; }
    .stat { padding: 16px; }
    .stat .value { font-size: 1.55rem; }
    .grid-2, .grid-auto { grid-template-columns: 1fr; }
    .api-steps { grid-template-columns: 1fr; }
    .quick-grid { grid-template-columns: 1fr; }
    .mini-strip { grid-template-columns: 1fr; }
    .sit { grid-template-columns: auto 1fr; }
    .sit-go { grid-column: 2; }
    form.stack { grid-template-columns: 1fr; }
    .wizard-panel { grid-template-columns: 1fr; }
    form.stack > p, form.stack > h3, form.stack > .btn-row { grid-column: auto; }
    dl.detail { grid-template-columns: 1fr; }
    dl.detail dt { min-height: auto; padding-bottom: 2px; border-bottom: 0; }
    dl.detail dd { padding-top: 2px; }
    .card { padding: 18px; }
    .card-foot { margin: 18px -18px -18px; padding-inline: 18px; }
}
/* 360 e non 420: un iPhone standard e' largo 390px, e con la soglia a 420 i riquadri
   dei numeri finivano tutti in colonna singola — cinque schermate di scorrimento per
   cinque numeri. Sotto i 360 la colonna doppia non ci sta davvero, e li' si collassa. */
@media (max-width: 360px) {
    .stat-grid, .hub-kpis { grid-template-columns: 1fr; }
    .tab { font-size: .56rem; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
