/* ============================================================
   TUA DIVISIONE FERROVIARIA — Fleet Management System v2
   Tema: Doppio (chiaro / scuro), font leggibile
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=Source+Sans+3:wght@400;500;600;700&display=swap');

/* ============================================================
   TEMA SCURO (default)
   ============================================================ */
:root {
  --bg-primary:   #111318;
  --bg-secondary: #1a1d24;
  --bg-card:      #1e2128;
  --bg-elevated:  #252830;
  --border:       #2e323c;
  --border-bright:#42475a;
  --text-primary:   #dde1ec;
  --text-secondary: #858ca8;
  --text-dim:       #4a5070;
  --tua-blue:      #2563eb;
  --tua-blue-light:#3b82f6;
  --tua-blue-dim:  #1e3a6e;
  --green:       #16a34a;
  --green-light: #22c55e;
  --green-bg:    #052e16;
  --yellow:      #ca8a04;
  --yellow-light:#eab308;
  --yellow-bg:   #1c1400;
  --red:         #dc2626;
  --red-light:   #ef4444;
  --red-bg:      #200a0a;
  --orange:      #c2410c;
  --orange-light:#f97316;
  --orange-bg:   #1c0e00;
  --gray:        #6b7280;
  --gray-bg:     #1a1d24;
  --shadow:    0 2px 12px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.6);
  --font-mono:  'IBM Plex Mono', 'Courier New', monospace;
  --font-main:  'Source Sans 3', 'Segoe UI', system-ui, sans-serif;
  --radius:    7px;
  --radius-sm: 4px;
  --transition: 0.15s ease;
}

/* ============================================================
   TEMA CHIARO
   ============================================================ */
[data-theme="light"] {
  --bg-primary:   #f0f2f7;
  --bg-secondary: #ffffff;
  --bg-card:      #ffffff;
  --bg-elevated:  #f5f7fc;
  --border:       #d1d5e0;
  --border-bright:#a8afc4;
  --text-primary:   #111827;
  --text-secondary: #4b5563;
  --text-dim:       #9ca3af;
  --tua-blue:      #1d4ed8;
  --tua-blue-light:#2563eb;
  --tua-blue-dim:  #dbeafe;
  --green:       #15803d;
  --green-light: #16a34a;
  --green-bg:    #dcfce7;
  --yellow:      #a16207;
  --yellow-light:#ca8a04;
  --yellow-bg:   #fef9c3;
  --red:         #b91c1c;
  --red-light:   #dc2626;
  --red-bg:      #fee2e2;
  --orange:      #c2410c;
  --orange-light:#ea580c;
  --orange-bg:   #ffedd5;
  --gray:        #6b7280;
  --gray-bg:     #f3f4f6;
  --shadow:    0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

/* ============================================================
   BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: 16px;
  scroll-behavior: smooth;
  overflow-x: hidden; /* impedisce scroll orizzontale */
  width: 100%;
}
body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-weight: 400;
  font-size: 1rem;
  line-height: 1.55;
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
  overflow-x: hidden;
  width: 100%;
}

::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 4px; }

.app-shell { display: grid; grid-template-rows: auto 1fr; min-height: 100vh; }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  position: sticky;
  top: 0;
  z-index: 500;
  box-shadow: var(--shadow);
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  isolation: isolate;
}

.topbar-logo { display: flex; align-items: center; gap: 0.55rem; text-decoration: none; flex-shrink: 1; min-width: 0; overflow: hidden; }
.topbar-logo .logo-mark {
  background: var(--tua-blue);
  color: white;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
}
.topbar-logo-wrap { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-logo .logo-text { font-weight: 700; font-size: 0.95rem; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-logo .logo-sub  { font-family: var(--font-mono); font-size: 0.62rem; color: var(--text-secondary); }

.topbar-nav { display: flex; gap: 0.2rem; margin-left: 0.75rem; }

.nav-link {
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  color: var(--text-secondary);
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius);
  transition: var(--transition);
  border: 1px solid transparent;
}
.nav-link:hover { color: var(--text-primary); background: var(--bg-elevated); }
.nav-link.active { color: var(--tua-blue-light); border-color: var(--tua-blue); background: var(--tua-blue-dim); }
[data-theme="light"] .nav-link.active { color: var(--tua-blue); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; min-width: 0; }

/* ---- THEME TOGGLE ---- */
.theme-toggle {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  width: 54px;
  height: 28px;
  cursor: pointer;
  position: relative;
  transition: var(--transition);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px;
}
.theme-toggle .icon-moon { font-size: 12px; }
.theme-toggle .icon-sun  { font-size: 12px; }
.theme-toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: transform 0.25s ease, background 0.25s;
}
[data-theme="light"] .theme-toggle::after {
  transform: translateX(26px);
  background: var(--tua-blue);
}

