/* =============================================================================
   Agenda — design system (SPEC §11.2)
   Un solo file: token, primitive, componenti. Niente framework, niente CDN.

   Regole non negoziabili: testo del corpo ≥ 14px (12px solo per le etichette),
   touch target ≥ 44px, contrasto AA in entrambi i temi, orari con
   tabular-nums, animazioni disattivabili.
   ========================================================================== */

/* --- Token ---------------------------------------------------------------- */

:root {
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", monospace;

    --fs-xs: 12px;   /* solo etichette */
    --fs-sm: 14px;   /* minimo per il testo */
    --fs-md: 16px;
    --fs-lg: 20px;
    --fs-xl: 28px;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-6: 24px;
    --space-8: 32px;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;

    --bg: #f7f7f8;
    --surface: #ffffff;
    --surface-2: #f0f0f2;
    --border: #e3e3e7;
    --text: #15151a;
    --text-2: #5b5b66;
    --text-3: #70707c;

    --pos: #15803d;
    --neg: #c81e1e;
    --warn: #b45309;
    --info: #1d4ed8;

    /* Accento dell'applicazione; un tenant può sovrascriverlo
       (tenants.settings.color, SPEC §11.2). */
    --accent: #1d4ed8;
    --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
    --on-accent: #ffffff;

    /* Palette dei calendari: dodici colori, non colori liberi. Gli stessi slug
       stanno in config/app.php sotto calendar.palette. */
    --cal-blue: #1d4ed8;
    --cal-indigo: #4338ca;
    --cal-violet: #6d28d9;
    --cal-magenta: #a21caf;
    --cal-red: #c81e1e;
    --cal-orange: #c2410c;
    --cal-amber: #a16207;
    --cal-lime: #4d7c0f;
    --cal-green: #15803d;
    --cal-teal: #0f766e;
    --cal-cyan: #0e7490;
    --cal-slate: #475569;

    --shadow-1: 0 1px 2px rgb(0 0 0 / .06);
    --shadow-2: 0 4px 16px rgb(0 0 0 / .08);

    --header-h: 56px;
    --tabbar-h: 60px;
}

html[data-theme="dark"],
html[data-theme="auto"] {
    color-scheme: light;
}

html[data-theme="dark"] {
    color-scheme: dark;
}

/* I colori chiari del tema chiaro, sul fondo scuro, scendono sotto l'AA:
   nel tema scuro sono schiariti, e il testo dentro ai pieni diventa scuro. */
html[data-theme="dark"] {
    --bg: #0b0b0f;
    --surface: #15151b;
    --surface-2: #1d1d25;
    --border: #2a2a34;
    --text: #f2f2f5;
    --text-2: #b0b0bb;
    --text-3: #8d8d99;

    --pos: #22c55e;
    --neg: #f87171;
    --warn: #fbbf24;
    --info: #60a5fa;

    --accent: #60a5fa;
    --on-accent: #15151a;

    --cal-blue: #60a5fa;
    --cal-indigo: #a5b4fc;
    --cal-violet: #c4b5fd;
    --cal-magenta: #f0abfc;
    --cal-red: #f87171;
    --cal-orange: #fb923c;
    --cal-amber: #fbbf24;
    --cal-lime: #a3e635;
    --cal-green: #4ade80;
    --cal-teal: #2dd4bf;
    --cal-cyan: #22d3ee;
    --cal-slate: #94a3b8;

    --shadow-1: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-2: 0 4px 16px rgb(0 0 0 / .5);
}

@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] {
        color-scheme: dark;

        --bg: #0b0b0f;
        --surface: #15151b;
        --surface-2: #1d1d25;
        --border: #2a2a34;
        --text: #f2f2f5;
        --text-2: #b0b0bb;
        --text-3: #8d8d99;

        --pos: #22c55e;
        --neg: #f87171;
        --warn: #fbbf24;
        --info: #60a5fa;

        --accent: #60a5fa;
        --on-accent: #15151a;

        --cal-blue: #60a5fa;
        --cal-indigo: #a5b4fc;
        --cal-violet: #c4b5fd;
        --cal-magenta: #f0abfc;
        --cal-red: #f87171;
        --cal-orange: #fb923c;
        --cal-amber: #fbbf24;
        --cal-lime: #a3e635;
        --cal-green: #4ade80;
        --cal-teal: #2dd4bf;
        --cal-cyan: #22d3ee;
        --cal-slate: #94a3b8;

        --shadow-1: 0 1px 2px rgb(0 0 0 / .4);
        --shadow-2: 0 4px 16px rgb(0 0 0 / .5);
    }
}

