:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #eef0f3;
    --border: #dde1e7;
    --text: #1d2330;
    --muted: #677184;
    --accent: #2f6fde;
    --accent-text: #ffffff;
    --ok: #1f8a4c;
    --ok-bg: #e3f4ea;
    --warn: #9a6400;
    --warn-bg: #fdf1d8;
    --bad: #c23434;
    --bad-bg: #fbe6e6;
    --problem-row: #fff7f7;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #11151c;
        --surface: #181d26;
        --surface-2: #212734;
        --border: #2c3442;
        --text: #e3e7ee;
        --muted: #8e98aa;
        --accent: #5b8ff0;
        --accent-text: #0b0f16;
        --ok: #5fcf8d;
        --ok-bg: #173325;
        --warn: #f0b752;
        --warn-bg: #3a2c12;
        --bad: #f07a7a;
        --bad-bg: #3d1a1d;
        --problem-row: #241a1d;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0; }
code { font-size: 0.9em; }

/* Layout */
.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 210px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.25rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.brand { font-weight: 700; font-size: 1.05rem; padding: 0 0.6rem 1rem; }
.brand span { color: var(--accent); }

.sidebar a {
    color: var(--text);
    text-decoration: none;
    padding: 0.45rem 0.6rem;
    border-radius: 6px;
}

.sidebar a:hover { background: var(--surface-2); }
.sidebar a.active { background: var(--surface-2); color: var(--accent); font-weight: 600; }
.signout { margin-top: auto; padding: 0 0.6rem; }

.content { flex: 1; min-width: 0; padding: 1.5rem 2rem 3rem; }

@media (max-width: 760px) {
    .shell { flex-direction: column; }
    .sidebar { width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: none; border-bottom: 1px solid var(--border); padding: 0.75rem 1rem; }
    .brand { padding: 0 0.6rem 0 0; }
    .signout { margin: 0 0 0 auto; }
    .content { padding: 1rem; }
}

/* Controls */
button {
    font: inherit;
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    border-radius: 6px;
    padding: 0.45rem 0.9rem;
    cursor: pointer;
}

button:disabled { opacity: 0.45; cursor: default; }
button.small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
button.link { background: none; color: var(--muted); padding: 0.45rem 0; }
button.link:hover { color: var(--text); }

input[type=search], input[type=text], input[type=password] {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
}

/* Page pieces */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.actions { display: flex; align-items: center; gap: 0.75rem; }

.note {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 6px;
    padding: 0.6rem 0.9rem;
    margin: 0 0 1rem;
}

.filters { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.filters input[type=search] { width: 16rem; max-width: 100%; }

.muted { color: var(--muted); }
.error-text { color: var(--bad); font-size: 0.85rem; }
.bad-text { color: var(--bad); font-weight: 600; }

.pill, .badge {
    display: inline-block;
    border-radius: 999px;
    padding: 0.1rem 0.6rem;
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--surface-2);
    color: var(--muted);
    white-space: nowrap;
}

.pill.ok, .badge.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn, .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }

.dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ok);
    margin-right: 0.35rem;
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse { 50% { opacity: 0.3; } }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tr.problem td { background: var(--problem-row); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.buttons { white-space: nowrap; }
td.buttons button + button { margin-left: 0.4rem; }

/* Dashboard */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }

.card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.1rem;
    color: inherit;
    text-decoration: none;
}

.card:hover { border-color: var(--accent); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.card dl { display: grid; grid-template-columns: 1fr auto; gap: 0.3rem 1rem; margin: 0; }
.card dt { color: var(--muted); }
.card dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem 1.1rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }

/* Log */
.log { list-style: none; margin: 0; padding: 0; font: 12.5px/1.55 ui-monospace, Consolas, monospace; }
.log li { padding: 0.15rem 0; border-bottom: 1px dashed var(--border); overflow-wrap: anywhere; }
.log li:last-child { border-bottom: none; }
.log time { color: var(--muted); margin-right: 0.5rem; }
.log li.debug { color: var(--muted); }
.log.full { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.9rem; }

/* Login */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem;
}

.login-card h1 { font-size: 1.25rem; }
.login-card form { display: flex; flex-direction: column; gap: 0.85rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.3rem; color: var(--muted); font-size: 0.9rem; }

/* Blazor reconnect / error banner */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.6rem 1rem;
    background: var(--warn-bg);
    color: var(--warn);
    border-top: 1px solid var(--border);
    z-index: 1000;
}

#blazor-error-ui .reload { margin-left: 0.5rem; }
