/* Dark theme modelled on the GoodWe app. Series colors validated for CVD on the card surface. */
:root {
    color-scheme: dark;
    --page: #0f0f0e;
    --surface: #1a1a19;
    --surface-2: #232321;
    --line: #2e2e2b;
    --grid-line: #262624;
    --text: #f5f5f4;
    --text-2: #c3c2b7;
    --text-3: #8a897f;

    --pv: #c98500;
    --load: #9085e9;
    --battery: #199e70;
    --grid: #3987e5;

    --good: #2fb36f;
    --warning: #d99a00;
    --critical: #e66767;

    --radius: 18px;
    font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--page);
    color: var(--text);
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

h1:focus { outline: none; }
h2 { font-size: 1rem; font-weight: 600; margin: 0 0 12px; }
.muted { color: var(--text-3); font-weight: 400; }
.mono { font-family: "Cascadia Mono", Consolas, monospace; font-size: .9em; }

/* ---------- top bar ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    /* Keep clear of the notch / status bar when running as a home-screen app. */
    padding: max(14px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 14px max(24px, env(safe-area-inset-left));
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 5;
    background: color-mix(in srgb, var(--page) 88%, transparent);
    backdrop-filter: blur(10px);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; }
.brand-mark { width: 26px; height: 26px; fill: none; stroke: var(--pv); stroke-width: 2.2; stroke-linecap: round; }

.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
    color: var(--text-2);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 8px;
}
.topbar nav a:hover { background: var(--surface-2); color: var(--text); }
.topbar nav a.active { background: var(--surface-2); color: var(--text); }

.status { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: .9rem; font-variant-numeric: tabular-nums; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.status.live .dot { background: var(--good); box-shadow: 0 0 0 0 var(--good); animation: ping 2s infinite; }
.status.stale .dot { background: var(--critical); }
.status.late .dot { background: var(--warning); }

.site-picker {
    appearance: none;
    background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23c3c2b7' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 30px 6px 10px;
    font: inherit;
    font-weight: 700;
    max-width: 60vw;
    text-overflow: ellipsis;
    cursor: pointer;
}
.site-picker:hover { border-color: var(--text-3); }

@keyframes ping {
    0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent); }
    100% { box-shadow: 0 0 0 8px transparent; }
}

/* ---------- layout ---------- */

main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 20px max(24px, env(safe-area-inset-right)) max(48px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
    display: grid;
    gap: 16px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px;
    min-width: 0;
}

.card-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }

.hero { display: grid; grid-template-columns: minmax(260px, 1fr) 2fr; gap: 16px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; }
.details { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; }

