:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f0f2f5; --text: #1b2430; --muted: #5d6b7c; --line: #dfe3e8;
  --brand: #d71920; --brand-ink: #ffffff;
  --ok: #1a8f4c; --ok-bg: #e5f5ec; --warn: #b36b00; --warn-bg: #fff3dc; --bad: #c42b2b; --bad-bg: #fde8e8; --legacy: #6b7787; --legacy-bg: #eceff3;
  --shadow: 0 1px 2px rgba(20,30,50,.06), 0 4px 14px rgba(20,30,50,.05);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --surface: #1b212a; --surface-2: #232b36; --text: #e8edf3; --muted: #9aa8b8; --line: #2d3744;
    --ok: #4cc57f; --ok-bg: #16301f; --warn: #f0b04a; --warn-bg: #36290f; --bad: #ff7a7a; --bad-bg: #3a1a1a; --legacy: #98a5b5; --legacy-bg: #232b36;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); } .small { font-size: .88rem; }
.logo { font-weight: 800; letter-spacing: -.02em; font-size: 1.25rem; } .logo span { color: var(--brand); }

/* login */
#login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(380px, 100%); background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: .92rem; color: var(--muted); }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: 44px; }
input:focus, select:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 1px; }
.err { color: var(--bad); min-height: 1.2em; font-size: .92rem; }

.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 10px; padding: 10px 16px; min-height: 44px; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); } .btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* top */
.top { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-right { display: flex; gap: 12px; align-items: center; }

.banner { margin: 16px 20px 0; padding: 14px 18px; border-radius: var(--radius); display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap; font-weight: 600; }
.banner.ok { background: var(--ok-bg); color: var(--ok); } .banner.warn { background: var(--warn-bg); color: var(--warn); } .banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner .sub { font-weight: 400; opacity: .9; font-size: .92rem; }
.banner .kill { display: flex; gap: 10px; align-items: center; }

.tabs { display: flex; gap: 6px; padding: 16px 20px 0; overflow-x: auto; }
.tab { font: inherit; font-weight: 600; border: 0; background: transparent; color: var(--muted); padding: 10px 14px; border-radius: 10px 10px 0 0; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; min-height: 44px; }
.tab.active { color: var(--text); border-bottom-color: var(--brand); }
main { padding: 4px 20px 60px; }
.panel { background: transparent; padding-top: 14px; }

/* griglia stazioni */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.st { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; border: 1px solid transparent; border-left: 6px solid var(--line); cursor: pointer; text-align: left; font: inherit; color: inherit; display: grid; gap: 8px; }
.st:hover { border-color: var(--line); }
.st.ok { border-left-color: var(--ok); } .st.warn { border-left-color: var(--warn); } .st.bad { border-left-color: var(--bad); } .st.legacy { border-left-color: var(--legacy); opacity: .85; }
.st-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.st-name { font-weight: 700; font-size: 1.1rem; } .st-code { color: var(--muted); font-size: .85rem; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .82rem; font-weight: 600; }
.pill.ok { background: var(--ok-bg); color: var(--ok); } .pill.warn { background: var(--warn-bg); color: var(--warn); } .pill.bad { background: var(--bad-bg); color: var(--bad); } .pill.legacy { background: var(--legacy-bg); color: var(--legacy); }
.pill.live { background: var(--bad-bg); color: var(--bad); } .pill.shadow { background: var(--surface-2); color: var(--muted); }
.st-line { color: var(--muted); font-size: .9rem; }
.st-nums { display: flex; gap: 14px; font-size: .9rem; } .st-nums b { font-variant-numeric: tabular-nums; }

/* eventi / registro */
.events { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.ev { display: grid; grid-template-columns: 92px 74px 1fr; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: .92rem; align-items: baseline; }
.ev:last-child { border-bottom: 0; }
.ev .t { color: var(--muted); font-variant-numeric: tabular-nums; } .ev .s { font-weight: 700; }
.ev.err .x { color: var(--bad); } .ev.warn .x { color: var(--warn); } .ev.act .x { color: var(--text); font-weight: 600; } .ev.sim .x { color: var(--muted); }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
label.inline { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-size: .92rem; }
label.inline input[type=checkbox] { min-height: 0; width: 18px; height: 18px; }
.num { width: 90px; }

/* impostazioni */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin: 14px 0; }
.tbl { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: .95rem; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; font-size: .85rem; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); }
.tbl td .btn { min-height: 34px; padding: 4px 10px; }
.tbl .empty-row td { color: var(--muted); text-align: center; }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.add-row input { width: 110px; }
.savebar { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; display: flex; gap: 14px; align-items: center; }