/* ---- USER CHIP ---- */
.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.2rem 0.8rem 0.2rem 0.2rem;
}
.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--tua-blue);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.75rem; color: white;
}
.user-name { font-size: 0.875rem; color: var(--text-primary); font-weight: 600; }
.user-role { font-family: var(--font-mono); font-size: 0.62rem; color: var(--text-secondary); }

/* ============================================================
   MAIN
   ============================================================ */
.main-content {
  padding: 1.75rem 2rem;
  max-width: 1560px;
  margin: 0 auto;
  width: 100%;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.page-title { font-weight: 700; font-size: 1.75rem; color: var(--text-primary); line-height: 1.2; }
.page-subtitle {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  margin-top: 3px;
}
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.4rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
}
.stat-card.green::before  { background: var(--green); }
.stat-card.red::before    { background: var(--red); }
.stat-card.yellow::before { background: var(--yellow); }
.stat-card.blue::before   { background: var(--tua-blue); }
.stat-card.gray::before   { background: var(--gray); }
.stat-card.orange::before { background: var(--orange); }
.stat-value {
  font-family: var(--font-mono);
  font-size: 2.4rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1;
}
.stat-label {
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ============================================================
   TABLE
   ============================================================ */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
  flex-wrap: wrap;
  background: var(--bg-secondary);
}
.table-title { font-weight: 700; font-size: 0.95rem; color: var(--text-primary); }

