/* ========================================================================
   Calendario Perpetuo GFB — design system
   ======================================================================== */

:root {
  /* Palette neutra */
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #fafbfd;
  --surface-3: #f1f4f9;
  --text: #0b1530;
  --text-2: #475569;
  --text-3: #94a3b8;
  --border: #e1e4ec;
  --border-strong: #c5ccd9;

  /* Accento */
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-ring: rgba(79, 70, 229, .18);
  --accent-glow: rgba(79, 70, 229, .35);

  /* Stati */
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;

  /* Griglia calendario */
  --weekend: #f3f4f6;
  --holiday: #fef2f2;
  --today: #fff8e1;

  /* Fasi — palette categoriale ad alto contrasto */
  --f0: #94a3b8;  /* F0 primo inserimento (neutro, senza timing) */
  /* Palette fasi GFB (schema del 2026-09-18) + colore del testo per fase: sono tinte
     chiare, il bianco non si leggerebbe. --fN-ink va usato ovunque c'è testo sul colore. */
  --f1: #FFE600;  --f1-ink: #3a3200;
  --f2: #E2C6FF;  --f2-ink: #3b1d66;
  --f3: #FF9F1C;  --f3-ink: #4a2800;
  --f4: #FF66B2;  --f4-ink: #4d0a2f;
  --f5: #B9FBC0;  --f5-ink: #0b3d1a;
  --f6: #D8BBFF;  --f6-ink: #2e1065;
  --f7: #33C1FF;  --f7-ink: #06304a;
  --f8: #E8DFF5;  --f8-ink: #3b2a5c;
  --f9: #FFF1C5;  --f9-ink: #4a3a00;
  --f10: #FFC6FF; --f10-ink: #5c0a5c;
  --f11: #52B788; --f11-ink: #052e1c;

  --coord: #f59e0b;
  --tecn: #3b82f6;

  /* Ombre stratificate (definite ma morbide) */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05), 0 3px 8px rgba(15, 23, 42, .07);
  --shadow:    0 2px 5px rgba(15, 23, 42, .06), 0 10px 22px rgba(15, 23, 42, .08);
  --shadow-md: 0 5px 14px rgba(15, 23, 42, .08), 0 18px 36px rgba(15, 23, 42, .09);
  --shadow-lg: 0 20px 40px rgba(15, 23, 42, .14), 0 36px 70px rgba(15, 23, 42, .10);

  /* Raggi */
  --r-xs: 6px;
  --r-sm: 8px;
  --r: 12px;
  --r-md: 14px;
  --r-lg: 18px;

  /* Transizioni (cubic moderna, leggermente "spring") */
  --t: 180ms cubic-bezier(.32, .72, 0, 1);
  --t-fast: 120ms cubic-bezier(.32, .72, 0, 1);
}

* { box-sizing: border-box; }
html { accent-color: var(--accent); }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11', 'ss01';
}
input[type="checkbox"], input[type="radio"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}
body { padding-top: var(--sticky-h, 130px); }
body::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: -1;
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(79, 70, 229, .07), transparent 60%),
    radial-gradient(900px 500px at 0% 110%, rgba(245, 158, 11, .04), transparent 60%),
    radial-gradient(600px 400px at 50% 50%, rgba(34, 211, 238, .025), transparent 70%);
}

/* Scrollbar raffinata */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: padding-box; border: 2px solid transparent; }

/* ========================================================================
   TOPBAR
   ======================================================================== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: rgba(255, 255, 255, .82);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  position: fixed; top: 0; left: 0; right: 0; z-index: 80;
  flex-wrap: wrap; gap: 10px;
  min-width: 0;
}
.topbar h1 { flex-shrink: 0; }
.topbar h1 {
  margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.01em;
  display: flex; align-items: center; gap: 12px;
}
.topbar h1 .brand {
  display: inline-flex; align-items: center; gap: 12px;
  font-size: 22px; font-weight: 800; letter-spacing: -0.025em;
  background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  text-decoration: none;
  transition: opacity var(--t);
}
.topbar h1 a.brand:hover { opacity: .85; }
.topbar h1 a.brand:focus-visible {
  outline: none; border-radius: 4px;
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.topbar h1 .brand-logo {
  height: 34px; width: auto; display: block;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 4px rgba(15, 23, 42, .15));
}
.topbar h1 .sub {
  font-weight: 550; color: var(--text-3); font-size: 12px;
  padding: 3px 11px; background: var(--surface-3); border-radius: 999px;
  border: 1px solid var(--border);
}
.topbar .actions {
  display: flex; gap: 6px; align-items: center;
  flex-wrap: wrap; flex: 1 1 auto; justify-content: flex-end;
  min-width: 0;
}

/* ========================================================================
   TOOLBAR
   ======================================================================== */
.toolbar {
  display: flex; align-items: flex-end; gap: 14px;
  padding: 12px 24px; background: rgba(255, 255, 255, .78);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  position: fixed; top: var(--topbar-h, 65px); left: 0; right: 0; z-index: 75;
  box-shadow: var(--shadow-xs);
}
.toolbar label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 10.5px; color: var(--text-3); font-weight: 650;
  text-transform: uppercase; letter-spacing: .06em;
}
.toolbar select, .toolbar input[type=date], .toolbar input[type=search] {
  padding: 8px 12px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font-family: inherit; font-weight: 550;
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
  cursor: pointer;
  min-height: 38px;
}
.toolbar select:hover, .toolbar input[type=date]:hover, .toolbar input[type=search]:hover { border-color: var(--border-strong); background: var(--surface-2); }
.toolbar select:focus, .toolbar input[type=date]:focus, .toolbar input[type=search]:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring);
  background: var(--surface);
}
.toolbar input[type=search] { min-width: 240px; }
.toolbar .nav {
  display: inline-flex; gap: 0; margin-left: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px;
  box-shadow: var(--shadow-xs);
}
.toolbar .nav .btn {
  min-height: 30px; padding: 4px 12px; border-radius: 999px;
  border: none; background: transparent; box-shadow: none;
  font-size: 13px; font-weight: 600; color: var(--text-2);
}
.toolbar .nav .btn:hover { background: var(--surface-3); color: var(--text); transform: none; box-shadow: none; }
.toolbar .nav .btn:active { transform: none; }

