/* Tokenizer Lab - superfici piatte, nessun gradiente; accento e testi allineati a ../css/tokens.css.
   Header e footer: ../css/chrome.css */
:root {
    --bg: #0f172a;
    --surface: #131d33;
    --surface-2: #1a2540;
    --surface-3: #22304f;
    --border: #2a3857;
    --border-strong: #3a4a6d;
    --text: #e8edf5;
    --text-muted: #aab4c5;
    --text-faint: #8e9ab0;     /* >= 4,6:1 su tutte le superfici */
    --primary: var(--site-color-accent-strong);
    --primary-hover: var(--site-color-accent-strong-hover);
    --primary-text: var(--site-color-accent);
    --ok: #4ade80;
    --ok-bg: #12301f;
    --family: #5eead4;
    --family-bg: #10302c;
    --api: #a5b4fc;
    --api-bg: #1f2450;
    --na: #97a3b8;
    --na-bg: #222b3d;
    --warn: #fbbf24;
    --warn-bg: #3a2c0c;
    --danger: #fca5a5;
    --bar: var(--site-color-accent-strong);
    --radius: 10px;
    --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
    font-family: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
    overflow-x: hidden;
}

a { color: var(--primary-text); }
a:hover { color: var(--text); }

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

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Pagina */
/* Area di lavoro piu larga del contenitore del sito (72rem): header e footer restano quelli comuni. */
.page { width: 100%; max-width: 110rem; margin: 0 auto; padding: 2rem var(--site-gutter) 3rem; display: flex; flex-direction: column; gap: 1.5rem; }
.page:focus { outline: none; }

.page-head { padding: 1rem 0 0.5rem; }
.eyebrow { color: var(--text-faint); font-size: 0.9rem; margin-bottom: 0.4rem; }
.eyebrow a { color: var(--text-muted); text-decoration: underline; text-underline-offset: 3px; }
.eyebrow a:hover { color: var(--text); }
h1 { font-size: 2.6rem; line-height: 1.1; font-weight: 700; letter-spacing: -0.8px; }
.lead { color: var(--text-muted); font-size: 1.08rem; max-width: 72ch; margin-top: 0.75rem; }

.meta { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.25rem; }
.meta > div { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.9rem; min-width: 0; }
.meta dt { color: var(--text-faint); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.4px; }
.meta dd { font-weight: 500; font-variant-numeric: tabular-nums; }

