:root {
    color-scheme: dark;
    --bg: #07111f;
    --panel: #0d1a2b;
    --panel-2: #122238;
    --line: #233750;
    --text: #e8f0f8;
    --muted: #8da3b9;
    --green: #35d07f;
    --yellow: #f1c84b;
    --red: #f35f68;
    --blue: #66a7ff;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, sans-serif; }
.topbar { display: flex; justify-content: space-between; gap: 24px; padding: 24px 30px; border-bottom: 1px solid var(--line); background: linear-gradient(115deg, #0b1a2d, #102943); }
.eyebrow { color: #79b7ff; text-transform: uppercase; letter-spacing: .13em; font-size: 11px; font-weight: 800; }
h1 { margin: 3px 0 2px; font-size: 25px; }
.topbar p { margin: 0; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 12px; }
.top-actions a, button { border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); color: var(--text); padding: 9px 13px; text-decoration: none; cursor: pointer; font-weight: 700; }
.connection { display: inline-flex; align-items: center; gap: 8px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 999px; }
.connection i { width: 9px; height: 9px; border-radius: 50%; background: var(--yellow); }
.connection.online i { background: var(--green); box-shadow: 0 0 10px var(--green); }
.connection.offline i { background: var(--red); }

.toolbar { display: flex; align-items: end; gap: 12px; padding: 16px 30px; border-bottom: 1px solid var(--line); background: #091524; position: sticky; top: 0; z-index: 10; }
.toolbar label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
select { min-width: 235px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: var(--panel-2); }
.poll-details { margin-left: auto; display: grid; text-align: right; }
.poll-details span { color: var(--muted); font-size: 11px; }
.error-message { color: #ff9ca3; max-width: 420px; }
main { padding: 20px 30px 40px; }
.summary-grid { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); gap: 12px; margin-bottom: 18px; }
.summary-grid article { padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.summary-grid span { display: block; color: var(--muted); font-size: 12px; }
.summary-grid strong { display: block; margin-top: 4px; font-size: 24px; }
.red-summary strong { color: var(--red); }
.warn-summary strong { color: var(--yellow); }
.station-grid { display: grid; gap: 18px; }
.station-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); }
.station-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 15px 18px; background: #102139; border-bottom: 1px solid var(--line); }
.station-title { display: flex; align-items: baseline; gap: 10px; }
.station-code { color: #7db8ff; font-size: 19px; font-weight: 900; }
.station-name { font-size: 16px; font-weight: 700; }
.station-meta { color: var(--muted); font-size: 12px; text-align: right; }
.asset-section { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.asset-section:last-child { border-bottom: 0; }
.section-title { display: flex; align-items: center; gap: 8px; margin: 0 0 11px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; }
.count-badge { color: var(--muted); background: #081322; border-radius: 999px; padding: 2px 7px; font-size: 11px; }
.signal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.signal-card { display: grid; grid-template-columns: 42px 1fr; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: #091625; }
.signal-card.aspect-red { border-color: var(--red); }
.signal-card.aspect-yellow { border-color: var(--yellow); }
.signal-card.aspect-green { border-color: var(--green); }
.lamp { width: 34px; height: 34px; border-radius: 50%; margin-top: 2px; background: #3b4653; box-shadow: inset 0 0 0 4px #172230; }
.aspect-red .lamp { background: var(--red); box-shadow: 0 0 15px rgba(243,95,104,.6), inset 0 0 0 4px rgba(80,5,10,.3); }
.aspect-yellow .lamp { background: var(--yellow); box-shadow: 0 0 15px rgba(241,200,75,.5), inset 0 0 0 4px rgba(80,60,0,.25); }
.aspect-green .lamp { background: var(--green); box-shadow: 0 0 15px rgba(53,208,127,.5), inset 0 0 0 4px rgba(0,70,35,.25); }
.signal-name { font-weight: 800; }
.signal-aspect { float: right; font-size: 11px; color: var(--muted); }
.relay-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.relay-pill { padding: 3px 6px; border-radius: 5px; font-size: 10px; background: #17283d; color: var(--muted); }
.relay-pill.up { color: #dce8f3; border: 1px solid #52657a; }
.relay-pill.down { color: #8091a3; border: 1px solid #33465b; opacity: .72; }
.relay-pill.relay-red { border-color: var(--red); }
.relay-pill.relay-yellow { border-color: var(--yellow); }
.relay-pill.relay-green { border-color: var(--green); }
.relay-pill.down.active-red { color: #fff; background: #9f2730; border-color: var(--red); opacity: 1; }
.relay-pill.down.active-yellow { color: #191500; background: var(--yellow); border-color: #ffe58a; opacity: 1; }
.relay-pill.down.active-green { color: #04170c; background: var(--green); border-color: #86efb5; opacity: 1; }
.asset-table { width: 100%; border-collapse: collapse; }
.asset-table th { color: var(--muted); font-size: 11px; text-align: left; font-weight: 600; }
.asset-table th, .asset-table td { padding: 7px 8px; border-bottom: 1px solid rgba(35,55,80,.65); }
.asset-table tr:last-child td { border-bottom: 0; }
.state { display: inline-flex; min-width: 72px; justify-content: center; padding: 3px 7px; border-radius: 999px; font-size: 10px; font-weight: 900; }
.state.up { color: #08180f; background: var(--green); }
.state.down { color: #20080b; background: var(--red); }
.state.clear { color: #07180e; background: var(--green); }
.state.occupied { color: #24070a; background: var(--red); }
.state.no-data { color: #aab6c2; background: #344252; }
.state.no-status { color: #201900; background: var(--yellow); }
.muted, .empty { color: var(--muted); }
.loading-card { padding: 35px; text-align: center; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); }

@media (max-width: 1050px) { .summary-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px) {
    .topbar, .toolbar { padding-left: 14px; padding-right: 14px; flex-wrap: wrap; }
    .topbar { align-items: flex-start; }
    .top-actions { width: 100%; }
    .poll-details { margin-left: 0; text-align: left; }
    main { padding: 14px; }
    .summary-grid { grid-template-columns: repeat(2, 1fr); }
    .station-head { align-items: flex-start; }
    .asset-table { display: block; overflow-x: auto; }
}
