:root{
  --bg:            #f4f6f9;
  --panel:         #ffffff;
  --panel-2:       #f0f2f6;
  --panel-3:       #e4e8ee;
  --border:        #dde2e9;
  --border-soft:   #e8ebf0;
  --text:          #1c2733;
  --text-muted:    #6b7684;
  --text-dim:      #94a0ae;
  --accent:        #0f9c92;
  --accent-soft:   rgba(15,156,146,.12);
  --amber:         #b9790a;
  --amber-soft:    rgba(185,121,10,.12);
  --danger:        #d63a2f;
  --danger-soft:   rgba(214,58,47,.12);
  --danger-text:   #b3261e;
  --select:        rgba(63,127,224,.35);
  --radius:        8px;
  --grid-zoom:     1;
  --font-display:  'Space Grotesk', 'Inter', sans-serif;
  --font-body:     'Inter', -apple-system, sans-serif;
  --font-mono:     'JetBrains Mono', ui-monospace, monospace;
}

/* ── Tema scuro ──────────────────────────────────────────────── */
html[data-theme="dark"]{
  --bg:            #10151c;
  --panel:         #171f29;
  --panel-2:       #1d2733;
  --panel-3:       #26313f;
  --border:        #2b3644;
  --border-soft:   #232d3a;
  --text:          #e7edf5;
  --text-muted:    #9aa8ba;
  --text-dim:      #6b7b8e;
  --accent:        #17b8ac;
  --accent-soft:   rgba(23,184,172,.16);
  --amber:         #e0a83a;
  --amber-soft:    rgba(224,168,58,.14);
  --danger:        #ef5b4e;
  --danger-soft:   rgba(239,91,78,.16);
  --danger-text:   #ff8579;
  --select:        rgba(96,165,250,.4);
}
html[data-theme="dark"] body{ background: var(--bg); }
html[data-theme="dark"] .topbar{ background: var(--panel); border-color: var(--border); }
html[data-theme="dark"] .btn{ background: var(--panel-2); color: var(--text); border-color: var(--border); }
html[data-theme="dark"] .btn:hover{ background: var(--panel-3); }
html[data-theme="dark"] .search-input{ background: var(--panel-2); color: var(--text); border-color: var(--border); }
html[data-theme="dark"] .grid-scroll{ background: var(--panel); border-color: var(--border); }
html[data-theme="dark"] .grid thead th{ background: #1a2330; color: var(--text-muted); }
html[data-theme="dark"] .grid thead th.col-name{ background: #1a2330; }
html[data-theme="dark"] .grid thead th.col-hd{ background: linear-gradient(180deg, #3a2e12, #33280e); color: #f0c766; }
html[data-theme="dark"] .grid tbody td.col-name{ background: #141b24; }
html[data-theme="dark"] .grid tbody tr:hover td.col-name{ background: #1c2632; }
html[data-theme="dark"] .th-sortable:hover{ background:#212c3a; }
html[data-theme="dark"] .modal{ background: var(--panel); border-color: var(--border); }
html[data-theme="dark"] .modal-header, html[data-theme="dark"] .modal-footer{ border-color: var(--border); }
html[data-theme="dark"] .field input, html[data-theme="dark"] .field select{ background: var(--panel-2); color: var(--text); border-color: var(--border); }
html[data-theme="dark"] .date-picker{ background: var(--panel-2); border-color: var(--border); color: var(--text); }
html[data-theme="dark"] .report-line{ background: var(--panel-2); }
html[data-theme="dark"] .cell-state-old{ background: rgba(239,91,78,.16); }
html[data-theme="dark"] .cell-state-empty{
  background: repeating-linear-gradient(-45deg, rgba(154,168,186,.06), rgba(154,168,186,.06) 4px, transparent 4px, transparent 9px);
}
html[data-theme="dark"] .brand-mark{ background: var(--amber-soft); }
html[data-theme="dark"] .checklist{ border-color: var(--border); }
html[data-theme="dark"] .warning-modal .modal-header{ background: linear-gradient(180deg, #3a1a17, #341614); }

/* ── Densità righe ───────────────────────────────────────────── */
:root{ --row-py: 9px; --row-fs: 12.5px; --dot-size: 16px; --th-py: 10px; }
html[data-density="compact"]{ --row-py: 2px; --row-fs: 11px; --dot-size: 13px; --th-py: 6px; }
html[data-density="comfortable"]{ --row-py: 16px; --row-fs: 13.5px; --dot-size: 18px; --th-py: 14px; }
.cell-input{ padding-top: var(--row-py); padding-bottom: var(--row-py); font-size: var(--row-fs); }
.cell-chip{ height: calc(var(--row-py) * 2 + 16px); padding-top: 0; padding-bottom: 0; }
.grid tbody td.col-name{ padding-top: var(--row-py); padding-bottom: var(--row-py); font-size: calc(var(--row-fs) + 0.5px); }
html[data-density="compact"] .grid tbody td.col-name{ padding-top: 0; padding-bottom: 0; height: 22px; }
.grid thead th{ padding-top: var(--th-py); padding-bottom: var(--th-py); }
.dot{ width: var(--dot-size); height: var(--dot-size); }

/* Selettore densità: gruppo di pulsanti segmentati dentro il menu Aspetto */
.density-toggle{ display:flex; gap:4px; padding: 2px; background: var(--panel-2); border-radius:7px; }
.density-btn{
  flex:1; font-family: var(--font-body); font-size:12px; font-weight:600;
  color: var(--text-muted); background:transparent; border:none; border-radius:5px;
  padding:6px 8px; cursor:pointer; transition: background .12s, color .12s;
}
.density-btn:hover{ background: var(--panel-3); color: var(--text); }
.density-btn.active{ background: var(--accent); color:#fff; }

*{ box-sizing: border-box; }
html,body{ height:100%; margin:0; }
body{
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
  transition: background .2s ease, color .2s ease;
}
#app{ height:100vh; display:flex; flex-direction:column; }

::-webkit-scrollbar{ width:11px; height:11px; }
::-webkit-scrollbar-track{ background: var(--panel-2); }
::-webkit-scrollbar-thumb{ background: #c7cedb; border-radius: 8px; border: 2px solid var(--panel-2); }
::-webkit-scrollbar-thumb:hover{ background:#b3bdcd; }

/* ── Top bar ─────────────────────────────────────────────────── */
.topbar{
  display:flex; align-items:center; gap:22px;
  padding: 9px 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  flex-shrink:0;
  flex-wrap: wrap;
  row-gap: 8px;
}
.brand{ display:flex; align-items:center; gap:10px; }
.brand-mark{
  color: var(--amber);
  display:flex; align-items:center; justify-content:center;
  width:36px; height:36px; border-radius:50%;
  background: var(--amber-soft);
  border: 1px solid rgba(185,121,10,.3);
}
.brand-text{ display:flex; flex-direction:column; line-height:1.15; }
.brand-title{ font-family: var(--font-display); font-weight:700; font-size:19px; letter-spacing:.02em; }
.brand-sub{ font-size:11px; color: var(--text-muted); letter-spacing:.02em; }

.toolbar{ display:flex; align-items:center; gap:8px; margin-left: 14px; }
.tool-group{ display:flex; flex-direction:column; gap:4px; }
.tool-label{ font-size:10px; text-transform:uppercase; letter-spacing:.08em; color: var(--text-dim); }
.tool-row{ display:flex; gap:6px; align-items:center; }
.tool-sep{ width:1px; height:26px; background: var(--border); margin: 0 2px; }
.tool-icons{ display:flex; gap:6px; align-items:center; }
.tool-search{ display:flex; gap:6px; align-items:center; }

.btn-icon{ padding:7px 9px; line-height:1; }

/* ── Menu a tendina (Aggiungi / Aspetto) ────────────────────────
   Raggruppano azioni usate meno spesso in un pannello, per tenere
   la barra sempre su una sola riga compatta. */
.menu{ position:relative; }
.menu-trigger{ display:flex; align-items:center; gap:4px; }
.menu-caret{ font-style:normal; font-size:9px; opacity:.7; }
.menu-trigger.menu-open{ background: var(--panel-2); border-color:#c7cedb; }
.menu-panel{
  position:absolute; top: calc(100% + 6px); left:0; z-index:30;
  min-width:190px; background: var(--panel);
  border:1px solid var(--border); border-radius:9px;
  box-shadow: 0 12px 28px rgba(28,39,51,.16);
  padding:6px; display:flex; flex-direction:column; gap:2px;
}
.menu-panel.hidden{ display:none; }
.menu-panel-wide{ min-width:260px; }
.menu-item{
  display:block; width:100%; text-align:left;
  font-family: var(--font-body); font-size:12.5px; font-weight:600;
  color: var(--text); background:transparent; border:none; border-radius:6px;
  padding:8px 10px; cursor:pointer; transition: background .12s;
}
.menu-item:hover{ background: var(--panel-2); }
.menu-item-danger{ color: var(--danger-text); }
.menu-item-danger:hover{ background: var(--danger-soft); }
.menu-sep{ height:1px; background: var(--border-soft); margin:5px 2px; }
.menu-section-label{ font-size:10px; text-transform:uppercase; letter-spacing:.07em; color: var(--text-dim); padding: 4px 8px 2px; }
.menu-zoom-row{ padding: 2px 6px 4px; }
html[data-theme="dark"] .menu-panel{ background: var(--panel); border-color: var(--border); box-shadow: 0 12px 28px rgba(0,0,0,.4); }

.zoom-row{ gap:8px; }
.zoom-slider{
  width:110px; height:4px; accent-color: var(--accent, #0f9c92);
  cursor:pointer;
}
.zoom-value{
  font-family: var(--font-mono); font-size:11.5px; color: var(--text-muted);
  min-width:38px; text-align:right;
}
#zoom-out, #zoom-in{ padding:4px 10px; font-weight:700; line-height:1; }

.btn{
  font-family: var(--font-body);
  font-size:12.5px; font-weight:600;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
  cursor:pointer;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover{ background: var(--panel-2); border-color:#c7cedb; }
.btn:active{ transform: translateY(1px); }
.btn-ghost{ background: transparent; }
.btn-amber{ background: var(--amber-soft); border-color: rgba(185,121,10,.35); color:#8a5c08; }
.btn-amber:hover{ background: rgba(185,121,10,.2); }
.btn-accent{ background: var(--accent); border-color: var(--accent); color:#ffffff; font-weight:700; }
.btn-accent:hover{ background:#0d8177; }
.btn-danger{ background: var(--danger-soft); border-color: rgba(214,58,47,.4); color: var(--danger-text); }
.btn-danger:hover{ background: rgba(214,58,47,.22); }
.btn-sm{ padding:5px 10px; font-size:11.5px; }
.btn:disabled{ opacity:.45; cursor:default; }

.search-input{
  font-family: var(--font-body);
  font-size:12.5px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
  width: 220px;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.search-input::placeholder{ color: var(--text-dim); }
.search-input:focus{ border-color: var(--select); box-shadow: 0 0 0 2px rgba(15,156,146,.15); }
.search-status{ font-size:11px; color: var(--text-dim); margin-left:8px; align-self:center; white-space:nowrap; }

.row-hidden{ display:none; }
mark.search-hit{ background: rgba(185,121,10,.35); color:inherit; border-radius:2px; padding:0 1px; }

.status{
  margin-left:auto; display:flex; align-items:center; gap:8px;
  font-size:12px; color: var(--text-muted); white-space:nowrap;
}
.status-dot{ width:8px; height:8px; border-radius:50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.status-dot.dirty{ background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.status-dot.autosaved{ animation: autosave-pulse 1.2s ease-out; }
@keyframes autosave-pulse{
  0%{ box-shadow: 0 0 0 0 rgba(15,156,146,.55); }
  100%{ box-shadow: 0 0 0 10px rgba(15,156,146,0); }
}

/* ── Grid ────────────────────────────────────────────────────── */
.grid-wrap{ flex:1; min-height:0; padding: 14px 20px 8px; }
.grid-scroll{ height:100%; overflow:auto; border-radius: var(--radius); border:1px solid var(--border); background: var(--panel); }
table.grid{ border-collapse: separate; border-spacing:0; width:max-content; min-width:100%; zoom: var(--grid-zoom, 1); }

.grid th, .grid td{
  border-right: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
  padding: 0;
  white-space: nowrap;
  -webkit-touch-callout: none; /* evita il menu nativo iOS su pressione prolungata */
}
.grid thead th{
  position: sticky; top:0; z-index:3;
  background: #f7f9fb;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-weight:600; font-size:11.5px; letter-spacing:.03em; text-transform:uppercase;
  padding: 10px 12px; text-align:left;
}
.th-sortable{ cursor:pointer; user-select:none; transition: background .15s ease; }
.th-sortable:hover{ background:#eef2f7; }
.th-sortable .th-label{ margin-right:4px; }
.sort-arrow{ font-size:8px; color: var(--accent); opacity:.9; }
.sort-arrow-ghost{ opacity:0; }
.th-sortable:hover .sort-arrow-ghost{ opacity:.35; }
.th-sorted{ color: var(--text); }
.grid thead th.col-name{ position: sticky; left:0; z-index:4; background:#f7f9fb; min-width:190px; }
.grid thead th.col-hd{ color:#8a5c08; background: linear-gradient(180deg, #fff6e0, #fdefc8); box-shadow: inset 0 0 0 1px rgba(185,121,10,.3); }
.grid thead th.col-hd .hd-flag{ display:inline-flex; align-items:center; gap:5px; }

.grid tbody td.col-name{
  position: sticky; left:0; z-index:2;
  background: #fbfcfd;
  font-family: var(--font-body); font-weight:600; font-size:13px;
  padding: 0 12px; color:var(--text);
  min-width:190px;
}
.grid tbody tr.row-airport td.col-name{ color:#1f5fbf; }
.grid tbody tr:hover td.col-name{ background:#eef2f7; }

.grid td.col-hd{ box-shadow: inset 0 0 0 1px rgba(185,121,10,.25); background: rgba(185,121,10,.05); }

.cell-input{
  width:120px; border:none; outline:none; background:transparent;
  color: var(--text); font-family: var(--font-mono); font-size:12.5px;
  padding: 9px 12px; text-align:center;
}
.cell-input::placeholder{ color:#b3bdcd; }
.cell-input:focus{ background: rgba(15,156,146,.06); box-shadow: inset 0 0 0 1px var(--select); }

.cell-chip{
  width:120px; height:34px; display:flex; align-items:center; justify-content:center; gap:7px;
  padding: 0 12px; cursor:pointer; font-family: var(--font-mono); font-size:11.5px;
  color: var(--text-muted); user-select:none;
}
.cell-chip:hover{ background: rgba(15,23,33,.045); }
.cell-chip .dot{ flex-shrink:0; }

.cell-state-normal{ }
.cell-state-old{ background: rgba(214,58,47,.20); box-shadow: inset 0 0 0 1px rgba(214,58,47,.5); }
.cell-state-old .cell-input{ color: #8f231c; font-weight:700; }
.cell-state-old .cell-chip{ color: #8f231c; }
.cell-state-empty{
  background: repeating-linear-gradient(
    -45deg,
    rgba(107,118,132,.07),
    rgba(107,118,132,.07) 4px,
    transparent 4px,
    transparent 9px
  );
}
.cell-state-empty .cell-chip{ color:#c3cbd6; }

.dot{
  display:inline-flex; align-items:center; justify-content:center;
  width:16px; height:16px; border-radius:50%; font-size:10px; line-height:1;
  color:#fff; font-weight:700;
}
.dot-normal{ background:#8f9aa8; }
.dot-normal::after{ content:"✓"; }
.dot-old{ background: var(--danger); box-shadow:0 0 6px rgba(214,58,47,.5); }
.dot-old::after{ content:"!"; }
.dot-empty{ background:transparent; border:1.5px dashed #9aa5b3; color:#9aa5b3; }
.dot-empty::after{ content:"○"; font-size:8px; }
.dot-hd{ background: var(--amber); box-shadow:0 0 5px rgba(185,121,10,.5); }
.dot-hd::after{ content:"★"; font-size:8px; }

.legend{
  display:flex; gap:22px; padding: 8px 22px 12px; font-size:11.5px; color: var(--text-muted); flex-shrink:0;
}
.legend-item{ display:flex; align-items:center; gap:6px; }
.legend-hd{ margin-left:auto; color:#8a5c08; }

/* ── Overlay & modals ────────────────────────────────────────── */
.overlay{
  position:fixed; inset:0; background: rgba(28,39,51,.35);
  backdrop-filter: blur(2px);
  display:flex; align-items:center; justify-content:center;
  z-index:50;
}
.overlay.hidden{ display:none; }

.modal{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(28,39,51,.25);
  width: 460px; max-width: 92vw;
  max-height: 86vh;
  display:flex; flex-direction:column;
  overflow:hidden;
}
.modal.modal-wide{ width: 720px; }
.modal-header{
  padding: 16px 20px; border-bottom:1px solid var(--border);
  display:flex; align-items:center; justify-content:space-between;
}
.modal-title{ font-family: var(--font-display); font-weight:700; font-size:15px; }
.modal-title small{ display:block; font-family:var(--font-body); font-weight:400; color:var(--text-muted); font-size:11.5px; margin-top:2px; }
.modal-close{ background:none; border:none; color: var(--text-muted); font-size:18px; cursor:pointer; line-height:1; padding:4px; }
.modal-close:hover{ color: var(--text); }
.modal-body{ padding: 18px 20px; overflow-y:auto; }
.modal-footer{ padding: 14px 20px; border-top:1px solid var(--border); display:flex; gap:8px; justify-content:flex-end; }

.field{ margin-bottom:14px; }
.field label{ display:block; font-size:11.5px; color: var(--text-muted); margin-bottom:6px; text-transform:uppercase; letter-spacing:.03em; }
.field input, .field select{
  width:100%; padding:9px 11px; border-radius:6px;
  background: #ffffff; border:1px solid var(--border); color: var(--text);
  font-family: var(--font-mono); font-size:13px; outline:none;
}
.field input:focus{ border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-error{ color: var(--danger-text); font-size:12px; margin-top:6px; }
.confirm-message{ font-size:13.5px; line-height:1.5; color: var(--text); margin:0; }

/* ── Input data + pulsante calendario ─────────────────────────── */
.cell-input-wrap{ display:flex; align-items:center; width:120px; }
.cell-input-wrap .cell-input{ width:auto; flex:1; min-width:0; padding-right:2px; }
.cell-dp-btn{
  flex-shrink:0; border:none; background:transparent; cursor:pointer;
  font-size:12px; line-height:1; padding:4px 6px; border-radius:4px; opacity:.55;
}
.cell-dp-btn:hover{ opacity:1; background: rgba(15,23,33,.06); }
.airport-field-row .cell-dp-btn{ padding:4px 3px; }

/* ── Selezione multipla celle ─────────────────────────────────── */
body.no-select{ user-select:none; }
td.cell-selected{ box-shadow: inset 0 0 0 2px var(--select); background: rgba(15,156,146,.10); }

.selection-toolbar{
  position: fixed; left:50%; bottom:22px; transform: translateX(-50%) translateY(20px);
  display:flex; align-items:center; gap:10px;
  background:#1c2430; color:#eef2f7; border-radius:10px; padding:10px 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  font-size:12.5px; z-index: 500;
  opacity:0; pointer-events:none; transition: opacity .15s, transform .15s;
}
.selection-toolbar.show{ opacity:1; pointer-events:auto; transform: translateX(-50%) translateY(0); }
.selection-toolbar .btn{ padding:6px 10px; font-size:12px; }
.selection-toolbar .btn-ghost{ color:#c7cedb; border-color:#3a4552; }

/* ── Calendario a comparsa ────────────────────────────────────── */
.date-picker{
  position: fixed; z-index: 600; width:220px;
  background:#ffffff; border:1px solid var(--border); border-radius:10px;
  box-shadow: 0 10px 30px rgba(20,30,45,.18); padding:10px;
  font-family: var(--font-body);
}
.dp-header{ display:flex; align-items:center; justify-content:space-between; margin-bottom:6px; }
.dp-label{ font-size:12.5px; font-weight:600; }
.dp-nav{ padding:3px 9px; }
.dp-dow{ display:grid; grid-template-columns: repeat(7,1fr); text-align:center; font-size:10.5px; color: var(--text-dim); margin-bottom:2px; }
.dp-grid{ display:grid; grid-template-columns: repeat(7,1fr); gap:2px; }
.dp-day{
  border:none; background:transparent; border-radius:6px; padding:5px 0;
  font-size:12px; cursor:pointer; color: var(--text);
}
.dp-day:hover{ background: rgba(15,156,146,.12); }
.dp-today{ font-weight:700; color: var(--accent); }
.dp-selected{ background: var(--accent); color:#fff; }
.dp-footer{ display:flex; justify-content:space-between; margin-top:8px; gap:6px; }
.dp-footer .btn{ flex:1; }

.airport-fields{ display:flex; flex-direction:column; gap:6px; }
.airport-field-row{
  display:grid; grid-template-columns: 1fr 130px 24px; grid-template-areas: "label input dp" "hint hint hint";
  gap:4px 8px; align-items:center; padding:4px 6px; border-radius:6px; transition: background .25s ease;
}
.airport-field-row label{ font-size:12.5px; color: var(--text-muted); overflow:hidden; text-overflow:ellipsis; grid-area: label; }
.airport-field-row input{ padding:7px 9px; font-size:12.5px; grid-area: input; }
.airport-field-row .cell-dp-btn{ grid-area: dp; }
.airport-field-row.old input{ border-color: rgba(214,58,47,.5); color: var(--danger-text); background: var(--danger-soft); }
.field-update-hint{
  grid-area: hint; display:flex; align-items:center; justify-content:space-between; gap:8px;
  font-size:11px; color:#8a5c08; background:#fdf3dc; border:1px solid rgba(154,105,8,.25);
  border-radius:6px; padding:5px 8px 5px 9px;
}
.field-update-hint .btn{ padding:4px 9px; font-size:11px; white-space:nowrap; }

@keyframes field-row-flash{
  0%{ background: rgba(214,58,47,.28); } 100%{ background: transparent; }
}
.field-row-flash{ animation: field-row-flash 1.8s ease-out 1; }

.btn-group-label{ font-size:10px; text-transform:uppercase; letter-spacing:.08em; color:#94a0ae; margin: 14px 0 6px; }
.btn-wrap{ display:flex; flex-wrap:wrap; gap:6px; }

.report-section{ margin-bottom:18px; }
.report-section h4{ font-family: var(--font-display); font-size:13px; margin:0 0 8px; color: var(--text); }
.report-section.hd h4{ color:#8a5c08; }
.report-line{
  font-family: var(--font-mono); font-size:12px; color: var(--text-muted);
  padding: 7px 10px; border-radius:6px; background: var(--panel-2); margin-bottom:5px;
  display:flex; flex-direction:column; gap:2px;
}
.report-line b{ color: var(--text); font-weight:600; }
.report-line .meta{ font-size:11px; color:#8a94a3; }
.report-line-clickable{ cursor:pointer; border:1px solid transparent; transition: border-color .15s ease, background .15s ease; }
.report-line-clickable:hover{ border-color: var(--accent, #3b82f6); background: var(--panel-3, #eef2f7); }
.report-line-go{
  font-size:10.5px; font-weight:600; letter-spacing:.02em; color: var(--accent, #3b82f6);
  opacity:0; transform: translateX(-4px); transition: opacity .15s ease, transform .15s ease;
}
.report-line-clickable:hover .report-line-go{ opacity:1; transform: translateX(0); }
.report-empty{ color: var(--text-muted); font-size:13px; padding: 10px 0; }
.report-total{ font-size:12px; color: var(--text-muted); margin-bottom:4px; }

@keyframes cell-flash{
  0%{ box-shadow: inset 0 0 0 2px rgba(59,130,246,.9), 0 0 0 4px rgba(59,130,246,.25); }
  100%{ box-shadow: inset 0 0 0 2px rgba(59,130,246,0), 0 0 0 4px rgba(59,130,246,0); }
}
.cell-flash{ animation: cell-flash 1.8s ease-out 1; border-radius:4px; }

.warning-modal .modal-header{ background: linear-gradient(180deg, #fdeceb, #fbe0de); border-color: rgba(214,58,47,.3); }
.warning-modal .modal-title{ color: var(--danger-text); display:flex; align-items:center; gap:8px; }

.checklist{ display:flex; flex-direction:column; gap:4px; max-height:220px; overflow-y:auto; padding:4px; border:1px solid var(--border); border-radius:8px; }
.checklist label{ display:flex; align-items:center; gap:8px; padding:6px 8px; font-size:12.5px; border-radius:5px; cursor:pointer; }
.checklist label:hover{ background: var(--panel-2); }

.toast{
  position:fixed; bottom:20px; left:50%; transform:translateX(-50%);
  background: #1c2733; border:1px solid #2a3745; color: #ffffff;
  padding: 10px 18px; border-radius: 8px; font-size:13px;
  box-shadow: 0 10px 30px rgba(28,39,51,.3);
  z-index: 80; opacity:0; transition: opacity .2s, transform .2s;
  pointer-events:none;
}
.toast.show{ opacity:1; transform:translateX(-50%) translateY(-4px); }

/* ── Checkpoint 1: badge, filtro, validazione ────────────────── */
.btn-with-badge{ position:relative; }
.badge-count{
  display:inline-flex; align-items:center; justify-content:center;
  min-width:17px; height:17px; padding:0 4px; margin-left:6px;
  background:#fff; color: var(--danger); font-size:10.5px; font-weight:800;
  border-radius:999px; box-shadow: inset 0 0 0 1px rgba(214,58,47,.5);
  vertical-align:middle;
}
.badge-count.hidden{ display:none; }

#filter-issues-toggle.active{
  background: var(--danger-soft); border-color: rgba(214,58,47,.45); color: var(--danger-text);
}

.input-invalid, .cell-input.input-invalid{
  background: var(--danger-soft) !important;
  box-shadow: inset 0 0 0 1.5px var(--danger) !important;
}

/* ── Checkpoint 2: cronologia, menu contestuale, drag colonne ──── */
#undo-btn:disabled, #redo-btn:disabled{ opacity:.4; cursor:default; }

.context-menu{
  position: fixed; z-index: 700; min-width:190px;
  background: var(--panel); border:1px solid var(--border); border-radius:8px;
  box-shadow: 0 12px 30px rgba(20,30,45,.25); padding:5px;
  font-family: var(--font-body); font-size:12.5px;
  animation: ctx-in .12s ease-out;
  transform-origin: top left;
}
.context-menu.hidden{ display:none; }
@keyframes ctx-in{ from{ opacity:0; transform: scale(.96); } to{ opacity:1; transform: scale(1); } }
.ctx-item{
  display:flex; align-items:center; gap:8px; padding:8px 10px; border-radius:6px;
  cursor:pointer; color: var(--text); white-space:nowrap; transition: background .1s ease;
}
.ctx-item:hover{ background: var(--panel-2); }
.ctx-item.ctx-danger{ color: var(--danger-text); }
.ctx-sep{ height:1px; background: var(--border); margin:5px 4px; }

.grid thead th.th-dragging{ opacity:.4; }
.grid thead th.th-drag-over{ box-shadow: inset 2px 0 0 0 var(--accent); }
.grid thead th[draggable="true"]{ cursor: grab; }
.grid thead th[draggable="true"]:active{ cursor: grabbing; }

/* ── Checkpoint 3: animazioni più fluide ─────────────────────── */
.grid tbody tr{ animation: row-in .18s ease-out; }
@keyframes row-in{ from{ opacity:0; transform: translateY(-3px); } to{ opacity:1; transform:translateY(0); } }
.grid td, .grid th{ transition: background-color .15s ease, box-shadow .15s ease; }
.btn{ transition: background .12s ease, border-color .12s ease, transform .08s ease, box-shadow .12s ease; }
.btn:active{ transform: scale(.97); }
.overlay{ transition: background .18s ease; }
.modal{ animation: modal-in .16s cubic-bezier(.2,.9,.3,1); }
@keyframes modal-in{ from{ opacity:0; transform: translateY(8px) scale(.98); } to{ opacity:1; transform:translateY(0) scale(1); } }
.toast{ transition: opacity .25s ease, transform .25s cubic-bezier(.2,.9,.3,1); }
@media (prefers-reduced-motion: reduce){
  .grid tbody tr, .modal, .context-menu{ animation: none !important; }
  *{ transition-duration: .01ms !important; }
}

/* ── Checkpoint 4: dashboard ──────────────────────────────────── */
.dash-grid{ display:grid; grid-template-columns: repeat(4, 1fr); gap:10px; margin-bottom:18px; }
.dash-card{
  background: var(--panel-2); border:1px solid var(--border-soft); border-radius:10px;
  padding:12px 14px; display:flex; flex-direction:column; gap:4px;
}
.dash-card .dash-val{ font-family: var(--font-display); font-size:22px; font-weight:700; color: var(--text); }
.dash-card .dash-label{ font-size:11px; color: var(--text-muted); text-transform:uppercase; letter-spacing:.03em; }
.dash-card.dash-warn .dash-val{ color: var(--danger-text); }
.dash-card.dash-ok .dash-val{ color: var(--accent); }
.dash-section-title{ font-family: var(--font-display); font-size:13px; font-weight:700; margin:16px 0 8px; color: var(--text); }
.dash-col-row{ display:flex; align-items:center; gap:10px; padding:6px 2px; font-size:12px; }
.dash-col-name{ width:150px; flex-shrink:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color: var(--text); font-weight:600; }
.dash-bar-track{ flex:1; height:8px; border-radius:5px; background: var(--panel-3); overflow:hidden; }

/* ══════════════════════════════════════════════════════════════
   Adattamento telefono / schermi stretti
   La griglia resta la stessa (scroll orizzontale + colonna nomi
   fissa, già presenti sopra): qui rendiamo più comodo il tocco su
   pulsanti e menu, e le finestre a schermo intero invece che
   "flottanti" al centro.
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 720px){

  /* Su iOS Safari, un campo di testo con font-size sotto i 16px fa
     zoomare automaticamente la pagina quando lo tocchi: lo evitiamo
     forzando 16px su tutti i campi editabili. */
  .cell-input, .search-input, .field input, .field select,
  .airport-field-row input{ font-size:16px !important; }

  #app{ height:100dvh; }

  .topbar{
    padding: 8px 10px;
    gap: 8px;
  }
  .brand-sub{ display:none; } /* sottotitolo superfluo su schermo stretto */
  .brand-title{ font-size:16px; }
  .brand-mark{ width:30px; height:30px; }

  .toolbar{
    margin-left:0;
    width:100%;
    order:3; /* la barra strumenti va sotto il marchio, su una riga tutta sua */
    flex-wrap: wrap;
    gap:6px;
  }
  .tool-sep{ display:none; } /* separatori verticali inutili quando tutto va a capo */
  .tool-search{ width:100%; order:10; }
  .search-input{ flex:1; min-width:0; width:auto; }

  .status{
    order:2; margin-left:auto;
  }

  /* Tocco più comodo: pulsanti e voci di menu più grandi */
  .btn{ padding:9px 12px; font-size:13px; min-height:38px; }
  .btn-icon{ padding:9px 11px; }
  .btn-sm{ min-height:32px; }
  .menu-item{ padding:11px 12px; font-size:13.5px; }
  .density-btn{ padding:9px 8px; }

  /* Le finestre (aggiungi/rinomina/dettaglio aeroporto/report) occupano
     tutto lo schermo invece di restare "flottanti" al centro: più
     spazio per leggere e più facile da toccare. */
  .modal, .modal.modal-wide{
    width: 100vw; max-width: 100vw;
    height: 100dvh; max-height: 100dvh;
    border-radius: 0; border-left:none; border-right:none;
  }
  .overlay{ padding:0; }

  .airport-field-row{
    grid-template-columns: 1fr 110px 24px;
  }

  .legend{ flex-wrap:wrap; gap:10px 16px; padding:8px 12px 10px; font-size:11px; }
  .legend-hd{ margin-left:0; flex-basis:100%; }

  .grid-wrap{ padding: 8px 8px 6px; }

  /* Il pannello data (calendario a comparsa) un po' più largo aiuta
     a toccare i singoli giorni senza sbagliare. */
  .date-picker{ width:250px; }
  .dp-day{ padding:8px 0; font-size:13px; }

  .selection-toolbar{ left:8px; right:8px; transform:none; width:auto; justify-content:center; flex-wrap:wrap; }
  .selection-toolbar.show{ transform:none; }
}
.dash-bar-fill{ height:100%; border-radius:5px; background: var(--accent); transition: width .4s cubic-bezier(.2,.9,.3,1); }
.dash-bar-fill.warn{ background: var(--danger); }
.dash-pct{ width:38px; text-align:right; color: var(--text-muted); font-family: var(--font-mono); font-size:11px; }