table { width: 100%; border-collapse: collapse; font-size: 0.94rem; }
thead th {
  background: var(--bg-elevated);
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: 0.7rem 1.1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
tbody tr:hover { background: var(--bg-elevated); }
tbody tr:last-child { border-bottom: none; }
tbody td { padding: 0.75rem 1.1rem; vertical-align: middle; color: var(--text-primary); }
.mono { font-family: var(--font-mono); font-size: 0.85rem; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-weight: 700; font-size: 0.75rem;
  letter-spacing: 0.04em; text-transform: uppercase;
  padding: 0.22rem 0.6rem; border-radius: var(--radius-sm);
  white-space: nowrap; border: 1px solid transparent;
}
.badge.in-service     { background: var(--green-bg);  color: var(--green-light);  border-color: var(--green); }
.badge.out-service    { background: var(--red-bg);    color: var(--red-light);    border-color: var(--red); }
.badge.long-stop      { background: var(--orange-bg); color: var(--orange-light); border-color: var(--orange); }
.badge.maintenance    { background: var(--yellow-bg); color: var(--yellow-light); border-color: var(--yellow); }
.badge.decommissioned { background: var(--gray-bg);   color: var(--gray);         border-color: var(--border); }
.badge.available      { background: var(--green-bg);  color: var(--green-light);  border-color: var(--green); }
.badge.occupied       { background: var(--yellow-bg); color: var(--yellow-light); border-color: var(--yellow); }
.badge.blocked        { background: var(--red-bg);    color: var(--red-light);    border-color: var(--red); }
.badge.admin          { background: var(--tua-blue-dim); color: var(--tua-blue-light); border-color: var(--tua-blue); }
.badge.writer         { background: var(--yellow-bg); color: var(--yellow-light); border-color: var(--yellow); }

/* Etichette di stato rotabile: larghezza uniforme, così la colonna Stato
   non "salta" da una riga all'altra. La larghezza è calibrata sulla voce
   più lunga ("Radiato / Inutilizzabile"). Non tocca le altre varianti di
   .badge (ruoli utente, stato binari), che restano a larghezza naturale. */
.badge.vehicle-status { width: 168px; justify-content: center; }
.badge.reader         { background: var(--gray-bg);   color: var(--gray);         border-color: var(--border); }

[data-theme="light"] .badge.in-service     { background:#dcfce7; color:#15803d; border-color:#16a34a; }
[data-theme="light"] .badge.out-service    { background:#fee2e2; color:#b91c1c; border-color:#dc2626; }
[data-theme="light"] .badge.long-stop      { background:#ffedd5; color:#c2410c; border-color:#ea580c; }
[data-theme="light"] .badge.maintenance    { background:#fef9c3; color:#a16207; border-color:#ca8a04; }
[data-theme="light"] .badge.decommissioned { background:#f3f4f6; color:#6b7280; border-color:#d1d5db; }
[data-theme="light"] .badge.available      { background:#dcfce7; color:#15803d; border-color:#16a34a; }
[data-theme="light"] .badge.occupied       { background:#fef9c3; color:#a16207; border-color:#ca8a04; }
[data-theme="light"] .badge.blocked        { background:#fee2e2; color:#b91c1c; border-color:#dc2626; }
[data-theme="light"] .badge.admin          { background:#dbeafe; color:#1d4ed8; border-color:#3b82f6; }
[data-theme="light"] .badge.writer         { background:#fef9c3; color:#a16207; border-color:#ca8a04; }
[data-theme="light"] .badge.reader         { background:#f3f4f6; color:#6b7280; border-color:#d1d5db; }

.dot { width:7px; height:7px; border-radius:50%; display:inline-block; flex-shrink:0; }
.dot.green  { background: var(--green-light); }
.dot.red    { background: var(--red-light); }
.dot.yellow { background: var(--yellow-light); }
.dot.orange { background: var(--orange-light); }
.dot.gray   { background: var(--gray); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-family: var(--font-main); font-weight: 600; font-size: 0.9rem;
  padding: 0.48rem 1rem; border-radius: var(--radius);
  border: 1px solid transparent; cursor: pointer; transition: var(--transition);
  text-decoration: none; white-space: nowrap; background: none;
  color: var(--text-primary); line-height: 1.3;
}
.btn-primary { background: var(--tua-blue); border-color: var(--tua-blue); color: white; }
.btn-primary:hover { filter: brightness(1.12); }
.btn-danger  { background: var(--red); border-color: var(--red); color: white; }
.btn-danger:hover  { filter: brightness(1.12); }
.btn-ghost { border-color: var(--border); color: var(--text-secondary); }
.btn-ghost:hover { border-color: var(--border-bright); color: var(--text-primary); background: var(--bg-elevated); }
.btn-success { background: var(--green); border-color: var(--green); color: white; }
.btn-success:hover { filter: brightness(1.12); }
.btn-sm   { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn-icon { padding: 0.38rem 0.5rem; }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 1.1rem; }
label {
  display: block; font-weight: 700; font-size: 0.82rem;
  letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--text-secondary); margin-bottom: 0.4rem;
}
input[type="text"], input[type="password"], input[type="email"],
input[type="number"], input[type="datetime-local"], select, textarea {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.95rem;
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--tua-blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
  padding-right: 2.4rem;
  cursor: pointer;
}
textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-hint { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.25rem; }

.search-wrap { position: relative; }
.search-wrap input { padding-left: 2.3rem; }
.search-icon { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--text-dim); pointer-events: none; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.55); backdrop-filter: blur(3px);
  z-index: 1000; align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 540px; max-height: 90vh; overflow-y: auto;
  animation: slideUp 0.18s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.4rem; border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}
.modal-title { font-weight: 700; font-size: 1.05rem; color: var(--text-primary); }
.modal-body  { padding: 1.4rem; }
.modal-footer {
  display: flex; gap: 0.5rem; justify-content: flex-end;
  padding: 1rem 1.4rem; border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

/* ============================================================
   PIAZZALE
   ============================================================ */
.piazzale-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.track-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem;
  transition: var(--transition); cursor: pointer;
  position: relative; overflow: hidden; box-shadow: var(--shadow);
}
.track-card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px; border-radius: 4px 0 0 4px;
}
.track-card.available::before { background: var(--green); }
.track-card.occupied::before  { background: var(--yellow); }
.track-card.blocked::before   { background: var(--red); }
.track-card:hover {
  border-color: var(--border-bright); background: var(--bg-elevated);
  transform: translateY(-1px); box-shadow: var(--shadow-lg);
}
.track-number { font-family: var(--font-mono); font-size: 1.3rem; font-weight:500; color: var(--text-primary); margin-bottom: 0.35rem; }
.track-vehicles { display: flex; flex-direction: column; gap: 0.3rem; margin-top: 0.5rem; }
.track-note { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.5rem; font-style: italic; }

/* ============================================================
   LOG
   ============================================================ */
.log-entry {
  display: grid; grid-template-columns: 160px 130px 1fr;
  gap: 1rem; padding: 0.7rem 1.25rem; border-bottom: 1px solid var(--border);
  font-size: 0.9rem; align-items: start;
}
.log-entry:last-child { border-bottom: none; }
.log-entry:hover { background: var(--bg-elevated); }
.log-time   { font-family: var(--font-mono); color: var(--text-dim); white-space: nowrap; font-size: 0.8rem; }
.log-user   { color: var(--tua-blue-light); font-weight: 600; }
[data-theme="light"] .log-user { color: var(--tua-blue); }
.log-action { color: var(--text-secondary); }
.log-action strong { color: var(--text-primary); }

/* ============================================================
   LOGIN
   ============================================================ */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg-primary); padding: 1rem; position: relative; overflow: hidden;
}
.login-bg-lines {
  position: absolute; inset: 0; opacity: 0.04;
  background-image:
    repeating-linear-gradient(0deg, var(--tua-blue) 0, transparent 1px, transparent 48px),
    repeating-linear-gradient(90deg, var(--tua-blue) 0, transparent 1px, transparent 48px);
}
.login-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2.5rem 2.25rem; width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); position: relative;
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo .big-mark {
  display: inline-block; background: var(--tua-blue); color: white;
  font-weight: 800; font-size: 1.6rem; letter-spacing: 0.08em;
  padding: 8px 20px; border-radius: var(--radius); margin-bottom: 0.8rem;
}
.login-logo h1 { font-weight: 700; font-size: 1.15rem; color: var(--text-primary); }
.login-logo p {
  font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-secondary);
  letter-spacing: 0.08em; margin-top: 0.3rem;
}
.login-error {
  background: var(--red-bg); border: 1px solid var(--red); color: var(--red-light);
  padding: 0.65rem 0.9rem; border-radius: var(--radius); font-size: 0.88rem;
  margin-bottom: 1rem; display: none;
}
.login-error.visible { display: block; }

/* ============================================================
   TOASTS
   ============================================================ */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.8rem 1.1rem; font-size: 0.9rem; color: var(--text-primary); box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 0.6rem; animation: toastIn 0.2s ease;
  min-width: 270px; max-width: 400px;
}
.toast.success { border-left: 4px solid var(--green); }
.toast.error   { border-left: 4px solid var(--red); }
.toast.info    { border-left: 4px solid var(--tua-blue); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(18px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   MISC
   ============================================================ */
.section { margin-bottom: 2rem; }
.section-title {
  font-weight: 700; font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-secondary); margin-bottom: 0.85rem; padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border);
}

.chip-filters { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.chip {
  font-weight: 600; font-size: 0.8rem; padding: 0.28rem 0.75rem;
  border-radius: 20px; border: 1px solid var(--border); background: none;
  color: var(--text-secondary); cursor: pointer; transition: var(--transition);
}
.chip:hover { border-color: var(--border-bright); color: var(--text-primary); }
.chip.active { border-color: var(--tua-blue); background: var(--tua-blue-dim); color: var(--tua-blue-light); }
[data-theme="light"] .chip.active { color: var(--tua-blue); }

.return-date { font-family: var(--font-mono); font-size: 0.82rem; color: var(--text-secondary); }
.return-date.soon    { color: var(--yellow-light); font-weight: 600; }
.return-date.overdue { color: var(--red-light);    font-weight: 600; }
[data-theme="light"] .return-date.soon    { color: var(--yellow); }
[data-theme="light"] .return-date.overdue { color: var(--red); }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-dim); }
.empty-state .icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty-state p { font-size: 0.95rem; }

.action-cell { display: flex; gap: 0.35rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.6rem; }
.perm-item { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; color: var(--text-secondary); cursor: pointer; }
.perm-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--tua-blue); cursor: pointer; }