/* --- Reset ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

/* Un elemento con l attributo `hidden` deve sparire, punto: qualunque
   `display` dichiarato altrove vince sulla regola del browser, e un pannello
   che si crede nascosto resta invece in mezzo alla pagina. */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

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

body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: var(--fs-sm);
    line-height: 1.5;
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
}

h1, h2, h3 { margin: 0 0 var(--space-2); line-height: 1.25; }
p { margin: 0 0 var(--space-3); }

a { color: var(--accent); }

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

/* Ogni orario e ogni data incolonnati: le cifre devono avere la stessa larghezza. */
time, .num, .time { font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--surface);
    color: var(--text);
    padding: var(--space-2) var(--space-3);
    z-index: 100;
}
.skip-link:focus { left: var(--space-2); top: var(--space-2); }

/* --- Struttura ------------------------------------------------------------ */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    height: var(--header-h);
    padding: 0 var(--space-4);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.app-header__brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
}

.app-header__logo {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    background: var(--accent);
    display: inline-block;
}

.app-header__title { font-size: var(--fs-md); }

.app-main {
    padding: var(--space-4);
    max-width: 960px;
    margin: 0 auto;
}

.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack--centered { min-height: 60vh; justify-content: center; align-items: center; }

/* --- Componenti ----------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-1);
    padding: var(--space-4);
}
.card--narrow { max-width: 420px; text-align: center; }
.card__title { font-size: var(--fs-lg); }
.card__text { color: var(--text-2); }

.link { color: var(--accent); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 var(--space-4);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--on-accent);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.btn--ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
}

.milestones { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }

.milestone {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.milestone__code {
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 6px;
    background: var(--border);
    color: var(--text-2);
}

.milestone--done .milestone__code { background: var(--pos); color: var(--surface); }
.milestone--next .milestone__code { background: var(--accent); color: var(--on-accent); }
.milestone__label { color: var(--text-2); }

.error__code {
    font-size: var(--fs-xl);
    font-weight: 700;
    color: var(--text-3);
    margin: 0;
}

/* --- Navigazione inferiore (mobile) --------------------------------------- */

.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: center;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 30;
}

.tabbar__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 44px;
    color: var(--text-3);
    text-decoration: none;
    font-size: var(--fs-xs);
}

.tabbar__item.is-active { color: var(--accent); }
.tabbar__label { font-size: var(--fs-xs); }

.fab {
    justify-self: center;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: var(--on-accent);
    font-size: var(--fs-lg);
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow-2);
}

/* Le icone arrivano in M2 come sprite SVG: qui vale il segnaposto. */
.icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    background: currentColor;
    mask-size: contain;
    -webkit-mask-size: contain;
    opacity: .7;
    border-radius: 4px;
}

/* --- Toast ---------------------------------------------------------------- */

.toast-host {
    position: fixed;
    left: 50%;
    bottom: calc(var(--tabbar-h) + var(--space-4));
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    z-index: 40;
    pointer-events: none;
}

.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-2);
    padding: var(--space-2) var(--space-4);
    max-width: 90vw;
}

/* --- Desktop -------------------------------------------------------------- */

@media (min-width: 900px) {
    body { padding-bottom: 0; }
    .tabbar { display: none; }
    .app-main { padding: var(--space-6); }
    .toast-host { bottom: var(--space-6); }
}

/* --- Form e campi --------------------------------------------------------- */

.form { display: flex; flex-direction: column; gap: var(--space-4); }

.form--grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    align-items: end;
}

/* `flex-direction` va ridichiarata: .form la mette a column, e senza questa
   riga i campi in linea resterebbero incolonnati. */
.form--inline {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-3);
}

.form__actions { display: flex; gap: var(--space-2); align-items: end; }

.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field--grow { flex: 1 1 220px; }
.field__label { font-size: var(--fs-xs); color: var(--text-2); font-weight: 600; }
.field__hint { font-size: var(--fs-xs); color: var(--text-3); }

.input, .select {
    min-height: 44px;
    padding: 0 var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: var(--fs-sm);
    width: 100%;
}

.input:focus-visible, .select:focus-visible { border-color: var(--accent); }