/* Legenda */
.legend {
  display: flex; gap: 8px; font-size: 11px; color: var(--text-2);
  flex-wrap: wrap; align-items: center; padding-top: 2px;
  flex-basis: 100%; max-width: 100%;
}
.legend .chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px;
  font-weight: 600; font-size: 11px; cursor: help;
  transition: all var(--t);
  box-shadow: var(--shadow-xs);
}
.legend .chip:hover { background: var(--surface-2); border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.legend .chip::before {
  content: ''; width: 10px; height: 10px; border-radius: 50%;
  background: var(--c, #ccc); display: inline-block;
  /* anello nel colore "scuro" della fase: la palette GFB è chiara e su bianco
     i dischetti pieni risultavano quasi invisibili. */
  box-shadow: 0 0 0 1.5px var(--ink, rgba(15, 23, 42, .35));
}

/* ========================================================================
   ICONS
   ======================================================================== */
.icon {
  display: inline-block;
  width: 16px; height: 16px;
  flex-shrink: 0;
  vertical-align: -3px;
  stroke: currentColor;
  fill: none;
}
.btn.small .icon { width: 14px; height: 14px; }
.btn.close .icon { width: 18px; height: 18px; vertical-align: middle; }

/* ========================================================================
   BUTTONS
   ======================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 10px;
  font-family: inherit; font-size: 13px; font-weight: 600; letter-spacing: -0.005em;
  cursor: pointer; user-select: none;
  transition: transform var(--t), background var(--t), border-color var(--t), box-shadow var(--t), color var(--t);
  box-shadow: var(--shadow-xs);
  min-height: 38px;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0) scale(.98); box-shadow: var(--shadow-xs); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--accent-ring), var(--shadow-xs); border-color: var(--accent); }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn:disabled:hover, .btn[disabled]:hover { transform: none; box-shadow: var(--shadow-xs); background: var(--surface); border-color: var(--border); }

.btn.primary {
  background: linear-gradient(135deg, var(--accent) 0%, #6366f1 100%);
  color: #fff; border-color: transparent;
  box-shadow: 0 1px 2px rgba(79, 70, 229, .35), 0 4px 12px rgba(79, 70, 229, .18);
}
.btn.primary:hover {
  background: linear-gradient(135deg, var(--accent-hover) 0%, #4f46e5 100%);
  box-shadow: 0 2px 6px rgba(79, 70, 229, .4), 0 10px 24px rgba(79, 70, 229, .25);
}
.btn.primary:active { box-shadow: 0 1px 2px rgba(79, 70, 229, .35); }

.btn.danger { background: var(--surface); color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); box-shadow: 0 4px 14px rgba(220, 38, 38, .28); }

.btn.small { padding: 5px 11px; font-size: 12px; min-height: 30px; border-radius: 8px; }
.btn.close {
  padding: 6px; background: transparent; border-color: transparent; box-shadow: none;
  color: var(--text-2); border-radius: 999px; min-height: 32px; min-width: 32px;
}
.btn.close:hover { background: var(--surface-3); color: var(--text); transform: none; }
.btn.active { background: var(--accent-soft); color: var(--accent); border-color: rgba(79, 70, 229, .35); box-shadow: var(--shadow-xs); }
.btn.active:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ========================================================================
   TOPBAR — gruppi di azioni (Nuovo ▾ · Sezioni · Strumenti ▾)
   I pulsanti in alto sono raggruppati per significato: creazione, sezioni
   (viste mutuamente esclusive) e strumenti. Separatori sottili tra i gruppi.
   ======================================================================== */
.act-sep {
  flex: 0 0 auto; align-self: center;
  width: 1px; height: 22px;
  background: var(--border-strong);
  opacity: .7;
  margin: 0 4px;
}

/* --- Dropdown generico della topbar (Nuovo, Strumenti) --- */
.topbar-dd { position: relative; display: inline-flex; flex: 0 0 auto; }
.topbar-dd-trigger { padding-right: 11px; }
.topbar-dd-trigger .caret {
  width: 15px; height: 15px; margin-left: 1px;
  opacity: .85;
  transition: transform var(--t);
}
.topbar-dd-trigger[aria-expanded="true"] .caret { transform: rotate(180deg); }
.topbar-dd-trigger[aria-expanded="true"] { box-shadow: 0 0 0 4px var(--accent-ring), var(--shadow-xs); }
.topbar-dd-trigger.primary[aria-expanded="true"] {
  box-shadow: 0 2px 6px rgba(79, 70, 229, .4), 0 10px 24px rgba(79, 70, 229, .25);
}

.topbar-dd-menu {
  position: absolute; top: calc(100% + 9px); left: 0;
  min-width: 264px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 7px; z-index: 95;
  display: flex; flex-direction: column; gap: 2px;
  animation: ddIn 160ms cubic-bezier(.32, .72, 0, 1);
}
.topbar-dd-menu[hidden] { display: none; }
@keyframes ddIn { from { opacity: 0; transform: translateY(-6px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
/* Strumenti è a destra: allinea il menu al bordo destro del trigger */
#ddStrumenti .topbar-dd-menu { left: auto; right: 0; }

.topbar-dd-item {
  display: flex; align-items: flex-start; gap: 11px; width: 100%;
  padding: 9px 11px; min-height: 0;
  background: transparent; border: 1px solid transparent; border-radius: var(--r-sm);
  font-family: inherit; color: var(--text); cursor: pointer; text-align: left;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.topbar-dd-item .icon {
  width: 18px; height: 18px; margin-top: 1px; flex-shrink: 0;
  color: var(--text-3); transition: color var(--t-fast);
}
.topbar-dd-item span { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.topbar-dd-item strong { font-size: 13px; font-weight: 650; letter-spacing: -0.005em; }
.topbar-dd-item em {
  font-style: normal; font-size: 11.5px; font-weight: 500; color: var(--text-3); line-height: 1.35;
}
.topbar-dd-item:hover { background: var(--accent-soft); border-color: rgba(79, 70, 229, .22); }
.topbar-dd-item:hover .icon,
.topbar-dd-item:hover strong { color: var(--accent); }
.topbar-dd-item:focus-visible { outline: none; background: var(--surface-3); border-color: var(--border-strong); }
.topbar-dd-item:active { transform: scale(.99); }

/* --- Gruppo sezioni mutuamente esclusive (Pending / Archivio / Cestino) ---
   Contenitore chiaro (niente fondo grigio "spento"): i pulsanti hanno il
   testo a piena intensità come gli altri della topbar; la sezione attiva si
   accende in accent. */
.seg {
  display: inline-flex; align-items: stretch; flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px; gap: 2px;
  box-shadow: var(--shadow-xs);
}
.seg .seg-btn {
  border: 1px solid transparent; background: transparent; box-shadow: none;
  border-radius: 8px; min-height: 32px; padding: 5px 13px;
  font-size: 13px; font-weight: 600; color: var(--text);
}
.seg .seg-btn .icon { color: var(--text-2); }
.seg .seg-btn:hover {
  background: var(--surface-3); color: var(--text);
  transform: none; box-shadow: none; border-color: transparent;
}
.seg .seg-btn:hover .icon { color: var(--text); }
.seg .seg-btn:active { transform: scale(.98); }
.seg .seg-btn.active {
  background: var(--accent-soft); color: var(--accent);
  border-color: rgba(79, 70, 229, .28);
  box-shadow: none;
}
.seg .seg-btn.active:hover { background: var(--accent-soft); color: var(--accent); }
.seg .seg-btn.active .icon { color: var(--accent); }

/* --- Modalità cliente (sola lettura + creazione, niente colorista) --- */
body.role-cliente .topbar { background: linear-gradient(180deg, #f0f9ff 0%, var(--surface) 100%); }
body.role-cliente .topbar h1::after {
  content: 'CLIENTE';
  display: inline-block; margin-left: 10px;
  padding: 2px 10px; border-radius: 20px;
  background: #0ea5e9; color: #fff;
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
}
/* Topbar: nascondi le azioni non consentite */
body.role-cliente #btnParking,
body.role-cliente #btnColoristi,
body.role-cliente #btnFestivita,
body.role-cliente #btnCestino,
body.role-cliente #btnLog,
body.role-cliente #btnUndo { display: none; }
/* Per il cliente il gruppo "Strumenti" resta vuoto: nascondi tutto il dropdown
   e i separatori (restano solo Nuovo ▾ e Archivio). */
body.role-cliente #ddStrumenti,
body.role-cliente .act-sep { display: none; }
/* User menu: nascondi accesso utenti (gia admin-only, ma rinforza) */
body.role-cliente #btnUsers { display: none !important; }
/* Modale dettagli storia: nascondi tutte le azioni di mutazione */
body.role-cliente #seDel,
body.role-cliente #seSposta,
body.role-cliente #seToParking { display: none; }
/* TOPO overview: nascondi rinomina e archivia (cliente non puo) */
body.role-cliente #toRinomina,
body.role-cliente #toArchivia,
body.role-cliente #toFattura,
body.role-cliente #toOrdine { display: none; }
/* Modali di creazione: nascondi il campo "Nome colorista" (cliente non lo imposta) */
body.role-cliente .modal-box label:has(#lsColorista),
body.role-cliente .modal-box label:has(#pkColorista),
body.role-cliente .modal-box label:has(#sColorista),
body.role-cliente .storia-extra label:has([data-k="nome_colorista"]) { display: none; }
/* Parking view: nascondi pulsante nuova storia pending */
body.role-cliente #btnParkingNuova { display: none; }
/* Stato disabilitato piu pulito per cliente */
body.role-cliente .storia-edit input:disabled,
body.role-cliente .storia-edit select:disabled,
body.role-cliente .storia-edit textarea:disabled {
  background: var(--surface-2); color: var(--text-2); cursor: not-allowed;
}

/* --- Modalità archivio --- */
body.archivio-mode .topbar { background: linear-gradient(180deg, #fff7ed 0%, var(--surface) 100%); }
body.archivio-mode .topbar h1::after {
  content: 'ARCHIVIO';
  display: inline-block; margin-left: 10px;
  padding: 2px 10px; border-radius: 20px;
  background: #f59e0b; color: #fff;
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
}
.arch-tag {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  background: #fef3c7; color: #92400e; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
}

/* In archivio: nascondi la legenda e "Raggruppa per" per fare spazio ai filtri;
   la barra dei filtri (Cerca/Anno/Colorista/Stile/Tipo/Stato + Pulisci) prende il loro posto.
   La legenda fasi è ridondante: i colori sono già visibili nelle barre del Gantt. */
body.archivio-mode .legend,
body.archivio-mode #lblGroup { display: none; }
body.archivio-mode #inpSearchArchivio { min-width: 220px; }

/* Gantt compatto in modalità archivio */
body.archivio-mode .gr-cell, body.archivio-mode .gh-cell { min-height: 26px; padding: 3px 6px; }
body.archivio-mode .gh-cell.day { padding: 3px 2px; }
body.archivio-mode .gh-cell.day .dow { font-size: 9px; }
body.archivio-mode .gh-cell.day .dn { font-size: 11px; }
body.archivio-mode .gr-cell.day { padding: 2px; gap: 1px; }
body.archivio-mode .phase {
  height: 16px; line-height: 16px; font-size: 9.5px;
  padding: 0 3px; border-radius: 3px;
}
body.archivio-mode .phase.sub { height: 13px; line-height: 13px; font-size: 8.5px; }
body.archivio-mode .label-storia { gap: 0; padding: 0; }
body.archivio-mode .label-storia .code { font-size: 12px; }
body.archivio-mode .label-storia .meta { font-size: 10px; }
body.archivio-mode .gr-cell.label.done { background: linear-gradient(90deg, #dcfce7 0%, #ecfdf5 60%); }

/* --- Modalità parking --- */
body.parking-mode .topbar { background: linear-gradient(180deg, #eff6ff 0%, var(--surface) 100%); }
body.parking-mode .topbar h1::after {
  content: 'PENDING';
  display: inline-block; margin-left: 10px;
  padding: 2px 10px; border-radius: 20px;
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
}
body.parking-mode .toolbar { display: none; }

/* ========================================================================
   VISTA COLORISTI — avanzamento lavori per colorista
   ======================================================================== */
body.coloristi-mode .topbar { background: linear-gradient(180deg, #faf5ff 0%, var(--surface) 100%); }
body.coloristi-mode .topbar h1::after {
  content: 'COLORISTI';
  display: inline-block; margin-left: 10px;
  padding: 2px 10px; border-radius: 20px;
  background: #9333ea; color: #fff;
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
}
body.coloristi-mode .toolbar { display: none; }

.coloristi-view { padding: 4px 0 24px; }
.col-head { margin: 0 0 18px; }
.col-head h2 { margin: 0 0 12px; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
/* Riga titolo + bottone "Anagrafica" (solo admin) della vista Coloristi. */
.col-head-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.col-head-top h2 { margin: 0; }

/* Form anagrafica colorista: campi su due colonne (indirizzo e IBAN a tutta riga). */
.ce-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.ce-grid .ce-full { grid-column: 1 / -1; }
@media (max-width: 640px) { .ce-grid { grid-template-columns: 1fr; } }

.col-summary { display: flex; flex-wrap: wrap; gap: 8px; }
.col-stat {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 7px 13px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-2); box-shadow: var(--shadow-xs);
}
.col-stat strong { color: var(--text); font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.col-stat.is-doing strong { color: var(--accent); }
.col-stat.is-done strong { color: var(--success); }
.col-stat.is-late { background: var(--danger-soft); border-color: #fecaca; }
.col-stat.is-late strong { color: var(--danger); }
.col-stat.is-warn { background: var(--warning-soft); border-color: #fde68a; }
.col-stat.is-warn strong { color: var(--warning); }
.col-stat.is-ordine strong { color: #7c3aed; }
.col-stat.is-fattforn strong { color: #0d9488; }

.col-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
}
@media (max-width: 560px) { .col-grid { grid-template-columns: 1fr; } }

.col-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; overflow: hidden;
}
.col-card-warn { border-color: #fcd34d; box-shadow: 0 0 0 1px #fcd34d, var(--shadow-sm); }
.col-card-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px 12px; }
.col-avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent) 0%, #9333ea 100%); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; letter-spacing: .02em;
  box-shadow: 0 4px 12px rgba(147, 51, 234, .28), inset 0 0 0 2px rgba(255, 255, 255, .18);
}
.col-avatar.is-warn { background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); box-shadow: 0 4px 12px rgba(217, 119, 6, .28), inset 0 0 0 2px rgba(255, 255, 255, .18); }
.col-id { display: flex; flex-direction: column; min-width: 0; }
.col-name { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-email { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.col-body {
  border-top: 1px solid var(--border); background: var(--surface-2);
  padding: 12px; display: flex; flex-direction: column; gap: 14px;
}
.col-sec { display: flex; flex-direction: column; gap: 6px; }
/* Titoli di sezione ben visibili a colpo d'occhio: banner colorato per stato
   (indaco = sta facendo, ambra = in attesa, verde = ha fatto). */
.col-sec-title {
  font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); padding: 6px 10px; border-radius: var(--r-sm);
  background: var(--surface); border-left: 4px solid var(--border);
}
.col-sec-title em { font-style: normal; font-weight: 700; opacity: .85; }
.col-sec-title.sec-doing { background: var(--accent-soft); color: var(--accent); border-left-color: var(--accent); }
.col-sec-title.sec-wait  { background: var(--warning-soft); color: var(--warning); border-left-color: var(--warning); }
.col-sec-title.sec-done  { background: var(--success-soft); color: var(--success); border-left-color: var(--success); }
.col-sec-title.sec-ordine { background: #f5f3ff; color: #7c3aed; border-left-color: #7c3aed; }
.col-sec-title.sec-fattforn { background: #f0fdfa; color: #0d9488; border-left-color: #0d9488; }
.col-sec-done { opacity: .92; }
/* Storico sezioni lunghe: oltre le prime 3 righe si ripiega dietro il bottone. */
.col-sec .col-story.col-extra { display: none; }
.col-sec.expanded .col-story.col-extra { display: flex; }
.col-ordine-toggle {
  align-self: flex-start; margin-top: 2px; padding: 5px 12px; cursor: pointer;
  font-family: inherit; font-size: 11.5px; font-weight: 700;
  color: #0d9488; background: var(--surface); border: 1px solid #99f6e4; border-radius: 999px;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.col-ordine-toggle:hover { background: #f0fdfa; border-color: #0d9488; }
.col-story {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left; font-family: inherit; cursor: pointer;
  padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text);
  transition: border-color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
}
.col-story:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
  box-shadow: var(--shadow-xs);
}
.col-story-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.col-story-code { font-weight: 700; font-size: 13px; color: var(--text); letter-spacing: -0.005em; }
.col-story-title { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.col-story-status { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex-shrink: 0; }
.col-deadline { font-size: 10.5px; color: var(--text-3); white-space: nowrap; }
.col-deadline strong { color: var(--text-2); font-weight: 700; }

.col-chip {
  font-size: 10.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  white-space: nowrap; letter-spacing: .01em;
}
.col-chip.is-doing { background: var(--accent-soft); color: var(--accent); }
.col-chip.is-soon { background: var(--warning-soft); color: var(--warning); }
.col-chip.is-late { background: var(--danger); color: #fff; }
.col-chip.is-done { background: var(--success-soft); color: var(--success); }
.col-chip.is-wait { background: var(--surface-3); color: var(--text-3); }
.col-chip.is-ordine { background: #f5f3ff; color: #7c3aed; }
.col-chip.is-fattforn { background: #f0fdfa; color: #0d9488; }
.col-empty { font-size: 12.5px; color: var(--text-3); padding: 6px 2px; }

.parking-view { padding: 4px 0 24px; }
.parking-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 0 18px; gap: 12px;
}
.parking-head h2 { margin: 0; font-size: 18px; font-weight: 700; }
.parking-head h2 .muted { font-weight: 500; font-size: 14px; margin-left: 6px; }

.parking-list { display: flex; flex-direction: column; gap: 10px; }
.parking-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(360px, 2fr) auto;
  gap: 14px; align-items: center;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--t), border-color var(--t), transform var(--t);
}
.parking-row:hover { box-shadow: var(--shadow-sm); border-color: var(--border-strong); transform: translateY(-1px); }
.parking-info .parking-title { font-weight: 700; font-size: 14px; color: var(--text); letter-spacing: -0.01em; }
.parking-info .parking-meta { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.parking-phases { display: flex; flex-wrap: wrap; gap: 5px; }
.parking-phase {
  --c: var(--accent);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font: 700 11px/1 inherit;
  letter-spacing: .02em;
  padding: 6px 9px; border-radius: 8px;
  cursor: pointer;
  transition: all var(--t);
  min-width: 34px;
}
.parking-phase:hover { border-color: var(--c); color: var(--ink, var(--c)); background: color-mix(in srgb, var(--c) 18%, var(--surface)); transform: translateY(-1px); }
.parking-phase.done {
  background: var(--c); color: var(--ink, #fff); border-color: var(--c);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .12);
}
.parking-phase.done:hover { filter: brightness(1.08); }
.parking-actions { display: flex; gap: 6px; align-items: center; }

@media (max-width: 768px) {
  .parking-row { grid-template-columns: 1fr; }
}

/* ========================================================================
   MAIN
   ======================================================================== */
main { padding: 20px 24px 40px; }

.footer {
  padding: 18px 24px;
  color: var(--text-3);
  font-size: 12px;
  text-align: center;
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: 40px;
}
.footer .foot-brand {
  font-weight: 800; letter-spacing: -0.01em;
  background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ========================================================================
   GANTT
   ======================================================================== */
.gantt {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  overflow: visible;
}
.gantt-inner { display: grid; min-width: max-content; }
.gantt-header, .gantt-row { display: contents; }

.gh-cell, .gr-cell {
  padding: 6px 8px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  min-height: 38px;
  display: flex; align-items: center;
}
.gh-cell {
  background: var(--surface-2); font-weight: 600; color: var(--text-2);
  position: sticky; top: calc(var(--sticky-h, 130px) + 28px); z-index: 60;
  box-shadow: 0 1px 0 var(--border);
}
.gh-cell.month-row {
  top: var(--sticky-h, 130px);
  min-height: 28px; padding: 4px 8px;
  justify-content: center; text-align: center;
  font-weight: 700; font-size: 12px; color: var(--text);
  text-transform: capitalize;
  overflow: hidden; white-space: nowrap;
  z-index: 65;
}
.gh-cell.month-row.spacer { left: 0; z-index: 80; }
.gh-cell.label, .gr-cell.label {
  position: sticky; left: 0; z-index: 55;
  min-width: 200px; max-width: 240px; font-weight: 500;
  overflow: hidden;
}
.gr-cell.label { background: var(--surface); }
.gh-cell.label { background: var(--surface-2); z-index: 70; }

.gh-cell.day {
  min-width: 40px; justify-content: center; flex-direction: column;
  padding: 6px 2px; gap: 1px; font-weight: 500; text-align: center;
}
.gh-cell.day .dow {
  font-size: 9.5px; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .05em;
}
.gh-cell.day .dn { font-size: 13px; font-weight: 600; color: var(--text); }
.gh-cell.day.month-start { border-left: 2px solid var(--accent); background: var(--accent-soft); }
.gh-cell.day.weekend, .gh-cell.day.holiday { color: var(--text-3); }
.gh-cell.day.weekend .dn, .gh-cell.day.holiday .dn { color: var(--text-3); font-weight: 500; }
.gh-cell.day.today { background: linear-gradient(180deg, var(--today) 0%, var(--surface-2) 100%); }
.gh-cell.day.today .dn { color: var(--warning); font-weight: 700; }

.gr-cell.day {
  min-width: 40px; padding: 3px;
  position: relative;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 2px;
}
.gr-cell.day.weekend { background: var(--weekend); }
.gr-cell.day.holiday { background: var(--holiday); }
.gr-cell.day.today { background: var(--today); }
.gr-cell.fasc-sep { border-top: 2px solid var(--border-strong); }
.gr-cell.label.done {
  background: linear-gradient(90deg, #dcfce7 0%, #ecfdf5 100%);
  box-shadow: inset 3px 0 0 #16a34a;
}
.gr-cell.label.done .label-storia .code { color: #14532d; }
.gr-cell.label.done .label-storia .meta { color: #166534; }
.done-check {
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: 6px;
  width: 16px; height: 16px;
  background: #16a34a; color: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(22, 163, 74, .35);
  vertical-align: 1px;
}
.done-check .icon { width: 11px; height: 11px; vertical-align: 0; }

/* Phase bars */
.phase {
  display: block; width: 100%; height: 22px;
  border-radius: var(--r-sm);
  font-size: 10.5px; color: var(--ink, #fff); text-align: center; line-height: 22px;
  font-weight: 650; letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform var(--t-fast), box-shadow var(--t-fast), filter var(--t-fast);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .15);
  flex-shrink: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 0 4px;
}
.phase.sub { height: 18px; line-height: 18px; font-size: 9.5px; }
.phase:hover {
  transform: scale(1.08); z-index: 50; position: relative;
  box-shadow: 0 6px 16px rgba(15, 23, 42, .2);
  filter: brightness(1.08);
}
.phase.done { background: #94a3b8 !important; color: #f1f5f9; text-decoration: line-through; opacity: .9; }
/* F1-F3 e F5 di una storia "già colorata caricata": fatte di default → grigio chiaro, senza barratura. */
.phase.phase-gia-auto { background: #cbd5e1 !important; color: #475569; text-decoration: none; opacity: 1; }
/* F3 "fatta": NON diventa grigia né barrata — resta arancione con un contorno scuro. La finestra si
   accorcia solo in base a F5 (ricezione coloriture), non alla spunta di F3. */
.phase.phase-f3-done { background: var(--f3) !important; color: var(--f3-ink, #fff); text-decoration: none; opacity: 1; box-shadow: inset 0 0 0 2px #5b2a0a, 0 1px 2px rgba(15, 23, 42, .2); }
/* Blocco "invio al colorista" nella scheda della fase F3 (pannello). */
.f3-scheda {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 9px 12px; margin-bottom: 8px;
  background: color-mix(in srgb, var(--f3) 9%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--f3) 32%, var(--border));
  border-radius: 8px;
}
.f3-scheda-info { font-size: 12px; color: var(--text-2); }
.f3-scheda-info strong { color: var(--text); }
.f3-scheda-btn { flex-shrink: 0; }
.phase.late { box-shadow: inset 0 0 0 2px var(--danger), 0 1px 2px rgba(15,23,42,.15); }
.phase[data-tip]:hover::after, .phase[data-tip]:hover::before { z-index: 200; }
.phase.selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--surface), 0 6px 18px rgba(15, 23, 42, .22);
  transform: scale(1.06);
  z-index: 45; position: relative;
  filter: brightness(1.06);
}
.phase.selected.done { opacity: .85; }
.list-view .list-item.selected {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

/* Label storia */
.label-storia {
  display: flex; flex-direction: column; gap: 2px; line-height: 1.2;
  padding: 2px 0;
  min-width: 0; max-width: 100%;
  flex: 1 1 0%;
}
.label-storia .code-row {
  display: flex; align-items: center; gap: 6px; min-width: 0;
}
.label-storia .code-row .code { flex: 0 1 auto; }
/* Badge (tipo / già colorata / check) come elementi flex affiancati al codice: il codice
   si accorcia con ellissi, i badge restano sempre interamente visibili (prima erano dentro
   .code con overflow:hidden e venivano tagliati). */
.label-storia .code-row > .tipo-badge,
.label-storia .code-row > .done-check { flex: 0 0 auto; margin-left: 0; }
.label-storia .code {
  font-weight: 650; font-size: 13px; color: var(--text);
  letter-spacing: -0.005em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Chip Fase 0 — primo inserimento TOPO (senza timing): segnalazione nella label Gantt. */
.f0-badge {
  flex: 0 0 auto;
  font-size: 10px; font-weight: 700; line-height: 1;
  padding: 2px 5px; border-radius: 999px;
  color: #fff; background: var(--f0);
  letter-spacing: .01em; white-space: nowrap;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}
.f0-badge.f0-none { opacity: .65; }
/* Storia ancora in F0 (timeline non generata): in attesa di 'Tratti caricati'. */
.f0-badge.f0-wait { background: var(--coord, #f59e0b); }

/* Stato fatturazione del TOPO */
.bill-badge {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; line-height: 1;
  padding: 2px 6px; border-radius: 999px;
  letter-spacing: .02em; text-transform: uppercase; white-space: nowrap;
  color: #fff;
}
.bill-badge.bill-fatturato { background: #16a34a; }   /* verde: proforma creata */
.bill-badge.bill-dafatturare { background: #dc2626; } /* rosso: lavori finiti, da fatturare */
.phase-item.phase0-wait { border-color: color-mix(in srgb, var(--coord, #f59e0b) 45%, var(--border)); }
.f0-wait-tag {
  display: inline-block; font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 999px; margin-right: 4px;
  color: #fff; background: var(--coord, #f59e0b);
}
.label-storia .meta {
  color: var(--text-3); font-size: 11px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 100%;
}

.gr-cell.label:hover .label-storia.clickable .code { color: var(--accent); }
.gr-cell.label.clickable-row { cursor: pointer; transition: background var(--t-fast); }
.gr-cell.label:has(.clickable):hover { background: var(--surface-2); }
.wrow-label:hover .label-storia .code { color: var(--accent); }

/* Badge "tipo" (Rev. tav. / PDF) — visibile inline nella colonna storie */
.tipo-badge {
  display: inline-block;
  font: 600 10px/1 inherit;
  letter-spacing: .02em;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid transparent;
  vertical-align: middle;
  margin-left: 6px;
  white-space: nowrap;
}
.tipo-badge.tipo-rev_tav {
  color: #1d4ed8;
  background: var(--accent-soft);
  border-color: rgba(37, 99, 235, .25);
}
.tipo-badge.tipo-pdf {
  color: #b45309;
  background: var(--warning-soft);
  border-color: rgba(217, 119, 6, .25);
}
.tipo-badge.tipo-gia-colorata {
  color: #fff;
  background: #7c3aed;
  border-color: #6d28d9;
}
body.archivio-mode .tipo-badge { font-size: 9px; padding: 1px 4px; }

/* Casella caricamento disabilitata (es. quando "Già colorata caricata" è attiva) */
.chk-disabled { opacity: .45; cursor: not-allowed; }
.chk-disabled input { cursor: not-allowed; }

/* ========================================================================
   LIST VIEW (Day)
   ======================================================================== */
.list-view {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.list-view .list-head {
  padding: 16px 22px; border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 14px; background: var(--surface-2);
  letter-spacing: -0.01em;
}
.list-view .list-item {
  padding: 14px 22px; border-bottom: 1px solid var(--border);
  display: grid; grid-template-columns: 96px 1fr 140px auto;
  gap: 14px; align-items: center; font-size: 13px;
  transition: background var(--t-fast);
}
.list-view .list-item:last-child { border-bottom: none; }
.list-view .list-item:hover { background: var(--surface-2); }
.list-view .list-item .pcol {
  color: var(--ink, #fff); padding: 6px 11px; border-radius: 8px;
  font-weight: 700; text-align: center; font-size: 12px;
  box-shadow: var(--shadow-xs);
  letter-spacing: .02em;
}
.list-view .empty {
  padding: 64px 24px; text-align: center; color: var(--text-3);
  font-size: 13.5px;
}
.empty h3 { color: var(--text-2); margin: 0 0 6px; font-size: 16px; font-weight: 700; }
.empty p { margin: 0 auto; max-width: 380px; line-height: 1.6; }
.empty a { color: var(--accent); font-weight: 600; text-decoration: none; }
.empty a:hover { text-decoration: underline; }

/* ========================================================================
   MONTH / WEEK
   ======================================================================== */
.month-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 0 0 var(--r) var(--r);
  box-shadow: var(--shadow-sm);
}
.month-grid .mh {
  background: var(--surface-2); padding: 10px;
  text-align: center; font-weight: 600; font-size: 11px;
  color: var(--text-2); text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border); border-right: 1px solid var(--border);
  position: sticky; top: var(--sticky-h, 130px); z-index: 60;
  box-shadow: 0 1px 0 var(--border);
}
.month-grid .mh:nth-child(7n) { border-right: none; }
.month-cell {
  min-height: 120px; padding: 6px 8px;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex; flex-direction: column; gap: 3px;
  overflow: hidden;
  transition: background var(--t-fast);
}
.month-cell:hover { background: var(--surface-2); }
.month-cell:nth-child(7n) { border-right: none; }
.month-cell.weekend { background: var(--weekend); }
.month-cell.holiday { background: var(--holiday); }
.month-cell.today { background: var(--today); outline: 2px solid var(--warning); outline-offset: -2px; }
.month-cell.other { opacity: .35; }
.month-cell .dn { font-size: 12px; font-weight: 600; color: var(--text-3); }
.month-cell.today .dn { color: var(--warning); font-weight: 700; }
.month-cell .phase { font-size: 10px; padding: 3px 6px; line-height: 14px; height: auto; border-radius: 4px; }

.week-grid {
  display: grid; grid-template-columns: 180px repeat(5, 1fr);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
}
.week-grid > * {
  padding: 10px; border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border); font-size: 12px;
}
.week-grid .wh {
  background: var(--surface-2); font-weight: 600;
  text-align: center; color: var(--text-2);
  position: sticky; top: var(--sticky-h, 130px); z-index: 60;
  box-shadow: 0 1px 0 var(--border);
}
.week-grid .wc { min-height: 56px; display: flex; flex-direction: column; gap: 3px; }
.week-grid .wc.weekend { background: var(--weekend); }
.week-grid .wc.holiday { background: var(--holiday); }
.week-grid .wc.today { background: var(--today); }
.week-grid .wrow-label {
  background: var(--surface-2); font-weight: 500;
  cursor: pointer; transition: background var(--t-fast);
}
.week-grid .wrow-label:hover { background: var(--surface-3); }

/* ========================================================================
   PANEL (side)
   ======================================================================== */
.panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 460px; max-width: 100vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 90;
  display: flex; flex-direction: column;
  animation: slideInRight 220ms cubic-bezier(.32, .72, 0, 1);
}
.panel.hidden { display: none; }
.panel.single-phase { bottom: auto; max-height: calc(100vh - 24px); }
.panel.single-phase #panelBody { overflow-y: visible; }
.panel.single-phase .phase-item:last-child { margin-bottom: 0; }
@keyframes slideInRight {
  from { transform: translateX(36px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
}
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.015em; }
#panelBody { overflow-y: auto; padding: 18px 22px; }

.lock-notice {
  background: var(--warning-soft); border: 1px solid #fde68a;
  color: #92400e; padding: 12px 16px; border-radius: 10px;
  font-size: 12.5px; margin-bottom: 16px; line-height: 1.55;
  display: flex; align-items: center; gap: 8px;
}
.lock-notice strong { font-weight: 700; }
.lock-notice .icon { color: #b45309; flex-shrink: 0; }
/* Variante neutra: le date sono guidate dai click (non è un blocco/errore). */
.lock-notice.lock-soft { background: var(--surface-3); border-color: var(--border); color: var(--text-2); }
.lock-notice.lock-soft .icon { color: var(--text-3); }
.phase-item.locked .detail input[disabled] {
  background: var(--surface-3); color: var(--text-3); cursor: not-allowed;
}
.storia-edit input[disabled] {
  background: var(--surface-3); color: var(--text-3); cursor: not-allowed;
}

/* Panel subtitle (card titolo + chips) */
.panel-subtitle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px 14px;
  margin-bottom: 16px;
}
.panel-sub-title {
  font-weight: 700; font-size: 14px; color: var(--text);
  letter-spacing: -0.01em; line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis;
}
.panel-sub-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.panel-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 4px 3px 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11.5px; font-weight: 600; color: var(--text-2);
}
.panel-chip-k {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-3);
}
.panel-chip-v {
  background: var(--surface-3);
  padding: 2px 9px; border-radius: 999px;
  font-variant-numeric: tabular-nums;
  font-weight: 700; color: var(--text);
}
.panel-chip.is-done .panel-chip-v {
  background: var(--success); color: #fff;
}

/* Link "vedi tutte le 11 fasi" */
.panel-allphases {
  margin-bottom: 14px;
  width: 100%; justify-content: flex-start;
  background: var(--accent-soft); color: var(--accent);
  border-color: rgba(79, 70, 229, .2);
}
.panel-allphases:hover {
  background: var(--accent); color: #fff;
  border-color: var(--accent);
}

/* Phase-item: card moderna con stati visivi */
@keyframes phaseIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.phase-item {
  border: 1px solid var(--border); border-radius: var(--r);
  padding: 14px 16px; margin-bottom: 10px;
  display: grid; grid-template-columns: 40px 1fr auto; gap: 12px;
  align-items: center;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--t), box-shadow var(--t), transform var(--t), background var(--t);
  animation: phaseIn 280ms cubic-bezier(.32, .72, 0, 1) both;
  position: relative;
}
.phase-item::before {
  content: ''; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px;
  background: var(--c, transparent); border-radius: 999px;
  transition: width var(--t);
}
.phase-item:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); transform: translateY(-1px); }

/* Stato: completata */
.phase-item.done {
  background: linear-gradient(180deg, #ecfdf5 0%, var(--surface) 80%);
  border-color: #a7f3d0;
}
.phase-item.done .pname { color: #065f46; }
.phase-item.done::before { background: #10b981; }

/* Stato: bloccata (predecessori non fatti) */
.phase-item.blocked { opacity: .68; }
.phase-item.blocked .pname { color: var(--text-2); }

/* Stato: selezionata (single-phase mode) */
.phase-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring), var(--shadow-sm);
}

/* Fase 0 — primo inserimento TOPO: riga informativa, sola lettura, senza timing.
   Niente checkbox né dettaglio: mostra solo la data reale di creazione del TOPO. */
.phase-item.phase0 {
  background: var(--surface-2, #f8fafc);
  border-style: dashed;
  animation: none;
  cursor: default;
}
.phase-item.phase0:hover { transform: none; box-shadow: var(--shadow-xs); border-color: var(--border); }
.phase-item.phase0 .pnum { box-shadow: 0 2px 6px rgba(0, 0, 0, .12), inset 0 0 0 2px rgba(255, 255, 255, .18); }
.phase-item.phase0 .pdate em { color: var(--text-3); font-style: normal; }

.phase-item .pnum {
  --c: var(--accent);
  width: 40px; height: 40px; border-radius: 50%;
  color: var(--ink, #fff); font-weight: 800; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .14), inset 0 0 0 2px rgba(255, 255, 255, .18);
  letter-spacing: .02em;
  position: relative;
}
.phase-item.done .pnum { box-shadow: 0 4px 12px rgba(16, 185, 129, .3), inset 0 0 0 2px rgba(255, 255, 255, .25); }

.phase-item .pinfo { font-size: 13px; min-width: 0; }
.phase-item .pinfo .pname {
  font-weight: 700; color: var(--text);
  display: inline-flex; align-items: center; gap: 6px;
  letter-spacing: -0.01em;
}
.phase-check-tick {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--success); color: #fff; flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(16, 185, 129, .35);
}
.phase-check-tick .icon { width: 10px; height: 10px; }
/* Fasi F7→F11: a livello TOPO (spuntarle le applica a tutte le storie del fascicolo). */
.phase-topo-tag {
  display: inline-block; vertical-align: middle; margin-left: 6px;
  font-size: 9.5px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  padding: 1px 6px; border-radius: 999px;
  color: #7c3aed; background: #f3e8ff; border: 1px solid rgba(124, 58, 237, .3);
}
.phase-item .pinfo .pdate { color: var(--text-2); font-size: 12px; margin-top: 2px; }
.phase-item .pinfo .pdate strong { color: var(--text); font-weight: 700; }
.phase-item .pinfo .pdate.pdate-deadline strong { color: var(--danger); }
.phase-item .pinfo .pdate em { color: var(--text-3); font-style: normal; font-size: 11px; }
.phase-item .pinfo .pdate em.pdate-slip { color: var(--warning); font-weight: 700; }
.phase-item .pinfo .pdate.pdate-mobile { color: var(--text-3); font-size: 11px; }
.phase-item .pinfo .pdate .pdate-giorno { color: var(--text-3); font-weight: 600; cursor: help; }
/* Fase bloccata dai predecessori: dice esplicitamente quali fasi mancano. */
.phase-item .pinfo .pdate.pdate-blocked { color: var(--warning); font-weight: 600; }
.phase-item .pinfo .pdate.pdate-blocked strong { color: var(--warning); }
.phase-item .pinfo .pop { color: var(--text-3); font-size: 11px; margin-top: 3px; line-height: 1.4; }

/* Checkbox come "pill toggle" moderno */
.phase-item .phase-cb {
  position: relative; cursor: pointer; user-select: none;
  display: inline-flex;
}
.phase-item .phase-cb input {
  position: absolute; opacity: 0; pointer-events: none;
  width: 1px; height: 1px;
}
.phase-item .phase-cb-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--surface); color: var(--text-2);
  border: 1.5px solid var(--border); border-radius: 999px;
  font-size: 12px; font-weight: 700;
  transition: all var(--t);
  white-space: nowrap;
}
.phase-item .phase-cb-pill .icon { width: 14px; height: 14px; }
.phase-item .phase-cb-pill .lbl-done { display: none; }
.phase-item .phase-cb-pill .lbl-todo { display: inline; }
.phase-item .phase-cb:hover .phase-cb-pill {
  border-color: var(--success); color: var(--success);
  background: var(--success-soft);
}
.phase-item .phase-cb input:checked + .phase-cb-pill {
  background: var(--success); color: #fff;
  border-color: var(--success);
  box-shadow: 0 2px 8px rgba(5, 150, 105, .3);
}
.phase-item .phase-cb input:checked + .phase-cb-pill .lbl-done { display: inline; }
.phase-item .phase-cb input:checked + .phase-cb-pill .lbl-todo { display: none; }
.phase-item .phase-cb input:focus-visible + .phase-cb-pill {
  box-shadow: 0 0 0 4px var(--accent-ring);
}
.phase-item .phase-cb.cb-blocked .phase-cb-pill {
  opacity: .55; cursor: not-allowed;
  background: var(--surface-3); color: var(--text-3); border-color: var(--border);
}
.phase-item .phase-cb.cb-blocked:hover .phase-cb-pill {
  border-color: var(--border); color: var(--text-3); background: var(--surface-3);
}

/* Detail (data effettiva, ritardo, note) */
.phase-item .detail {
  grid-column: 1 / -1; padding-top: 12px; margin-top: 4px;
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  font-size: 12px;
}
.phase-item .detail label {
  flex-direction: column; align-items: flex-start; gap: 5px;
  font-weight: 700; text-transform: uppercase;
  font-size: 10px; letter-spacing: .05em;
  color: var(--text-3);
}
.phase-item .detail input, .phase-item .detail textarea {
  width: 100%; padding: 8px 11px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 12.5px; font-family: inherit; font-weight: 500;
  letter-spacing: normal; text-transform: none;
  color: var(--text); background: var(--surface);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.phase-item .detail input:hover, .phase-item .detail textarea:hover { border-color: var(--border-strong); }
.phase-item .detail input:focus, .phase-item .detail textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring);
}

/* ========================================================================
   MODAL
   ======================================================================== */
.modal {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .42);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 24px;
  animation: fadeIn var(--t);
}
.modal.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(14px) scale(.985); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }

.modal-box {
  background: var(--surface); border-radius: var(--r-lg);
  padding: 26px 30px; width: 480px; max-width: 94vw; max-height: 90vh;
  overflow-y: auto; box-shadow: var(--shadow-lg);
  animation: slideUp 220ms cubic-bezier(.32, .72, 0, 1);
  border: 1px solid rgba(255, 255, 255, .6);
}
#modalFasc .modal-box { width: 660px; }
#modalStoriaEdit .modal-box { width: 740px; }
#modalTopoOverview .modal-box { width: 720px; }
.modal-box.modal-large { width: 760px; }

/* Log attività */
.log-list { display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow-y: auto; padding: 4px 2px; }
.log-row {
  display: grid; grid-template-columns: 150px 100px 1fr; gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
  align-items: center; font-size: 12.5px;
  transition: border-color var(--t), background var(--t);
}
.log-row:hover { border-color: var(--border-strong); background: var(--surface-2); }
.log-row.undone { opacity: .55; background: var(--surface-2); }
.log-row .log-ts { color: var(--text-3); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.log-row .log-action {
  color: var(--text-2); font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .05em; font-weight: 700;
  background: var(--surface-3); border-radius: 999px; padding: 3px 9px;
  text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.log-row .log-desc { color: var(--text); }
.log-row .log-tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 10px;
  font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin-left: 6px;
}
.log-row .log-tag.undone { background: #fee2e2; color: #991b1b; }
.log-row .log-tag.next { background: var(--accent-soft); color: var(--accent); }

/* Cestino */
.cestino-view { padding: 12px 0 24px; }
.cestino-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 10px; gap: 12px; flex-wrap: wrap; }
.cestino-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.35; overflow: visible; }
.cestino-head h2 .muted { font-weight: 500; font-size: 14px; margin-left: 6px; }
.cestino-list { display: flex; flex-direction: column; gap: 8px; }
.cestino-row {
  display: grid; grid-template-columns: minmax(140px, 200px) 1fr auto; gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--t), border-color var(--t), transform var(--t);
  align-items: center;
}
.cestino-row:hover { box-shadow: var(--shadow-sm); border-color: var(--border-strong); transform: translateY(-1px); }
.cestino-row .ces-code { font-weight: 700; color: var(--text); font-size: 13.5px; letter-spacing: -0.01em; }
.cestino-row .ces-meta { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.cestino-row .ces-actions { display: flex; gap: 6px; }
.cestino-row.archiviato .ces-code::after {
  content: "archiviato"; display: inline-block;
  font-size: 10px; font-weight: 700; padding: 1px 7px;
  background: var(--warning-soft); color: #92400e; border-radius: 999px;
  margin-left: 8px; text-transform: uppercase; letter-spacing: .04em;
  vertical-align: 1px;
}

.modal-box h2 {
  margin: 0 0 6px; font-size: 19px; font-weight: 700;
  letter-spacing: -0.02em; color: var(--text);
}
.modal-box h2 + .muted { margin-top: 0; margin-bottom: 18px; font-size: 13px; line-height: 1.55; }
/* Riga "Importa da Word (AI)" in cima alla modale Nuovo TOPO */
.modal-box .import-ai {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 0 0 18px; padding-bottom: 16px; border-bottom: 1px dashed var(--border);
}
.modal-box .import-ai .muted { font-size: 12.5px; line-height: 1.4; }

/* Pulsante AI: grande, colorato, con badge e micro-animazioni. */
.btn.btn-import {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; gap: 9px;
  padding: 12px 20px; min-height: 46px;
  font-size: 15px; font-weight: 700; letter-spacing: -0.01em;
  color: #fff; border: none; border-radius: 12px;
  background: linear-gradient(120deg, #4f46e5 0%, #7c3aed 45%, #d946ef 100%);
  box-shadow: 0 6px 18px rgba(124, 58, 237, .38), inset 0 0 0 1px rgba(255, 255, 255, .08);
}
.btn.btn-import .icon { width: 20px; height: 20px; animation: importSparkle 2.6s ease-in-out infinite; }
.btn.btn-import em {
  font-style: normal; font-size: 10.5px; font-weight: 800; letter-spacing: .06em;
  padding: 2px 7px; border-radius: 999px;
  background: rgba(255, 255, 255, .22); color: #fff;
}
.btn.btn-import:hover {
  transform: translateY(-2px);
  background: linear-gradient(120deg, #4338ca 0%, #7c3aed 45%, #e879f9 100%);
  box-shadow: 0 10px 26px rgba(124, 58, 237, .5), inset 0 0 0 1px rgba(255, 255, 255, .12);
}
.btn.btn-import:active { transform: translateY(0) scale(.98); }
.btn.btn-import:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--accent-ring), 0 6px 18px rgba(124, 58, 237, .42); }
.btn.btn-import[disabled], .btn.btn-import[disabled]:hover {
  opacity: .7; cursor: progress; transform: none;
  background: linear-gradient(120deg, #4f46e5 0%, #7c3aed 45%, #d946ef 100%);
  box-shadow: 0 6px 18px rgba(124, 58, 237, .3);
}
/* riflesso che attraversa il pulsante */
.btn.btn-import::after {
  content: ""; position: absolute; top: 0; left: -60%; width: 45%; height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .38), transparent);
  transform: skewX(-20deg); pointer-events: none;
  animation: importSheen 3.8s ease-in-out infinite;
}
@keyframes importSheen { 0%, 100% { left: -60%; } 55%, 70% { left: 135%; } }
@keyframes importSparkle {
  0%, 100% { transform: scale(1) rotate(0); opacity: .92; }
  50% { transform: scale(1.14) rotate(-8deg); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .btn.btn-import::after, .btn.btn-import .icon { animation: none; }
}
.modal-box label {
  display: block; margin-bottom: 14px; font-size: 11px;
  font-weight: 700; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .05em;
}
.modal-box label input,
.modal-box label textarea,
.modal-box label select {
  width: 100%; padding: 10px 13px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 14px; margin-top: 6px; font-family: inherit; font-weight: 500;
  letter-spacing: normal; text-transform: none;
  color: var(--text); background: var(--surface);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.modal-box label input:hover,
.modal-box label textarea:hover,
.modal-box label select:hover { border-color: var(--border-strong); }
.modal-box label input:focus,
.modal-box label textarea:focus,
.modal-box label select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
  background: var(--surface);
}
.modal-box label input::placeholder,
.modal-box label textarea::placeholder { color: var(--text-3); font-weight: 400; }

.modal-box fieldset {
  border: 1px solid var(--border); border-radius: var(--r);
  padding: 16px; margin-bottom: 16px;
  background: var(--surface-2);
}
.modal-box legend {
  padding: 3px 10px; font-weight: 700; font-size: 11px;
  color: var(--text-2); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px;
  letter-spacing: .05em; text-transform: uppercase;
}

/* TOPO overview modal */
.topo-stats {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin: 6px 0 14px;
}
.topo-stat {
  display: inline-flex; gap: 6px; align-items: baseline;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-2);
}
.topo-stat strong { color: var(--text); font-size: 13px; font-weight: 700; }
.topo-stat.is-done { background: color-mix(in srgb, var(--success, #16a34a) 12%, var(--surface-2)); border-color: color-mix(in srgb, var(--success, #16a34a) 35%, var(--border)); }
.topo-stat.is-done strong { color: var(--success, #16a34a); }
.topo-storie {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 360px; overflow-y: auto;
  padding: 2px;
}
/* Chiusura rapida fase (F8–F11) per tutte le storie del TOPO con un click. */
.topo-bulk {
  margin-top: 12px; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.topo-bulk-label { font-size: 12px; color: var(--text-2); }
.topo-bulk-label strong { color: var(--text); font-weight: 700; }
.topo-bulk-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.bulk-phase { font-variant-numeric: tabular-nums; }
.bulk-phase .bulk-count { font-size: 10px; font-weight: 700; opacity: .65; margin-left: 1px; }
.bulk-phase.is-done {
  color: var(--success); border-color: rgba(22, 163, 74, .35); background: var(--success-soft);
}
.bulk-phase.is-done .bulk-count { opacity: 1; color: var(--success); }
.topo-storia-row {
  display: grid; grid-template-columns: 44px 1fr auto auto;
  gap: 12px; align-items: center;
  width: 100%; text-align: left;
  padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer; font-family: inherit; color: var(--text);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.topo-storia-row:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
}
.topo-storia-row:focus-visible {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.topo-storia-row.done {
  background: color-mix(in srgb, var(--success, #16a34a) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--success, #16a34a) 30%, var(--border));
}
.topo-storia-row .ts-num {
  font-weight: 700; font-size: 14px;
  color: var(--text-2);
  background: var(--surface-2);
  border-radius: var(--r-sm);
  padding: 6px 0; text-align: center;
}
.topo-storia-row .ts-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.topo-storia-row .ts-title {
  font-weight: 600; font-size: 13.5px; color: var(--text);
  display: flex; align-items: center; gap: 6px; min-width: 0;
}
/* Solo il testo del titolo va in ellissi; i badge accanto restano sempre visibili. */
.topo-storia-row .ts-title-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.topo-storia-row .ts-title .tipo-badge { flex: 0 0 auto; margin-left: 0; }
.topo-storia-row .ts-meta { font-size: 12px; color: var(--text-3); }
.topo-storia-row .ts-progress {
  padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 11.5px; font-weight: 600; color: var(--text-2);
}
.topo-storia-row .ts-progress.done {
  background: var(--success, #16a34a); color: #fff;
  border-color: var(--success, #16a34a);
}
.topo-storia-row .ts-open { color: var(--text-3); display: flex; }
.topo-storia-row:hover .ts-open { color: var(--accent); }
@media (max-width: 680px) {
  .topo-storia-row { grid-template-columns: 36px 1fr auto; gap: 8px; }
  .topo-storia-row .ts-open { display: none; }
}

/* --- Vista archivio: elenco TOPO (nessuna linea temporale) --- */
.archivio-list { display: flex; flex-direction: column; gap: 14px; }
.arch-group {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); overflow: hidden; box-shadow: var(--shadow-sm);
}
.arch-group-head {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 13px 18px; background: var(--surface-2);
  border: none; border-bottom: 1px solid var(--border);
  cursor: pointer; text-align: left; font: inherit; color: var(--text);
  transition: background var(--t-fast);
}
.arch-group-head:hover { background: var(--surface-3); }
.arch-code { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; min-width: 86px; }
.arch-stats { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 1; }
.arch-date { font-size: 12px; color: var(--text-3); margin-left: auto; white-space: nowrap; }
.arch-group-head .ts-open { color: var(--text-3); display: flex; }
.arch-group-head:hover .ts-open { color: var(--accent); }
.arch-group .topo-storie { max-height: none; overflow: visible; padding: 10px 12px 12px; }
@media (max-width: 680px) {
  .arch-group-head { flex-wrap: wrap; gap: 8px; }
  .arch-date { margin-left: 0; }
}

/* Archivio: nascondi i controlli della linea temporale e il filtro Tipo */
body.archivio-mode .toolbar label:has(#selVista),
body.archivio-mode #lblGroup,
body.archivio-mode .toolbar label:has(#inpData),
body.archivio-mode .toolbar .nav,
body.archivio-mode #legend,
body.archivio-mode .toolbar label:has(#archTipo),
body.archivio-mode .toolbar label:has(#archStato) { display: none; }

.modal-box .storia-entry { margin-bottom: 6px; }
.modal-box .storia-row {
  display: grid;
  grid-template-columns: 36px minmax(120px, 1fr) 60px 64px;
  gap: 6px; align-items: center;
}
.modal-box .storia-row input[type=number] { text-align: right; }
.modal-box .storia-row input { min-width: 0; }
.modal-box .storia-row input,
.modal-box fieldset input {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--r-sm);
  font-size: 13px; font-family: inherit; color: var(--text); background: var(--surface);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.modal-box .storia-row input:focus,
.modal-box fieldset input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
.modal-box .storia-head {
  display: grid;
  grid-template-columns: 36px minmax(120px, 1fr) 60px 64px;
  gap: 6px; font-size: 10px; font-weight: 600;
  text-transform: uppercase; color: var(--text-3);
  margin-bottom: 8px; padding: 0 2px;
  letter-spacing: .04em;
}
.modal-box .storia-actions {
  display: flex; gap: 4px; align-items: center; justify-content: flex-end;
}
.modal-box .storia-actions .btn.small {
  padding: 4px 6px; min-width: 26px; line-height: 1;
}
.modal-box .storia-toggle { font-size: 12px; }
.modal-box .storia-extra {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px;
  margin: 6px 0 10px 42px; padding: 10px 12px;
  background: var(--surface-2); border: 1px dashed var(--border);
  border-radius: var(--r-sm);
}
.modal-box .storia-extra.hidden { display: none; }
.modal-box .storia-extra label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--text-2);
}
.modal-box .storia-extra label:nth-child(3),
.modal-box .storia-extra label:nth-child(4),
.modal-box .storia-extra label:nth-child(5),
.modal-box .storia-extra label:nth-child(6) { grid-column: 1 / -1; }
.modal-box .storia-extra input,
.modal-box .storia-extra select {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--r-sm);
  font-size: 13px; font-family: inherit; color: var(--text); background: var(--surface);
}
.modal-box .storia-extra input:focus,
.modal-box .storia-extra select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}

/* Conferme caricamento materiali: 3 checkbox in fila orizzontale (tratti / sceneggiature / RD) */
.modal-box .chine-checks {
  display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center;
}
.modal-box .chine-chk {
  display: flex; align-items: center; gap: 6px; white-space: nowrap; margin: 0;
  font-size: 12px; font-weight: 500; color: var(--text-2); cursor: pointer;
}
.modal-box .chine-chk input { accent-color: var(--accent); margin: 0; }

/* Riga sempre visibile sotto la storia nel Nuovo TOPO: checkbox + nota */
.modal-box .chine-line {
  display: flex; flex-direction: column; gap: 7px;
  margin: 2px 0 8px 42px; padding: 8px 10px;
  background: var(--surface-2); border: 1px dashed var(--border);
  border-radius: var(--r-sm);
}
.modal-box .chine-line .chine-nota {
  width: 100%; min-width: 0; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  font-size: 12.5px; font-family: inherit; color: var(--text); background: var(--surface);
}
.modal-box .chine-line .chine-nota:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}

/* Blocco nei modali statici (Extra, Pending, Nuova/Modifica storia) */
.modal-box .chine-field {
  margin-bottom: 12px; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm);
}
.modal-box .chine-field .chine-checks { margin-bottom: 10px; }
.modal-box .chine-field .chine-nota-label { margin-bottom: 0; }
/* Intestazione della sezione caricamenti (sopra le 3 checkbox) */
.chine-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-3); margin-bottom: 8px;
}

.modal-actions {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 20px;
  padding-top: 18px; border-top: 1px solid var(--border);
}
.modal-actions .btn { flex-shrink: 0; }

/* Specialista colore: select + pulsante "Scheda colorista" affiancati */
.colorista-row { display: flex; gap: 8px; align-items: center; }
.colorista-row select { flex: 1 1 auto; min-width: 0; }
.colorista-row .btn { flex: 0 0 auto; white-space: nowrap; }

/* Modale anteprima scheda colorista */
.modal-box.scheda-box { max-width: 720px; width: 92vw; }
#schedaTo { font-size: 12.5px; }
.scheda-preview {
  margin-top: 10px; border: 1px solid var(--border); border-radius: var(--r-sm);
  overflow: hidden; background: #f1f5f9; height: 60vh; max-height: 560px;
}
.scheda-preview iframe { width: 100%; height: 100%; border: 0; display: block; background: #f1f5f9; }

/* Anteprima riepiloghi coloristi: si apre SOPRA la panoramica TOPO (che resta aperta
   sotto). I .modal condividono z-index 100 e vincerebbe l'ordine nel DOM, dove la
   panoramica viene dopo → serve un livello dedicato. */
#modalRiepiloghi { z-index: 110; }
/* Anteprima riepiloghi coloristi: una linguetta per colorista sopra l'iframe. */
.rp-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 6px; }
.rp-tab {
  padding: 6px 12px; cursor: pointer; font-family: inherit;
  font-size: 12px; font-weight: 600; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.rp-tab em { font-style: normal; opacity: .7; }
.rp-tab:hover { border-color: var(--border-strong); }
.rp-tab.active { background: #4f46e5; border-color: #4f46e5; color: #fff; }
.rp-tab.warn { border-color: #f59e0b; color: #b45309; }
.rp-tab.warn.active { background: #f59e0b; border-color: #f59e0b; color: #fff; }
#rpTo { font-size: 12.5px; margin: 4px 0 0; }

.modal-box .row {
  display: grid; grid-template-columns: auto 1fr auto;
  gap: 8px; margin-top: 12px; align-items: center;
}
.modal-box .modal-split {
  display: flex; gap: 10px; align-items: flex-end; margin-bottom: 12px;
}
.modal-box .modal-split > label { margin-bottom: 0; }
.modal-box .row-check {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  font-weight: 500; cursor: pointer; margin-bottom: 14px;
  transition: background var(--t-fast);
}
.modal-box .row-check:hover { background: var(--surface-3); }
.modal-box .row-check input { accent-color: var(--accent); }
.modal-box .row-check em { font-weight: 400; font-style: normal; font-size: 11px; color: var(--text-3); }

.modal-box .fasc-total {
  padding: 10px 0 4px; font-size: 13px;
  border-top: 1px dashed var(--border); margin-top: 8px;
}
.modal-box .fasc-total strong { color: var(--accent); font-weight: 700; }

.muted { color: var(--text-3); font-size: 12px; }

/* Storia edit (dentro modal dettagli storia) */
.storia-edit {
  display: grid; grid-template-columns: 1fr 130px; gap: 14px;
  margin-bottom: 18px; padding: 18px;
  background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r);
}
/* F1 (data disponibilità) in sola lettura: fissata dalla spunta Tratti, non digitabile. */
.se-f1-row {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  padding: 9px 12px; border-radius: 8px;
  background: var(--surface); border: 1px dashed var(--border);
  font-size: 12px;
}
.se-f1-k { font-weight: 700; color: var(--text-2); }
.se-f1-v { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.se-f1-row em { color: var(--text-3); font-style: normal; }
.storia-edit label {
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; color: var(--text-3);
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 0;
  letter-spacing: .055em;
}
.storia-edit input,
.storia-edit select,
.storia-edit textarea {
  padding: 9px 12px; border: 1.5px solid var(--border);
  border-radius: 10px; font-size: 13px; color: var(--text);
  background: var(--surface); font-family: inherit; font-weight: 500;
  letter-spacing: normal; text-transform: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.storia-edit input:hover,
.storia-edit select:hover,
.storia-edit textarea:hover { border-color: var(--border-strong); }
.storia-edit input:focus,
.storia-edit select:focus,
.storia-edit textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring);
}
.storia-edit .se-section {
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-2);
  border-top: 1px dashed var(--border); padding-top: 12px; margin-top: 2px;
}
.storia-edit .se-fixed {
  font-size: 13px; color: var(--text-2); padding: 4px 0;
}
.storia-edit .se-fixed strong { color: var(--text); font-weight: 650; }
.modal-box .gfb-fixed {
  font-size: 13px; color: var(--text-2); padding: 6px 2px 0;
}
.modal-box .gfb-fixed strong { color: var(--text); font-weight: 650; }
.storia-edit .fasc-tot-line {
  grid-column: 1 / -1; font-size: 12px; color: var(--text-2);
  border-top: 1px dashed var(--border); padding-top: 10px; line-height: 1.6;
}
.storia-edit .fasc-tot-line strong { color: var(--text); font-weight: 650; }
.storia-edit .warn { color: var(--danger); font-weight: 650; }
.storia-edit em {
  color: var(--text-3); font-weight: 400; font-style: normal; font-size: 10px;
}

/* Festività list */
#festList { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow-y: auto; padding: 2px; margin-bottom: 10px; }
.fest-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; font-size: 13px; font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
  transition: border-color var(--t), background var(--t);
}
.fest-item:hover { border-color: var(--border-strong); background: var(--surface-2); }
.fest-item button {
  background: transparent; border: none; color: var(--danger);
  cursor: pointer; font-size: 12px; padding: 5px 10px;
  border-radius: 8px; transition: background var(--t-fast);
  font-family: inherit; font-weight: 600;
}
.fest-item button:hover { background: var(--danger-soft); }

/* ========================================================================
   TOOLTIP fumetto (portato al body via JS — vedi tooltip.js)
   ======================================================================== */
.tip-floating {
  position: fixed; left: -9999px; top: -9999px;
  background: #0f172a; color: #fff;
  padding: 9px 13px; border-radius: 10px;
  font-size: 11.5px; font-weight: 500; line-height: 1.5;
  white-space: pre-wrap; max-width: 300px;
  z-index: 9999; pointer-events: none;
  box-shadow: 0 10px 25px rgba(0, 0, 0, .28);
  opacity: 0; transform: translateY(2px);
  transition: opacity 120ms ease-out, transform 120ms ease-out;
  font-family: inherit; text-align: left;
}
.tip-floating.visible { opacity: 1; transform: translateY(0); }
.tip-arrow {
  position: absolute; top: 100%; left: 50%;
  width: 0; height: 0;
  border: 6px solid transparent; border-top-color: #0f172a;
  transform: translateX(-50%);
}
.tip-floating.arrow-up .tip-arrow {
  top: auto; bottom: 100%;
  border-top-color: transparent; border-bottom-color: #0f172a;
}

/* ========================================================================
   RESPONSIVE
   ======================================================================== */
@media (max-width: 720px) {
  .topbar { padding: 14px 16px; }
  .topbar h1 { font-size: 15px; }
  .toolbar { gap: 10px; padding: 12px 16px; }
  main { padding: 14px 16px 60px; }
  .panel { width: 100%; }
  .list-view .list-item { grid-template-columns: 1fr; gap: 4px; }
  .storia-edit { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  #modalFasc .modal-box { width: 94vw; }
  #modalStoriaEdit .modal-box { width: 94vw; }
  .modal-box .storia-head { display: none; }
  .modal-box .storia-row { grid-template-columns: 36px 1fr 64px; grid-auto-rows: auto; row-gap: 4px; }
  .modal-box .storia-row input[type=number],
  .modal-box .storia-row input[type=date] { grid-column: 2 / 3; }
  .modal-box .storia-extra { grid-template-columns: 1fr; margin-left: 0; }
  .modal-box .storia-extra label:nth-child(n) { grid-column: 1 / -1; }
  .modal-box .chine-line { margin-left: 0; flex-wrap: wrap; }
}

/* ========================================================================
   AUTH SPLASH (verifica sessione)
   ======================================================================== */
body.auth-pending > *:not(#authSplash):not(script) { visibility: hidden; }
.auth-splash {
  position: fixed; inset: 0; z-index: 999;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.auth-splash-card {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 28px 32px; border-radius: var(--r-lg);
  background: var(--surface); box-shadow: var(--shadow-md);
}
.auth-splash-spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.auth-splash-text { color: var(--text-2); font-size: 13px; font-weight: 550; }

/* ========================================================================
   LOGIN PAGE
   ======================================================================== */
body.login-page { padding-top: 0; min-height: 100vh; overflow-x: hidden; }
body.login-page::before {
  background:
    radial-gradient(800px 500px at 80% -10%, rgba(79, 70, 229, .14), transparent 60%),
    radial-gradient(700px 500px at -10% 110%, rgba(124, 58, 237, .12), transparent 60%),
    radial-gradient(500px 400px at 50% 50%, rgba(34, 211, 238, .04), transparent 70%);
}
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 32px 20px;
}
.login-stack {
  display: flex; flex-direction: column; align-items: center;
  width: 100%; max-width: 420px;
}
.login-title-out {
  margin: 0 0 28px;
  font-size: 44px; font-weight: 800; letter-spacing: -0.04em;
  background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 50%, #ec4899 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  text-align: center; line-height: 1;
  filter: drop-shadow(0 4px 16px rgba(79, 70, 229, .2));
}
.login-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 38px 30px;
  width: 100%;
}
.login-card::before {
  content: '';
  position: absolute; top: -1px; left: -1px; right: -1px; height: 4px;
  background: linear-gradient(90deg, var(--accent) 0%, #7c3aed 50%, #ec4899 100%);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}
.login-logo {
  display: block; margin: 0 auto 28px;
  height: 96px; width: auto; max-width: 180px;
  object-fit: contain;
  filter: drop-shadow(0 8px 20px rgba(15, 23, 42, .18));
}
.login-card form label {
  display: block; margin-bottom: 16px; font-size: 11px;
  font-weight: 700; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .055em;
}
.login-card form input {
  width: 100%; padding: 12px 14px; margin-top: 6px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 14px; font-family: inherit; font-weight: 500;
  letter-spacing: normal; text-transform: none;
  color: var(--text); background: var(--surface);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.login-card form input:hover { border-color: var(--border-strong); }
.login-card form input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring);
}
.login-error {
  background: var(--danger-soft); color: var(--danger);
  border: 1px solid #fecaca; border-radius: 10px;
  padding: 10px 13px; font-size: 13px; margin-bottom: 14px;
  font-weight: 500; line-height: 1.45;
}
.login-submit {
  width: 100%; justify-content: center;
  padding: 13px 16px; font-size: 14px;
  margin-top: 8px; border-radius: 10px;
}
.login-foot { font-size: 12px; margin-top: 22px; text-align: center; line-height: 1.5; }

@media (max-width: 480px) {
  .login-title-out { font-size: 36px; margin-bottom: 22px; }
  .login-card { padding: 28px 26px 24px; }
  .login-logo { height: 80px; margin-bottom: 22px; }
}

/* ========================================================================
   USER MENU (topbar)
   ======================================================================== */
.user-menu { position: relative; flex-shrink: 0; order: 99; }
.user-menu[hidden] { display: none !important; }
.user-trigger {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 5px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; cursor: pointer;
  font-family: inherit; font-size: 13px; color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.user-trigger:hover { border-color: var(--border-strong); background: var(--surface-2); }
.user-trigger:focus-visible {
  outline: none; box-shadow: 0 0 0 3px var(--accent-ring); border-color: var(--accent);
}
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 11.5px; letter-spacing: .02em;
  flex-shrink: 0;
}
.user-menu[data-role="admin"] .user-avatar { background: var(--accent); }
.user-menu[data-role="editor"] .user-avatar { background: var(--coord); }
.user-meta { display: flex; flex-direction: column; line-height: 1.15; text-align: left; min-width: 0; }
.user-name { font-weight: 600; font-size: 12.5px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 10.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 240px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--shadow-md);
  padding: 6px; z-index: 90;
  animation: slideUp var(--t);
}
.user-dropdown-head {
  padding: 10px 12px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px;
}
.user-name-full { font-weight: 650; font-size: 13.5px; color: var(--text); }
.user-email { font-size: 12px; color: var(--text-3); margin-top: 2px; word-break: break-all; }
.user-dd-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 9px 10px; background: transparent; border: none; border-radius: 6px;
  font-family: inherit; font-size: 13px; color: var(--text); cursor: pointer;
  text-align: left;
  transition: background var(--t-fast);
}
.user-dd-item:hover { background: var(--surface-3); }
.user-dd-item .icon { width: 16px; height: 16px; color: var(--text-2); }

/* ========================================================================
   GESTIONE UTENTI
   ======================================================================== */
.users-toolbar { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.users-list { display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow-y: auto; padding: 2px; }
.user-row {
  display: grid;
  grid-template-columns: 40px 1fr auto auto;
  gap: 12px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface);
}
.user-avatar-lg { width: 36px; height: 36px; font-size: 13px; }
.user-info { min-width: 0; }
.user-row-name { font-weight: 600; font-size: 13.5px; color: var(--text); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.user-row-email { font-size: 12px; color: var(--text-3); margin-top: 1px; word-break: break-all; }
.user-row-actions { display: flex; gap: 6px; }
.user-role-pill {
  font-size: 11px; font-weight: 600; padding: 4px 9px; border-radius: 999px;
  letter-spacing: .02em; white-space: nowrap;
}
.user-role-pill.role-admin { background: var(--accent-soft); color: var(--accent); }
.user-role-pill.role-editor { background: #fff7ed; color: #b45309; }
.user-role-pill.role-cliente { background: #e0f2fe; color: #075985; }
.user-badge {
  display: inline-block; font-size: 10px; font-weight: 600;
  padding: 1px 7px; border-radius: 999px; letter-spacing: .03em;
  text-transform: uppercase;
}
.user-badge.me { background: var(--success-soft); color: var(--success); }
.user-badge.inactive { background: #fee2e2; color: #991b1b; }
.ue-attivo {
  display: flex !important; align-items: center; gap: 8px;
  font-size: 13px !important; font-weight: 500 !important; color: var(--text) !important;
}
.ue-attivo input[type=checkbox] { width: auto !important; margin: 0 !important; }

/* Riga log: aggiunge l'autore sotto al timestamp. */
.log-row .log-who { display: block; color: var(--text-2); font-size: 10.5px; margin-top: 1px; font-weight: 600; }

/* ========================================================================
   USER MENU — responsive
   ======================================================================== */
@media (max-width: 720px) {
  .user-meta { display: none; }
  .user-trigger { padding: 3px; }
}
@media (max-width: 680px) {
  .user-row { grid-template-columns: 32px 1fr auto; }
  .user-row-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .user-avatar-lg { width: 32px; height: 32px; font-size: 12px; }
}

/* ========================================================================
   COLORITURA — checkbox listino + box prezzo
   (selettori scoped con .colori-box per vincere su .modal-box label
    e .modal-box .storia-extra label nelle righe storia dinamiche)
   ======================================================================== */
.modal-box .colori-field { margin: 4px 0; }
.modal-box .storia-extra .colori-field { grid-column: 1 / -1; }
.modal-box .colori-field-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.modal-box .colori-field-title em { font-weight: 400; }

.modal-box .colori-box { display: flex; flex-direction: column; gap: 12px; }
.modal-box .colori-box .colori-sec-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-3); margin-bottom: 6px;
}
.modal-box .colori-box .colori-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px;
}
.modal-box .colori-box .colori-item {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 9px; align-items: start;
  margin: 0; padding: 8px 10px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.modal-box .colori-box .colori-item:hover { border-color: var(--border-strong); background: var(--surface-2); }
.modal-box .colori-box .colori-item input[type=checkbox] {
  grid-row: 1 / span 2; align-self: center; width: auto; min-width: 0; margin: 0; padding: 0;
}
.modal-box .colori-box .colori-label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.modal-box .colori-box .colori-desc { font-size: 11px; color: var(--text-3); line-height: 1.3; }
.modal-box .colori-box .colori-item:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
/* Voci a blocchi (Correzioni in itinere): campo numerico al posto della checkbox,
   centrato in colonna con la dicitura "Blocchi" sotto — niente spazi morti. */
.modal-box .colori-box .blocchi-item .blocchi-input {
  grid-row: 1 / span 2; align-self: center;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.modal-box .colori-box .blocchi-item input[type=number] {
  width: 56px; padding: 4px 2px; text-align: center; font-size: 14px; font-weight: 700;
  border: 1.5px solid var(--border); border-radius: 6px; font-family: inherit;
  background: var(--surface);
}
.modal-box .colori-box .blocchi-item .blocchi-unit {
  font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3);
}
.modal-box .colori-box .blocchi-item:has(input[type=number]:not([value="0"])) { border-color: var(--accent); }
.modal-box .colori-box .colori-item:has(input:disabled) { opacity: .55; cursor: not-allowed; }
.modal-box .colori-box .colori-item:has(input:disabled:checked) { opacity: 1; } /* FLAT base resta evidente */

/* Box prezzo */
.modal-box .prezzo-box {
  margin-top: 12px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface-3);
}
.modal-box .prezzo-box:empty { display: none; }
.modal-box .prezzo-head { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.modal-box .prezzo-extra {
  font-size: 11px; font-weight: 600; color: var(--warning);
  background: var(--warning-soft); padding: 1px 8px; border-radius: 20px; margin-left: 4px;
}
.modal-box .prezzo-warn { font-size: 12px; color: var(--warning); margin-bottom: 8px; }
.modal-box .prezzo-tab { width: 100%; border-collapse: collapse; font-size: 13px; }
.modal-box .prezzo-tab th {
  font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3);
  font-weight: 600; text-align: right; padding: 2px 6px;
}
.modal-box .prezzo-tab th:first-child { text-align: left; }
.modal-box .prezzo-tab td { padding: 3px 6px; text-align: right; color: var(--text); }
.modal-box .prezzo-tab td:first-child { text-align: left; color: var(--text-2); font-size: 12px; }
.modal-box .prezzo-tab .prezzo-scontato td { font-weight: 700; color: var(--success); }
.modal-box .prezzo-foot { margin-top: 8px; font-size: 11px; color: var(--text-3); }

/* Impostazioni listino: tempi di lavorazione (minuti/tavola) */
#modalListino .modal-box { max-height: 88vh; overflow-y: auto; }
.modal-box .set-minuti-title { font-size: 13px; font-weight: 600; color: var(--text); margin: 14px 0 8px; }
.modal-box .set-minuti-title em { font-weight: 400; }
.modal-box .set-min-sec { margin-bottom: 12px; }
.modal-box .set-min-sec-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-3); margin-bottom: 6px;
}
.modal-box .set-min-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 6px 12px;
}
/* Riga voce: nome + prezzo di acquisto (compenso colorista) + prezzo di vendita.
   Colonne larghe: l'etichetta accanto al campo è per esteso ("€ Acquisto" / "€ Vendita"). */
.modal-box .set-min-item {
  display: grid; grid-template-columns: 1fr 158px 158px; align-items: center; gap: 8px;
  margin: 0; font-size: 12px; color: var(--text-2);
}
.modal-box .set-min-input { display: flex; align-items: center; gap: 5px; }
.modal-box .set-min-input input { width: 100%; min-width: 0; text-align: right; padding-left: 6px; padding-right: 6px; }
.modal-box .set-min-unit { flex: 0 0 auto; font-size: 11px; color: var(--text-3); }

/* --- Dialoghi in-app (uiAlert / uiConfirm) --------------------------------- */
.uid-overlay {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15, 23, 42, .45);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  padding: 20px;
}
.uid-overlay.hidden { display: none; }
.uid-card {
  background: #fff; color: #0f172a;
  border-radius: 16px; box-shadow: 0 20px 60px rgba(15, 23, 42, .35);
  max-width: 460px; width: 100%; padding: 20px 22px;
  animation: uidPop .18s cubic-bezier(.2, .9, .3, 1.4);
}
@keyframes uidPop {
  from { transform: scale(.92) translateY(8px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.uid-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.uid-ico { font-size: 22px; line-height: 1; }
.uid-title { font-size: 16px; font-weight: 800; letter-spacing: -.01em; }
.uid-msg {
  font-size: 13.5px; line-height: 1.55; color: #475569;
  white-space: pre-line; word-break: break-word;
  max-height: 50vh; overflow: auto;
}
.uid-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* --- Semaforo storia (pallino verde/rosso) --------------------------------- */
.sem-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  flex: 0 0 auto; vertical-align: middle;
}
.code-row .sem-dot { margin-right: 5px; }
.sem-verde { background: #22c55e; box-shadow: 0 0 0 2px rgba(34, 197, 94, .18); }
.sem-rosso {
  background: #ef4444; box-shadow: 0 0 0 2px rgba(239, 68, 68, .22);
  animation: semPulse 1.6s ease-in-out infinite;
}
@keyframes semPulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(239, 68, 68, .22); }
  50%      { box-shadow: 0 0 0 4px rgba(239, 68, 68, .10); }
}
.se-semaforo { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sem-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid #bbf7d0; background: #f0fdf4; color: #166534;
  border-radius: 999px; padding: 6px 14px;
  font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.sem-toggle.is-rosso { color: #991b1b; border-color: #fecaca; background: #fef2f2; }
.sem-toggle:disabled { opacity: .6; cursor: default; }

/* Toggle semaforo nelle righe storia del modale Nuovo TOPO */
.sem-toggle-mini {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid #e2e8f0; background: #fff; cursor: pointer; padding: 0;
}
.sem-toggle-mini:hover { border-color: #94a3b8; }

/* --- Nota interna di studio (mai in email/PDF/vista cliente) --------------- */
.nota-interna-field { display: block; }
.nota-interna-title {
  display: block; font-size: 12px; font-weight: 700; color: #92400e;
  margin-bottom: 4px;
}
.nota-interna-title .muted { font-weight: 500; }
.nota-interna-field textarea {
  width: 100%; background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px;
  padding: 8px 10px; font: inherit; font-size: 13px; color: #0f172a; resize: vertical;
}
.nota-interna-field textarea:focus { outline: none; border-color: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, .15); }
body.role-cliente .nota-interna-field { display: none; }

/* Campi obbligatori: marcatore accanto all'etichetta */
.req-mark {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: #b45309; background: #fef3c7; border-radius: 999px; padding: 1px 7px; margin-left: 4px;
}
.colorista-hint { font-size: 12px; white-space: nowrap; align-self: center; }

/* Bustina "scheda inviata al colorista" nella colonna storie */
.scheda-badge {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; line-height: 1; color: #047857;
  background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 5px;
  padding: 2px 4px; margin-left: 4px; cursor: help;
}
/* Riga "scheda inviata" nel pannello della fase F3 */
.f3-scheda-sent {
  margin-top: 4px; font-size: 11.5px; color: #047857;
  background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 6px;
  padding: 3px 8px; display: inline-block;
}

/* F3: nota di fase storica (il campo attivo è la Nota / link FTP della storia) */
.f3-nota-legacy {
  font-size: 11.5px; color: #78716c; background: #fafaf9; border: 1px dashed #e7e5e4;
  border-radius: 6px; padding: 4px 8px; margin-top: 4px;
}


/* --- Lucchetto opzioni coloritura (stile + blocchi congelati) --------------- */
.colori-lock {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin-top: 10px; padding: 8px 12px;
  border: 1px dashed #cbd5e1; border-radius: 10px;
  font-size: 12.5px; color: #475569;
}
.colori-lock.is-locked { border-style: solid; border-color: #c7d2fe; background: #eef2ff; color: #3730a3; }
.colori-lock .colori-lock-stato { line-height: 1.4; }


/* --- Selettore Fatt./R.A. nella lista anagrafica coloristi ----------------- */
.fr-sel { display: flex; gap: 4px; flex: 0 0 auto; margin-right: 10px; }
.fr-btn {
  border: 1px solid var(--border, #e2e8f0); background: var(--surface, #fff);
  color: #64748b; border-radius: 8px; padding: 4px 9px;
  font-size: 11px; font-weight: 700; cursor: pointer; line-height: 1;
}
.fr-btn.active { background: #4f46e5; border-color: #4f46e5; color: #fff; }
.fr-btn:not(.active):hover { border-color: #94a3b8; color: #334155; }

/* --- Storico ordini OF con pulsante documento (vista Coloristi) ------------ */
.ff-of-head {
  display: flex; align-items: center; gap: 8px;
  margin-top: 8px; padding: 5px 8px;
  background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px;
  font-size: 12px;
}
.ff-of-head.col-extra { display: none; }
.col-sec.expanded .ff-of-head.col-extra { display: flex; }
.ff-of-code { font-weight: 800; color: #047857; }
.ff-of-date { color: #64748b; font-size: 11px; flex: 1; }
.ff-doc-btn { white-space: nowrap; }

/* --- Modale documento colorista -------------------------------------------- */
.dc-fields { display: flex; gap: 14px; flex-wrap: wrap; margin: 10px 0; }
.dc-fields label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: #475569; }
.dc-fields input, .dc-fields select { padding: 6px 8px; border: 1px solid var(--border, #e2e8f0); border-radius: 8px; font: inherit; }
.dc-fields input[type=number] { width: 90px; }
.dc-warn {
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px;
  padding: 8px 12px; font-size: 12px; color: #92400e; line-height: 1.5; margin: 8px 0;
}


/* --- Doppia approvazione opzioni coloritura (conferma cliente + convalida GFB) --- */
.colori-lock { flex-direction: column; align-items: stretch; gap: 6px; }
.lk-step { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 3px 0; }
.lk-step input[type=checkbox] { margin: 0 8px 0 0; width: 16px; height: 16px; flex: 0 0 auto; }
.lk-step > span { flex: 1; line-height: 1.4; }
.lk-step.done { color: #166534; }
label.lk-step { cursor: pointer; }
label.lk-step input:disabled + span { cursor: default; }


/* Step della doppia approvazione dentro .storia-edit: neutralizza lo stile delle label di form */
.storia-edit label.lk-step {
  flex-direction: row; align-items: center; gap: 0;
  font-size: 12.5px; font-weight: 500; text-transform: none; letter-spacing: normal; color: inherit;
}
.storia-edit label.lk-step.done { color: #166534; }
.storia-edit .lk-step input[type=checkbox] { padding: 0; border: 0; border-radius: 3px; width: 16px; height: 16px; margin: 0 8px 0 0; }


/* --- Confronto "Aggiorna da documento" ------------------------------------- */
.ri-body { max-height: 55vh; overflow: auto; margin: 10px 0; }
.ri-sec { margin-bottom: 14px; }
.ri-sec-t {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-2, #64748b); margin-bottom: 6px;
}
.ri-sec-t em { font-weight: 500; text-transform: none; letter-spacing: 0; }
.ri-row {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 6px 8px; border-bottom: 1px solid #f1f5f9; font-size: 13px;
}
.ri-code { font-weight: 700; white-space: nowrap; min-width: 96px; color: #0f172a; }
.ri-code.ri-new { color: #047857; }
.ri-diff { display: flex; flex-direction: column; gap: 2px; }
.ri-field s { color: #94a3b8; }
.ri-only-sem, .ri-keep { color: #64748b; font-style: italic; }

.ri-note { font-size: 11.5px; color: #64748b; font-style: italic; margin-top: 10px; line-height: 1.5; }

/* --- Riepilogo mensile ritenute / F24 -------------------------------------- */
.rt-body { max-height: 60vh; overflow: auto; margin: 6px 0; }
.rt-sec-t { font-weight: 800; font-size: 12.5px; color: #fff; background: #1e3a8a; padding: 6px 10px; border-radius: 8px 8px 0 0; margin-top: 12px; }
.rt-sec-t.rt-fatt { background: #92400e; }
.rt-tab { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.rt-tab th, .rt-tab td { border: 1px solid #e2e8f0; padding: 5px 8px; text-align: left; }
.rt-tab .rt-head th { background: #eff6ff; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: #1e3a8a; }
.rt-tab .rt-nome { font-weight: 700; }
.rt-tab .rt-num { text-align: right; white-space: nowrap; }
.rt-tab .rt-tot td { background: #e2e8f0; font-weight: 800; }
.rt-na, .rt-ded { color: #64748b; font-style: italic; font-size: 11px; }
.rt-f24 { margin-top: 18px; border: 2px solid #1e3a8a; border-radius: 10px; overflow: hidden; }
.rt-f24-t { background: #1e3a8a; color: #fff; font-weight: 800; padding: 6px 10px; font-size: 12.5px; }
.rt-f24-tab { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.rt-f24-tab td { border-bottom: 1px solid #e2e8f0; padding: 5px 10px; }
.rt-f24-tab td:first-child { width: 42%; background: #f8fafc; color: #475569; }
.rt-f24-tab em { color: #64748b; font-size: 11px; }

/* --- Banner modalità test email -------------------------------------------- */
.email-test-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 250;
  background: #fef3c7; border-top: 2px solid #f59e0b; color: #92400e;
  padding: 8px 16px; font-size: 12.5px; text-align: center;
  display: flex; align-items: center; justify-content: center; gap: 12px;
}
.email-test-bar.hidden { display: none; }
body.has-test-bar { padding-bottom: 42px; }

/* --- Elenco documenti coloristi del TOPO ----------------------------------- */
.dt-body { max-height: 50vh; overflow: auto; margin: 10px 0; }
.dt-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--border, #e2e8f0); border-radius: 10px; margin-bottom: 8px;
}
.dt-info { flex: 1; min-width: 0; }
.dt-of { font-size: 13.5px; color: #0f172a; }
.dt-meta { font-size: 12px; color: #64748b; margin-top: 2px; word-break: break-word; }

/* Riga anagrafica CON selettore Fatt./R.A.: serve una colonna in più, altrimenti il
   selettore finisce nella colonna da 40px dell'avatar e il secondo pulsante sparisce. */
.user-row:has(.fr-sel) { grid-template-columns: auto 40px 1fr auto auto; }
.fr-sel { white-space: nowrap; }
@media (max-width: 680px) {
  .user-row:has(.fr-sel) { grid-template-columns: auto 32px 1fr; }
}

/* Linguetta di reinvio nell'anteprima documenti */
.rp-tab.redo { border-style: dashed; }

/* Documenti coloristi: sopra al modale TOPO che lo apre */
#modalDocsTopo { z-index: 110; }

/* Ordine al colorista: apertura del link (tracciamento) */
.f3-aperta { color: #059669; font-weight: 600; }
.f3-non-aperta { color: #94a3b8; }
.scheda-badge.opened { color: #059669; }

/* Sposta partenza della singola storia (riga F1 del modale storia) */
.se-f1-sposta { display: inline-flex; gap: 6px; align-items: center; margin-left: auto; }
.se-f1-sposta input[type="date"] { width: auto; padding: 4px 8px; font-size: 12.5px; }

/* Re-import: abbinamento storie modificabile */
.ri-match { align-items: center; flex-wrap: wrap; }
.ri-match .ri-diff { flex: 1 1 260px; }
.ri-sel { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #475569; white-space: nowrap; }
.ri-sel select { max-width: 360px; font-size: 12.5px; padding: 4px 6px; }
.ri-match.incerto { background: #fffbeb; }
.ri-incerto { color: #b45309; font-size: 11.5px; font-style: italic; margin-left: 6px; }

/* Vista Coloristi: sezione Preassegnazione */
.col-sec-title.sec-preass { color: #0369a1; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.col-sec-title.sec-preass .col-preass-btn { margin-left: auto; font-weight: 600; }
.col-sec-preass { background: #f0f9ff; border-radius: 8px; padding: 6px 8px; }

/* Documenti cumulativi: scelta dei TOPO da aggregare */
.rp-topi { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0 10px; }
.rp-topi.hidden { display: none; }
.rp-topi .rp-topi-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 700; margin-right: 2px; }
.rp-topi .rp-topo {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 9px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 12px; font-weight: 600; color: var(--text-2);
  transition: all var(--t);
}
.rp-topi .rp-topo:hover { border-color: var(--border-strong); }
.rp-topi .rp-topo.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); color: var(--text); }
.rp-topi .rp-topo em { font-style: normal; font-size: 10.5px; color: var(--text-3); }
.rp-topi .rp-topo .rp-topo-n { background: var(--surface-2); border-radius: 999px; padding: 1px 7px; font-size: 11px; color: var(--text-2); }
.rp-topi .rp-topo.on .rp-topo-n { background: var(--accent); color: #fff; }

/* Le caselle dei TOPO stanno dentro <label> di modale: senza questo reset il checkbox
   eredita width:100% dai campi form e spezza il codice del TOPO su due righe. */
.rp-topi .rp-topo input[type=checkbox] { width: auto; min-width: 0; margin: 0; }
.rp-topi .rp-topo { margin-bottom: 0; text-transform: none; letter-spacing: normal; }
.rp-topi .rp-topo em { text-transform: uppercase; }
/* Con molti TOPO l'intestazione cresce: i pulsanti restano agganciati al fondo. */
#modalRiepiloghi .modal-actions {
  position: sticky; bottom: 0; z-index: 2;
  background: var(--surface); padding-top: 10px; margin-top: 4px;
  box-shadow: 0 -8px 12px -10px rgba(15, 23, 42, .25);
}

/* Documenti cumulativi: TOPO rimasti fuori, con il motivo */
.rp-topi .rp-fuori { flex-basis: 100%; font-size: 11.5px; color: var(--text-3); line-height: 1.5; margin-top: 2px; }
.rp-topi .rp-fuori strong { color: var(--text-2); font-weight: 700; }

/* Finestra "TOPO non inclusi" (documenti cumulativi) */
#modalFuori { z-index: 120; }            /* sopra l'anteprima dei documenti */
#modalFuori .modal-box { max-width: 680px; }
.fu-body { max-height: 52vh; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.fu-body .fu-row {
  display: flex; gap: 12px; align-items: baseline;
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.fu-body .fu-row:last-child { border-bottom: 0; }
.fu-body .fu-row:nth-child(odd) { background: var(--surface-2); }
.fu-body .fu-code { font-weight: 800; color: var(--text); white-space: nowrap; min-width: 92px; }
.fu-body .fu-motivi { color: var(--text-2); line-height: 1.5; }
.fu-body .fu-motivi em { font-style: normal; color: var(--text-3); font-size: 11.5px; }