.table-scroll { overflow-x: auto; }

/* ============================================================
   KM
   ============================================================ */
.km-entry {
  display: grid;
  grid-template-columns: 170px 150px 1fr auto;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  align-items: center;
}
.km-entry:hover { background: var(--bg-elevated); }
.km-entry:last-child { border-bottom: none; }
.km-value { font-family: var(--font-mono); font-size: 1rem; font-weight: 500; color: var(--text-primary); }
.km-delta { font-family: var(--font-mono); font-size: 0.82rem; color: var(--text-secondary); }
.km-delta.pos { color: var(--green-light); }
[data-theme="light"] .km-delta.pos { color: var(--green); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .main-content { padding: 1.25rem 1rem; }
  .topbar { padding: 0 1rem; }
  .topbar-nav { display: none; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .piazzale-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  .log-entry { grid-template-columns: 1fr; gap: 0.15rem; }
  .km-entry  { grid-template-columns: 1fr 1fr; }

  .mobile-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--bg-secondary); border-top: 1px solid var(--border);
    display: flex; z-index: 200; padding: 0.4rem 0.5rem; gap: 0.2rem;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.15);
    width: 100%; box-sizing: border-box;
    /* Sempre visibile, non scompare mai */
  }
  .mobile-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    gap: 0.15rem; padding: 0.5rem 0.25rem; text-decoration: none;
    color: var(--text-secondary); font-size: 0.65rem; font-weight: 600;
    letter-spacing: 0.03em; text-transform: uppercase; border-radius: var(--radius);
    transition: var(--transition); min-height: 52px; justify-content: center;
  }
  .mobile-nav a.active { color: var(--tua-blue-light); background: var(--tua-blue-dim); }
  [data-theme="light"] .mobile-nav a.active { color: var(--tua-blue); }
  .mobile-nav .nav-icon { font-size: 1.3rem; }
  .app-shell { padding-bottom: 72px; }
}
@media (min-width: 901px) { .mobile-nav { display: none !important; } }