.input--code {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    letter-spacing: .18em;
}

.select--small { min-height: 36px; width: auto; }

.check {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
    color: var(--text-2);
}

.btn--block { width: 100%; }
.btn--small { min-height: 36px; padding: 0 var(--space-3); font-size: var(--fs-xs); }

.card--form { text-align: left; }
.card__subtitle { font-size: var(--fs-md); margin-top: var(--space-4); }

.rule { border: 0; border-top: 1px solid var(--border); margin: var(--space-6) 0 var(--space-4); }

/* --- Messaggi ------------------------------------------------------------- */

.banner {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    margin: 0 0 var(--space-4);
}

.banner--ok    { border-color: color-mix(in srgb, var(--pos) 40%, var(--border)); }
.banner--warn  { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); }
.banner--error { border-color: color-mix(in srgb, var(--neg) 45%, var(--border)); }

/* --- Elenchi -------------------------------------------------------------- */

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }

.list__item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border);
}

.list__item:last-child { border-bottom: 0; }
.list__title { margin: 0; font-weight: 600; display: flex; align-items: center; gap: var(--space-2); }
.list__meta { margin: 0; font-size: var(--fs-xs); color: var(--text-3); }
.list__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

.tag {
    font-size: var(--fs-xs);
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text-2);
    border: 1px solid var(--border);
}

.tag--accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tag--warn   { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); border-color: transparent; }

/* Il colore di un gruppo o di un calendario in una pagina fatta dal server:
   niente stile inline (la CSP lo blocca), passa da data-color. */
[data-color="blue"]    { --calendar-color: var(--cal-blue); }
[data-color="indigo"]  { --calendar-color: var(--cal-indigo); }
[data-color="violet"]  { --calendar-color: var(--cal-violet); }
[data-color="magenta"] { --calendar-color: var(--cal-magenta); }
[data-color="red"]     { --calendar-color: var(--cal-red); }
[data-color="orange"]  { --calendar-color: var(--cal-orange); }
[data-color="amber"]   { --calendar-color: var(--cal-amber); }
[data-color="lime"]    { --calendar-color: var(--cal-lime); }
[data-color="green"]   { --calendar-color: var(--cal-green); }
[data-color="teal"]    { --calendar-color: var(--cal-teal); }
[data-color="cyan"]    { --calendar-color: var(--cal-cyan); }
[data-color="slate"]   { --calendar-color: var(--cal-slate); }

.swatch {
    display: inline-block;
    inline-size: 0.75rem;
    block-size: 0.75rem;
    border-radius: 50%;
    background: var(--calendar-color, currentColor);
    vertical-align: middle;
}

.group-card   { border-inline-start: 4px solid var(--calendar-color, transparent); }
.group-nested { margin-inline-start: 1.5rem; }

/* --- Segreti da copiare --------------------------------------------------- */

.secret {
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    word-break: break-all;
    background: var(--surface-2);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
    user-select: all;
}

.codes { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-2); }
.codes__item { font-family: var(--font-mono); font-size: var(--fs-sm); user-select: all; }

/* --- Intestazione: organizzazione e azioni -------------------------------- */

.app-header__actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.app-header__tenant { font-size: var(--fs-xs); color: var(--text-2); }
.tenant-switch { display: flex; align-items: center; gap: var(--space-2); }
.tenant-switch .select { min-height: 36px; width: auto; max-width: 200px; }

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

@media (max-width: 640px) {
    .app-header { flex-wrap: wrap; height: auto; padding: var(--space-2) var(--space-3); gap: var(--space-2); }
    .app-header__actions { width: 100%; justify-content: flex-end; }
}

/* =============================================================================
   Calendario (SPEC §11.1)
   La griglia è posizionata in pixel al minuto: --px-per-minute è l'unica
   manopola, e cambia la densità senza toccare nient'altro.
   ========================================================================== */

.calendar-page {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-height: 0;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-3);
}

.toolbar__nav { display: flex; align-items: center; gap: var(--space-1); }
.toolbar__title { font-size: var(--fs-lg); margin: 0; text-transform: capitalize; }

.segmented {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--surface);
}

.segmented__item {
    min-height: 36px;
    padding: 0 var(--space-3);
    border: 0;
    background: transparent;
    color: var(--text-2);
    font: inherit;
    font-size: var(--fs-xs);
    cursor: pointer;
}

