:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e3e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --ok: #16a34a;
    --ok-soft: #dcfce7;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --err: #dc2626;
    --err-soft: #fee2e2;
    --run: #2563eb;
    --run-soft: #dbeafe;
    --accent: #0f172a;
    --accent-text: #ffffff;
    --radius: 14px;
    --shadow: 0 1px 2px rgb(15 23 42 / 0.06);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1120;
        --surface: #111a2e;
        --surface-2: #0f172a;
        --border: #1f2a44;
        --text: #e2e8f0;
        --muted: #94a3b8;
        --ok: #4ade80;
        --ok-soft: rgb(34 197 94 / 0.15);
        --warn: #fbbf24;
        --warn-soft: rgb(251 191 36 / 0.14);
        --err: #f87171;
        --err-soft: rgb(248 113 113 / 0.15);
        --run: #60a5fa;
        --run-soft: rgb(96 165 250 / 0.15);
        --accent: #e2e8f0;
        --accent-text: #0f172a;
        --shadow: none;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
button { font: inherit; cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { margin: 0; font-size: 15px; font-weight: 700; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; gap: 6px; }
.topbar-actions form { margin: 0; }
.ghost {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
}
.ghost:hover { background: var(--surface-2); }
.ghost[disabled] { opacity: 0.5; cursor: progress; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 16px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

/* ---------- summary tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.tile .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.tile .value { font-size: 24px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--muted); }
.tile.err .value { color: var(--err); }
.tile.warn .value { color: var(--warn); }
.tile.ok .value { color: var(--ok); }

/* ---------- issues ---------- */
.banner { margin-top: 12px; border-radius: var(--radius); padding: 12px 14px; font-weight: 600; display: flex; gap: 10px; align-items: center; }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.issues { margin-top: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.issues h2 { margin: 0; padding: 10px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
.issue { display: flex; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--border); align-items: flex-start; }
.issue:first-of-type { border-top: 0; }
.issue .proj { font-weight: 700; }
.issue .msg { color: var(--muted); }

/* ---------- badges & dots ---------- */
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; margin-top: 4px; background: var(--muted); }
.dot.ok, .dot.success, .dot.online { background: var(--ok); }
.dot.warning { background: var(--warn); }
.dot.error, .dot.errored, .dot.stopped, .dot.missing { background: var(--err); }
.dot.running { background: var(--run); }
.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 1px 8px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge.ok, .badge.success, .badge.online { background: var(--ok-soft); color: var(--ok); }
.badge.warning { background: var(--warn-soft); color: var(--warn); }
.badge.error, .badge.errored, .badge.stopped, .badge.missing, .badge.failure { background: var(--err-soft); color: var(--err); }
.badge.running { background: var(--run-soft); color: var(--run); }
.badge.muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; margin: 18px 0 12px; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; width: fit-content; max-width: 100%; overflow-x: auto; }
.tabs button { border: 0; background: transparent; color: var(--muted); padding: 7px 14px; border-radius: 999px; font-weight: 700; font-size: 13px; white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-text); }

/* ---------- project cards ---------- */
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 4px 11px; font-size: 12px; font-weight: 700; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.card.error { border-color: color-mix(in srgb, var(--err) 45%, var(--border)); }
.card.warning { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card-head h3 { margin: 0; font-size: 15px; }
.card-head .server { font-size: 12px; color: var(--muted); }
.problems { margin: 10px 0 0; padding: 0; list-style: none; }
.problems li { font-size: 12px; padding: 6px 8px; border-radius: 8px; margin-top: 4px; }
.problems li.error { background: var(--err-soft); color: var(--err); }
.problems li.warning { background: var(--warn-soft); color: var(--warn); }
.section-label { margin: 12px 0 4px; font-size: 11px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.row { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-top: 1px dashed var(--border); font-size: 13px; min-width: 0; }
.row:first-of-type { border-top: 0; }
.row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
details.logs { margin-top: 8px; }
details.logs summary { font-size: 12px; color: var(--muted); cursor: pointer; font-weight: 600; }
pre.log { margin: 6px 0 0; padding: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; font-size: 11px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto; }

/* ---------- activity ---------- */
.day { margin-bottom: 14px; }
.day h3 { margin: 0 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.feed { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.event { display: flex; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--border); text-decoration: none; }
.event:first-child { border-top: 0; }
a.event:hover { background: var(--surface-2); }
.event .time { width: 64px; white-space: nowrap; flex: none; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; padding-top: 1px; }
.event .body { min-width: 0; flex: 1; }
.event .title { font-weight: 700; font-size: 13px; }
.event .msg { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.counts { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }

/* ---------- servers ---------- */
.meter { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.meter > span { display: block; height: 100%; background: var(--ok); }
.meter.warn > span { background: var(--warn); }
.meter.err > span { background: var(--err); }
.stat { margin-top: 10px; font-size: 13px; }
.stat .top { display: flex; justify-content: space-between; }
.stat .top span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }

.note { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 12px 14px; color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.empty { color: var(--muted); padding: 24px; text-align: center; }

/* ---------- login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 24px; box-shadow: 0 10px 30px rgb(15 23 42 / 0.08); }
.login-form { display: grid; gap: 12px; margin-top: 18px; }
.login-form label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; }
.login-form input { font: inherit; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); font-size: 16px; }
.login-form button { margin-top: 4px; border: 0; border-radius: 10px; padding: 12px; background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 15px; }
.login-error { margin: 16px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--err-soft); color: var(--err); font-size: 13px; font-weight: 600; }

@media (max-width: 720px) {
    .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid { grid-template-columns: 1fr; }
    .hide-sm { display: none; }
    .wrap { padding: 12px; }
}

/* ---------- project URL ---------- */
.card-head .url, .store-top .url { display: inline-block; margin-top: 1px; font-size: 12px; font-weight: 600; color: var(--run); text-decoration: none; }
.card-head .url:hover, .store-top .url:hover { text-decoration: underline; }

/* ---------- storage ---------- */
.storage-card { margin-bottom: 12px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.store-row { padding: 9px 0; border-top: 1px dashed var(--border); }
.store-row:first-of-type { border-top: 0; }
.store-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.store-top .name { min-width: 0; overflow-wrap: anywhere; }
.store-top .size { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.store-detail { margin-top: 4px; font-size: 12px; color: var(--muted); }
.stack { display: flex; height: 10px; margin-top: 6px; border-radius: 999px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.stack span { height: 100%; }
.seg-deps { background: #8b5cf6; }
.seg-build { background: #0ea5e9; }
.seg-uploads { background: #f59e0b; }
.seg-files { background: #64748b; }
.seg-db { background: #10b981; }
.seg-containers { background: #ec4899; }
.seg-shared { background: #94a3b8; }