/* ============================================================
   SORTABLE TABLE HEADERS
   ============================================================ */
th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sortable:hover { color: var(--text-primary); background: var(--bg-card); }
.sort-icon { font-size: 0.75rem; margin-left: 0.3rem; color: var(--tua-blue-light); }

/* ============================================================
   MOBILE IMPROVEMENTS
   ============================================================ */
.hide-mobile { }

@media (max-width: 900px) {
  /* Nascondi colonne meno importanti su mobile */
  .hide-mobile { display: none !important; }

  /* Tabella veicoli più compatta su mobile */
  table { font-size: 0.9rem; }
  thead th { padding: 0.55rem 0.6rem; font-size: 0.72rem; }
  tbody td { padding: 0.6rem 0.6rem; }

  /* Celle compatte */
  .badge { font-size: 0.7rem; padding: 0.18rem 0.45rem; }

  /* Bottoni azione più grandi su mobile (touch target) */
  .action-cell .btn { min-width: 36px; min-height: 36px; font-size: 1rem; justify-content: center; }

  /* Modal più alto su mobile */
  .modal { max-height: 95vh; border-radius: var(--radius) var(--radius) 0 0; }
  .modal-overlay { align-items: flex-end; padding: 0; }

  /* Page header compatto */
  .page-title { font-size: 1.4rem; }
  .page-header { margin-bottom: 1rem; }

  /* Stat grid 2 colonne più compatte */
  .stat-grid { gap: 0.6rem; }
  .stat-card { padding: 0.8rem 1rem; }
  .stat-value { font-size: 2rem; }

  /* Piazzale: 2 colonne su mobile */
  .piazzale-grid { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
  .track-card { padding: 0.75rem; }
  .track-number { font-size: 1.1rem; }

  /* Chip filters scrollabili orizzontalmente */
  .chip-filters { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .chip-filters::-webkit-scrollbar { height: 3px; }
  .chip { white-space: nowrap; flex-shrink: 0; }

  /* Topbar compatta */
  .topbar { height: 52px; padding: 0 0.75rem; }
  .topbar-logo .logo-sub  { display: none; } /* nasconde sottotitolo su mobile */
  .topbar-logo .logo-text { display: none; } /* nasconde "Divisione Ferroviaria" su mobile */
  .theme-toggle { width: 40px; height: 24px; }
  .theme-toggle::after { width: 16px; height: 16px; }
  [data-theme="light"] .theme-toggle::after { transform: translateX(16px); }
  /* Pulsante Esci → icona su mobile */
  .btn.btn-ghost.btn-sm[onclick="logout()"] { font-size: 0.72rem; padding: 0.3rem 0.5rem; }
}

/* Card mobile per stato rapido veicolo */
@media (max-width: 600px) {
  /* Su schermi molto piccoli, la tabella diventa card */
  .mobile-card-table thead { display: none; }
  .mobile-card-table tbody tr {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.6rem;
    padding: 0.75rem;
  }
  .mobile-card-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.2rem 0;
    border: none;
    font-size: 0.88rem;
  }
  .mobile-card-table tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 0.72rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.04em;
    margin-right: 0.5rem;
  }
  .mobile-card-table tbody td:last-child {
    justify-content: flex-end;
    padding-top: 0.4rem;
    margin-top: 0.4rem;
    border-top: 1px solid var(--border);
  }
}

