:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --accent: #1d4ed8;
    --ok: #16a34a;
    --late: #dc2626;
    --cancelled: #7c3aed;
    --scheduled: #64748b;
    --idle: #94a3b8;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1419;
        --surface: #182028;
        --text: #e5e7eb;
        --muted: #9ca3af;
        --border: #2b3640;
        --accent: #60a5fa;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

a { color: var(--accent); }

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }

.shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: .75rem 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.brand { font-weight: 700; font-size: 1.15rem; letter-spacing: .02em; }

.topbar nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.topbar nav a { text-decoration: none; color: var(--muted); padding: .25rem 0; border-bottom: 2px solid transparent; }
.topbar nav a:hover { color: var(--text); }
.topbar nav a.active { color: var(--text); border-bottom-color: var(--accent); }

main { flex: 1; padding: 1.25rem 16px 2rem; max-width: 1200px; width: 100%; margin: 0 auto; }

.muted { color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .75rem; margin-bottom: .75rem; }

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .75rem 1rem;
    display: flex;
    flex-direction: column;
}
.stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .8rem; }
.stat.late .stat-value { color: var(--late); }
.stat.cancelled .stat-value { color: var(--cancelled); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.card .table-wrap { border: 0; border-radius: 0; }

table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { text-align: left; padding: .6rem .85rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }

.badge {
    display: inline-block;
    padding: .15rem .55rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
    color: #fff;
    background: var(--idle);
}
.badge.ok { background: var(--ok); }
.badge.late { background: var(--late); }
.badge.cancelled { background: var(--cancelled); }
.badge.scheduled { background: var(--scheduled); }
.badge.idle { background: var(--idle); }

.banner { padding: .65rem .9rem; border-radius: 8px; margin-bottom: .75rem; }
.banner.warn { background: #fef3c7; color: #78350f; border: 1px solid #fcd34d; }

.toolbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.toolbar label { display: flex; align-items: center; gap: .4rem; color: var(--muted); }
select {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .35rem .5rem;
    font: inherit;
}

.legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; font-size: .85rem; color: var(--muted); }
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; margin-right: .25rem; vertical-align: middle; background: var(--idle); }
.dot.ok { background: var(--ok); }
.dot.late { background: var(--late); }
.dot.scheduled { background: var(--scheduled); }

.map { height: 62vh; min-height: 360px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }

.train-marker { background: transparent; border: 0; }
.train-pin {
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    text-align: center;
    line-height: 24px;
    height: 24px;
    min-width: 46px;
    padding: 0 6px;
    border-radius: 12px;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}

.chart-box { position: relative; height: 340px; }
.chart-box.short { height: 260px; }

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    padding: .6rem 1rem;
    background: #fef3c7;
    color: #78350f;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; float: right; }

@media (max-width: 600px) {
    main { padding-top: 1rem; }
    h1 { font-size: 1.3rem; }
    .map { height: 55vh; }
}
