/* ========== RESET & BASE ========== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Poppins', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: #0f172a;
  color: #e2e8f0;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; }

/* ========== COLOR TOKENS ========== */
:root {
  --bg: #0f172a;
  --bg-1: #1e293b;
  --bg-2: #334155;
  --border: #334155;
  --border-2: #475569;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --text-dimmer: #64748b;
  --accent: #38bdf8;
  --accent-2: #0284c7;
  --warn: #fbbf24;
  --danger: #ef4444;
  --ok: #22c55e;
  --orange: #f97316;
}

/* ========== WIZARD ========== */
.wizard {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.wizard-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 32px 40px;
  width: 100%; max-width: 520px;
}
.wizard-card h1 { color: var(--accent); margin: 0 0 4px; font-size: 28px; }
.wizard-card .sub { color: var(--text-dim); margin: 0 0 24px; font-size: 13px; }
.wizard-card h2 { color: var(--warn); margin: 0 0 8px; font-size: 16px; }
.wizard-card p { color: var(--text-dim); line-height: 1.5; margin: 0 0 16px; }
.wizard-step input[type=text],
.wizard-step input[type=password],
.wizard-step select.login-select {
  width: 100%; padding: 10px 12px; background: var(--bg);
  border: 1px solid var(--border-2); border-radius: 6px;
  color: var(--text); font-size: 14px; margin-bottom: 12px;
  font-family: inherit;
}
.wizard-step select.login-select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}
.wizard-step select.login-select:focus,
.wizard-step input[type=password]:focus,
.wizard-step input[type=text]:focus {
  outline: none; border-color: var(--accent);
}
.login-actions {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-top: 4px;
}
.info-line {
  margin-top: 12px; padding: 8px 12px; border-radius: 6px;
  font-family: ui-monospace, monospace; font-size: 12px;
  background: var(--bg); color: var(--text-dim);
}
.info-line.ok { background: #14532d; color: #86efac; }
.info-line.err { background: #7f1d1d; color: #fca5a5; }

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 6px;
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: background 0.1s;
}
.btn.primary { background: var(--accent-2); color: white; }
.btn.primary:hover { background: #0369a1; }
.btn.secondary {
  background: var(--bg-2); color: var(--text);
  border-color: var(--border-2);
}
.btn.secondary:hover { background: var(--border-2); }
.btn.ghost { background: transparent; color: var(--text-dim); }
.btn.ghost:hover { color: var(--text); }
.btn.danger { background: var(--danger); color: white; }
.btn.danger:hover { background: #dc2626; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-tiny {
  background: transparent; color: var(--text-dim); border: none;
  cursor: pointer; padding: 4px 8px; border-radius: 4px;
  font-size: 11px;
}
.btn-tiny:hover { background: var(--bg-2); color: var(--text); }

/* ========== APP LAYOUT ========== */
.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  height: 100vh;
}

/* SIDEBAR */
.sidebar {
  background: #0b1220; border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px; border-bottom: 1px solid var(--border);
}
.brand-mark {
  background: var(--accent); color: #0b1220;
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}
.brand-title { font-weight: 600; font-size: 14px; }
.brand-sub { font-size: 11px; color: var(--text-dim); }

.nav { flex: 1; padding: 8px 0; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; color: var(--text-dim);
  text-decoration: none; font-size: 13px;
  border-left: 3px solid transparent;
}
.nav a:hover { background: var(--bg-1); color: var(--text); }
.nav a.active {
  background: var(--bg-1); color: var(--accent);
  border-left-color: var(--accent);
}
.nav-icon {
  display: inline-block; width: 22px; text-align: center;
  background: var(--bg-2); border-radius: 4px;
  font-size: 10px; font-weight: 700;
  padding: 2px 0; color: var(--text-dim);
}
.nav a.active .nav-icon { background: var(--accent); color: #0b1220; }
.nav-section {
  padding: 16px 16px 4px; font-size: 10px;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-dimmer); font-weight: 600;
}

.sidebar-footer {
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto auto;
  column-gap: 6px;
  row-gap: 8px;
  align-items: center;
}
.user-info {
  grid-column: 1 / -1;
  min-width: 0;
}
.user-name {
  font-size: 13px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-folder {
  font-size: 11px; color: var(--text-dimmer);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-footer .btn-tiny {
  border: 1px solid var(--border); background: var(--bg-2);
}
.sidebar-footer #btnLogout { grid-column: 2; }
.sidebar-footer #btnSettings { grid-column: 3; }

/* MAIN */
.main {
  display: flex; flex-direction: column;
  overflow: hidden;
}
.topbar {
  background: var(--bg-1); border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar-left h1 { margin: 0; font-size: 18px; font-weight: 600; }
.page-sub { font-size: 12px; color: var(--text-dim); margin-left: 12px; }
.topbar-right { display: flex; align-items: center; gap: 16px; font-size: 12px; }
.today-date { color: var(--text-dim); }

.sync-status {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-dim);
}
.sync-status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok); display: inline-block;
}
.sync-status.syncing .dot { background: var(--warn); animation: pulse 1s infinite; }
.sync-status.error .dot { background: var(--danger); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }

.page-content {
  flex: 1; overflow-y: auto;
  padding: 24px;
}

/* ========== CARDS, GRID, COMMON ========== */
.card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.card-title {
  font-size: 11px; text-transform: uppercase;
  color: var(--text-dim); letter-spacing: 0.5px; font-weight: 600;
}

.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 16px; margin-bottom: 24px;
}
.kpi {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px;
}
.kpi-label {
  font-size: 11px; text-transform: uppercase;
  color: var(--text-dim); letter-spacing: 0.5px; margin-bottom: 8px;
}
.kpi-value {
  font-size: 28px; font-weight: 700; color: var(--text);
  line-height: 1; margin-bottom: 4px;
}
.kpi-sub { font-size: 12px; color: var(--text-dim); }
.kpi.danger .kpi-value { color: var(--danger); }
.kpi.warn .kpi-value { color: var(--warn); }
.kpi.ok .kpi-value { color: var(--ok); }

.empty-state {
  padding: 48px 24px; text-align: center;
  color: var(--text-dim);
}
.empty-state h3 { color: var(--text); font-weight: 500; margin: 0 0 8px; }
.empty-state p { margin: 0 0 16px; }

/* ========== AUDIT LOG ========== */
.al-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.al-filters label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.al-filters input, .al-filters select {
  background: var(--bg); border: 1px solid var(--border-2);
  color: var(--text); padding: 6px 10px; border-radius: 6px;
  font-size: 13px; font-family: inherit;
  text-transform: none; letter-spacing: 0;
}
.al-filters input:focus, .al-filters select:focus {
  outline: none; border-color: var(--accent);
}
.al-filters .al-grow { grid-column: span 2; }
.al-pager {
  display: flex; align-items: center; justify-content: center;
  gap: 16px; margin-top: 16px;
  color: var(--text-dim); font-size: 12px;
}

/* ========== TOOLBAR ========== */
.toolbar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px;
}
.toolbar .search {
  flex: 1; max-width: 360px;
  background: var(--bg-1); border: 1px solid var(--border-2);
  color: var(--text); padding: 8px 12px; border-radius: 6px;
  font-size: 13px; font-family: inherit;
}
.toolbar-info {
  margin-left: auto; color: var(--text-dim); font-size: 12px;
}