.notice {
    margin-top: 1rem; padding: 0.75rem 1rem; border-radius: var(--radius);
    background: var(--warn-bg); border: 1px solid #6b5216; color: #fde68a; font-size: 0.95rem;
}

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1.5rem; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.5rem; }
.panel-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* Controlli */
.btn {
    font: inherit; font-weight: 500; font-size: 0.92rem;
    border-radius: 8px; padding: 0.55rem 0.95rem; cursor: pointer;
    border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
    min-height: 40px; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn-ghost { background: transparent; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; padding: 0.7rem 1.6rem; min-height: 46px; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn:disabled { opacity: 0.55; cursor: progress; }

.input {
    font: inherit; font-size: 0.95rem; color: var(--text);
    background: var(--bg); border: 1px solid var(--border-strong); border-radius: 8px;
    padding: 0.5rem 0.7rem; min-height: 40px; width: 100%;
}
.input:focus { outline: 2px solid var(--primary-text); outline-offset: 1px; border-color: var(--primary); }
select.input { cursor: pointer; }
input[type="date"].input { color-scheme: dark; }
/* Focus sull'icona calendario (interna al campo): il contorno resta sul campo */
input[type="date"].input:focus-within { outline: 2px solid var(--primary-text); outline-offset: 1px; border-color: var(--primary); }
.panel-actions .input { width: auto; min-width: 180px; }

/* Campi di testo */
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.field { display: flex; flex-direction: column; min-width: 0; }
.field-system { grid-column: 1 / -1; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; margin-bottom: 0.4rem; flex-wrap: wrap; }
.field-head > label:first-child { font-weight: 600; }
.opt { color: var(--text-faint); font-weight: 400; font-size: 0.85rem; margin-left: 0.3rem; }
textarea {
    font-family: var(--mono); font-size: 0.86rem; line-height: 1.55; color: var(--text);
    background: var(--bg); border: 1px solid var(--border-strong); border-radius: 8px;
    padding: 0.75rem 0.85rem; resize: vertical; width: 100%; min-height: 120px;
}
textarea:focus { outline: 2px solid var(--primary-text); outline-offset: 1px; border-color: var(--primary); }
.field-foot { color: var(--text-faint); font-size: 0.82rem; margin-top: 0.3rem; font-variant-numeric: tabular-nums; }
.file-btn { color: var(--primary-text); font-size: 0.85rem; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.file-btn input { display: none; }
.privacy { color: var(--text-faint); font-size: 0.85rem; margin-top: 1rem; max-width: 100ch; }

/* Selezione modelli */
.legend { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; margin-bottom: 1rem; font-size: 0.85rem; color: var(--text-muted); }
.legend span.item { display: inline-flex; align-items: center; gap: 0.45rem; }
.providers { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1rem; }
.provider { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); min-width: 0; }
.provider-head { display: flex; justify-content: space-between; align-items: center; padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--border); }
.provider-head h3 { margin: 0; font-size: 0.98rem; }
.provider-head button { font: inherit; font-size: 0.8rem; color: var(--primary-text); background: none; border: 0; cursor: pointer; padding: 0.25rem; }
.provider ul { list-style: none; padding: 0.35rem; }
.model-opt label {
    display: grid; grid-template-columns: auto 1fr auto; gap: 0.6rem; align-items: center;
    padding: 0.45rem 0.5rem; border-radius: 6px; cursor: pointer; min-height: 40px;
}
.model-opt label:hover { background: var(--surface-2); }
.model-opt input { width: 17px; height: 17px; accent-color: var(--primary); }
.model-opt .mname { font-size: 0.92rem; min-width: 0; overflow-wrap: anywhere; }
.model-opt .mname small { display: block; color: var(--text-faint); font-family: var(--mono); font-size: 0.74rem; }
.model-opt.disabled label { cursor: not-allowed; opacity: 0.6; }
.model-opt.hidden { display: none; }

.badge {
    display: inline-block; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.2px;
    padding: 0.12rem 0.5rem; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap;
}
.badge.exact { color: var(--ok); background: var(--ok-bg); }
.badge.exact_family { color: var(--family); background: var(--family-bg); }
.badge.api { color: var(--api); background: var(--api-bg); }
.badge.unavailable { color: var(--na); background: var(--na-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }

/* Parametri */
.params { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem 1.25rem; }
.param { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; color: var(--text-muted); min-width: 0; }
.param small { color: var(--text-faint); font-size: 0.78rem; }
.param-check { flex-direction: row; align-items: center; gap: 0.6rem; color: var(--text); min-height: 40px; }
.param-check input { width: 18px; height: 18px; accent-color: var(--primary); flex: none; }
.run-bar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 1.4rem; padding-top: 1.2rem; border-top: 1px solid var(--border); }
.hint { color: var(--text-faint); font-size: 0.85rem; }
.status { font-size: 0.9rem; color: var(--text-muted); }
.status.error { color: var(--danger); }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 1.1rem; }
.kpi { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.85rem 1rem; min-width: 0; }
.kpi .label { color: var(--text-faint); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.4px; }
.kpi .value { font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 0.15rem; overflow-wrap: anywhere; }
.kpi .sub { color: var(--text-muted); font-size: 0.85rem; overflow-wrap: anywhere; }

/* Tabelle */
.table-wrap { position: relative; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.65rem 0.55rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-muted); font-weight: 500; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.35px; white-space: nowrap; background: var(--surface); }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--text); }
th.sorted-asc::after { content: " \2191"; }
th.sorted-desc::after { content: " \2193"; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.num .sub { display: block; color: var(--text-faint); font-size: 0.78rem; }
.results tbody tr.row:hover { background: var(--surface-2); }
.results .mcell { min-width: 190px; }
.results .mcell strong { display: block; font-weight: 600; }
.results .mcell small { color: var(--text-faint); font-family: var(--mono); font-size: 0.75rem; }
.results .na { color: var(--text-faint); }
.results .err { color: var(--danger); }
.results .best { color: var(--ok); font-weight: 600; }
.bar { height: 4px; background: var(--surface-3); border-radius: 2px; margin-top: 0.35rem; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--bar); }
.toggle-detail { font: inherit; font-size: 0.82rem; color: var(--primary-text); background: none; border: 1px solid var(--border-strong); border-radius: 6px; padding: 0.3rem 0.6rem; cursor: pointer; white-space: nowrap; min-height: 32px; }
.toggle-detail:hover { background: var(--surface-3); }
tr.detail-row td { background: var(--bg); padding: 1rem 1.1rem; }
.detail { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; font-size: 0.88rem; color: var(--text-muted); }
.detail h4 { color: var(--text); font-size: 0.85rem; font-weight: 600; margin-bottom: 0.35rem; text-transform: uppercase; letter-spacing: 0.35px; }
.detail dl { display: grid; grid-template-columns: auto 1fr; gap: 0.2rem 0.75rem; }
.detail dt { color: var(--text-faint); }
.detail dd { font-variant-numeric: tabular-nums; color: var(--text); }
.detail ul { padding-left: 1.1rem; }
.detail li { margin-bottom: 0.25rem; }
.src { display: block; margin-top: 0.35rem; font-size: 0.82rem; overflow-wrap: anywhere; }
.src time { color: var(--text-faint); }
.table-note { color: var(--text-faint); font-size: 0.82rem; margin-top: 0.75rem; }
.sources td { font-size: 0.86rem; color: var(--text-muted); }
.sources td:first-child { min-width: 260px; }
.sources td a { overflow-wrap: anywhere; }
.sources-title { margin-top: 1.5rem; }