@media (max-width: 1100px) {
    .tiles { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 820px) {
    .hero, .pair { grid-template-columns: 1fr; }
    .tiles { grid-template-columns: repeat(2, 1fr); }
    .topbar {
        padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
        gap: 12px;
        flex-wrap: wrap;
    }
    main { padding: 16px max(16px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
}

/* ---------- waiting ---------- */

.waiting { display: flex; align-items: center; gap: 14px; color: var(--text-2); }
.pulse { width: 12px; height: 12px; border-radius: 50%; background: var(--pv); animation: ping 1.5s infinite; }

/* ---------- SOC ring ---------- */

.soc-card { display: grid; place-items: center; }
.soc { position: relative; width: min(100%, 260px); aspect-ratio: 1; }
.soc-ring { width: 100%; height: 100%; }
.soc-track { fill: none; stroke: color-mix(in srgb, var(--good) 16%, var(--surface)); stroke-width: 10; }
.soc-fill { fill: none; stroke-width: 10; stroke-linecap: round; transition: stroke-dasharray .8s ease; }
.soc-fill.good { stroke: var(--good); filter: drop-shadow(0 0 6px color-mix(in srgb, var(--good) 45%, transparent)); }
.soc-fill.warning { stroke: var(--warning); }
.soc-fill.critical { stroke: var(--critical); }
.soc-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 2px; }
.soc-value { font-size: 3.4rem; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.soc-value small { font-size: 1.4rem; color: var(--text-2); margin-left: 2px; }
.soc-label { color: var(--text-2); margin-top: 4px; }
.soc-power { font-size: 1.35rem; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; }
.soc-mode { color: var(--text-3); font-size: .85rem; }

/* ---------- power flow ---------- */

.flow { width: 100%; height: auto; max-height: 340px; display: block; }
.flow-track { stroke: var(--line); stroke-width: 2; }
.flow-line { stroke-width: 3; stroke-linecap: round; stroke-dasharray: 2 12; animation: flow 1s linear infinite; }
.flow-line.rev { animation-direction: reverse; }
@keyframes flow { to { stroke-dashoffset: -14; } }

.flow .node { fill: var(--surface-2); stroke-width: 2; transition: stroke .4s; }
.flow .hub { fill: var(--surface-2); stroke: var(--line); }
.flow .icon { fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.flow .icon.dim { stroke: var(--text-3); }
.flow .node-name { fill: var(--text-2); font-size: 13px; }
.flow .node-value { fill: var(--text); font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.flow .node-dir { fill: var(--text-3); font-size: 12px; }

/* On a phone the diagram is scaled to ~55%; enlarge its text so it stays readable. */
@media (max-width: 820px) {
    .soc { width: min(100%, 210px); }
    .flow .node-name { font-size: 21px; }
    .flow .node-value { font-size: 27px; }
    .flow .node-dir { font-size: 19px; }
}

/* ---------- tiles ---------- */

.tile { display: grid; gap: 6px; align-content: start; }
.tile-label { color: var(--text-2); font-size: .9rem; display: flex; align-items: center; gap: 8px; }
.tile-value { font-size: 2rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tile-value small { font-size: .95rem; color: var(--text-2); margin-left: 4px; font-weight: 400; }
.tile-sub { color: var(--text-3); font-size: .82rem; }
.tile-pair { display: grid; gap: 4px; font-variant-numeric: tabular-nums; font-weight: 600; }
.tile-pair .muted { display: inline-block; width: 82px; }

.key { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

/* ---------- legends & charts ---------- */

.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--text-2); font-size: .85rem; }
.legend li { display: flex; align-items: center; gap: 6px; }

.chart { position: relative; width: 100%; }
.chart-svg { display: block; overflow: visible; }
.chart .axis text { fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .axis .grid { stroke: var(--grid-line); stroke-width: 1; }
.chart .axis .zero { stroke: var(--line); stroke-width: 1; }
.chart .ring { stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--text-3); stroke-width: 1; }
.chart .band-hover { fill: var(--surface-2); }
.chart .empty { fill: var(--text-3); font-size: 13px; }

.chart-tip {
    display: none;
    position: absolute;
    pointer-events: none;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: .82rem;
    box-shadow: 0 8px 24px rgb(0 0 0 / .4);
    white-space: nowrap;
    z-index: 2;
}
.tip-title { color: var(--text-2); margin-bottom: 4px; }
.tip-row { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 8px; }
.tip-row b { font-variant-numeric: tabular-nums; font-weight: 600; margin-left: 12px; }
.tip-row .key { width: 10px; height: 10px; }

/* ---------- details ---------- */

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

.grid-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.grid-table th { text-align: right; color: var(--text-3); font-weight: 400; padding: 6px 0; border-bottom: 1px solid var(--line); }
.grid-table td { text-align: right; padding: 7px 0; border-bottom: 1px solid var(--grid-line); }
.grid-table th:first-child, .grid-table td:first-child { text-align: left; color: var(--text-2); }
.grid-table tr.total td { font-weight: 600; border-bottom: none; }

/* ---------- blazor chrome ---------- */

#blazor-error-ui {
    background: var(--critical);
    color: #000;
    bottom: 0;
    display: none;
    left: 0;
    padding: .6rem 1.25rem .7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

/* ---------- year overview ---------- */

.year-totals { display: flex; flex-wrap: wrap; gap: 6px 24px; margin: 4px 0 10px; font-variant-numeric: tabular-nums; }
.year-totals b { font-weight: 600; margin-left: 4px; }

/* ---------- day navigation ---------- */

.day-nav { display: flex; align-items: center; gap: 8px; }
.icon-btn {
    width: 28px; height: 28px; border-radius: 8px;
    border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
    font-size: 1.1rem; line-height: 1; cursor: pointer;
}
.icon-btn:hover:not(:disabled) { border-color: var(--text-3); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.link-btn { background: none; border: none; color: var(--grid); cursor: pointer; font-size: .85rem; padding: 0 4px; }

/* ---------- WebAssembly boot screen ---------- */

.boot { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--text-3); }
.boot img { border-radius: 18px; animation: ping 1.6s infinite; }

/* ---------- overview: all sites, compact enough for two on one phone screen ---------- */

.overview { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.site-card { display: grid; gap: 4px; color: inherit; text-decoration: none; transition: border-color .2s; }
.site-card:hover { border-color: var(--text-3); }
.site-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.site-title { display: grid; gap: 2px; min-width: 0; }
.site-title h2 { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-title .muted { font-size: .82rem; }
.site-head .status { margin-left: 0; white-space: nowrap; font-size: .82rem; }
.site-card .flow { max-height: 280px; }
.site-today { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .85rem; font-variant-numeric: tabular-nums; color: var(--text-2); }
.site-today > span { display: inline-flex; align-items: center; gap: 6px; }

@media (max-width: 820px) {
    .overview { gap: 10px; }
    .site-card { padding: 12px 14px; }
    .site-card .flow { max-height: 190px; }
}