/* ============================================================
   STILI PER PALLINO STATO E BADGE INTERNO/ESTERNO (GRIGIO)
   ============================================================ */

/* Pallino stato */
.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.4rem;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.1);
}

/* Badge Interno/Esterno — indaco (interno) / giallo sole (esterno) */
.loc-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 900;
  margin-left: 0.3rem;
  flex-shrink: 0;
  line-height: 1;
}

/* Interno = indaco notte (al coperto) */
.loc-badge.loc-interno {
  background: #4338ca;
  color: #e0e7ff;
  border: none;
}

/* Esterno = giallo sole (all'aperto) */
.loc-badge.loc-esterno {
  background: #a16207;
  color: #fef9c3;
  border: none;
}

[data-theme="light"] .loc-badge.loc-interno {
  background: #e0e7ff;
  color: #4338ca;
  border: none;
}

[data-theme="light"] .loc-badge.loc-esterno {
  background: #fef9c3;
  color: #a16207;
  border: none;
}

/* Gli stili delle pill .track-vehicle-item sono definiti in piazzale.html
   (unico punto d'uso), per evitare duplicazioni e conflitti di specificità. */

/* Cella binario in dashboard */
.track-cell {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.fuori-piazzale {
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.85rem;
}

/* ============================================================
   MOBILE CARD LAYOUT - DEFINITIVO
   ============================================================ */
@media (max-width: 900px) {
  /* Forza la visualizzazione a card */
  table.mobile-card-table thead {
    display: none !important;
  }
  
  table.mobile-card-table tbody tr {
    display: block !important;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    margin-bottom: 1rem;
    padding: 1rem;
    box-shadow: var(--shadow);
  }
  
  table.mobile-card-table tbody td {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0;
    border: none;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    gap: 0.75rem;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    text-align: left !important;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  /* Il valore (dopo l'etichetta ::before) può andare a capo e restare nel riquadro */
  table.mobile-card-table tbody td > * {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
    text-align: right;
  }

  table.mobile-card-table tbody tr {
    max-width: 100%;
    overflow: hidden;
  }

  /* In modalità card lo scroll orizzontale non serve e causerebbe overflow */
  .table-scroll:has(table.mobile-card-table),
  .table-scroll-cards {
    overflow-x: hidden;
  }
  
  table.mobile-card-table tbody td:last-child {
    border-bottom: none;
    padding-bottom: 0;
  }
  
  table.mobile-card-table tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    min-width: 100px;
    flex-shrink: 0;
  }
  
  table.mobile-card-table tbody td:last-child::before {
    display: none;
  }
  
  table.mobile-card-table tbody td:last-child {
    justify-content: flex-end;
    padding-top: 0.75rem;
    margin-top: 0.25rem;
  }
  
  .action-cell {
    display: flex;
    gap: 0.75rem;
    width: 100%;
    justify-content: flex-end;
  }
  
  .action-cell .btn {
    min-height: 44px;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
  }
  
  /* Nascondi intestazioni ordinabili su mobile */
  th.sortable {
    display: none !important;
  }
  
  /* Filtri scrollabili */
  .chip-filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.4rem;
    padding-bottom: 0.5rem;
  }
  
  .chip-filters::-webkit-scrollbar {
    height: 3px;
  }
  
  .chip {
    white-space: nowrap;
    font-size: 0.8rem;
    padding: 0.4rem 0.9rem;
  }
  
  /* Stat cards compatte */
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
    margin-bottom: 1rem;
  }
  
  .stat-card {
    padding: 0.7rem 0.8rem;
  }
  
  .stat-value {
    font-size: 1.8rem;
  }
  
  .stat-label {
    font-size: 0.65rem;
  }
  
  .page-title {
    font-size: 1.4rem;
  }
  
  .page-actions .btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
  }
  
  .main-content {
    padding: 1rem 0.75rem;
  }
}

