:root {
    --g-green: #1a8a5a;
    --g-green-d: #0f6f47;
    --ink: #0f1c2e;
    --ink-2: #40566d;
    --muted: #8195a9;
    --line: #e6ecf3;
    --bg: #f4f7fb;
    --card: #ffffff;
    --blue: #2f6bd6;
    --amber: #e69a17;
    --red: #d64545;
    --radius: 14px;
    --shadow: 0 2px 4px rgba(15,28,46,.04), 0 8px 24px rgba(15,28,46,.06);
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }

.app { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
    width: 240px; flex-shrink: 0; background: #0f1c2e; color: #cdd8e4;
    display: flex; flex-direction: column; padding: 22px 16px;
    position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 22px; }
.brand-mark {
    width: 42px; height: 42px; border-radius: 11px; flex-shrink: 0;
    background: linear-gradient(135deg, var(--g-green), var(--g-green-d));
    display: grid; place-items: center; font-weight: 800; font-size: 22px; color: #fff;
    box-shadow: 0 4px 12px rgba(26,138,90,.4);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15px; letter-spacing: .5px; color: #fff; }
.brand-text span { font-size: 11px; color: #7f92a6; }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.nav-item {
    display: flex; align-items: center; gap: 11px; padding: 11px 13px;
    border-radius: 10px; color: #b6c4d4; text-decoration: none;
    font-size: 14px; font-weight: 500; transition: all .15s;
}
.nav-item .ic { font-size: 15px; width: 18px; text-align: center; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: linear-gradient(135deg, var(--g-green), var(--g-green-d)); color: #fff; }

.sidebar-foot {
    margin-top: auto; font-size: 11.5px; color: #7f92a6;
    display: flex; align-items: center; gap: 8px; padding: 12px 6px 0;
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #2ec27e; box-shadow: 0 0 0 3px rgba(46,194,126,.2); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* ── Main ── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 22px 32px; background: var(--card); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 10;
}
.topbar h1 { margin: 0; font-size: 21px; font-weight: 700; }
.crumb { margin: 3px 0 0; font-size: 13px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.clock { font-size: 13px; color: var(--ink-2); font-weight: 600; white-space: nowrap; }

/* ── Data-health strip ── */
.health-strip {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 10px 32px; font-size: 13px; font-weight: 600;
    border-bottom: 1px solid var(--line);
}
.health-strip.live { background: #eef7f2; color: #147a4e; }
.health-strip.idle { background: #fdf6e8; color: #b6820f; }
.health-strip.down, .health-strip.nodata { background: #fdeceb; color: #c33; }
.hs-cams { display: flex; gap: 14px; flex-wrap: wrap; margin-left: auto; }
.hs-cam { font-weight: 500; color: var(--ink-2); white-space: nowrap; }

.content { padding: 26px 32px; flex: 1; }
.foot { padding: 18px 32px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }

/* ── Buttons & controls ── */
.btn {
    border: 1px solid var(--line); background: #fff; color: var(--ink);
    padding: 9px 15px; border-radius: 9px; font-size: 13px; font-weight: 600;
    cursor: pointer; transition: all .15s; text-decoration: none; display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { border-color: var(--g-green); color: var(--g-green); }
.btn-ghost { background: transparent; }
.btn-primary { background: var(--g-green); border-color: var(--g-green); color: #fff; }
.btn-primary:hover { background: var(--g-green-d); color: #fff; }

select, input[type=date] {
    border: 1px solid var(--line); background: #fff; color: var(--ink);
    padding: 9px 12px; border-radius: 9px; font-size: 13px; font-weight: 500; font-family: inherit;
}
select:focus, input:focus { outline: none; border-color: var(--g-green); }

/* ── KPI tiles ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi {
    background: var(--card); border-radius: var(--radius); padding: 18px 20px;
    box-shadow: var(--shadow); border: 1px solid var(--line); position: relative; overflow: hidden;
}
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--g-green); }
.kpi.blue::before { background: var(--blue); }
.kpi.amber::before { background: var(--amber); }
.kpi.red::before { background: var(--red); }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.kpi-value { font-size: 30px; font-weight: 800; margin: 6px 0 2px; letter-spacing: -.5px; }
.kpi-sub { font-size: 12.5px; color: var(--ink-2); }

/* ── Cards & grid ── */
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.span-2 { grid-column: span 2; }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } .span-2 { grid-column: auto; } }

.card {
    background: var(--card); border-radius: var(--radius); padding: 20px;
    box-shadow: var(--shadow); border: 1px solid var(--line);
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-title { font-size: 15px; font-weight: 700; margin: 0; }
.card-sub { font-size: 12px; color: var(--muted); margin: 2px 0 0; }
.card-badge { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 20px; background: #eef7f2; color: var(--g-green); }

.chart-wrap { position: relative; height: 300px; }
.chart-wrap.tall { height: 360px; }
.chart-wrap.short { height: 220px; }

/* ── Filter bar ── */
.filterbar {
    background: var(--card); border-radius: var(--radius); padding: 16px 20px; margin-bottom: 22px;
    box-shadow: var(--shadow); border: 1px solid var(--line);
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.filterbar .spacer { margin-left: auto; }

/* ── Status pills & table ── */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 4px 11px; border-radius: 20px; }
.pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.normal { background: #eef7f2; color: #1a8a5a; }
.pill.alert { background: #fdf3e3; color: #c67f0e; }
.pill.dirty { background: #fdeceb; color: #d64545; }
.pill.emergency { background: #fbe6e6; color: #b01e1e; }
.pill.in_progress { background: #eaf1fc; color: #2f6bd6; }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 10px 12px; border-bottom: 2px solid var(--line); }
table.data td { padding: 12px; border-bottom: 1px solid var(--line); }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #fafcfe; }

.bar-mini { height: 7px; border-radius: 4px; background: var(--line); overflow: hidden; min-width: 90px; }
.bar-mini > span { display: block; height: 100%; border-radius: 4px; background: var(--g-green); }
.bar-mini.warn > span { background: var(--amber); }
.bar-mini.danger > span { background: var(--red); }

/* ── Status tiles ── */
.status-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.status-tile { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; background: var(--card); box-shadow: var(--shadow); }
.status-tile .st-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.status-tile .st-name { font-weight: 700; font-size: 14px; }
.status-tile .st-count { font-size: 26px; font-weight: 800; }
.status-tile .st-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ── Heatmap ── */
.heatmap { overflow-x: auto; }
.heatmap table { border-collapse: collapse; font-size: 10.5px; }
.heatmap td, .heatmap th { text-align: center; padding: 0; }
.heatmap th { color: var(--muted); font-weight: 600; padding: 3px 4px; }
.heatmap .hcell { width: 26px; height: 26px; border-radius: 4px; border: 2px solid #fff; }
.heatmap .rowlabel { text-align: right; padding-right: 8px; color: var(--ink-2); font-weight: 600; white-space: nowrap; }

.legend-row { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); margin-top: 10px; }
.legend-swatch { width: 16px; height: 16px; border-radius: 4px; }

/* ── Insights + language toggle ── */
.insights-card { border-left: 4px solid var(--g-green); }
.insights-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.insights-list li { font-size: 14px; color: var(--ink-2); padding-left: 22px; position: relative; line-height: 1.5; }
.insights-list li::before { content: '•'; position: absolute; left: 6px; color: var(--g-green); font-weight: 800; }
.insights-list li b { color: var(--ink); }
.lang-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.lang-btn { border: none; background: #fff; padding: 6px 14px; font-size: 13px; font-weight: 700; cursor: pointer; color: var(--muted); }
.lang-btn.active { background: var(--g-green); color: #fff; }

/* ── Forecast tiles ── */
.forecast-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.fc-tile { border: 1px solid var(--line); border-radius: 12px; padding: 15px; border-left-width: 4px; }
.fc-tile.ok { border-left-color: var(--g-green); }
.fc-tile.warn { border-left-color: var(--amber); background: #fffdf7; }
.fc-tile.danger { border-left-color: var(--red); background: #fdf4f3; }
.fc-name { font-weight: 700; font-size: 13.5px; }
.fc-time { font-size: 26px; font-weight: 800; margin: 4px 0; }
.fc-tile.danger .fc-time { color: var(--red); }
.fc-tile.warn .fc-time { color: var(--amber); }
.fc-msg { font-size: 12px; color: var(--ink-2); }
.fc-load { font-size: 11.5px; color: var(--muted); margin-top: 6px; }

/* ── AI recommendations ── */
.ai-card { border-left: 4px solid var(--blue); }
.ai-list { display: grid; gap: 10px; }
.ai-item { font-size: 14px; padding: 12px 15px; border-radius: 10px; background: #f7fafc; border-left: 3px solid var(--muted); line-height: 1.5; }
.ai-item b { color: var(--ink); }
.ai-item.high { background: #fdf4f3; border-left-color: var(--red); }
.ai-item.mid { background: #fffdf7; border-left-color: var(--amber); }
.ai-item.ok { background: #eef7f2; border-left-color: var(--g-green); }
.rating-note { background: #f7fafc; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: 12.5px; color: var(--ink-2); margin-bottom: 14px; line-height: 1.5; }

.loading { color: var(--muted); font-size: 13px; padding: 20px; text-align: center; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 30px; }

/* ── Print ── */
@media print {
    .sidebar, .topbar-right, .filterbar .btn, .foot { display: none !important; }
    .app { display: block; }
    .main { display: block; }
    .content { padding: 0; }
    .card, .kpi { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
    body { background: #fff; }
}