/* Segmentazione */
.pieces-meta { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 0.75rem; }
.pieces {
    font-family: var(--mono); font-size: 0.85rem; line-height: 2;
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 0.85rem; max-height: 420px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere;
}
.tok { border-radius: 3px; padding: 0.1rem 0; margin-right: 1px; }
.tok.c0 { background: #1f3a5f; }
.tok.c1 { background: #3b2f5c; }
.tok.c2 { background: #1f4a3a; }
.tok.c3 { background: #4f3a1c; }
.tok.c4 { background: #4a2436; }
.tok.cont { background: transparent; outline: 1px dashed var(--border-strong); padding: 0.1rem 0.25rem; }
.tok.ws { color: var(--text-faint); }

/* Metodologia */
.method { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; color: var(--text-muted); font-size: 0.92rem; }
.method ul { padding-left: 1.1rem; }
.method li { margin-bottom: 0.45rem; }
.method strong { color: var(--text); font-weight: 600; }


/* Proiezioni */
.panel-intro { color: var(--text-muted); font-size: 0.95rem; max-width: 95ch; margin: -0.4rem 0 1.1rem; }
.proj-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem 1.25rem; margin-bottom: 1.25rem; align-items: start; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.seg button {
    font: inherit; font-size: 0.88rem; font-weight: 500; color: var(--text); background: transparent;
    border: 0; border-right: 1px solid var(--border-strong); padding: 0.45rem 0.75rem; min-height: 40px; cursor: pointer;
    font-variant-numeric: tabular-nums;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--surface-3); }
.seg button[aria-pressed="true"] { background: var(--primary); color: #fff; }
.seg button:focus-visible { outline-offset: -3px; }
.seg-sm button { font-size: 0.82rem; min-height: 34px; padding: 0.3rem 0.65rem; }

.series-picker { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin: 1.1rem 0 1rem; }
.series-picker__label { color: var(--text-muted); font-size: 0.88rem; }
.series-picker__list { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
    display: inline-flex; align-items: center; gap: 0.45rem; font: inherit; font-size: 0.84rem; color: var(--text-muted);
    background: transparent; border: 1px solid var(--border-strong); border-radius: 999px; padding: 0.3rem 0.75rem; min-height: 34px; cursor: pointer;
}
.chip[aria-pressed="true"] { color: var(--text); background: var(--surface-2); }
.chip:disabled { opacity: 0.5; cursor: not-allowed; }
.chip__swatch { width: 10px; height: 10px; border-radius: 2px; border: 1px solid var(--border-strong); flex: none; }
.chip[aria-pressed="true"] .chip__swatch { border-color: transparent; }

.charts { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.chart { margin: 0; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; min-width: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.75rem 1rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.chart-head h3 { margin-bottom: 0.2rem; }
.chart-head p { color: var(--text-muted); font-size: 0.86rem; max-width: 70ch; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.lg { display: inline-flex; align-items: center; gap: 0.4rem; }
.lg__swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; }
.chart-body { position: relative; min-height: 60px; }
.chart-svg { display: block; max-width: 100%; height: auto; overflow: visible; }
.chart-svg text { font-family: inherit; }
.chart-svg .axis { fill: var(--text-faint); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart-svg .lbl { fill: var(--text); font-size: 12.5px; }
.chart-svg .val { fill: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart-svg .grid { stroke: #22304a; stroke-width: 1; }
.chart-svg .baseline { stroke: var(--border-strong); stroke-width: 1; }
.chart-svg .marker { stroke: var(--text-faint); stroke-width: 1; stroke-dasharray: 4 4; }
.chart-svg .crosshair { stroke: var(--text-faint); stroke-width: 1; }
.chart-svg .dot { stroke: var(--bg); stroke-width: 2; }
.chart-svg .hit { fill: transparent; cursor: crosshair; }
.chart-tip {
    position: absolute; z-index: 3; pointer-events: none; min-width: 190px; max-width: 320px;
    background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 8px;
    padding: 0.55rem 0.7rem; font-size: 0.82rem; color: var(--text); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.tip-title { font-weight: 600; margin-bottom: 0.3rem; }
.tip-row { display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: 0.45rem; padding: 0.1rem 0; }
.tip-name { color: var(--text-muted); overflow-wrap: anywhere; }  /* a capo, mai troncato */
.tip-val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tip-foot { color: var(--text-faint); margin-top: 0.25rem; }
.chart-data { margin-top: 0.75rem; font-size: 0.85rem; }
.chart-data summary { cursor: pointer; color: var(--primary-text); min-height: 32px; display: inline-flex; align-items: center; }
.chart-data .table-wrap { margin-top: 0.5rem; }
table.data { font-size: 0.84rem; }
table.data th[scope="row"] { color: var(--text); font-weight: 500; text-transform: none; letter-spacing: 0; font-size: 0.86rem; white-space: normal; min-width: 150px; background: transparent; }
table.data td.best { color: var(--ok); font-weight: 600; }
.empty { color: var(--text-faint); font-size: 0.9rem; padding: 1rem 0; }

/* Schermi larghi: piu colonne invece di spazio vuoto */
@media (min-width: 1100px) {
    .charts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    #ch-comp, #ch-miles { grid-column: 1 / -1; }
    .proj-controls .param-wide { grid-column: span 2; }
}
@media (min-width: 1440px) {
    .fields { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) minmax(0, 1.3fr); }
    .field-system { grid-column: auto; }
    .fields textarea { min-height: 220px; }
    .params { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
}

/* Tabella delle soglie come schede su schermi stretti */
@media (max-width: 900px) {
    .mtable thead { display: none; }
    .mtable, .mtable tbody, .mtable tr, .mtable th, .mtable td { display: block; width: 100%; }
    .mtable tr { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 0.75rem; padding: 0.35rem 0; }
    .mtable th[scope="row"] { padding: 0.5rem 0.75rem; border: 0; font-weight: 600; }
    .mtable td { border: 0; padding: 0.3rem 0.75rem; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
    .mtable td::before { content: attr(data-label); color: var(--text-faint); font-size: 0.82rem; text-align: left; flex: none; }
    .mtable td .sub { display: block; }
}

/* Tablet */
@media (max-width: 1024px) {
    .params { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .detail { grid-template-columns: 1fr 1fr; }
}

/* Tabella risultati come schede su tablet e telefono (9 colonne non entrano sotto 1100px) */
@media (max-width: 1100px) {
    .results thead { display: none; }
    .results, .results tbody, .results tr, .results td { display: block; width: 100%; }
    .results tr.row { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 0.75rem; padding: 0.4rem 0.2rem; background: var(--bg); }
    .results td { border: 0; padding: 0.35rem 0.75rem; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
    .results td::before { content: attr(data-label); color: var(--text-faint); font-size: 0.82rem; text-align: left; flex: none; }
    .results td.mcell { display: block; text-align: left; padding-top: 0.5rem; }
    .results td.mcell::before { content: none; }
    .results td.num { white-space: normal; }
    .results td.num > div { min-width: 0; }
    .results td.actions { justify-content: flex-start; }
    .results td.actions::before { content: none; }
    .results tr.detail-row { margin: -0.6rem 0 0.75rem; border: 1px solid var(--border); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); }
    .results tr.detail-row td { display: block; text-align: left; }
    .results tr.detail-row td::before { content: none; }
    .bar { width: 100%; }
}

/* Telefono */
@media (max-width: 768px) {
    .page { padding: 1rem var(--site-gutter) 2rem; gap: 1rem; }
    h1 { font-size: 2rem; }
    .lead { font-size: 1rem; }
    .panel { padding: 1rem; border-radius: 12px; }
    .fields { grid-template-columns: 1fr; }
    .params { grid-template-columns: 1fr; }
    .kpis { grid-template-columns: 1fr 1fr; }
    .kpi .value { font-size: 1.1rem; }
    .method { grid-template-columns: 1fr; }
    .detail { grid-template-columns: 1fr; }
    .panel-actions { width: 100%; }
    .panel-actions .input { flex: 1 1 100%; min-width: 0; }
    .panel-actions .btn { flex: 1 1 auto; }
    .providers { grid-template-columns: 1fr; }
    .btn-primary { flex: 1 1 100%; }

    .sources td:first-child { min-width: 200px; }
    .proj-controls { grid-template-columns: 1fr 1fr; }
    .proj-controls .param-wide { grid-column: 1 / -1; }
    .chart { padding: 0.85rem; }
}