/* Intestazioni ordinabili desktop */
th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.sortable:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

.sort-icon {
  font-size: 0.75rem;
  margin-left: 0.3rem;
  color: var(--tua-blue-light);
}
/* ============================================================
   TOGGLE SWITCH — checkbox "Interno (coperto)"
   ============================================================ */
.toggle-switch-label {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  padding: 0.55rem 0.9rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition);
  text-transform: none;
  font-weight: 400;
  font-size: 0.95rem;
  color: var(--text-primary);
  min-height: 42px;
  width: 100%;
}
.toggle-switch-label:hover { border-color: var(--tua-blue); }
.toggle-switch-label input[type="checkbox"] { display: none; }

.toggle-switch {
  width: 40px;
  height: 22px;
  background: var(--border-bright);
  border-radius: 11px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.toggle-switch-label input:checked ~ .toggle-switch,
.toggle-switch-label input:checked + .toggle-switch {
  background: #1e40af;
}
.toggle-switch-label input:checked ~ .toggle-switch::after,
.toggle-switch-label input:checked + .toggle-switch::after {
  transform: translateX(18px);
}
.toggle-text { line-height: 1.3; }

/* ============================================================
   BINARIO + POSIZIONE SULLA STESSA RIGA (modale desktop)
   ============================================================ */
.form-row-inline {
  display: flex;
  align-items: flex-end;
  gap: 0.7rem;
}
.form-row-inline > div:first-child { flex: 1.4; min-width: 0; }
.interno-toggle-wrap { flex: 1; min-width: 0; }
.interno-toggle-label {
  width: 100%;
  justify-content: space-between;
  height: 42px;
  box-sizing: border-box;
}
@media (max-width: 480px) {
  .form-row-inline { flex-direction: column; align-items: stretch; }
}

/* ============================================================
   SELETTORE DECORRENZA (cambio stato con data/ora)
   ============================================================ */
.dec { position: relative; }
.dec-trigger {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; font-family: var(--font-mono); font-size: .85rem;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-secondary);
  padding: .45rem .6rem; cursor: pointer; transition: var(--transition);
}
.dec-trigger:hover { border-color: var(--border-bright); }
.dec-trigger.set { color: var(--text-primary); border-color: var(--tua-blue); }
.dec-caret { font-size: .7rem; opacity: .6; }
.dec-panel {
  margin-top: .4rem; background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .6rem;
}
.dec-row { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; }
.dec-row + .dec-row { margin-top: .45rem; }
.dec-lab {
  font-family: var(--font-mono); font-size: .62rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-dim); margin: .55rem 0 .3rem;
}
.dec-chip {
  font-family: var(--font-mono); font-size: .78rem; font-weight: 600;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-secondary);
  padding: .25rem .55rem; cursor: pointer; transition: var(--transition);
}
.dec-chip:hover { border-color: var(--border-bright); color: var(--text-primary); }
.dec-chip.on { background: var(--tua-blue-dim); border-color: var(--tua-blue); color: var(--tua-blue-light); }
[data-theme="light"] .dec-chip.on { color: var(--tua-blue); }
.dec-slots { display: grid; grid-template-columns: repeat(6, 1fr); }
.dec-date, .dec-time {
  font-family: var(--font-mono); font-size: .8rem; background: var(--bg-elevated);
  color: var(--text-primary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .22rem .4rem; flex: 1; min-width: 110px;
}
.dec-clear {
  font-family: var(--font-mono); font-size: .72rem; background: transparent;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-dim); padding: .25rem .5rem; cursor: pointer;
}
.dec-clear:hover { color: var(--text-primary); border-color: var(--border-bright); }
.dec-hint { font-size: .72rem; color: var(--text-dim); margin-top: .5rem; line-height: 1.4; }
@media (max-width: 520px) {
  .dec-slots { grid-template-columns: repeat(3, 1fr); }
}