.segmented__item[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); font-weight: 600; }

.calendar-layout {
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr);
    gap: var(--space-4);
    align-items: start;
}

.calendars { display: flex; flex-direction: column; gap: var(--space-2); }
.calendars__heading { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); margin: 0; }
.calendars__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.calendars__item { display: flex; }

.calendars__label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 36px;
    width: 100%;
    cursor: pointer;
}

.calendars__dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    background: var(--calendar-color, var(--accent));
    flex: none;
}

.calendars__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calendars__hint { font-size: var(--fs-xs); color: var(--text-3); margin-top: var(--space-3); }

.calendars__hint kbd {
    font-family: var(--font-mono);
    font-size: 11px;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0 3px;
}

.calendar-grid {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    min-width: 0;
}

/* --- Griglia settimanale --------------------------------------------------- */

.cal { --px-per-minute: .75; display: flex; flex-direction: column; max-height: 72vh; }

.cal__head,
.cal__allday {
    display: grid;
    grid-template-columns: 52px repeat(var(--days, 7), minmax(0, 1fr));
    border-bottom: 1px solid var(--border);
}

.cal__dayhead {
    padding: var(--space-2);
    text-align: center;
    font-size: var(--fs-xs);
    color: var(--text-2);
    border-left: 1px solid var(--border);
    text-transform: capitalize;
}

.cal__dayhead.is-today { color: var(--accent); font-weight: 700; }
.cal__dayhead.is-weekend { background: var(--surface-2); }

.cal__gutter {
    font-size: 10px;
    color: var(--text-3);
    padding: var(--space-1);
    text-align: right;
}

.cal__allday.is-empty { display: none; }

.cal__allday-col {
    border-left: 1px solid var(--border);
    padding: 2px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 26px;
}

.cal__body {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.cal__hours { position: relative; height: calc(1440px * var(--px-per-minute)); }

.cal__hour {
    position: absolute;
    top: calc(var(--minute) * 1px * var(--px-per-minute));
    right: var(--space-2);
    transform: translateY(-50%);
    font-size: 11px;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

.cal__grid {
    display: grid;
    grid-template-columns: repeat(var(--days, 7), minmax(0, 1fr));
    height: calc(1440px * var(--px-per-minute));
    position: relative;
    touch-action: none;
}

.cal__daycol { position: relative; border-left: 1px solid var(--border); }
.cal__daycol.is-weekend { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.cal__daycol.is-today { background: color-mix(in srgb, var(--accent) 4%, transparent); }

.cal__hourline {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(var(--minute) * 1px * var(--px-per-minute));
    border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
    pointer-events: none;
}

.cal__selection {
    position: absolute;
    left: 2px;
    right: 2px;
    top: calc(var(--from) * 1px * var(--px-per-minute));
    height: calc(var(--duration) * 1px * var(--px-per-minute));
    border-radius: 6px;
    background: var(--accent-soft);
    border: 1px dashed var(--accent);
    color: var(--accent);
    font-size: 11px;
    padding: 2px 4px;
    pointer-events: none;
}

/* --- Evento ---------------------------------------------------------------- */

.event {
    position: absolute;
    top: calc(var(--from) * 1px * var(--px-per-minute));
    height: calc(var(--duration) * 1px * var(--px-per-minute));
    left: calc(var(--column) / var(--columns) * 100%);
    width: calc(100% / var(--columns));
    padding: 2px 5px;
    border-radius: 6px;
    border: 1px solid var(--calendar-color, var(--accent));
    border-left: 3px solid var(--calendar-color, var(--accent));
    background: color-mix(in srgb, var(--calendar-color, var(--accent)) 14%, var(--surface));
    color: var(--text);
    font-size: var(--fs-xs);
    line-height: 1.25;
    overflow: hidden;
    cursor: grab;
    transform: translate(var(--drag-x, 0), var(--drag-y, 0));
    z-index: 1;
}

.event:focus-visible { z-index: 3; }
.event.is-dragging { opacity: .85; cursor: grabbing; z-index: 5; box-shadow: var(--shadow-2); }
.event.is-resizing { z-index: 5; }
.event.is-tentative { border-style: dashed; background: var(--surface); }
.event.is-cancelled { opacity: .55; text-decoration: line-through; }
.event.is-free { background: var(--surface); border-style: dotted; }
/* Solo occupato: grigio tratteggiato, mai il colore di un calendario. Si deve
   capire al volo che non è un impegno che si può aprire. */
.event.is-opaque,
.chip.is-opaque {
    color: var(--text-3);
    border-color: color-mix(in srgb, var(--text-3) 50%, transparent);
    background:
        repeating-linear-gradient(135deg, color-mix(in srgb, var(--text-3) 16%, transparent) 0 4px, transparent 4px 8px),
        var(--surface);
}

/* Come un impegno ti riguarda (estensione del 15/09/2026, ui/event-badges.js). */
.event.is-watching,
.chip.is-watching,
.agenda__entry.is-watching { background: var(--surface); }

.event.is-pending,
.chip.is-pending { opacity: .72; }
.event.is-pending::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 14px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--calendar-color, var(--accent));
}

.event.is-declined,
.chip.is-declined { opacity: .55; }
.event.is-declined .event__title,
.chip.is-declined .chip__title,
.agenda__entry.is-declined .agenda__title { text-decoration: line-through; }

.event.has-team,
.chip.has-team { border-left-color: var(--team-a); border-left-width: 4px; }
.event.has-two-teams,
.chip.has-two-teams {
    border-left: 0;
    box-shadow: inset 3px 0 0 var(--team-a), inset 6px 0 0 var(--team-b);
    padding-left: 9px;
}

.event__format { margin-left: 3px; }

.team-chips {
    display: inline-flex;
    gap: 2px;
    margin-left: 4px;
    vertical-align: middle;
}
.team-chip {
    font-size: var(--fs-xs);
    font-weight: 700;
    line-height: 1.2;
    padding: 0 3px;
    border-radius: 3px;
    border: 1px solid var(--chip-color, var(--text-3));
    background: color-mix(in srgb, var(--chip-color, var(--text-3)) 28%, var(--surface));
    color: var(--text);
}
.team-chip--more { border-style: dashed; }

/* Invitati e risposta, nella scheda dell'impegno. */
.attendees > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.attendees__list {
    display: grid;
    gap: 2px;
    max-height: 14rem;
    overflow: auto;
    margin-block: var(--space-1);
}
.attendees__item { min-height: 44px; align-items: center; gap: var(--space-1); }
.attendees__item[hidden] { display: none; }

.answer { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); }
.answer[hidden] { display: none; }
.answer .btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.event.continues-before { border-top-left-radius: 0; border-top-right-radius: 0; border-top-style: dashed; }
.event.continues-after { border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom-style: dashed; }
.event.is-short { display: flex; align-items: center; gap: var(--space-1); padding-top: 0; padding-bottom: 0; }

