/* ── SKYNET design tokens (light: grayscale + red accent) ────────── */
:root {
  --bg:             #f5f5f6;
  --panel:          #ffffff;
  --panel-2:        #f0f0f2;
  --panel-3:        #e6e7ea;
  --border:         #d8d9dd;
  --border-strong:  #b8bac1;
  --text:           #0a0b0d;
  --muted:          #6b6f78;
  --primary:        #d72020;
  --primary-soft:   #fde7e7;
  --primary-strong: #a81818;
  --shadow:         0 4px 14px rgba(10, 11, 13, 0.06);
  --radius:         10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { accent-color: var(--primary); color-scheme: light; }
body {
  color: var(--text);
  background: var(--bg);
  font-family: ui-sans-serif, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.app { width: 100%; margin: 0; padding: 14px 24px 48px; box-sizing: border-box; transition: padding .25s ease; }

/* ── Topbar ─────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 14px;
  margin: 4px 2px 16px; padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-size: 16px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; }
.topbar .brand span { color: var(--primary); }
.topbar .brand .model { display: inline-block; vertical-align: middle; margin-left: 8px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: none; color: var(--muted, #6b6f78); background: var(--panel-2, #f0f0f2); border: 1px solid var(--border, #d8d9dd); border-radius: 5px; padding: 1px 6px; }
.topbar .brand small {
  font-weight: 400; color: var(--muted); font-size: 11px;
  letter-spacing: 0.06em; margin-left: 10px; text-transform: none;
}

/* ── Tabs ───────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 6px; margin: 0 2px 14px; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--border-strong); background: var(--panel);
  color: var(--muted); border-radius: 8px; padding: 8px 16px;
  font: inherit; font-weight: 600; cursor: pointer;
}
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── Sotto-tab ──────────────────────────────────────────────────── */
.subtabs { display: flex; gap: 4px; margin: 0 2px 12px; flex-wrap: wrap; border-bottom: 2px solid var(--border); }
.subtab {
  border: none; background: transparent; color: var(--muted);
  padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.subtab:hover { color: var(--text); }
.subtab.active { color: var(--primary-strong); border-bottom-color: var(--primary); }

/* ── Card ───────────────────────────────────────────────────────── */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.card-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.card-head h1 { font-size: 19px; margin: 0; }
.card-head .sub { color: var(--muted); font-size: 13px; }

/* ── Table ──────────────────────────────────────────────────────── */
/* Regola: le tabelle si adattano alla larghezza disponibile, niente scroll-bar
   orizzontale. table-layout:fixed distribuisce le colonne e il testo va a capo. */
.table-scroll { overflow-x: hidden; border-radius: 8px; }
table.grid { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td {
  border: 1px solid var(--border); padding: 6px 8px; text-align: left;
  white-space: normal; overflow-wrap: anywhere; word-break: break-word; vertical-align: top;
}
table.grid thead th { background: var(--panel-2); font-weight: 700; position: sticky; top: 0; z-index: 1; }
th.filterable .th-label { user-select: none; cursor: pointer; }
th.filterable .th-label:hover { color: var(--primary-strong); }
th.filterable.has-filter .th-label { color: var(--primary-strong); }
.th-funnel { display: inline-flex; vertical-align: middle; margin-left: 6px; color: var(--muted); cursor: pointer; opacity: .75; }
.th-funnel:hover { color: var(--primary); opacity: 1; }
th.filterable.has-filter .th-funnel { color: var(--primary); opacity: 1; }

/* Filtro inline dentro l'intestazione */
.th-filter { margin-top: 6px; }
.th-input {
  width: 100%; box-sizing: border-box; min-width: 0; border: 1px solid var(--border-strong);
  border-radius: 6px; padding: 3px 6px; font: inherit; font-size: 11px; font-weight: 400;
  background: var(--panel); color: var(--text);
}
.th-input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
table.grid tbody tr:nth-child(even) { background: var(--panel-2); }
table.grid td.null { color: var(--muted); }
table.grid td.flag-p { color: #1f7a3a; font-weight: 700; text-align: center; }
table.grid td.flag-n { color: var(--primary); font-weight: 700; text-align: center; }
table.grid td.flag-np { color: var(--muted); font-weight: 700; text-align: center; }
table.grid th.center, table.grid td.center { text-align: center; }
.foto-link { text-decoration: none; cursor: pointer; }
.foto-link:hover { opacity: .7; }

/* ── Drill-down (programma → analitico) ─────────────────────────── */
.col-exp { width: 44px; text-align: center; }
tr.master-row.has-analitico { cursor: pointer; }
tr.master-row.has-analitico:hover td { background: var(--primary-soft); }
tr.master-row .go { color: var(--primary); font-weight: 700; font-size: 16px; }
.badge.inline {
  font-size: 12px; font-weight: 700; color: var(--primary);
  background: var(--primary-soft); padding: 0 7px; border-radius: 999px;
}

.card-head.drill { display: flex; align-items: center; gap: 16px; }
.card-head.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.drill-left { display: flex; align-items: center; gap: 16px; }
.btn-export {
  border: 1px solid var(--border-strong); background: var(--panel); color: var(--text);
  border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.btn-export:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-strong); }
.card-head h1 .muted { color: var(--muted); font-weight: 400; }
.back-btn {
  border: 1px solid var(--border-strong); background: var(--panel); color: var(--text);
  border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.back-btn:hover { background: var(--panel-2); }

/* ── Stato rilievo (derivato dall'esistenza della rilevazione) ───── */
.stato-badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 9px; border-radius: 999px; white-space: nowrap;
}
.stato-compl { background: #e3f5e8; color: #1f7a3a; }  /* Completato — analitico pronto (verde) */
.stato-ril   { background: #fff1de; color: #9a5b00; }   /* Rilevato — video caricato (ambra) */
.stato-prog  { background: var(--panel-3); color: var(--muted); }  /* Programmato (grigio) */
.stato-ricontrollo { background: #ffe1c2; color: #9a3b00; font-weight: 700; }  /* Da ricontrollare D1/D2/D3 (arancione) */
.head-actions { display: flex; align-items: center; gap: 10px; }
.mese-sel { border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; font: inherit; font-size: 13px; background: var(--panel); color: var(--text); cursor: pointer; }
.stato-canc  { background: #e7edf6; color: #34557f; }   /* Treno cancellato */
.stato-ann   { background: #fde7e7; color: #a81818; }   /* Turno annullato */
.stato-nonamm{ background: #efe6f6; color: #6a3a86; }   /* Rilievo non ammissibile */

/* Colonna Video: pill grigia = non caricato, verde = caricato (cliccabile → apre il video) */
td.vpill-cell { text-align: center; white-space: nowrap; }
/* Orario effettivamente RILEVATO (dal form) vs programmato: leggermente evidenziato */
td.ril-actual { font-weight: 600; color: var(--text); }
.vpill {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 10px; border-radius: 999px; white-space: nowrap;
  text-decoration: none; line-height: 1.6;
}
.vpill-ok { background: #e3f5e8; color: #1f7a3a; }
.vpill[role="button"] { cursor: pointer; }
a.vpill-ok:hover, .vpill[role="button"]:hover { background: #cfeed9; }
.vpill-no { background: var(--panel-3); color: var(--muted); }

/* Pannello laterale col player video: slide da DESTRA, restringe il contenuto a sinistra (no overlay) */
.video-drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(460px, 92vw);
  background: var(--panel); border-left: 1px solid var(--border-strong);
  box-shadow: -14px 0 36px rgba(0, 0, 0, .18);
  transform: translateX(100%); transition: transform .25s ease;
  z-index: 60; display: flex; flex-direction: column;
}
.video-drawer.open { transform: translateX(0); }
body.drawer-open .app { padding-right: calc(min(460px, 92vw) + 24px); }
@media (max-width: 820px) {
  .video-drawer { width: 100vw; }
  body.drawer-open .app { padding-right: 24px; }
}
.vd-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border); }
.vd-title { font-weight: 700; font-size: 14px; }
.vd-close { border: 1px solid var(--border-strong); background: var(--panel); color: var(--muted); border-radius: 8px; width: 30px; height: 30px; cursor: pointer; font-size: 15px; line-height: 1; }
.vd-close:hover { color: var(--primary); border-color: var(--primary); }
.vd-body { padding: 16px; overflow: auto; }

/* Player verticale (video da smartphone) */
.video-box { position: relative; height: min(74vh, 720px); aspect-ratio: 9/16; max-width: 100%; margin: 0 auto; background: #000; border-radius: 12px; overflow: hidden; border: 1px solid var(--border-strong); }
.video-box iframe, .video-box video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #000; object-fit: contain; }

.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ── Vista Regole (Markdown) ────────────────────────────────────── */
.md-content { max-width: 920px; line-height: 1.6; }
.md-content h1 { font-size: 24px; margin: 0 0 14px; }
.md-content h2 { font-size: 19px; margin: 26px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.md-content h3 { font-size: 15px; margin: 18px 0 8px; }
.md-content p { margin: 8px 0; }
.md-content ul { margin: 8px 0; padding-left: 22px; }
.md-content li { margin: 3px 0; }
.md-content hr { border: none; border-top: 1px solid var(--border); margin: 22px 0; }
.md-content code {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 5px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px;
}
.md-content blockquote {
  margin: 12px 0; padding: 8px 14px; border-left: 3px solid #a35a00;
  background: #fbeed1; border-radius: 0 8px 8px 0; color: #6b4e00;
}
.md-content table.md-table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13px; }
.md-content table.md-table th, .md-content table.md-table td {
  border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top;
}
.md-content table.md-table thead th { background: var(--panel-2); font-weight: 700; }
.md-content table.md-table tbody tr:nth-child(even) { background: var(--panel-2); }
