/* Sonnenwende Monitoring — one stylesheet for all pages. Colors are tokens; dark mode redefines
   them (its own steps, not an automatic inversion). Status colors are reserved for state and
   always come with a text label. */

/* Company colors: Sonnenwendeblau #3665a9 (primary) and Goldorange #ff9a1f (secondary). */
:root {
    --brand-blue: #3665a9;
    --brand-orange: #ff9a1f;

    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef2f8;
    --border: #dbe2ec;
    --text: #17202e;
    --text-2: #4a5568;
    --muted: #5f6b7a;

    --primary: var(--brand-blue);   /* primary buttons, in both modes */
    --primary-ink: #ffffff;         /* text on --primary (5.9:1) */
    --primary-text: var(--brand-blue); /* blue text and focus rings on the page background */
    --secondary: var(--brand-orange); /* brand accent only — never text, never a state */
    --secondary-ink: #17202e;       /* text on --secondary (7.7:1); stays dark in dark mode */

    --good: #0ca30c;
    --warning: #fab219;
    --critical: #d03b3b;
    --unknown: #8a94a3;
    --critical-soft: #fbeaea;
    --good-soft: #e7f6e7;

    --radius: 10px;
    --shadow: 0 1px 2px rgba(23, 32, 46, 0.06);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f141b;
        --surface: #171e27;
        --surface-2: #1e2732;
        --border: #2b3644;
        --text: #eef2f7;
        --text-2: #c3cbd6;
        --muted: #8e99a8;

        /* Sonnenwendeblau as text on dark surfaces is too dark (2.9:1): a lighter step of the same
           hue for text and focus rings. Buttons keep the brand blue — white on it stays 5.9:1. */
        --primary-text: #7aa2e0;

        --critical-soft: #3a2020;
        --good-soft: #1d311d;
        --unknown: #6f7a89;
        --shadow: none;
    }
}

* { box-sizing: border-box; }

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

h1, h2 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 650; color: var(--primary-text); }
h2 { font-size: 1.1rem; font-weight: 650; margin-bottom: 0.6rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }

/* --- Top bar, page, footer --- */

.topbar {
    background: var(--surface);
    border-top: 3px solid var(--secondary);
    border-bottom: 1px solid var(--border);
}

.topbar-inner, .page, .footer {
    max-width: 72rem;
    margin: 0 auto;
    padding-left: 1.25rem;
    padding-right: 1.25rem;
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 3.5rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text);
    font-weight: 650;
    text-decoration: none;
}

.brand-logo { display: flex; }
.brand-logo img { height: 2rem; width: auto; }

/* Alpha phase: badge next to the name and a notice under the top bar, in Goldorange with dark text
   (7.7:1 in both modes — white on the orange would be only 2.1:1). It's close to the warning color,
   but it's a full-width banner with its own wording, not a pill on a tile. Remove together with
   ALPHA_NOTICE in Html.kt. */
.stage-badge {
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    background: var(--secondary);
    color: var(--secondary-ink);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.stage-notice {
    background: var(--secondary);
    color: var(--secondary-ink);
    border-bottom: 2px solid rgba(23, 32, 46, 0.25);
    font-size: 1rem;
    font-weight: 500;
}

.stage-notice-inner {
    max-width: 72rem;
    margin: 0 auto;
    padding: 0.8rem 1.25rem;
}

.stage-notice strong { font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; margin-right: 0.25rem; }


nav.user { display: flex; align-items: center; gap: 0.75rem; }
nav.user form { margin: 0; }
.user-name { color: var(--text-2); font-size: 0.9rem; }
.nav-link { color: var(--primary-text); font-size: 0.9rem; text-decoration: none; }
.nav-link:hover { text-decoration: underline; }

.page { padding-top: 1.75rem; padding-bottom: 2rem; }
.page-head { margin-bottom: 1.25rem; }
.page-head p { margin-top: 0.25rem; }

.footer {
    padding-top: 1rem;
    padding-bottom: 2rem;
    color: var(--muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
}

.section { margin-top: 2rem; }
.section > p.muted { margin: -0.3rem 0 0.75rem; }

/* --- Cards, tiles --- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card.empty { padding: 1rem 1.25rem; color: var(--muted); }

.tiles {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
}

.tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.1rem;
}

.tile-label { color: var(--text-2); font-size: 0.85rem; }
.tile-value { font-size: 1.75rem; font-weight: 650; margin: 0.15rem 0; }
.tile-note { color: var(--muted); font-size: 0.85rem; }

/* --- Status pills: a colored dot plus the label in text color --- */

.status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.1rem 0.55rem 0.1rem 0.45rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 550;
    white-space: nowrap;
}

.status .dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--unknown); }
.status-ok .dot { background: var(--good); }
.status-warning .dot { background: var(--warning); }
.status-critical .dot { background: var(--critical); }