.event__time { font-variant-numeric: tabular-nums; color: var(--text-2); margin-right: 4px; }
.event__title { font-weight: 600; }
.event__badge { position: absolute; top: 1px; right: 3px; font-size: 10px; opacity: .8; }

.event__resize {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 7px;
    cursor: ns-resize;
}

/* --- Chip: giornata intera e vista mese ------------------------------------ */

.chip {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    text-align: left;
    border: 0;
    border-left: 3px solid var(--calendar-color, var(--accent));
    border-radius: 4px;
    background: color-mix(in srgb, var(--calendar-color, var(--accent)) 14%, var(--surface));
    color: var(--text);
    font: inherit;
    font-size: 11px;
    padding: 2px 4px;
    cursor: pointer;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chip--month { background: transparent; }
.chip.is-allday { background: color-mix(in srgb, var(--calendar-color, var(--accent)) 18%, var(--surface)); }
.chip.is-cancelled { opacity: .55; text-decoration: line-through; }
.chip__time { color: var(--text-3); font-variant-numeric: tabular-nums; flex: none; }
.chip__title { overflow: hidden; text-overflow: ellipsis; }

/* --- Vista mese ------------------------------------------------------------ */

.month {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    grid-auto-rows: minmax(96px, auto);
}

.month__weekday {
    padding: var(--space-2);
    font-size: var(--fs-xs);
    color: var(--text-3);
    text-align: center;
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
}

.month__day {
    border-left: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 2px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.month__day.is-outside { background: var(--surface-2); }
.month__day.is-outside .month__daynum-btn { color: var(--text-3); }
.month__day.is-today .month__daynum-btn { background: var(--accent); color: var(--on-accent); }

.month__daynum { display: flex; justify-content: flex-end; }

.month__daynum-btn {
    min-width: 24px;
    height: 24px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--text-2);
    font: inherit;
    font-size: var(--fs-xs);
    font-variant-numeric: tabular-nums;
    cursor: pointer;
}

.month__events { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.month__more {
    border: 0;
    background: transparent;
    color: var(--text-3);
    font: inherit;
    font-size: 11px;
    text-align: left;
    cursor: pointer;
    padding: 0 4px;
}

/* --- Popover di creazione rapida ------------------------------------------- */

.popover {
    position: fixed;
    left: var(--left, 50%);
    top: var(--top, 30%);
    z-index: 60;
    width: min(280px, calc(100vw - 24px));
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-2);
    padding: var(--space-3);
}

.popover__form { display: flex; flex-direction: column; gap: var(--space-2); }
.popover__when { margin: 0; font-size: var(--fs-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }
.popover__actions { display: flex; justify-content: space-between; gap: var(--space-2); }

/* --- Scheda laterale ------------------------------------------------------- */

.sheet {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(420px, 100vw);
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-2);
    z-index: 70;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sheet__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}

.sheet__title { margin: 0; font-size: var(--fs-md); }
.sheet__body { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-4); }
.sheet__grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.sheet__flags { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.sheet__actions { display: flex; gap: var(--space-2); }
.sheet__meta { font-size: var(--fs-xs); color: var(--text-3); margin: 0; }
.sheet__history { border-top: 1px solid var(--border); padding-top: var(--space-3); }

.input--area { min-height: 72px; padding: var(--space-2) var(--space-3); resize: vertical; }

.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.history__item { display: flex; flex-direction: column; font-size: var(--fs-xs); }
.history__what { color: var(--text); }
.history__who { color: var(--text-3); font-variant-numeric: tabular-nums; }

/* --- Schermi stretti ------------------------------------------------------- */

@media (max-width: 900px) {
    .calendar-layout { grid-template-columns: minmax(0, 1fr); }
    .calendars { order: 2; }
    .cal { max-height: 65vh; --px-per-minute: .6; }
    .toolbar__title { width: 100%; order: 3; font-size: var(--fs-md); }
}

/* Il calendario ha bisogno di tutta la larghezza: 960px bastano a un modulo,
   non a sette colonne di ore. */
body.page-calendar .app-main { max-width: 1360px; }

/* Trascinare un evento non deve selezionarne il testo. */
.cal__grid, .cal__grid * { user-select: none; -webkit-user-select: none; }

/* --- Ricorrenza (M3) ------------------------------------------------------- */

.recurrence { display: flex; flex-direction: column; gap: var(--space-2); }

.recurrence__days { display: flex; flex-wrap: wrap; gap: var(--space-1); }

.recurrence__day {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: var(--fs-xs);
    cursor: pointer;
    text-transform: capitalize;
}

.recurrence__day:has(input:checked) {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

.recurrence__end { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.recurrence__summary { margin: 0; font-size: var(--fs-xs); color: var(--text-3); }

.input--tiny { width: auto; min-width: 110px; min-height: 36px; }

/* --- Dialogo di ambito ----------------------------------------------------- */

.modal {
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / .35);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    z-index: 80;
}

.modal__box {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-2);
    padding: var(--space-4);
    max-width: 420px;
    width: 100%;
}

.modal__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* --- Vista agenda ---------------------------------------------------------- */

.agenda { display: flex; flex-direction: column; max-height: 72vh; overflow-y: auto; }

.agenda__day { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.agenda__day.is-today { background: color-mix(in srgb, var(--accent) 5%, transparent); }

.agenda__date {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0 0 var(--space-2);
    font-size: var(--fs-sm);
    text-transform: capitalize;
    color: var(--text-2);
}

.agenda__add {
    margin-left: auto;
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
    color: var(--text-2);
    font: inherit;
    cursor: pointer;
}

.agenda__empty { margin: 0; font-size: var(--fs-xs); color: var(--text-3); }
.agenda__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); }

