:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #111827; --muted: #6b7280; --line: #e5e7eb; --accent: #f5b301;
  --av: #7b2d8e; --avlo: #00b5ad; --ld: #1d4ed8; --md: #ea7a0c; --cerc: #d62828; --iryo: #b4002d; --ouigo: #e6007e;
  --ok: #16a34a; --warn: #d97706; --bad: #dc2626; --crit: #7f1d1d;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b0f17; --panel: #121826; --ink: #e5e7eb; --muted: #9aa3b2; --line: #232b3b; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); display: flex; flex-direction: column; }
h1 { font-size: 16px; margin: 0; display: flex; align-items: center; gap: 8px; }
h2 { font-size: 16px; margin: 0; }
.muted { color: var(--muted); }

.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 1000; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { font-size: 22px; }
.sub { margin: 0; color: var(--muted); font-size: 12px; }
.live { font-size: 11px; font-weight: 600; color: var(--bad); display: inline-flex; align-items: center; gap: 4px; text-transform: uppercase; letter-spacing: .04em; }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--bad); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.kpis { display: flex; gap: 18px; margin-left: auto; overflow-x: auto; }
.kpi { display: flex; flex-direction: column; align-items: flex-end; white-space: nowrap; }
.kpi b { font-size: 18px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 11px; color: var(--muted); }
.icon-btn { background: none; border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 16px; }
#toggleSide { display: none; }

.layout { flex: 1; display: flex; min-height: 0; }
.side { width: 380px; max-width: 100%; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; padding: 10px 4px; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; cursor: pointer; font-size: 13px; }
.tab.active { color: var(--ink); border-color: var(--accent); }
.tab b { background: var(--bad); color: #fff; border-radius: 10px; padding: 0 6px; font-size: 11px; }
.tab b:empty { display: none; }
.panel { display: none; flex: 1; overflow: auto; padding: 12px; min-height: 0; }
.panel.active { display: block; }
input[type=search], input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: inherit; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px 3px 6px; cursor: pointer; font-size: 12px; user-select: none; }
.chip input { width: auto; margin: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); display: inline-block; }
.dot.est { background: transparent; border: 2px dashed var(--c); }
.sortbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.sortbar select { width: auto; padding: 4px 8px; }
.list { list-style: none; margin: 0; padding: 0; }
.item { padding: 9px 8px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 6px; }
.item:hover { background: var(--bg); }
.item .t1 { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.item .t2 { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; color: #fff; background: var(--c, #555); font-weight: 600; }
.tag.light { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.delay { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; }
.delay.ok { color: var(--ok); } .delay.warn { color: var(--warn); } .delay.bad { color: var(--bad); }
.lvl-severe { border-left: 4px solid var(--crit); } .lvl-warning { border-left: 4px solid var(--bad); }
.lvl-info, .lvl-works { border-left: 4px solid var(--ld); } .lvl-user { border-left: 4px solid var(--accent); }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; border-radius: 3px; }
.note { font-size: 12px; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0 0 10px; }
form label { display: block; margin: 10px 0; font-weight: 600; font-size: 13px; }
form label input, form label select, form label textarea { margin-top: 4px; font-weight: 400; }
.row { display: flex; align-items: center; gap: 10px; }
.btn { background: var(--accent); color: #111; border: 0; border-radius: 8px; padding: 9px 14px; font-weight: 700; cursor: pointer; }
.btn.ghost { background: none; color: var(--ink); border: 1px solid var(--line); font-weight: 600; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.sources { border-top: 1px solid var(--line); padding: 8px 12px; font-size: 11px; color: var(--muted); }
.sources .s { display: inline-flex; align-items: center; gap: 4px; margin-right: 10px; }
.sources .s i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.sources .s.off i { background: var(--bad); }

.mapwrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--bg); }
.legend { position: absolute; right: 10px; bottom: 22px; z-index: 500; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 10px; padding: 8px 10px; font-size: 12px; display: flex; flex-direction: column; gap: 3px; }
.legend input { width: auto; }
.legend .hint { color: var(--muted); font-size: 11px; margin-top: 3px; }

.train-ico { width: 22px; height: 22px; display: grid; place-items: center; }
.train-ico .arrow { width: 16px; height: 16px; border-radius: 50% 50% 50% 0; background: var(--c); border: 2px solid #fff; transform: rotate(var(--r, -45deg)); box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.train-ico.nob .arrow { border-radius: 50%; }
.train-ico.est .arrow { background: rgba(255,255,255,.85); border: 2.5px dashed var(--c); }
.train-ico.sel .arrow { box-shadow: 0 0 0 3px var(--accent); }
.inc-ico { font-size: 18px; filter: drop-shadow(0 1px 1px rgba(0,0,0,.4)); }
.leaflet-popup-content { font-size: 13px; min-width: 230px; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--ink); }
.leaflet-container { font: inherit; }
.leaflet-popup-content h3 { margin: 0 0 4px; font-size: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin-top: 6px; }
.kv dt { color: #6b7280; } .kv dd { margin: 0; font-weight: 600; }
.warnbox { background: #fff7e6; border: 1px solid #f5d38a; color: #6b4a00; border-radius: 6px; padding: 5px 7px; font-size: 12px; margin-top: 6px; }

dialog { border: 0; border-radius: 12px; padding: 0; width: min(760px, 96vw); max-height: 86vh; background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
#boardBody { padding: 8px 16px 16px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.cancelled td { text-decoration: line-through; color: var(--muted); }

@media (max-width: 820px) {
  .kpis { display: none; }
  #toggleSide { display: block; margin-left: auto; }
  .side { position: fixed; z-index: 1100; left: 0; right: 0; bottom: 0; top: auto; height: 55vh; width: 100%; border-right: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,.15); transform: translateY(calc(100% - 44px)); transition: transform .25s; }
  .side.open { transform: none; }
  .legend { bottom: 64px; right: 6px; font-size: 11px; padding: 6px 8px; }
  .leaflet-control-attribution { margin-bottom: 44px !important; font-size: 9px; }
}
