.dash-shell {
  display: flex;
  min-height: calc(100vh - 65px);
}

/* Sidebar */
.sidebar {
  width: 300px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 20px;
  background: var(--bg-elevated);
}
.sidebar h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-tertiary); margin: 20px 0 10px; }
.sidebar h4:first-child { margin-top: 0; }

.asset-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  margin-bottom: 4px;
}
.asset-item:hover { background: var(--bg-card-hover); }
.asset-item.active { background: var(--bg-card); border-color: var(--sea); }
.asset-item-enter { animation: asset-item-in 0.3s cubic-bezier(0.16,1,0.3,1) backwards; }
@keyframes asset-item-in { from { opacity: 0; transform: translateX(-6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .asset-item-enter { animation: none; } }
.asset-icon { font-size: 16px; display: inline-flex; align-items: center; color: var(--text-secondary); }
.asset-name { display: block; font-size: 13.5px; font-weight: 600; }
.asset-meta { display: block; font-size: 11.5px; color: var(--text-tertiary); }
.asset-status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-left: auto; background: var(--border-strong); transition: background-color 0.3s ease, box-shadow 0.3s ease; }
.asset-status-dot.ok { background: var(--success); }
.asset-status-dot.warning { background: var(--warning); }
.asset-status-dot.critical { background: var(--critical); box-shadow: 0 0 0 3px color-mix(in srgb, var(--critical) 25%, transparent); animation: pulse-dot 1.4s ease-in-out infinite; }
@keyframes pulse-dot { 50% { opacity: 0.4; } }

.legend-note { font-size: 12px; color: var(--text-tertiary); line-height: 1.5; }

/* Main area */
.dash-main { flex: 1; min-width: 0; padding: 22px 26px 60px; }

.dash-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.dash-header h1 { font-size: 22px; margin: 0; }
.dash-header .asset-region { font-size: 13px; color: var(--text-secondary); font-family: var(--font-mono); }
#status-line { font-size: 12px; color: var(--text-tertiary); }

.map-wrap { position: relative; margin-bottom: 16px; }
/* Mappa a piena larghezza (richiesta esplicita: "estesa in orizzontale") —
   altezza legata al viewport così resta proporzionata anche su schermi
   larghi, con un tetto per non diventare eccessiva su monitor molto alti. */
.map-wrap-wide #map { height: min(62vh, 620px); }
#map { height: 420px; border-radius: var(--radius); border: 1px solid var(--border); }
.map-toggles {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}
.map-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(10, 15, 26, 0.85);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}
.map-toggle input { margin: 0; cursor: pointer; }
.map-toggle-hint {
  background: rgba(10, 15, 26, 0.85);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 10.5px;
  color: var(--text-secondary);
  max-width: 200px;
  text-align: right;
}
:root:not([data-theme="dark"]) .map-toggle-hint { background: rgba(255, 255, 255, 0.92); }

.map-mode-badge {
  position: absolute;
  bottom: 10px;
  left: 10px;
  z-index: 400;
  background: rgba(10, 15, 26, 0.85);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 11.5px;
  color: var(--text-secondary);
}
:root:not([data-theme="dark"]) .map-mode-badge,
:root:not([data-theme="dark"]) .map-toggle { background: rgba(255, 255, 255, 0.92); }

/* Legenda rotta (Weather Routing) — stessa posizione/stile degli altri overlay mappa. */
.map-legend {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 400;
  display: none;
  flex-direction: column;
  gap: 4px;
  background: rgba(10, 15, 26, 0.85);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 11px;
  color: var(--text-secondary);
}
.map-legend.visible { display: flex; }
.map-legend-item { display: flex; align-items: center; gap: 6px; }
.map-legend-swatch { width: 18px; height: 0; border-top-width: 3px; border-top-style: solid; flex-shrink: 0; }
:root:not([data-theme="dark"]) .map-legend { background: rgba(255, 255, 255, 0.92); }

/* Timeline trascinabile lungo la rotta calcolata da Weather Routing — punti
   stimati (triorari su rotte brevi, più radi su rotte lunghe) con meteo al
   tempo di transito; trascinando si sposta un marker "fantasma" sulla mappa. */
.route-timeline { padding: 14px 16px; }
.route-timeline-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.route-timeline-readout { font-size: 12.5px; color: var(--text-secondary); }
.route-timeline-slider {
  width: 100%;
  accent-color: #a78bfa;
  cursor: pointer;
  margin: 4px 0;
}
.route-timeline-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-tertiary, var(--text-secondary));
  padding: 0 2px;
}
.route-timeline-hint { margin: 8px 0 0; font-size: 11.5px; color: var(--text-secondary); }
/* Marker nave sulla timeline rotta — stessa forma del marker di flotta
   (.ship-marker), con un anello viola (colore della rotta ottimizzata) per
   distinguerlo dalla posizione reale della nave, visibile in parallelo. */
.route-timeline-marker { box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.9), 0 0 0 6px rgba(167, 139, 250, 0.25); border-radius: 50%; }

