:root {
    --bg: #0f1115;
    --panel: #181b22;
    --panel-2: #1f232c;
    --text: #e7e9ee;
    --muted: #8b91a0;
    --border: #2a2f3a;
    --up: #2ecc71;
    --down: #e74c3c;
    --stale: #f0a020;
    --accent: #4c8dff;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); }
.small { font-size: .8rem; }

/* ---------- Login ---------- */
.login-page {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
}
.login-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 2.2rem 2rem;
    width: min(360px, 92vw);
    text-align: center;
}
.login-card h1 { margin: 0 0 .2rem; font-size: 1.4rem; }
.login-card .subtitle { margin: 0 0 1.4rem; color: var(--muted); }
.login-card input,
.login-card button {
    width: 100%;
    padding: .75rem .9rem;
    border-radius: 9px;
    font-size: 1rem;
    border: 1px solid var(--border);
}
.login-card input {
    background: var(--panel-2);
    color: var(--text);
    margin-bottom: .8rem;
}
.login-card button {
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    font-weight: 600;
}
.login-card button:hover { filter: brightness(1.08); }
.login-card .error {
    background: rgba(231, 76, 60, .12);
    color: #ff8b7e;
    padding: .6rem;
    border-radius: 8px;
    margin: 0 0 1rem;
    font-size: .9rem;
}

/* ---------- Top bar ---------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .9rem 1.4rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand { font-weight: 700; letter-spacing: .2px; }
.summary { display: flex; align-items: center; gap: .7rem; flex: 1; }
.logout {
    color: var(--muted);
    text-decoration: none;
    font-size: .9rem;
    border: 1px solid var(--border);
    padding: .35rem .7rem;
    border-radius: 8px;
}
.logout:hover { color: var(--text); }

.pill {
    padding: .25rem .7rem;
    border-radius: 999px;
    font-size: .82rem;
    font-weight: 600;
}
.pill.up   { background: rgba(46, 204, 113, .15); color: var(--up); }
.pill.down { background: rgba(231, 76, 60, .15);  color: var(--down); }

/* ---------- Layout ---------- */
main { padding: 1.4rem; } /* full page width */
.empty { color: var(--muted); }
.group-title {
    font-size: .85rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    margin: 1.6rem 0 .7rem;
}
.grid {
    display: grid;
    /* auto-fill so cards keep a consistent width and flow left-to-right across
       the full page width (more per row on wide screens) rather than a few
       cards stretching to fill. */
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1rem;
    align-items: start; /* each card sizes to its own content, not the tallest */
}

/* ---------- Card ---------- */
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    border-radius: 12px;
    padding: 1rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: .6rem;
}
.card.up    { border-left-color: var(--up); }
.card.down  { border-left-color: var(--down); }
.card.stale { border-left-color: var(--stale); }

.card-head { display: flex; align-items: center; gap: .55rem; }
.card-head h3 { margin: 0; font-size: 1.02rem; flex: 1; min-width: 0; }
.card-icon {
    width: 24px; height: 24px; flex: none;
    border-radius: 6px; object-fit: cover;
    background: var(--panel-2);
}
.version {
    font-size: .72rem;
    color: var(--muted);
    background: var(--panel-2);
    padding: .12rem .45rem;
    border-radius: 6px;
    font-variant-numeric: tabular-nums;
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.up { background: var(--up); box-shadow: 0 0 0 3px rgba(46, 204, 113, .15); }
.dot.down { background: var(--down); box-shadow: 0 0 0 3px rgba(231, 76, 60, .15); }
.dot.stale { background: var(--stale); }

.card-meta { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; font-size: .82rem; }
.badge {
    padding: .12rem .5rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: .74rem;
}
.badge.up    { background: rgba(46, 204, 113, .15); color: var(--up); }
.badge.down  { background: rgba(231, 76, 60, .15);  color: var(--down); }
.badge.stale { background: rgba(240, 160, 32, .15); color: var(--stale); }
.badge.unknown { background: var(--panel-2); color: var(--muted); }

.card-error {
    margin: 0;
    font-size: .8rem;
    color: #ff9a8f;
    background: rgba(231, 76, 60, .08);
    padding: .4rem .55rem;
    border-radius: 7px;
    word-break: break-word;
}

.metric-group-title {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    margin: .6rem 0 .1rem;
    padding-top: .5rem;
    border-top: 1px solid var(--border);
}
.metric-group-title:first-child { border-top: none; padding-top: 0; }

.metrics {
    list-style: none;
    margin: .2rem 0 0;
    padding: 0;
    display: grid;
    /* wider columns so values like "584 224,5 CHF" sit on one line */
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: .6rem 1rem;
}
.metrics li { display: flex; flex-direction: column; min-width: 0; }
.m-value {
    font-size: 1.2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
    overflow-wrap: anywhere; /* long values like "584 224.47 CHF" wrap, not overflow */
}
.m-label { font-size: .74rem; color: var(--muted); }
.stale-tag { color: var(--stale); font-weight: 700; }
.uptime-warn { color: var(--stale); font-weight: 600; }

.card-foot { border-top: 1px solid var(--border); padding-top: .5rem; }

/* ---------- Mobile: one card per row ---------- */
@media (max-width: 640px) {
    main { padding: 1rem; }
    .grid { grid-template-columns: 1fr; }
    .topbar { flex-wrap: wrap; gap: .4rem .8rem; padding: .8rem 1rem; }
    .summary { order: 3; flex-basis: 100%; }
}

/* ---------- Light theme ---------- */
@media (prefers-color-scheme: light) {
    :root {
        --bg: #f4f6fa;
        --panel: #ffffff;
        --panel-2: #eef1f6;
        --text: #1a1d24;
        --muted: #6b7280;
        --border: #e2e6ee;
    }
}
