/* Cozy storybook theme: parchment and honey (light), cocoa and honey (dark).
   Chart marks use --data, validated for each surface (light #b7791f on #fffaf0, dark #b8822b on #211a14).
   Status colors are the fixed status palette and always ship with an icon + label. */

:root {
    --bg: #f7f0e1;
    --surface: #fffaf0;
    --surface-2: #f4ead6;
    --line: #e7d9bf;
    --ink: #2b2118;
    --ink-2: #5e4d3b;
    --ink-3: #7a6753;
    --accent: #e0a93b;
    --accent-hover: #d39a2a;
    --accent-ink: #3b2a0c;
    --data: #b7791f;
    --track: #f1e2c3;
    --good: #0ca30c;
    --warning: #fab219;
    --serious: #ec835a;
    --critical: #d03b3b;
    --danger-bg: #b3352e;
    --shadow: 0 1px 2px rgb(60 40 10 / 6%), 0 4px 16px rgb(60 40 10 / 6%);
    --radius: 14px;
    --font: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
    --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #17120d;
        --surface: #211a14;
        --surface-2: #2b221a;
        --line: #3b2f24;
        --ink: #f4eadb;
        --ink-2: #cdbca6;
        --ink-3: #a8957f;
        --accent-ink: #2a1d07;
        --data: #b8822b;
        --track: #3a2d1f;
        --danger-bg: #c0453d;
        --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #17120d;
    --surface: #211a14;
    --surface-2: #2b221a;
    --line: #3b2f24;
    --ink: #f4eadb;
    --ink-2: #cdbca6;
    --ink-3: #a8957f;
    --accent-ink: #2a1d07;
    --data: #b8822b;
    --track: #3a2d1f;
    --danger-bg: #c0453d;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
    color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
p { margin: 0; }
a { color: inherit; }
.muted { color: var(--ink-3); }
.small { font-size: 0.85rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-end { justify-content: flex-end; }
.grow { flex: 1; }
code, pre { font-family: var(--mono); }

/* ── Buttons & fields ─────────────────────────────── */

.btn {
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 8px 14px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    background: var(--surface-2);
    color: var(--ink);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn:hover { border-color: var(--line); }
.btn:focus-visible, input:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger-bg); color: #fff; }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-sm { padding: 5px 10px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.field { display: grid; gap: 4px; }
.field > span { font-weight: 600; font-size: 0.9rem; }
.field small { color: var(--ink-3); }
input[type="text"], input[type="password"], input[type="search"], input[type="file"], select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
}
textarea { resize: vertical; min-height: 60px; }
select:disabled { opacity: 0.55; }
fieldset { border: 0; margin: 0; padding: 0; }
legend { font-weight: 600; font-size: 0.9rem; padding: 0; margin-bottom: 4px; }
.form-error { color: var(--critical); font-weight: 600; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); flex: none; }
.checklist {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 14px;
    max-height: 260px; overflow-y: auto; padding: 10px 12px;
    border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.checklist .check { min-width: 0; }
.checklist .check span:first-of-type { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-discord { background: #5865f2; color: #fff; justify-content: center; padding: 11px 16px; }
.btn-discord:hover { background: #4752c4; }

/* ── Login ────────────────────────────────────────── */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
    width: min(380px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
    display: grid;
    gap: 14px;
    text-align: center;
}
.login-card .field { text-align: left; }

/* ── Shell ────────────────────────────────────────── */

.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 18px 14px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; padding: 4px 6px; }
.brand strong { display: block; font-size: 1.05rem; }
.brand small { display: block; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); object-fit: cover; }
.avatar-lg { width: 72px; height: 72px; margin: 0 auto; }
.avatar-sm { width: 30px; height: 30px; flex: none; }
.nav { display: grid; gap: 14px; }
.nav-group { display: grid; gap: 2px; }
.nav-heading { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); padding: 0 12px 2px; }
.picker { padding: 0 4px; }
.picker > span { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
.user-chip { display: flex; align-items: center; gap: 8px; font-weight: 600; padding: 0 6px; min-width: 0; }
.user-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav a {
    padding: 9px 12px;
    border-radius: 10px;
    text-decoration: none;
    color: var(--ink-2);
    font-weight: 600;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; }

.content { min-width: 0; padding: 24px 28px 48px; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page { display: grid; gap: 18px; }

/* ── Cards & tiles ────────────────────────────────── */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    display: grid;
    gap: 12px;
    align-content: start;
    min-width: 0;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; display: grid; gap: 2px; }
.tile-label { color: var(--ink-2); font-size: 0.85rem; }
.tile-value { font-size: 1.5rem; font-weight: 700; }
.tile-note { color: var(--ink-3); font-size: 0.8rem; }

.hero { display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: center; }
.hero-figure { font-size: 3.5rem; font-weight: 700; line-height: 1; }
.hero-label { color: var(--ink-2); font-weight: 600; }
.greeting { color: var(--ink-2); }

/* ── Status ───────────────────────────────────────── */

.status-pill {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 999px; padding: 4px 12px; font-size: 0.85rem; font-weight: 600;
}
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot-good { background: var(--good); }
.dot-warning { background: var(--warning); }
.dot-serious { background: var(--serious); }
.dot-critical { background: var(--critical); }

/* ── Charts: horizontal bars & meters ─────────────── */

.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 160px) 1fr; gap: 12px; align-items: center; }
.bar-label { color: var(--ink-2); font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { position: relative; height: 24px; display: flex; align-items: center; gap: 8px; cursor: default; }
.bar-fill {
    height: 18px;
    min-width: 4px;
    background: var(--data);
    border-radius: 0 4px 4px 0;
}
.bar-value { font-size: 0.85rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-track:hover .bar-fill, .bar-track:focus .bar-fill { filter: brightness(1.08); }

.meter { height: 8px; border-radius: 999px; background: var(--track); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--data); border-radius: 999px; }

.table-toggle { justify-self: start; }
.tooltip {
    position: fixed; z-index: 50; pointer-events: none;
    background: var(--ink); color: var(--surface);
    padding: 6px 10px; border-radius: 8px; font-size: 0.85rem; max-width: 260px;
    box-shadow: var(--shadow);
}

/* ── Tables & lists ───────────────────────────────── */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--ink-2); font-weight: 600; font-size: 0.85rem; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }

.list { display: grid; gap: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.rank { width: 28px; text-align: center; font-weight: 700; color: var(--ink-2); }

.server { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; }
.server-icon {
    width: 48px; height: 48px; border-radius: 14px; background: var(--surface-2);
    display: grid; place-items: center; font-weight: 700; color: var(--ink-2); object-fit: cover;
}
.server-meta { display: flex; gap: 14px; flex-wrap: wrap; color: var(--ink-2); font-size: 0.88rem; }
.server-icon-lg { width: 56px; height: 56px; }
.server-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.chip-link { text-decoration: none; padding: 5px 12px; font-size: 0.85rem; }
.chip-link:hover { color: var(--ink); }
.chip-on { background: var(--accent); color: var(--accent-ink); }
.member-row { width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); font: inherit; color: inherit; cursor: pointer; text-align: left; padding: 10px 6px; border-radius: 0; }
.member-row:hover { background: var(--surface-2); }
.mod-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.mod-actions select { width: auto; }
.log-entry { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.log-entry:last-child { border-bottom: 0; }
.log-icon { width: 24px; text-align: center; flex: none; }
.quote { border-left: 3px solid var(--line); padding-left: 8px; margin-top: 2px; overflow-wrap: anywhere; }
.changes { margin: 4px 0 0; padding-left: 18px; color: var(--ink-2); }
.danger-zone { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; border: 1px solid var(--danger-bg); border-radius: 12px; padding: 12px 14px; }
.chip {
    display: inline-flex; align-items: center; gap: 4px;
    background: var(--surface-2); border-radius: 999px; padding: 2px 9px; font-size: 0.78rem; font-weight: 600; color: var(--ink-2);
}

details.log { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
details.log summary { cursor: pointer; padding: 12px 14px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
details.log summary .title { font-family: var(--mono); font-size: 0.85rem; overflow-wrap: anywhere; }
details.log pre {
    margin: 0; padding: 12px 14px; border-top: 1px solid var(--line);
    max-height: 360px; overflow: auto; font-size: 0.8rem; white-space: pre-wrap; overflow-wrap: anywhere;
}

.empty { text-align: center; padding: 28px 12px; color: var(--ink-3); }
.loading { color: var(--ink-3); padding: 20px 0; }
.note { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; color: var(--ink-2); font-size: 0.88rem; }

/* ── Toasts & dialog ──────────────────────────────── */

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; }
.toast {
    background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--good);
    border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); max-width: 340px;
}
.toast-error { border-left-color: var(--critical); }
.dialog {
    border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink);
    padding: 22px; width: min(420px, calc(100vw - 32px)); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgb(20 12 4 / 45%); }
.dialog form { display: grid; gap: 14px; }

/* ── Small screens ────────────────────────────────── */

@media (max-width: 900px) {
    .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 760px) {
    .shell { grid-template-columns: minmax(0, 1fr); }
    .sidebar {
        position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line);
        padding: 12px 16px; gap: 10px;
    }
    .nav { gap: 6px; }
    .nav-group { grid-auto-flow: column; grid-auto-columns: max-content; overflow-x: auto; padding-bottom: 2px; }
    .nav-heading { display: none; }
    .sidebar { overflow: visible; }
    .sidebar-foot { margin-top: 0; }
    .content { padding: 16px 16px 40px; }
    .hero { grid-template-columns: minmax(0, 1fr); gap: 8px; }
    .server { grid-template-columns: auto minmax(0, 1fr); }
    .server > :last-child { grid-column: 1 / -1; }
    .bar-row { grid-template-columns: minmax(0, 1fr); gap: 4px; }
}

@media (forced-colors: active) {
    .bar-fill, .meter > span { background: CanvasText; }
}