.agenda__entry {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
    width: 100%;
    text-align: left;
    border: 0;
    border-left: 3px solid var(--calendar-color, var(--accent));
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--calendar-color, var(--accent)) 8%, transparent);
    padding: var(--space-2) var(--space-3);
    font: inherit;
    color: var(--text);
    cursor: pointer;
    min-height: 44px;
}

.agenda__entry.is-cancelled { opacity: .55; text-decoration: line-through; }
.agenda__entry.is-tentative { border-left-style: dashed; }

.agenda__time {
    font-variant-numeric: tabular-nums;
    font-size: var(--fs-xs);
    color: var(--text-2);
    flex: none;
    min-width: 96px;
}

.agenda__body { display: flex; flex-direction: column; min-width: 0; }
.agenda__title { font-weight: 600; }
.agenda__meta { font-size: var(--fs-xs); color: var(--text-3); }

@media (max-width: 640px) {
    .agenda__entry { flex-direction: column; align-items: stretch; gap: 2px; }
    .agenda__time { min-width: 0; }
}

/* --- Agenti: permessi e attività ------------------------------------------ */

.scopes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.scopes code { font-size: var(--fs-xs); color: var(--text-3); }

/*
 * Il grafico delle chiamate per ora. L'altezza arriva da una classe e non da
 * un attributo style: la CSP vieta gli stili in linea (SPEC §12). Dieci
 * gradini non sono una misura, ma bastano a far vedere a occhio la notte in
 * cui un agente è andato in ciclo.
 */