/* Marker nave — freccia ruotata sulla rotta (COG); il div wrapper ruota, il
   glifo interno resta leggibile. Una forma minimale (SHIP_GLYPH_SVG in
   dashboard.js) invece di un'emoji per tipo di vascello: un'emoji ha una
   direzione già disegnata al suo interno, che ruotata secondo la prua reale
   sembra "storta" invece di indicare una direzione — richiesta esplicita.
   Bianco pieno di default: sulla mappa (satellite/oceano, sempre chiara)
   serve un colore fisso e leggibile, non uno legato al tema dell'interfaccia. */
.ship-marker { display: flex; align-items: center; justify-content: center; width: 26px; height: 26px; transform-origin: center; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6)); }
.ship-marker .glyph { display: inline-flex; color: #fff; }
.ship-marker.sev-warning .glyph { color: var(--warning); filter: drop-shadow(0 0 4px var(--warning)); }
.ship-marker.sev-critical .glyph { color: var(--critical); filter: drop-shadow(0 0 5px var(--critical)); }
.port-marker { font-size: 20px; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5)); }
.leaflet-popup-content { font-size: 12.5px; }
.simulated-tag { font-size: 10px; color: var(--warning); font-weight: 700; text-transform: uppercase; }

#conditions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.conditions-wide { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)) !important; }

.stat { }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-tertiary); margin-bottom: 3px; }
.stat-value { font-size: 19px; font-weight: 700; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }

/* Applicata via JS quando un blocco di stat viene aggiornato (nuovo punto
   timeline, refresh dati) — un lampo breve invece di un salto secco dei
   numeri, così un cambio di valore si nota senza essere un'animazione vera
   e propria. */
#conditions.stat-refresh .stat-value,
.fuel-result.stat-refresh .stat-value {
  animation: stat-flash 0.5s ease;
}
@keyframes stat-flash {
  0% { color: var(--accent); }
  100% { color: var(--text-primary); }
}
@media (prefers-reduced-motion: reduce) {
  #conditions.stat-refresh .stat-value, .fuel-result.stat-refresh .stat-value { animation: none; }
}

/* Rosa dei venti — affiancata alla griglia di stat, non sostitutiva: chi
   vuole il numero grezzo lo trova comunque nella stat "Vento". */
.conditions-layout { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; }
.conditions-layout #conditions { flex: 1; min-width: 220px; }
.wind-compass { width: 168px; flex-shrink: 0; text-align: center; }
.wind-compass-svg { width: 100%; height: auto; display: block; }
.wind-compass-legend { margin-top: 4px; }
.wind-compass-force { font-size: 11.5px; font-weight: 600; }
.wind-compass-gust { font-size: 10.5px; color: var(--text-tertiary); margin-top: 1px; }
@media (max-width: 640px) {
  .wind-compass { width: 140px; margin: 0 auto; }
}

.card { margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }
.card-head h3 { font-size: 15px; margin: 0; }
.card-head .meta { font-size: 11.5px; color: var(--text-tertiary); }

#bulletin-headline { font-size: 16px; font-weight: 600; margin-bottom: 10px; }
#bulletin-confidence { font-size: 12px; color: var(--text-tertiary); margin-bottom: 14px; }

.bulletin-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 16px; }
.bulletin-cols h5 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-tertiary); margin: 0 0 8px; }
.bulletin-cols ul { margin: 0; padding-left: 18px; font-size: 13.5px; color: var(--text-secondary); }
.bulletin-cols li { margin-bottom: 6px; }

.meteorologist-note {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}
.meteorologist-note::before { content: "👤"; flex-shrink: 0; }

.system-analysis-box {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--badge-warning-bg);
  border: 1px solid color-mix(in srgb, var(--warning) 40%, transparent);
  border-radius: var(--radius-sm);
}
.system-analysis-box h5 { margin: 0 0 6px; font-size: 12px; color: var(--warning); }
.system-analysis-box .sa-text { margin: 0; font-size: 13px; color: var(--text-primary); line-height: 1.6; }

.meteorologist-note-box {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--badge-success-bg);
  border: 1px solid color-mix(in srgb, var(--success) 40%, transparent);
  border-radius: var(--radius-sm);
}
.meteorologist-note-box h5 { margin: 0 0 6px; font-size: 12px; color: var(--badge-success-fg); }
.meteorologist-note-box .mn-text { margin: 0; font-size: 13px; color: var(--text-primary); line-height: 1.6; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.alert-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--border); }
.alert-item:first-child { border-top: none; padding-top: 0; }
.alert-label { font-size: 13.5px; font-weight: 600; }
.alert-time { font-size: 12px; color: var(--text-tertiary); font-family: var(--font-mono); }

.empty-state { font-size: 13px; color: var(--text-tertiary); margin: 0; }

.chart-wrap { height: 260px; position: relative; }

.attribution { font-size: 11px; color: var(--text-tertiary); text-align: center; margin-top: 20px; }
.attribution a { color: var(--text-secondary); text-decoration: underline; }