/* --- Tables --- */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th, td {
    padding: 0.65rem 1rem;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
}

thead th {
    color: var(--text-2);
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--surface-2);
}

tbody tr.top td { vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.plant-name { font-weight: 600; }


/* --- Plants: one group per portal, a tile per plant --- */

.portal-group + .portal-group { margin-top: 1.5rem; }

.portal-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.35rem 0.75rem;
    margin-bottom: 0.6rem;
}

.portal-head h3 { margin: 0; font-size: 1rem; font-weight: 650; }
/* The name next to it says the same, so the logo is decorative (alt=""). Fixed height, natural
   width: square icons and wide wordmarks alike. */
.portal-logo { align-self: center; height: 20px; width: auto; margin-right: -0.25rem; }
.portal-head .status { align-self: center; }
/* Under the tiles: last fetch and the portal link, quiet. Left on desktop, right on phones. */
.portal-meta { margin-top: 0.5rem; font-size: 0.85rem; }
.portal-link { color: var(--primary-text); text-decoration: none; white-space: nowrap; }
.portal-link:hover { text-decoration: underline; }

.plant-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 0.75rem;
}

.plant-tile {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.9rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* An open issue also marks the tile's edge; the pill still carries the label. */
.plant-tile-warning { border-left: 4px solid var(--warning); }
.plant-tile-critical { border-left: 4px solid var(--critical); }

/* Name, then the status under it — the same in every tile, however long the name. */
.plant-tile-head {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
}

.plant-tile-head h4 { margin: 0; font-size: 0.98rem; }
.plant-address { margin: -0.2rem 0 0; }
.tile-power { font-size: 1.6rem; font-weight: 650; line-height: 1.2; }
.plant-tile-facts { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.2rem 0.75rem; font-size: 0.88rem; }
.plant-tile-issue { color: var(--text-2); font-size: 0.85rem; padding-top: 0.35rem; border-top: 1px solid var(--border); }

/* --- Alerts --- */

.alerts { display: grid; gap: 0.75rem; }

.alert {
    padding: 1rem 1.25rem;
    border-left: 4px solid var(--critical);
}

.alert-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; }

details { margin-top: 0.6rem; color: var(--text-2); font-size: 0.85rem; }
summary { cursor: pointer; }
details code {
    display: block;
    margin-top: 0.4rem;
    padding: 0.6rem 0.75rem;
    border-radius: 6px;
    background: var(--surface-2);
    white-space: pre-wrap;
    word-break: break-word;
}

/* --- Messages --- */

.message {
    margin-bottom: 1rem;
    padding: 0.7rem 1rem;
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: 8px;
    background: var(--surface);
    white-space: pre-wrap;
    word-break: break-word;
}

.message.success { border-left-color: var(--good); background: var(--good-soft); }
.message.error { border-left-color: var(--critical); background: var(--critical-soft); }

/* --- Buttons and forms --- */

.button {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 550;
    cursor: pointer;
}

.button:hover { background: var(--surface-2); border-color: var(--primary-text); }
.button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.button.primary:hover { filter: brightness(1.1); }
.button.ghost { padding: 0.35rem 0.75rem; font-size: 0.9rem; }
.button:focus-visible, input:focus-visible { outline: 2px solid var(--primary-text); outline-offset: 2px; }

.notify { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem; }
.notify form { margin: 0; flex-shrink: 0; }

.login { max-width: 24rem; margin: 3rem auto 0; padding: 1.75rem; }
.login > p.muted { margin: 0.25rem 0 1.25rem; }
.login form { display: flex; flex-direction: column; gap: 0.9rem; }
.login label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; color: var(--text-2); }
.login input {
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}
.login .button.primary { justify-content: center; margin-top: 0.3rem; padding: 0.65rem; }

/* --- Narrow screens --- */

@media (max-width: 52rem) {
    .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 40rem) {
    body { font-size: 14px; }
    .topbar-inner, .page, .footer { padding-left: 1rem; padding-right: 1rem; }
    /* The logo alone on phones; the name stays readable for screen readers. */
    .brand span {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }
    h1 { font-size: 1.35rem; }
    .tile-value { font-size: 1.4rem; }
    th, td { padding: 0.55rem 0.6rem; }
    .secondary, .date { display: none; }
    .portal-meta { text-align: right; }
    .notify { flex-direction: column; align-items: flex-start; }
    .user-name { display: none; }
}