.sparkline {
    list-style: none;
    margin: var(--space-3) 0 0;
    padding: 0;
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 72px;
}

.sparkline__bar {
    flex: 1 1 0;
    min-width: 3px;
    background: var(--accent-soft);
    border-radius: 2px 2px 0 0;
    height: 10%;
}

.sparkline__bar--1  { height: 10%; }
.sparkline__bar--2  { height: 20%; }
.sparkline__bar--3  { height: 30%; }
.sparkline__bar--4  { height: 40%; }
.sparkline__bar--5  { height: 50%; }
.sparkline__bar--6  { height: 60%; }
.sparkline__bar--7  { height: 70%; }
.sparkline__bar--8  { height: 80%; }
.sparkline__bar--9  { height: 90%; }
.sparkline__bar--10 { height: 100%; background: var(--accent); }

/* --- Task: chip in cima al giorno (SPEC §5.5) ------------------------------ */

/*
 * Un task non è un impegno, e non deve sembrarlo: sta nella fascia delle
 * giornate intere perché non occupa un'ora, e il bordo tratteggiato lo dice
 * a colpo d'occhio senza bisogno di un'etichetta.
 */
.chip--task {
    background: transparent;
    border: 1px dashed var(--border-strong, var(--border));
    color: var(--text-2);
    font-style: normal;
}

.chip--task::before {
    content: '○ ';
    color: var(--text-3);
}

.chip--task.is-done {
    opacity: .6;
    text-decoration: line-through;
}

.chip--task.is-done::before {
    content: '● ';
    color: var(--ok, var(--accent));
}

/* --- Amministrazione: numeri e registro ------------------------------------ */

.stats {
    list-style: none;
    margin: var(--space-4) 0 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-6);
}

.stats__item { display: flex; flex-direction: column; }

.stats__value {
    font-size: var(--fs-xl, 24px);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.stats__label { font-size: var(--fs-xs); color: var(--text-2); }

/*
 * Il registro è lungo per natura: si scorre dentro il suo riquadro invece di
 * allungare la pagina all'infinito.
 */
.list--log {
    max-height: 60vh;
    overflow-y: auto;
}

.list--log .list__title { font-weight: 500; }
.list--log code { font-size: var(--fs-xs); }

.list__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* Il selettore del tema usa .is-active come le altre barre segmentate. */
.segmented__item.is-active { background: var(--accent); color: var(--on-accent); font-weight: 600; }

/* --- Intestazione su schermo stretto --------------------------------------- */

/*
 * Su un telefono i link dell'intestazione andavano a capo tre volte, mangiando
 * un terzo dello schermo prima ancora di mostrare un impegno. Restano tutti —
 * togliendoli, Persone, Agenti e Organizzazione non si raggiungerebbero più da
 * mobile — ma su una riga sola che scorre di lato.
 */
@media (max-width: 640px) {
    .app-header {
        gap: var(--space-2);
        align-items: center;
    }

    .app-header__actions {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        /* Lo spazio per l'ombra del focus, che senza verrebbe tagliata. */
        padding: 2px;
        margin: -2px;
    }

    .app-header__actions::-webkit-scrollbar { display: none; }
    .app-header__actions > * { flex: none; }
    .app-header__title { font-size: var(--fs-md); }
}