/* dettaglio */
dialog { border: 0; border-radius: var(--radius); padding: 20px; background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35); width: min(820px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; }
dialog::backdrop { background: rgba(10,15,25,.55); }
.dlg-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.stats { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-bottom: 14px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; } .stat .k { color: var(--muted); font-size: .82rem; } .stat .v { font-weight: 700; font-size: 1.05rem; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.log { background: #0f141a; color: #cfe3d4; border-radius: 10px; padding: 12px; font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; max-height: 340px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
#cInput { text-transform: uppercase; margin-top: 4px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); z-index: 20; max-width: calc(100vw - 32px); }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 560px) {
  .top, .banner, .tabs, main { padding-left: 14px; padding-right: 14px; } .banner { margin-left: 14px; margin-right: 14px; }
  .ev { grid-template-columns: 1fr; gap: 2px; }
}

/* ───────── impostazioni (stile popup SSEngine) ───────── */
.card.flush { padding: 0; overflow: hidden; }
.ph { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.ph .small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.srow { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.srow:last-child { border-bottom: 0; }
.nm { font-weight: 600; } .cd { color: var(--muted); font-size: .82rem; }
.note { color: var(--muted); font-size: .88rem; padding: 10px 16px 14px; line-height: 1.5; }
.save-state { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: .95rem; }
.save-state .ico { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--ok-bg); color: var(--ok); font-size: .8rem; font-weight: 700; }
.save-state.busy .ico { background: var(--warn-bg); color: var(--warn); }
.save-state.err .ico { background: var(--bad-bg); color: var(--bad); }

.sblk { border-bottom: 1px solid var(--line); }
.sblk:last-child { border-bottom: 0; }
.shead { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 16px; }
.sname { display: flex; align-items: center; gap: 10px; cursor: pointer; flex: 1; min-width: 0; padding: 4px 0; background: none; border: 0; font: inherit; color: inherit; text-align: left; min-height: 44px; }
.chev { display: inline-block; width: 12px; color: var(--muted); transition: transform .15s; font-size: .8rem; }
.sblk.open .chev { transform: rotate(90deg); }
.badge-ov { font-size: .72rem; background: var(--warn-bg); color: var(--warn); padding: 2px 9px; border-radius: 999px; margin-left: 6px; font-weight: 600; white-space: nowrap; }
.glist { background: var(--surface-2); border-top: 1px solid var(--line); }
.grow { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 16px 6px 38px; border-bottom: 1px solid var(--line); min-height: 46px; }
.grow:last-child { border-bottom: 0; }
.gname { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92rem; }
.gname.sans { font-family: inherit; }
.tagov { font-size: .7rem; color: var(--warn); margin-left: 8px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.tagoff { font-size: .7rem; color: var(--muted); margin-left: 8px; text-transform: uppercase; letter-spacing: .05em; }
.ctl { display: flex; align-items: center; gap: 8px; }
.stp { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stp button { border: 0; background: var(--surface); color: var(--text); width: 40px; height: 40px; font-size: 1.15rem; line-height: 1; cursor: pointer; }
.stp button:hover { background: var(--surface-2); }
.stp .v { min-width: 62px; text-align: center; font-weight: 700; font-size: .9rem; padding: 0 8px; height: 40px; display: grid; place-items: center; color: #fff; font-variant-numeric: tabular-nums; }
.xbtn { border: 0; background: var(--warn-bg); color: var(--warn); width: 32px; height: 32px; border-radius: 8px; font-size: 1.05rem; cursor: pointer; line-height: 1; }
.xbtn:hover { filter: brightness(.95); }
.legend { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem; }
.legend .dot { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 5px; color: #fff; font-size: .72rem; font-weight: 700; }
.addgrp { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 16px 12px 38px; border-top: 1px solid var(--line); }
.addgrp select { min-height: 38px; padding: 6px 10px; }
.fleetnote { padding: 8px 16px 6px 38px; color: var(--muted); font-size: .82rem; }
@media (max-width: 560px) { .grow, .addgrp, .fleetnote { padding-left: 18px; } .srow { flex-wrap: wrap; } }

@media (max-width: 640px) {
  .shead { flex-wrap: wrap; padding-bottom: 12px; }
  .sname { flex: 1 1 100%; min-height: 40px; }
  .shead .ctl, .srow .ctl { padding-left: 22px; }
  .srow { align-items: flex-start; }
  .ph { flex-wrap: wrap; }
  .badge-ov { display: inline-block; margin: 4px 0 0 0; }
  .grow { padding-left: 22px; flex-wrap: wrap; }
  .tabs { scrollbar-width: none; } .tabs::-webkit-scrollbar { display: none; }
}

@media (min-width: 900px) {
  main, .tabs { max-width: 1500px; margin-left: auto; margin-right: auto; }
  .banner { max-width: 1460px; margin-left: auto; margin-right: auto; }
  /* le altre sezioni restano strette e allineate a sinistra come le schede in alto; la griglia stazioni usa tutta la larghezza */
  .panel:not(#tab-stazioni) { max-width: 1020px; }
}

/* schede stazione compatte: 13 stazioni in una schermata, senza scorrere */
@media (min-width: 900px) {
  .banner { margin-top: 12px; padding: 10px 16px; }
  .tabs { padding-top: 10px; }
  .tab { min-height: 38px; padding: 8px 14px; }
  .panel { padding-top: 10px; }
  main { padding-bottom: 24px; }
  #grid { gap: 10px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
  #grid .st { padding: 10px 12px; gap: 5px; border-left-width: 5px; }
  #grid .st-name { font-size: 1rem; }
  #grid .st-code { font-size: .78rem; }
  #grid .pill { padding: 2px 8px; font-size: .76rem; }
  #grid .st-line { font-size: .8rem; line-height: 1.3; }
}

/* salute del server (barra in alto) e elenco avvisi nel banner */
.top { gap: 14px; flex-wrap: wrap; }
.sys { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-left: auto; margin-right: 6px; }
.chip { display: inline-flex; gap: 6px; align-items: baseline; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .78rem; white-space: nowrap; }
.chip b { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 700; }
.chip.ok b { color: var(--ok); } .chip.warn { background: var(--warn-bg); } .chip.warn b { color: var(--warn); } .chip.bad { background: var(--bad-bg); } .chip.bad b { color: var(--bad); }
.alerts { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; font-weight: 500; font-size: .92rem; }
.alerts li::before { content: '●'; margin-right: 8px; font-size: .7em; vertical-align: 1px; }
.alerts li.bad::before { color: var(--bad); } .alerts li.warn::before { color: var(--warn); } .alerts li.more { opacity: .75; } .alerts li.more::before { content: ''; margin: 0; }
@media (max-width: 899px) { .sys { order: 3; flex-basis: 100%; margin: 0; } .top { position: static; } }