/* ============================================================
   VISIBILITA' VOCI DI MENU — senza sfarfallio
   ------------------------------------------------------------
   Le classi vengono applicate su <html> dallo script sincrono in
   <head>, leggendo ruolo e permessi memorizzati al login. Cosi'
   la barra e' gia' corretta al primo disegno: nessuna voce che
   compare o sparisce a pagina caricata.
   ============================================================ */
/* Le regole sono limitate alle barre di navigazione: il logo punta a
   dashboard.html e non deve mai sparire. */
html.nav-no-admin        .topbar-nav a[href="admin.html"],
html.nav-no-admin        .mobile-nav a[href="admin.html"],
html.nav-no-dashboard    .topbar-nav a[href="dashboard.html"],
html.nav-no-dashboard    .mobile-nav a[href="dashboard.html"],
html.nav-no-piazzale     .topbar-nav a[href="piazzale.html"],
html.nav-no-piazzale     .mobile-nav a[href="piazzale.html"],
html.nav-no-disponibilita .topbar-nav a[href="disponibilita.html"],
html.nav-no-disponibilita .mobile-nav a[href="disponibilita.html"],
html.nav-no-chilometri   .topbar-nav a[href="chilometri.html"],
html.nav-no-chilometri   .mobile-nav a[href="chilometri.html"],
html.nav-no-log          .topbar-nav a[href="log.html"],
html.nav-no-log          .mobile-nav a[href="log.html"] { display: none !important; }


/* ============================================================
   TABELLA -> SCHEDE SU MOBILE
   ------------------------------------------------------------
   Aggiungere la classe .card-table alla <table> e l'attributo
   data-label a ogni <td>. Sotto i 900px la tabella si scompone
   in schede verticali, eliminando lo scorrimento orizzontale che
   tagliava le colonne fuori schermo.
   ============================================================ */
@media (max-width: 900px) {
  .table-scroll:has(> table.card-table) { overflow-x: visible; }

  table.card-table { display: block; }
  table.card-table thead { display: none; }
  table.card-table tbody { display: block; }

  table.card-table tbody tr {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: .7rem;
    padding: .85rem 1rem;
    box-shadow: var(--shadow);
  }

  table.card-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    width: 100%;
    padding: .5rem 0;
    border: none;
    border-bottom: 1px solid var(--border);
    text-align: left !important;
    font-size: .9rem;
    white-space: normal;
  }

  table.card-table tbody td::before {
    content: attr(data-label);
    font-family: var(--font-mono);
    font-size: .66rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-dim);
    flex-shrink: 0;
  }

  /* celle senza etichetta (azioni) */
  table.card-table tbody td[data-label=""]::before,
  table.card-table tbody td:not([data-label])::before { display: none; }

  table.card-table tbody td:last-child {
    border-bottom: none;
    padding-bottom: 0;
    justify-content: flex-end;
  }
  table.card-table tbody td:last-child::before { display: none; }

  table.card-table tbody tr.is-empty { padding: 1.5rem 1rem; text-align: center; }
  table.card-table tbody tr.is-empty td { justify-content: center; border: none; }
  table.card-table tbody tr.is-empty td::before { display: none; }
}