/* 0.7 non 0.55: con la barra di caricamento in nav (styles.css) come segnale
   primario, il dimming sotto può restare più leggero — resta comunque
   chiaro che i dati in vista sono momentaneamente stantii. */
body.loading .dash-main { opacity: 0.7; pointer-events: none; transition: opacity 0.2s ease; }

/* Fuel Optimization / CO2 — Commercial & Professional */
.fuel-result { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 14px; }
/* Selettore discendente, non composto: penalty-positive/negative è sullo
   <span> dentro .stat-value (vedi renderFuelResult in dashboard.js), non su
   .stat-value stesso — con il selettore composto questa regola non ha mai
   applicato colore, bug pre-esistente trovato durante la verifica. */
.fuel-result .stat-value .penalty-positive { color: var(--warning); }
.fuel-result .stat-value .penalty-negative { color: var(--success); }

.checkbox-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.checkbox-chip {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 400; color: var(--text-secondary);
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 8px 10px; cursor: pointer; margin: 0;
}
.checkbox-chip input { width: auto; padding: 0; }
.checkbox-chip:has(input:checked) { border-color: var(--sea); color: var(--text-primary); }

.ondemand-item { padding: 12px 0; border-top: 1px solid var(--border); }
.ondemand-item:first-child { border-top: none; padding-top: 0; }
.ondemand-item .oq { font-size: 13.5px; font-weight: 600; margin-bottom: 4px; }
.ondemand-item .oa { font-size: 13px; color: var(--text-secondary); margin-top: 6px; padding: 8px 10px; background: var(--bg-elevated); border-radius: var(--radius-sm); }
.ondemand-item .om { font-size: 11.5px; color: var(--text-tertiary); }

@media (max-width: 980px) {
  .two-col, .bulletin-cols, .fuel-result, .checkbox-grid { grid-template-columns: 1fr; }
  .dash-shell { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
}

@media (max-width: 640px) {
  #company-line, #status-line { display: none; }
  #theme-toggle { font-size: 12px; padding: 6px 8px; }
  .dash-main { padding: 16px 14px 40px; }
  #bulletin-judgment-row { justify-content: flex-start; }
  #bulletin-judgment-row button { margin-left: 0 !important; }
}

/* Assistente AI — accento viola (--accent-2), coerente in tutto il prodotto. */
.chat-fab {
  position: fixed; bottom: 22px; right: 22px; z-index: 900;
  width: 52px; height: 52px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-2), color-mix(in srgb, var(--accent-2) 70%, var(--accent)));
  color: var(--accent-2-fg); border: none;
  font-size: 22px; cursor: pointer; box-shadow: 0 8px 24px -6px color-mix(in srgb, var(--accent-2) 50%, transparent);
}
.chat-panel {
  position: fixed; bottom: 86px; right: 22px; z-index: 900;
  width: 360px; max-width: calc(100vw - 44px); height: 480px; max-height: 70vh;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-card); display: flex; flex-direction: column; overflow: hidden;
}
.chat-panel.hidden { display: none; }
.chat-panel-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent-2) 6%, transparent);
}
.chat-messages { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-bubble { max-width: 85%; padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.5; }
.chat-bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-fg); border-bottom-right-radius: 3px; }
.chat-bubble.assistant { align-self: flex-start; background: color-mix(in srgb, var(--accent-2) 10%, var(--bg-elevated)); color: var(--text-primary); border-bottom-left-radius: 3px; }
.chat-bubble.system { align-self: center; background: transparent; color: var(--text-tertiary); font-size: 11.5px; text-align: center; }
.chat-form { display: flex; gap: 8px; padding: 10px 14px 14px; }
.chat-form input { flex: 1; min-width: 0; }
.chat-form input:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-2) 18%, transparent); }

/* Notifiche push per alert critici (WebSocket, js/ws.js) — pila compatta in
   alto a destra, non deve coprire il contenuto sotto; cliccabili per saltare
   all'asset coinvolto. Una riga sola per asset+label, testo troncato se
   troppo lungo invece di far crescere il box in altezza. */
.critical-toast-stack {
  position: fixed;
  top: 62px;
  right: 12px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  max-width: min(240px, calc(100vw - 24px));
}
.critical-toast {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--critical);
  border-left-width: 3px;
  border-radius: 999px;
  box-shadow: var(--shadow-card);
  padding: 5px 10px;
  cursor: pointer;
  animation: toast-in 0.2s ease-out;
  font-size: 11px;
  line-height: 1.3;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.critical-toast.leaving { opacity: 0; transform: translateX(16px); }
.critical-toast:hover { background: color-mix(in srgb, var(--critical) 6%, var(--bg-card)); }
.critical-toast-icon { flex-shrink: 0; font-size: 12px; }
.critical-toast-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.critical-toast-asset { font-weight: 700; color: var(--critical); }
.critical-toast-label { color: var(--text-secondary); }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }
@media (prefers-reduced-motion: reduce) {
  .critical-toast { animation: none; }
  .critical-toast.leaving { transition: none; display: none; }
}