/* ========== FILTER BAR (pills) ========== */
.filter-bar {
  display: flex; align-items: center; gap: 24px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.filter-group {
  display: flex; align-items: center; gap: 6px;
}
.filter-group > label {
  font-size: 11px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-right: 4px;
}
.pill {
  background: var(--bg-1); border: 1px solid var(--border-2);
  color: var(--text-dim); padding: 5px 12px;
  border-radius: 14px; cursor: pointer; font-size: 12px;
  font-family: inherit; font-weight: 500;
}
.pill:hover { color: var(--text); border-color: var(--accent); }
.pill.active {
  background: var(--accent); color: #0b1220;
  border-color: var(--accent); font-weight: 600;
}

/* ========== TABLE ========== */
.table {
  width: 100%; border-collapse: collapse;
}
.table th, .table td {
  text-align: left; padding: 10px 12px;
  font-size: 13px; border-bottom: 1px solid var(--border);
}
.table th {
  background: #0b1220; color: var(--text-dim);
  font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.5px; position: sticky; top: 0;
}
.table tbody tr { cursor: pointer; transition: background 0.05s; }
/* Zebra leggera per distinguere le righe senza coprire hover/row-modified/row-saved. */
.table tbody tr:nth-child(even) { background: rgba(148, 163, 184, 0.05); }
.table tbody tr:hover { background: rgba(56, 189, 248, 0.06); }
.table tbody tr:last-child td { border-bottom: none; }
.table-empty {
  text-align: center; padding: 32px; color: var(--text-dim);
}
.table tbody tr.row-inactive { opacity: 0.55; }
.table tbody tr.row-inactive td:first-child strong { color: var(--text-dim); }
.row-sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.mono { font-family: ui-monospace, monospace; font-size: 12px; color: var(--text-dim); }
.map-link {
  display: inline-block; margin-left: 6px;
  font-size: 10px; padding: 1px 6px; border-radius: 3px;
  background: var(--bg-2); color: var(--text-dim); text-decoration: none;
}
.map-link:hover { background: var(--accent); color: #0b1220; }

/* ========== READINGS PAGE ========== */
.readings-bar {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 16px;
  display: flex; align-items: center; gap: 24px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.readings-bar .field { display: flex; flex-direction: column; gap: 4px; }
.readings-bar .field label {
  font-size: 11px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.readings-bar input[type=date] {
  background: var(--bg); border: 1px solid var(--border-2);
  color: var(--text); padding: 6px 10px; border-radius: 6px;
  font-size: 13px; font-family: inherit;
}
.readings-bar .stat {
  display: flex; flex-direction: column; gap: 2px;
  font-size: 12px; color: var(--text-dim);
}
.readings-bar .stat strong { color: var(--text); font-size: 16px; }

.table.readings input[type=number],
.table.readings input[type=text] {
  width: 100%; max-width: 80px;
  background: var(--bg); border: 1px solid var(--border-2);
  color: var(--text); padding: 4px 6px; border-radius: 4px;
  font-size: 12px; font-family: inherit;
  text-align: right;
}
.table.readings input[type=text].notes { max-width: 180px; text-align: left; }
.table.readings input:focus {
  outline: none; border-color: var(--accent);
  background: rgba(56,189,248,0.08);
}
/* Selettore con type+classe: serve specificita' sufficiente a battere la
   regola .table.readings input[type=number]. Stesso giallo del campo Consumo. */
.table.readings input[type=number].input-override-changed {
  background: rgba(251, 191, 36, 0.16);
  border-color: var(--warn);
  color: var(--warn);
  font-weight: 600;
}
.table.readings .btn-reset-row {
  background: transparent; border: 1px solid var(--border-2);
  color: var(--text-dim); cursor: pointer;
  width: 24px; height: 24px; padding: 0; border-radius: 4px;
  font-size: 14px; line-height: 1;
}
.table.readings .btn-reset-row:hover {
  background: var(--bg-2); color: var(--text); border-color: var(--accent);
}
.table.readings .cust-link { color: inherit; text-decoration: none; cursor: pointer; }
.table.readings .cust-link:hover { color: var(--accent); text-decoration: underline; }

/* 7 colonne: livello previsto del serbatoio nei giorni dopo la consegna */
.table.readings th.proj-col, .table.readings td.proj-cell {
  width: 42px; text-align: center;
  font-size: 11px; font-variant-numeric: tabular-nums;
}
.table.readings td.proj-cell { color: var(--text-dim); }
.table.readings td.proj-cell.proj-low { color: #fca5a5; font-weight: 700; }
.table.readings .proj-first { border-left: 2px solid var(--border-2); }

/* Intestazioni bloccate: la tabella scorre (in verticale e orizzontale) dentro
   la card, mentre il thead resta fisso in alto grazie a position:sticky (gia'
   su .table th). La card deve avere un'altezza limitata, altrimenti lo sticky
   non ha un contenitore di scroll a cui agganciarsi. */
.readings-table-card {
  overflow: auto;
  max-height: calc(100vh - 300px);
}
.table.readings thead th { z-index: 3; }
.table.readings tr.row-modified td:first-child { border-left: 3px solid var(--accent); }
.table.readings tr.row-saved td:first-child { border-left: 3px solid var(--ok); }

/* Colonne Consumo: "Cons. 2025" e "Cons. estraz." in sola lettura, "Usa" con
   il selettore. La colonna scelta dal selettore viene evidenziata. */
.table.readings td.cons-cell { white-space: nowrap; font-variant-numeric: tabular-nums; }
.table.readings td.cons-2025, .table.readings td.cons-estr {
  color: var(--text-dim); font-size: 11px;
}
.table.readings td.cons-cell.cons-active { color: var(--accent); font-weight: 700; }
/* La cella "Usa": select sopra, input manuale (quando visibile) sotto, in
   colonna. Senza display:block i due controlli scivolano in linea e il manuale
   sborda sulla colonna Consegna consigliata. */
.table.readings td.cons-use { white-space: normal; }
.table.readings select.sel-cons-mode {
  display: block;
  width: 100%; max-width: 100px;
  background: var(--bg); border: 1px solid var(--border-2);
  color: var(--text); padding: 4px 6px; border-radius: 4px;
  font-size: 12px; font-family: inherit;
}
.table.readings select.sel-cons-mode:focus {
  outline: none; border-color: var(--accent);
}
/* Campo consumo manuale: e' sempre un valore impostato a mano -> giallo */
.table.readings input[type=number].inp-cons-manual {
  display: block;
  margin-top: 4px;
  width: 100%; max-width: 100px;
  background: rgba(251, 191, 36, 0.16);
  border-color: var(--warn);
  color: var(--warn);
  font-weight: 600;
}

/* Colonna Consegna consigliata */
.table.readings td.next-cell { white-space: nowrap; }
.next-badge {
  display: inline-block; padding: 2px 7px; border-radius: 4px;
  font-size: 11px; font-weight: 600;
}
.next-badge small { font-weight: 400; opacity: 0.85; }
.next-badge.prio-red    { background: #7f1d1d; color: #fca5a5; }
.next-badge.prio-orange { background: #7c2d12; color: #fdba74; }
.next-badge.prio-yellow { background: #78350f; color: #fcd34d; }
.next-badge.prio-green  { background: #14532d; color: #86efac; }
.next-na { font-size: 11px; color: var(--text-dimmer); }
.next-na.warn { color: var(--warn); }
.flag-badges { display: inline-flex; gap: 4px; margin-left: 6px; }
.flag-badge {
  font-size: 9px; padding: 1px 5px; border-radius: 3px;
  background: var(--bg-2); color: var(--text-dim);
  font-weight: 600;
}
.flag-badge.gen { background: #78350f; color: #fcd34d; }
.flag-badge.no-semi { background: #7f1d1d; color: #fca5a5; }
.flag-badge.three-ax { background: #1e3a8a; color: #93c5fd; }

/* ========== SINTESY IMPORT ========== */
.bookmarklet-drag {
  display: inline-flex; align-items: center; gap: 6px;
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: white; padding: 10px 18px; border-radius: 8px;
  font-weight: 600; text-decoration: none; font-size: 14px;
  cursor: grab; user-select: none;
  border: 1px dashed rgba(255,255,255,0.4);
}
.bookmarklet-drag::before { content: '☆'; font-size: 18px; }
.bookmarklet-drag:hover { background: linear-gradient(135deg, #0369a1, #075985); }
.bookmarklet-drag:active { cursor: grabbing; }

.sintesy-step { margin-bottom: 18px; }
.sintesy-step h3 {
  font-size: 12px; color: var(--accent); margin: 0 0 8px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.sintesy-step p, .sintesy-step ol, .sintesy-step ul {
  margin: 0 0 8px; color: var(--text-dim); line-height: 1.5; font-size: 13px;
}
.sintesy-step ol, .sintesy-step ul { padding-left: 20px; }
.sintesy-step textarea {
  width: 100%; min-height: 100px; background: var(--bg);
  border: 1px solid var(--border-2); border-radius: 6px;
  color: var(--text); font-family: ui-monospace, monospace;
  font-size: 11px; padding: 8px 10px;
}

.analysis-summary {
  display: flex; gap: 16px; margin: 12px 0;
  padding: 10px 12px; background: var(--bg); border-radius: 6px;
  font-size: 13px;
}
.analysis-summary .num { font-size: 20px; font-weight: 700; }
.analysis-summary .ok { color: var(--ok); }
.analysis-summary .warn { color: var(--warn); }
.analysis-summary .err { color: var(--danger); }

.table.analysis th, .table.analysis td {
  font-size: 12px; padding: 6px 8px;
}
.table.analysis tr.match-ok td:first-child { border-left: 3px solid var(--ok); }
.table.analysis tr.match-ambig td:first-child { border-left: 3px solid var(--warn); }
.table.analysis tr.match-none td:first-child { border-left: 3px solid var(--danger); opacity: 0.7; }
.table.analysis select {
  background: var(--bg); border: 1px solid var(--border-2);
  color: var(--text); padding: 4px 6px; border-radius: 4px; font-size: 11px;
  max-width: 220px;
}

/* Messaggi di stato (import) */
.status { padding: 8px 10px; border-radius: 6px; font-size: 12px; line-height: 1.5; }
.status.err { background: rgba(239, 68, 68, 0.12); color: #fca5a5; }

/* Elenco file CSV nella cartella "import ambra" */
.ambra-files {
  display: flex; flex-direction: column; gap: 4px;
  max-height: 180px; overflow-y: auto;
}
.ambra-file {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--bg); border: 1px solid var(--border-2); color: var(--text);
  padding: 7px 10px; border-radius: 6px; cursor: pointer;
  font-size: 12px; font-family: inherit; text-align: left;
}
.ambra-file:hover { border-color: var(--accent); }
.ambra-file.selected { border-color: var(--accent); background: rgba(56, 189, 248, 0.1); }
.ambra-file .fn { font-weight: 600; }
.ambra-file .fd { color: var(--text-dimmer); font-size: 11px; white-space: nowrap; }

.faq summary {
  cursor: pointer; padding: 8px 12px; background: var(--bg);
  border-radius: 6px; font-weight: 500; color: var(--accent);
  font-size: 13px; margin-top: 12px;
}
.faq summary:hover { background: var(--bg-2); }
.faq[open] summary { margin-bottom: 8px; }
.faq-content { padding: 0 12px; font-size: 13px; color: var(--text-dim); line-height: 1.6; }
.faq-content h4 { color: var(--text); margin: 14px 0 4px; font-size: 13px; }
.faq-content p, .faq-content ol, .faq-content ul { margin: 0 0 8px; }
.faq-content ol, .faq-content ul { padding-left: 20px; }
.faq-content code {
  background: var(--bg-2); padding: 1px 5px; border-radius: 3px;
  font-size: 11px; color: var(--warn);
}

/* ========== PLANNING (LAVAGNA OPERATIVA) ========== */
.planning-bar {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 16px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.planning-bar .week-nav {
  display: flex; align-items: center; gap: 4px;
}
.planning-bar .week-nav button {
  background: var(--bg-2); border: 1px solid var(--border-2);
  color: var(--text); padding: 4px 10px; border-radius: 4px;
  cursor: pointer; font-size: 12px;
}
.planning-bar .week-info { font-size: 13px; color: var(--text-dim); }
.planning-bar .week-info strong { color: var(--text); font-size: 14px; }
.planning-bar select {
  background: var(--bg); border: 1px solid var(--border-2);
  color: var(--text); padding: 4px 8px; border-radius: 4px; font-size: 12px;
}

.planning-layout {
  display: grid; grid-template-columns: 260px 1fr;
  gap: 12px; height: calc(100vh - 220px); min-height: 500px;
}
.planning-pool {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 8px; display: flex; flex-direction: column;
  overflow: hidden;
}
.pool-header {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-dim); font-weight: 600;
  display: flex; align-items: center; justify-content: space-between;
}
.pool-list {
  flex: 1; overflow-y: auto; padding: 8px;
  display: flex; flex-direction: column; gap: 6px;
}

.tank-card {
  background: var(--bg); border: 1px solid var(--border-2);
  border-radius: 6px; padding: 8px 10px; cursor: grab;
  border-left: 3px solid var(--border-2); font-size: 12px;
}
.tank-card:hover { background: var(--bg-2); }
.tank-card.dragging { opacity: 0.4; }
.tank-card.priority-red    { border-left-color: var(--danger); }
.tank-card.priority-orange { border-left-color: var(--orange); }
.tank-card.priority-yellow { border-left-color: var(--warn); }
.tank-card.priority-green  { border-left-color: var(--ok); }
.tank-card .cust { font-weight: 600; color: var(--text); }
.tank-card .meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.tank-card .next { font-size: 11px; margin-top: 4px; }
.tank-card .next.urgent { color: var(--danger); font-weight: 600; }
.tank-card.is-planned { opacity: 0.55; }
.tank-card.is-planned:hover { opacity: 0.8; }
.planned-badge {
  display: inline-block; margin-left: 6px; vertical-align: middle;
  background: var(--accent); color: var(--bg);
  font-size: 9px; font-weight: 700; padding: 1px 5px; border-radius: 8px;
}
.pool-divider {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--text-dimmer); font-weight: 600;
  padding: 8px 4px 4px; margin-top: 4px;
  border-top: 1px dashed var(--border-2);
}
.pool-note {
  font-size: 11px; color: var(--text-dimmer); text-align: center;
  padding: 10px 4px;
}

.planning-days {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr);
  gap: 8px; overflow-x: auto; min-height: 100%;
}
.planning-day {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 8px; display: flex; flex-direction: column;
  min-height: 200px;
}
.planning-day.is-holiday { opacity: 0.6; }
.planning-day.is-holiday .day-header { background: var(--bg-2); }
.day-header {
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim);
  display: flex; align-items: center; justify-content: space-between;
}
.day-header strong { color: var(--text); font-size: 13px; }
.day-header .badge.holiday { background: #7f1d1d; color: #fca5a5; font-size: 10px; }
.day-trips { flex: 1; padding: 6px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
/* Rilascio nell'area vuota della colonna = crea un NUOVO giro.
   Mostra un riquadro tratteggiato esplicito cosi' l'azione e' chiara. */
.day-trips.drag-over {
  background: rgba(56,189,248,0.05);
}
.day-trips.drag-over::after {
  content: "Rilascia qui per creare un NUOVO giro";
  display: block; flex: none;
  margin-top: 4px; padding: 14px 8px;
  border: 2px dashed var(--accent); border-radius: 6px;
  text-align: center; font-size: 10px; font-weight: 700;
  letter-spacing: 0.3px; color: var(--accent);
  background: rgba(56,189,248,0.06);
}
.btn-add-trip {
  width: 100%; background: transparent; border: 1px dashed var(--border-2);
  color: var(--text-dim); padding: 6px 8px; border-radius: 6px;
  cursor: pointer; font-size: 11px; margin: 6px;
}
.btn-add-trip:hover { color: var(--accent); border-color: var(--accent); }
.btn-add-trip.drag-over {
  border-style: solid; border-color: var(--accent);
  color: var(--accent); background: rgba(56,189,248,0.12);
}

.trip-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 6px; padding: 6px 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
/* Rilascio SULLA card di un giro = aggiungi la tappa a QUEL giro. */
.trip-card.drag-over {
  outline: 2px solid var(--accent); outline-offset: -1px;
  background: rgba(56,189,248,0.08);
}
.trip-card.drag-over::after {
  content: "+ Aggiungi a QUESTO giro";
  display: block; margin-top: 5px; padding-top: 3px;
  text-align: center; font-size: 10px; font-weight: 700;
  letter-spacing: 0.3px; color: var(--accent);
  border-top: 1px dashed var(--accent);
}
/* Prodotto incompatibile: il giro consegna un gas diverso da quello trascinato. */
.trip-card.drag-invalid {
  outline: 2px solid var(--danger); outline-offset: -1px;
  background: rgba(239,68,68,0.08);
}
.trip-card.drag-invalid::after {
  content: attr(data-invalid-reason, "Non compatibile con questo giro");
  display: block; margin-top: 5px; padding-top: 3px;
  text-align: center; font-size: 10px; font-weight: 700;
  color: var(--danger);
  border-top: 1px dashed var(--danger);
}

/* Chip prodotto: identifica a colpo d'occhio il gas di un giro / serbatoio */
.prod-chip {
  display: inline-block; font-size: 9px; font-weight: 700;
  padding: 1px 5px; border-radius: 3px; letter-spacing: 0.3px;
  background: var(--bg-2); color: var(--text-dim);
  vertical-align: middle; flex: none;
}
.prod-chip[data-p="N2"]  { background: #14304d; color: #7dd3fc; }
.prod-chip[data-p="AR"]  { background: #3d3115; color: #fcd34d; }
.prod-chip[data-p="CO2"] { background: #321d44; color: #d8b4fe; }
.prod-chip[data-p="O2"]  { background: #14402c; color: #86efac; }
.trip-head {
  display: flex; align-items: center; gap: 6px; margin-bottom: 6px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.trip-head select.veh {
  flex: 1; min-width: 0; background: var(--bg-1); border: 1px solid var(--border-2);
  color: var(--text); padding: 2px 6px; border-radius: 4px; font-size: 11px;
}
.trip-head .btn-rm {
  background: transparent; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 12px; padding: 0 4px;
}
.trip-head .btn-rm:hover { color: var(--danger); }

.stop-list { display: flex; flex-direction: column; gap: 3px; min-height: 24px; }
.stop-row {
  display: grid; grid-template-columns: 16px 1fr 64px 16px;
  gap: 4px; align-items: center; padding: 4px 6px;
  background: var(--bg-1); border-radius: 4px; font-size: 11px;
  cursor: grab;
}
.stop-row:hover { background: var(--bg-2); }
.stop-row.dragging { opacity: 0.4; }
.stop-row .seq { color: var(--text-dim); font-family: ui-monospace, monospace; }
.stop-row .cust { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-row input.lt {
  background: var(--bg); border: 1px solid var(--border-2);
  color: var(--text); padding: 2px 4px; border-radius: 3px;
  font-size: 11px; text-align: right; width: 100%;
  font-family: ui-monospace, monospace;
}
.stop-row .btn-rm-stop {
  background: transparent; border: none; color: var(--text-dimmer);
  cursor: pointer; font-size: 12px; padding: 0;
}
.stop-row .btn-rm-stop:hover { color: var(--danger); }

/* Trip head extras: starting liters input */
.trip-head input.start-lt {
  width: 56px; background: var(--bg-1); border: 1px solid var(--border-2);
  color: var(--text); padding: 2px 4px; border-radius: 4px;
  font-size: 11px; text-align: right; font-family: ui-monospace, monospace;
}

/* Depot row inside trip card */
.trip-depot {
  display: flex; align-items: center; gap: 4px;
  padding: 3px 6px; margin: 2px 0;
  background: rgba(56, 189, 248, 0.07);
  border-left: 2px solid var(--accent);
  border-radius: 3px;
  font-size: 10px; color: var(--accent);
  font-weight: 600;
}
.trip-depot .lt { color: var(--text-dim); font-weight: 400; margin-left: auto; }
.trip-depot.is-maint {
  background: rgba(250, 204, 21, 0.08);
  border-left-color: #facc15;
  color: #facc15;
}
.route-stop.depot.is-maint .route-marker {
  background: #3b2a05; color: #facc15; border-color: #a16207;
}
.route-stop.depot.is-maint .route-name { color: #facc15; }
.maint-tag {
  font-size: 9px; font-weight: 700; letter-spacing: 0.3px;
  text-transform: uppercase; opacity: 0.85;
}

/* Stop type variants */
.stop-row.refill {
  background: rgba(56, 189, 248, 0.08);
  border-left: 2px solid var(--accent);
}
.stop-row.refill .seq { color: var(--accent); }
.stop-row.delivery .seq { color: var(--text-dim); }
.stop-row.maintenance {
  background: rgba(250, 204, 21, 0.07);
  border-left: 2px solid #facc15;
}
.stop-row.maintenance .seq { color: #facc15; }
.stop-row.maintenance .lt-placeholder { text-align: center; font-size: 11px; }
.stop-row select.sup,
.stop-row select.mnt {
  background: var(--bg); border: 1px solid var(--border-2);
  color: var(--text); padding: 2px 4px; border-radius: 3px; font-size: 11px;
  font-weight: 500;
  /* il select non si restringe sotto la larghezza dell'opzione piu' lunga:
     min-width:0 lo lascia comprimere nella colonna della griglia, evitando
     che un fornitore con nome lungo sfori i margini del riquadro giro */
  width: 100%; min-width: 0; max-width: 100%;
  text-overflow: ellipsis;
}

/* Lotto del carico (riga sotto la tappa di rifornimento) */
.stop-lotto { padding: 1px 6px 2px 22px; }
.stop-lotto input.lotto {
  background: var(--bg); border: 1px solid var(--border-2);
  color: var(--text); padding: 2px 5px; border-radius: 3px;
  font-size: 10px; width: 100%;
}
.stop-lotto input.lotto::placeholder { color: var(--text-dimmer); }

/* Running cistern level under each stop */
.stop-residue {
  font-size: 10px; color: var(--text-dimmer);
  font-family: ui-monospace, monospace;
  padding: 0 6px 2px 22px;
  display: flex; gap: 6px;
}
.stop-residue.warn { color: var(--warn); }
.stop-residue.err { color: var(--danger); font-weight: 600; }

/* Add refill / maintenance buttons (riga sotto le tappe del giro) */
.trip-add-row { display: flex; gap: 4px; margin-top: 4px; }
.trip-add-row .btn-add-refill { margin-top: 0; }
.btn-add-refill {
  width: 100%; background: rgba(56,189,248,0.08); border: 1px dashed var(--accent);
  color: var(--accent); padding: 3px 6px; border-radius: 4px;
  cursor: pointer; font-size: 10px; margin-top: 4px;
}
.btn-add-refill:hover { background: rgba(56,189,248,0.15); }
.btn-add-maint {
  flex: 0 0 auto; background: rgba(250,204,21,0.07);
  border: 1px dashed #facc15; color: #facc15;
  padding: 3px 8px; border-radius: 4px;
  cursor: pointer; font-size: 10px; white-space: nowrap;
}
.btn-add-maint:hover { background: rgba(250,204,21,0.18); }

/* ===== PLANNING: pannello dettaglio giro ===== */
.trip-card { cursor: pointer; }
.trip-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 2px 10px rgba(0,0,0,0.45);
}

.planning-layout.has-detail {
  grid-template-columns: 260px 1fr 760px;
}
.planning-detail {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 8px; display: none; flex-direction: column;
  overflow: hidden;
}
.planning-layout.has-detail .planning-detail { display: flex; }

.detail-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.detail-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--text);
}
.detail-day {
  font-size: 11px; color: var(--text-dim);
  margin-top: 3px; text-transform: capitalize;
}
.detail-close {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 20px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.detail-close:hover { color: var(--danger); }

.detail-body { flex: 1; overflow-y: auto; padding: 12px; }

.detail-summary {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  margin-bottom: 16px;
}
.detail-summary > div {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 9px;
  font-size: 10px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.3px;
}
.detail-summary > div span {
  display: block; font-size: 15px; font-weight: 700;
  color: var(--text); text-transform: none; letter-spacing: 0;
  margin-bottom: 1px;
}
.detail-summary > div.over span { color: var(--danger); }

.detail-section { margin-bottom: 16px; }
.detail-section h4 {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-dim); font-weight: 600;
  margin: 0 0 8px; padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.detail-field { margin-bottom: 8px; }
.detail-field label {
  display: block; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.4px; color: var(--text-dimmer); margin-bottom: 3px;
}
.detail-field select,
.detail-field input,
.detail-field textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border-2);
  color: var(--text); padding: 6px 8px; border-radius: 4px;
  font-size: 12px; font-family: inherit;
}
.detail-field textarea { resize: vertical; }
.detail-field select:focus,
.detail-field input:focus,
.detail-field textarea:focus { outline: none; border-color: var(--accent); }

/* timeline del percorso */
.route-stop { display: flex; gap: 8px; align-items: flex-start; }
.route-marker {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700;
  background: var(--bg-2); color: var(--text); border: 1px solid var(--border-2);
}
.route-stop.depot .route-marker {
  background: var(--accent); color: var(--bg); border-color: var(--accent);
}
.route-stop.refill .route-marker {
  background: #14304d; color: #7dd3fc; border-color: #1e5a8a;
}
.route-stop.maintenance .route-marker {
  background: #3b2a05; color: #facc15; border-color: #a16207;
}
.route-stop.maintenance .route-name { color: #facc15; }
.route-edit input.mnt-notes {
  background: var(--bg); border: 1px solid var(--border-2);
  color: var(--text); padding: 3px 6px; border-radius: 3px;
  font-size: 11px; flex: 1; min-width: 0;
}
.route-edit input.mnt-notes::placeholder { color: var(--text-dimmer); }
.route-edit select.mnt {
  background: var(--bg); border: 1px solid var(--border-2);
  color: var(--text); padding: 2px 4px; border-radius: 3px;
  font-size: 11px; flex: 1; min-width: 0;
}
.route-info { flex: 1; min-width: 0; padding-bottom: 2px; }
.route-name { font-size: 12px; font-weight: 600; color: var(--text); }
.route-name a { text-decoration: none; font-size: 12px; }
.route-sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.route-leg {
  font-size: 10px; color: var(--text-dimmer);
  font-family: ui-monospace, monospace;
  padding: 2px 0 2px 30px;
}
.route-badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.con-badge {
  font-size: 9px; padding: 1px 5px; border-radius: 3px;
  background: var(--bg-2); color: var(--text-dim); font-weight: 600;
}
.con-badge.warn { background: #7c2d12; color: #fdba74; }
.route-edit {
  display: flex; align-items: center; gap: 4px; margin-top: 5px;
}
.route-edit .reorder {
  flex: none; background: var(--bg-2); border: 1px solid var(--border-2);
  color: var(--text-dim); cursor: pointer; border-radius: 3px;
  font-size: 9px; line-height: 1; padding: 4px 5px;
}
.route-edit .reorder:hover:not(:disabled) {
  color: var(--accent); border-color: var(--accent);
}
.route-edit .reorder:disabled { opacity: 0.3; cursor: not-allowed; }
.route-edit input.lt {
  width: 68px; background: var(--bg); border: 1px solid var(--border-2);
  color: var(--text); padding: 3px 5px; border-radius: 3px;
  font-size: 11px; text-align: right; font-family: ui-monospace, monospace;
}
.route-edit select.sup {
  flex: 1; min-width: 0; background: var(--bg);
  border: 1px solid var(--border-2); color: var(--text);
  padding: 3px 5px; border-radius: 3px; font-size: 11px;
}
.route-edit input.lotto {
  flex: 1; min-width: 0; background: var(--bg);
  border: 1px solid var(--border-2); color: var(--text);
  padding: 3px 5px; border-radius: 3px; font-size: 11px;
}
.route-edit .btn-rm-stop {
  background: transparent; border: none; color: var(--text-dimmer);
  cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px;
  margin-left: auto;
}
.route-edit .btn-rm-stop:hover { color: var(--danger); }
.route-residue {
  font-size: 10px; color: var(--text-dimmer);
  font-family: ui-monospace, monospace; margin-top: 4px;
}
.route-residue.warn { color: var(--warn); }
.route-residue.err { color: var(--danger); font-weight: 600; }

/* ===== Riordino tappe: indicatore di rilascio drag & drop ===== */
/* Linea accesa che mostra dove la tappa trascinata verra' inserita. */
.stop-row.drop-before  { box-shadow: inset 0 3px 0 var(--accent); }
.stop-row.drop-after   { box-shadow: inset 0 -3px 0 var(--accent); }
.route-stop.drop-before { box-shadow: inset 0 3px 0 var(--accent); }
.route-stop.drop-after  { box-shadow: inset 0 -3px 0 var(--accent); }
.route-stop.dragging { opacity: 0.4; }
/* Il numero della tappa nel dettaglio fa da maniglia di trascinamento. */
.route-marker.drag-handle { cursor: grab; }
.route-marker.drag-handle:active { cursor: grabbing; }

.detail-actions { display: flex; flex-direction: column; gap: 6px; }
.detail-actions .d-add-refill { margin-top: 0; }
.detail-del {
  width: 100%; background: transparent; border: 1px solid var(--danger);
  color: var(--danger); padding: 6px; border-radius: 6px;
  cursor: pointer; font-size: 11px;
}
.detail-del:hover { background: var(--danger); color: white; }

/* mini-mappa del percorso */
.minimap {
  /* sticky: la mappa resta in primo piano in cima al pannello dettaglio
     mentre il resto delle informazioni scorre dietro. position:sticky
     fa comunque da contenitore per i tile/SVG posizionati in absolute. */
  position: sticky; top: 0; z-index: 5;
  width: 100%; height: 380px;
  border: 1px solid var(--border); border-radius: 6px;
  overflow: hidden; background: #1a2535; margin-bottom: 8px;
}
.minimap-tile {
  position: absolute; width: 256px; height: 256px;
  user-select: none; -webkit-user-drag: none;
}
.minimap-svg { position: absolute; left: 0; top: 0; pointer-events: none; }
.minimap-attr {
  position: absolute; right: 0; bottom: 0;
  background: rgba(15,23,42,0.72); color: var(--text-dim);
  font-size: 9px; padding: 1px 5px; border-top-left-radius: 4px;
}
.minimap-empty {
  position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center; text-align: center;
  color: var(--text-dimmer); font-size: 11px; line-height: 1.6;
}
.minimap-gmaps {
  display: block; text-align: center; margin-bottom: 14px;
  font-size: 11px; color: var(--accent); text-decoration: none;
  padding: 5px; border: 1px solid var(--border-2); border-radius: 4px;
}
.minimap-gmaps:hover { background: var(--bg-2); border-color: var(--accent); }

/* ========== BADGES ========== */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600;
}
.badge.ok { background: #14532d; color: #86efac; }
.badge.warn { background: #78350f; color: #fcd34d; }
.badge.err { background: #7f1d1d; color: #fca5a5; }
.badge.info { background: #1e3a8a; color: #93c5fd; }
.badge.neutral { background: var(--bg-2); color: var(--text-dim); }

/* ========== ROLE SELECT (pagina Utenze) ========== */
.role-select {
  border: 1px solid transparent; border-radius: 10px;
  padding: 3px 22px 3px 10px; font-size: 11px; font-weight: 700;
  font-family: inherit; cursor: pointer;
  text-transform: uppercase; letter-spacing: 0.4px;
  appearance: none; -webkit-appearance: none;
  background-repeat: no-repeat;
  background-position: calc(100% - 8px) 55%, calc(100% - 4px) 55%;
  background-size: 4px 4px, 4px 4px;
}
.role-select:focus { outline: none; filter: brightness(1.1); }
.role-select:disabled { opacity: 0.55; cursor: not-allowed; }
.role-select option { background: var(--bg-1); color: var(--text); font-weight: 500; }

.role-select.role-admin {
  background-color: #7f1d1d; color: #fecaca; border-color: #b91c1c;
  background-image: linear-gradient(45deg, transparent 50%, #fecaca 50%),
                    linear-gradient(135deg, #fecaca 50%, transparent 50%);
}
.role-select.role-advisor {
  background-color: #1e3a8a; color: #bfdbfe; border-color: #2563eb;
  background-image: linear-gradient(45deg, transparent 50%, #bfdbfe 50%),
                    linear-gradient(135deg, #bfdbfe 50%, transparent 50%);
}
.role-select.role-operatore {
  background-color: #14532d; color: #bbf7d0; border-color: #16a34a;
  background-image: linear-gradient(45deg, transparent 50%, #bbf7d0 50%),
                    linear-gradient(135deg, #bbf7d0 50%, transparent 50%);
}

/* ========== MODAL ========== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  z-index: 150; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 10px; width: 100%; max-width: 720px;
  max-height: 90vh; display: flex; flex-direction: column;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 16px; color: var(--accent); }
.modal-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 22px; cursor: pointer; padding: 0 8px; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body {
  padding: 20px; overflow-y: auto; flex: 1;
}
.modal-footer {
  padding: 12px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ========== FORM ========== */
.form-section {
  margin-bottom: 20px;
}
.form-section h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--warn); margin: 0 0 10px; font-weight: 600;
}
.form-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}
.form-grid .full { grid-column: 1 / -1; }

.form-row { display: flex; flex-direction: column; gap: 4px; }
.form-row label {
  font-size: 11px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500;
}
.form-row label .req { color: var(--danger); margin-left: 2px; }
.form-row input[type=text],
.form-row input[type=number],
.form-row input[type=date],
.form-row select,
.form-row textarea {
  background: var(--bg); border: 1px solid var(--border-2);
  color: var(--text); padding: 8px 10px; border-radius: 6px;
  font-size: 13px; font-family: inherit;
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: none; border-color: var(--accent);
}
.form-row input[readonly] {
  background: #0b1220; color: var(--text-dim); cursor: not-allowed;
}
.form-row textarea { min-height: 60px; resize: vertical; }
.form-row .hint { font-size: 11px; color: var(--text-dimmer); }
.form-row.checkbox {
  flex-direction: row; align-items: center; gap: 8px;
}
.form-row.checkbox label {
  text-transform: none; letter-spacing: normal;
  font-size: 13px; color: var(--text);
}

/* ========== SUB-LIST (events, compartments) ========== */
.sublist {
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); margin-bottom: 8px;
}
.sublist-row {
  display: grid; gap: 8px;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  align-items: center; font-size: 13px;
}
.sublist-row:last-child { border-bottom: none; }
.sublist-row .btn-rm {
  background: transparent; border: 1px solid var(--border-2);
  color: var(--text-dim); padding: 4px 8px; border-radius: 4px;
  cursor: pointer; font-size: 11px;
}
.sublist-row .btn-rm:hover { color: var(--danger); border-color: var(--danger); }
.sublist-empty { padding: 12px; text-align: center; color: var(--text-dimmer); font-size: 12px; }

/* ========== ACCESS SCHEDULE MATRIX ========== */
#accessScheduleMatrix { overflow-x: auto; }

.schedule-table {
  border-collapse: collapse;
  user-select: none;
  width: 100%;
  table-layout: fixed;
}
.schedule-table th {
  padding: 7px 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--bg-1);
  border: 1px solid var(--border);
  text-align: center;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.schedule-table th.day-weekend { color: var(--warn); }
.schedule-table .slot-label-col { width: 52px; }

.slot-label {
  padding: 0 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dimmer);
  background: var(--bg-1);
  border: 1px solid var(--border);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  letter-spacing: -0.2px;
}

.slot-cell {
  height: 24px;
  cursor: pointer;
  background: var(--bg);
  border: 1px solid var(--border);
  transition: background 0.08s, border-color 0.08s;
}
.slot-cell:hover          { background: var(--bg-2); }
.slot-cell.active         { background: rgba(56,189,248,0.28); border-color: rgba(56,189,248,0.5); }
.slot-cell.active:hover   { background: rgba(56,189,248,0.40); }
.slot-cell.weekend        { background: rgba(11,18,32,0.7); }
.slot-cell.weekend.active { background: rgba(251,191,36,0.28); border-color: rgba(251,191,36,0.5); }
.slot-cell.weekend.active:hover { background: rgba(251,191,36,0.40); }

.slot-extreme .slot-label { color: #3b4a60; height: 18px; }
.slot-extreme .slot-cell  { height: 18px; background: #0b1220; }
.slot-extreme .slot-cell.active { background: rgba(56,189,248,0.15); border-color: rgba(56,189,248,0.3); }
.slot-extreme .slot-cell.weekend { background: #080e1a; }
.slot-extreme .slot-cell.weekend.active { background: rgba(251,191,36,0.15); }

.slot-boundary td { border-top: 2px solid var(--border-2) !important; }

/* ========== TOASTS ========== */
.toasts {
  position: fixed; bottom: 16px; right: 16px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--bg-1); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: 6px;
  font-size: 13px; min-width: 240px;
  animation: slideIn 0.2s ease-out;
}
.toast.ok { border-left: 3px solid var(--ok); }
.toast.err { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Chip generatore (sulla cisterna: verde elettrico, simile al prod-chip) */
.gen-chip {
  display: inline-block; font-size: 9px; font-weight: 700;
  padding: 1px 5px; border-radius: 3px; letter-spacing: 0.3px;
  background: #1a3a1a; color: #4ade80;
  vertical-align: middle; flex: none;
}

/* ========== MEZZI: selettore motrice nella card giro ========== */
.trip-motrice {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 4px; padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.trip-motrice .mot-label {
  font-size: 10px; color: var(--text-dimmer); white-space: nowrap; flex: none;
}
.trip-motrice select.mot {
  flex: 1; min-width: 0; background: var(--bg-1); border: 1px solid var(--border-2);
  color: var(--text); padding: 2px 6px; border-radius: 4px; font-size: 11px;
}

/* Alert nella card giro (badge compatti, uno per riga) */
.trip-alerts {
  display: flex; flex-direction: column; gap: 2px; margin-bottom: 4px;
}
.trip-alerts .badge {
  display: block; font-size: 10px; border-radius: 3px;
  padding: 2px 6px; line-height: 1.4; white-space: normal;
}

/* Alert nel pannello dettaglio (più spaziosi) */
.detail-alerts {
  display: flex; flex-direction: column; gap: 4px;
  margin: 0 0 12px;
}
.detail-alert {
  padding: 6px 10px; border-radius: 5px; font-size: 12px; line-height: 1.4;
}
.detail-alert.err  { background: rgba(127,29,29,0.45); color: #fca5a5; border: 1px solid rgba(239,68,68,0.3); }
.detail-alert.warn { background: rgba(120,53,15,0.45); color: #fcd34d; border: 1px solid rgba(251,191,36,0.3); }

/* ============================================================
   KPI PAGE
   ============================================================ */

/* Toolbar: pillole periodo + filtri tradizionali */
.kpi-toolbar {
  display: flex; flex-direction: row; align-items: center;
  gap: 16px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.kpi-toolbar .filter-bar { margin-bottom: 0; }
.kpi-quick {
  display: flex; gap: 6px; flex-wrap: wrap;
}

/* Sottotitolo sotto card-title */
.card-sub {
  font-size: 11px; color: var(--text-dimmer);
  margin-top: 2px;
}

/* Tile KPI con icona laterale e tono colorato (sopra le definizioni di .kpi) */
.kpi-grid--lg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 8px; margin-bottom: 18px;
  overflow-x: auto;          /* scroll orizzontale su schermi molto stretti */
}
/* Tile compatti per stare tutti su una sola riga */
.kpi-grid--lg .kpi-tile { padding: 10px; gap: 8px; min-width: 0; }
.kpi-grid--lg .kpi-tile .kpi-icon { width: 28px; height: 28px; font-size: 13px; border-radius: 6px; }
.kpi-grid--lg .kpi-tile .kpi-label,
.kpi-grid--lg .kpi-tile .kpi-sub {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi-grid--lg .kpi-tile .kpi-value { font-size: 17px; }
.kpi-tile {
  display: flex; align-items: stretch; gap: 12px;
  padding: 14px; position: relative; overflow: hidden;
  transition: transform 0.12s, border-color 0.12s;
}
.kpi-tile::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--accent);
}
.kpi-tile:hover { transform: translateY(-1px); border-color: var(--border-2); }
.kpi-tile .kpi-icon {
  flex: none; width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(56, 189, 248, 0.12); color: var(--accent);
  font-size: 16px; font-weight: 700;
  font-family: ui-monospace, monospace;
}
.kpi-tile .kpi-body { flex: 1; min-width: 0; }
.kpi-tile .kpi-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--text-dim); margin-bottom: 4px;
}
.kpi-tile .kpi-value {
  font-size: 22px; font-weight: 700; color: var(--text);
  line-height: 1.1; margin-bottom: 3px;
  font-variant-numeric: tabular-nums;
}
.kpi-tile .kpi-sub { font-size: 11px; color: var(--text-dimmer); }

/* Toni colorati per il bordo + icona dei tile */
.kpi-tone-accent::before { background: var(--accent); }
.kpi-tone-accent .kpi-icon { background: rgba(56,189,248,0.14); color: var(--accent); }
.kpi-tone-green::before  { background: var(--ok); }
.kpi-tone-green .kpi-icon  { background: rgba(34,197,94,0.14); color: var(--ok); }
.kpi-tone-orange::before { background: var(--orange); }
.kpi-tone-orange .kpi-icon { background: rgba(249,115,22,0.14); color: var(--orange); }
.kpi-tone-cyan::before   { background: #67e8f9; }
.kpi-tone-cyan .kpi-icon   { background: rgba(103,232,249,0.14); color: #67e8f9; }
.kpi-tone-warn::before   { background: var(--warn); }
.kpi-tone-warn .kpi-icon   { background: rgba(251,191,36,0.14); color: var(--warn); }
.kpi-tone-danger::before { background: var(--danger); }
.kpi-tone-danger .kpi-icon { background: rgba(239,68,68,0.14); color: var(--danger); }

/* Layout a due colonne (grafico + side card) */
.kpi-row-two {
  display: grid; grid-template-columns: 2fr 1fr;
  gap: 14px; margin-bottom: 14px;
}
@media (max-width: 1100px) {
  .kpi-row-two { grid-template-columns: 1fr; }
}

.kpi-chart-card { padding: 14px 16px; }
.kpi-chart {
  position: relative;
  width: 100%; height: 240px;
  margin-top: 4px;
}
.kpi-chart-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.kpi-chart-empty {
  padding: 40px 16px; text-align: center;
  color: var(--text-dimmer); font-size: 12px;
}

/* Grid + assi del bar chart */
.kpi-chart-svg .chart-grid { stroke: var(--border); opacity: 0.55; }
.kpi-chart-svg .chart-axis { stroke: var(--border-2); opacity: 0.8; }
.kpi-chart-svg .chart-tick {
  font-size: 10px; fill: var(--text-dimmer);
  font-family: ui-monospace, "SF Mono", monospace;
}
.kpi-chart-svg .chart-ylabel {
  font-size: 10px; fill: var(--text-dim); font-weight: 600;
  letter-spacing: 0.5px;
}
.kpi-chart-svg .chart-xtick {
  font-size: 10px; fill: var(--text-dimmer);
}

/* Linea media + marker "oggi" */
.kpi-chart-svg .chart-avg line { stroke: var(--orange); opacity: 0.7; }
.kpi-chart-svg .chart-avg-label {
  font-size: 9px; fill: var(--orange); font-weight: 600;
}
.kpi-chart-svg .chart-today line {
  stroke: var(--warn); opacity: 0.85; stroke-width: 1.2;
}
.kpi-chart-svg .chart-today-label {
  font-size: 9px; fill: var(--warn); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
}

/* Media mobile: area + linea */
.kpi-chart-svg .chart-trend {
  fill: none; stroke: #fbbf24; stroke-width: 1.6;
  stroke-linejoin: round; stroke-linecap: round;
  filter: drop-shadow(0 1px 2px rgba(251,191,36,0.25));
}
.kpi-chart-svg .chart-trend-area { fill: url(#kpiTrendArea); }

/* Barre */
.kpi-chart-svg .chart-bar .bar-fill {
  fill: url(#kpiBarGrad);
  transition: filter 0.12s, opacity 0.12s;
}
.kpi-chart-svg .chart-bar.is-weekend .bar-fill { fill: url(#kpiBarGradWE); opacity: 0.85; }
.kpi-chart-svg .chart-bar.is-today   .bar-fill { fill: url(#kpiBarGradTd); }
/* Barra "scaricato" affiancata: usa sempre il gradiente verde, anche su weekend/oggi. */
.kpi-chart-svg .chart-bar .bar-fill-del,
.kpi-chart-svg .chart-bar.is-weekend .bar-fill-del,
.kpi-chart-svg .chart-bar.is-today   .bar-fill-del { fill: url(#kpiBarGradDel); opacity: 1; }
.kpi-chart-svg .chart-bar:hover .bar-fill,
.kpi-chart-svg .chart-bar.is-hovered .bar-fill {
  filter: brightness(1.18) drop-shadow(0 2px 4px rgba(56,189,248,0.35));
}
.kpi-chart-svg .chart-bar.is-faded .bar-fill { opacity: 0.32; }
.kpi-chart-svg .chart-bar { cursor: default; }

/* Tooltip HTML sopra il chart */
.chart-tip {
  position: absolute; pointer-events: none;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid var(--border-2);
  border-radius: 6px; padding: 8px 10px;
  font-size: 12px; color: var(--text);
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
  min-width: 140px; max-width: 220px;
  z-index: 4;
  backdrop-filter: blur(4px);
}
.chart-tip .tip-day {
  font-size: 11px; font-weight: 600; color: var(--text);
  text-transform: capitalize; margin-bottom: 4px;
  padding-bottom: 4px; border-bottom: 1px solid var(--border);
}
.chart-tip .tip-row {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text); margin-top: 2px;
}
.chart-tip .tip-sub { color: var(--text-dim); font-size: 11px; }
.chart-tip .dot {
  width: 8px; height: 8px; border-radius: 2px;
  display: inline-block; flex: none;
}
.tip-dot-bar   { background: linear-gradient(180deg, #7dd3fc, #0284c7); }
.tip-dot-del   { background: linear-gradient(180deg, #86efac, #16a34a); }
.tip-dot-we    { background: linear-gradient(180deg, #a5b4fc, #4f46e5); }
.tip-dot-td    { background: linear-gradient(180deg, #fde68a, #f59e0b); }
.tip-dot-trend { background: #fbbf24; border-radius: 50%; }

/* Legenda sotto al chart */
.chart-legend {
  display: flex; flex-wrap: wrap; gap: 12px 18px;
  margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: 11px; color: var(--text-dim);
}
.chart-legend > span {
  display: inline-flex; align-items: center; gap: 6px;
}

/* Card laterali con top list */
.kpi-side-card { padding: 14px 16px; }
.top-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 10px;
}
.top-row { display: flex; flex-direction: column; gap: 3px; }
.top-row-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.top-name {
  font-size: 13px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.top-value {
  font-size: 12px; color: var(--text-dim);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.top-bar {
  height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden;
  border: 1px solid var(--border);
}
.top-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #7dd3fc, #0284c7);
  border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18);
  transition: width 0.35s ease;
}
.top-row:hover .top-bar-fill { filter: brightness(1.12); }
.top-bar-fill.alt {
  background: linear-gradient(90deg, #86efac, #22c55e);
}
.top-row-meta {
  font-size: 10px; color: var(--text-dimmer);
  font-family: ui-monospace, monospace;
}
.top-empty {
  padding: 24px 8px; text-align: center;
  color: var(--text-dimmer); font-size: 11px;
}

/* ===== Donut Mix prodotto ===== */
.donut-wrap {
  display: flex; align-items: center; gap: 16px;
  padding: 4px 0;
}
.donut-svg { flex: none; }
.donut-svg .donut-slice {
  transition: transform 0.15s, filter 0.15s, opacity 0.15s;
  transform-origin: 50% 50%;
  cursor: default;
}
.donut-svg .donut-slice:hover {
  filter: brightness(1.15) drop-shadow(0 2px 6px rgba(0,0,0,0.4));
  transform: scale(1.025);
}
.donut-svg:hover .donut-slice:not(:hover) { opacity: 0.55; }
.donut-svg .donut-label {
  font-size: 9px; fill: var(--text-dimmer);
  letter-spacing: 0.8px; font-weight: 600;
}
.donut-svg .donut-value {
  font-size: 18px; fill: var(--text); font-weight: 700;
  font-family: ui-monospace, monospace;
}
.donut-svg .donut-unit {
  font-size: 9px; fill: var(--text-dim); letter-spacing: 0.3px;
}
.donut-legend {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 8px;
  flex: 1; min-width: 0;
}
.donut-legend li {
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 12px;
}
.donut-legend .legend-swatch {
  flex: none; width: 10px; height: 10px; border-radius: 2px;
  margin-top: 4px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08) inset;
}
.donut-legend .legend-text { min-width: 0; flex: 1; }
.donut-legend .legend-name {
  display: flex; align-items: center; gap: 6px;
  color: var(--text); font-weight: 600; font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.donut-legend .legend-sub {
  font-size: 11px; color: var(--text-dim);
  font-family: ui-monospace, monospace; margin-top: 1px;
}
@media (max-width: 520px) {
  .donut-wrap { flex-direction: column; align-items: stretch; }
  .donut-svg { align-self: center; }
}

/* Tabella dettaglio: righe cliccabili con chevron */
.kpi-table tbody tr.trip-row { cursor: pointer; }
.kpi-table tbody tr.trip-row:hover { background: rgba(56, 189, 248, 0.10); }
.kpi-table td.row-chevron {
  text-align: center; color: var(--text-dimmer);
  font-size: 18px; font-weight: 700; width: 24px;
}
.kpi-table tbody tr.trip-row:hover td.row-chevron { color: var(--accent); }

/* ============================================================
   MODALE GENERICA + DETTAGLIO VIAGGIO
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(2, 6, 23, 0.72);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fadeIn 0.15s ease-out;
}
.modal-card {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  width: 100%; max-width: 960px; max-height: 90vh;
  display: flex; flex-direction: column;
  animation: slideUp 0.18s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 14px 18px;
  background: var(--bg-2); border-bottom: 1px solid var(--border);
  border-radius: 10px 10px 0 0;
}
.modal-head-main { min-width: 0; flex: 1; }
.modal-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 16px; font-weight: 600; color: var(--text);
}
.modal-sub {
  font-size: 12px; color: var(--text-dim); margin-top: 4px;
}
.modal-close {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 28px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.modal-close:hover { color: var(--danger); }

.modal-body { flex: 1; overflow-y: auto; padding: 16px 18px; }
.modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 12px 18px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
}
.modal-foot-info { margin-right: auto; color: var(--text-dimmer); font-size: 12px; }

/* Layout a due colonne nel modale dettaglio viaggio */
.trip-modal-body {
  display: grid; grid-template-columns: 1.2fr 1fr;
  gap: 18px;
}
@media (max-width: 820px) {
  .trip-modal-body { grid-template-columns: 1fr; }
}
.trip-modal-left .minimap {
  /* override del position:sticky globale: nella modale non serve, ma il
     container deve restare "positioned" (relative) perché i tile e l'SVG
     della mini-mappa sono assoluti e si appoggiano a lui. */
  position: relative; top: auto;
  height: 320px; margin-bottom: 10px;
}
.trip-modal-summary {
  grid-template-columns: repeat(2, 1fr);
}
.trip-modal-right .route {
  display: flex; flex-direction: column; gap: 10px;
}
.trip-modal-right .route-stop {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px;
}
.trip-modal-right .route-stop.depot {
  background: rgba(56, 189, 248, 0.06);
  border-color: rgba(56, 189, 248, 0.3);
}
.trip-modal-right .route-stop.refill {
  background: rgba(125, 211, 252, 0.06);
  border-color: rgba(30, 90, 138, 0.4);
}
.route-qty {
  float: right;
  background: var(--bg-2); color: var(--text);
  padding: 1px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 700;
  font-family: ui-monospace, monospace;
}
.route-qty.refill { background: #14304d; color: #7dd3fc; }
.modal-notes {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 12px;
  font-size: 13px; color: var(--text-dim); line-height: 1.5;
  white-space: pre-wrap;
}
