:root {
    --bg: #0f1115;
    --surface: #181b22;
    --surface-2: #20242e;
    --border: #2b3140;
    --text: #e6e8ee;
    --muted: #8b93a7;
    --primary: #3b82f6;
    --primary-hover: #2f6fe0;
    --danger: #ef4444;
    --ok: #22c55e;
    --error: #ef4444;
    --radius: 10px;
}

* { 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);
    line-height: 1.45;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.75rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar .brand a { color: var(--text); font-weight: 700; }
.topbar nav { display: flex; gap: 1rem; }
.topbar nav a { color: var(--muted); }
.topbar nav a:hover { color: var(--text); text-decoration: none; }
.topbar .user { margin-left: auto; display: flex; gap: 0.75rem; align-items: center; color: var(--muted); }

.container { max-width: 1080px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.5rem; }

.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 0.85rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
    margin-bottom: 1.1rem;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.1rem; }
@media (max-width: 800px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { display: flex; flex-direction: column; gap: 0.2rem; }
.stat-num { font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.85rem; }

.btn {
    display: inline-block;
    padding: 0.5rem 0.9rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.12s, opacity 0.12s;
}
.btn:hover { background: #2a3140; text-decoration: none; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #d83a3a; }
.btn-ghost { background: transparent; }
.btn.small { padding: 0.25rem 0.55rem; font-size: 0.8rem; }
.btn-row { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.8rem; }

.field { display: block; margin: 0.6rem 0; color: var(--muted); font-size: 0.9rem; }
.range { display: inline-flex; gap: 0.4rem; align-items: center; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 0.45rem 0.6rem;
    font-size: 0.9rem;
}
input:focus { outline: 2px solid var(--primary); outline-offset: 0; }

.filterbar { display: flex; gap: 0.8rem; align-items: end; flex-wrap: wrap; margin-bottom: 1rem; }
.filterbar label { color: var(--muted); font-size: 0.85rem; display: flex; flex-direction: column; gap: 0.2rem; }

.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.tbl th, .tbl td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
.tbl th { color: var(--muted); font-weight: 600; }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl tbody tr:hover { background: var(--surface-2); }

.group-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.group-meta { display: flex; align-items: center; gap: 0.6rem; }

/* client card wraps a top-level collapsible */
.client-card { padding: 0.4rem 0.9rem; }
.client-group > summary {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 0.6rem 0.2rem; cursor: pointer; list-style: none;
}
.client-group > summary::-webkit-details-marker { display: none; }
.client-group > summary::before { content: '▸'; color: var(--muted); margin-right: 0.5rem; display: inline-block; transition: transform 0.12s; }
.client-group[open] > summary::before { transform: rotate(90deg); }
.client-group > summary:hover { background: var(--surface-2); border-radius: 6px; }
.cg-name { flex: 1; font-weight: 600; font-size: 1.02rem; }
.cg-meta { display: flex; align-items: center; gap: 0.7rem; white-space: nowrap; }
.client-body { padding: 0.2rem 0 0.4rem 1.4rem; }

/* project level */
.proj-group { border-top: 1px solid var(--border); }
.proj-group > summary {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 0.5rem 0.2rem; cursor: pointer; list-style: none; font-weight: 500;
}
.proj-group > summary::-webkit-details-marker { display: none; }
.proj-group > summary::before { content: '▸'; color: var(--muted); margin-right: 0.5rem; display: inline-block; transition: transform 0.12s; }
.proj-group[open] > summary::before { transform: rotate(90deg); }
.proj-group > summary:hover { background: var(--surface-2); border-radius: 6px; }
.proj-group > .tgroup { margin-left: 1.4rem; }

/* expandable title-groups within a project */
.tgroup { border-top: 1px solid var(--border); }
.tgroup:first-of-type { border-top: none; }
.tgroup > summary {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 0.55rem 0.2rem; cursor: pointer; list-style: none;
}
.tgroup > summary::-webkit-details-marker { display: none; }
.tgroup > summary::before { content: '▸'; color: var(--muted); margin-right: 0.5rem; transition: transform 0.12s; display: inline-block; }
.tgroup[open] > summary::before { transform: rotate(90deg); }
.tgroup > summary:hover { background: var(--surface-2); border-radius: 6px; }
.tg-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-meta { display: flex; align-items: center; gap: 0.7rem; white-space: nowrap; }
.tgroup .tbl { margin: 0 0 0.6rem 1.4rem; width: calc(100% - 1.4rem); }

.badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.75rem; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.badge.ok { color: #062; background: #bbf7d0; border-color: #bbf7d0; }
.badge.error { color: #7f1010; background: #fecaca; border-color: #fecaca; }
.badge.running { color: #06263f; background: #bfdbfe; border-color: #bfdbfe; }

.log-head { display: flex; align-items: center; justify-content: space-between; }
.joblog {
    background: #0b0d12;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.9rem;
    max-height: 24rem;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.82rem;
    white-space: pre-wrap;
    color: #cbd5e1;
}

.flash { padding: 0.6rem 0.9rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid var(--border); }
.flash-success { background: #10331f; border-color: #1c6b3a; color: #b7f0cb; }
.flash-error { background: #3a1414; border-color: #7f2020; color: #f6c3c3; }

/* inline async task editor */
.edit-row > td { background: var(--surface-2); border-radius: 8px; }
.inline-edit { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.6rem 0.8rem; padding: 0.5rem 0.2rem; }
.inline-edit label { display: flex; flex-direction: column; gap: 0.2rem; color: var(--muted); font-size: 0.75rem; }
.inline-edit input[type=text] { min-width: 12rem; }
.inline-edit input[type=number] { width: 6.5rem; }
.applied-live { align-self: center; font-size: 0.85rem; }
.edit-note { flex-basis: 100%; }
.edit-note b { color: var(--text); }
.applied-live b { color: var(--text); font-variant-numeric: tabular-nums; }
.edit-actions { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.save-msg { font-size: 0.8rem; }
.save-msg.ok { color: var(--ok); }
.save-msg.err { color: var(--error); }
.lock-cell { cursor: help; }

.applied-rate { margin: 0.4rem 0 0.2rem; color: var(--muted); font-size: 0.9rem; }
.applied-rate strong { color: var(--text); font-variant-numeric: tabular-nums; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.login-wrap { min-height: 70vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 20rem; display: flex; flex-direction: column; gap: 0.5rem; }
.login-card h1 { text-align: center; }
.login-card label { color: var(--muted); font-size: 0.85rem; margin-top: 0.4rem; }
.login-card input { width: 100%; }
.login-card button { margin-top: 1rem; }

/* --- preset chips + compact filter --- */
.presets { display: inline-flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.chip {
    display: inline-block; padding: 0.25rem 0.6rem; border-radius: 999px;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
    font-size: 0.8rem; cursor: pointer; text-decoration: none;
}
.chip:hover { color: var(--text); text-decoration: none; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.filterbar.compact { gap: 0.6rem; margin: 0.6rem 0 0; }
.row-muted { opacity: 0.55; }

/* --- horizontal bar chart (magnitude by identity) --- */
.hbars { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.4rem; }
.hbar { display: grid; grid-template-columns: 9rem 1fr 5rem; align-items: center; gap: 0.6rem; }
.hbar-label { color: var(--muted); font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { background: var(--surface-2); border-radius: 5px; height: 0.85rem; overflow: hidden; }
.hbar-fill { display: block; height: 100%; background: #5b9dff; border-radius: 5px; min-width: 2px; }
.hbar-val { text-align: right; font-size: 0.82rem; color: var(--text); font-variant-numeric: tabular-nums; }

/* --- vertical bar chart (change over time) --- */
.vbars { display: flex; align-items: flex-end; gap: 2px; height: 9rem; margin-top: 0.4rem; }
.vbar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.3rem; height: 100%; justify-content: flex-end; }
.vbar-col { width: 100%; height: 100%; display: flex; align-items: flex-end; background: var(--surface-2); border-radius: 4px 4px 0 0; }
.vbar-fill { width: 100%; background: #5b9dff; border-radius: 4px 4px 0 0; min-height: 2px; }
.vbar-label { color: var(--muted); font-size: 0.68rem; }

@media (max-width: 800px) {
    .hbar { grid-template-columns: 6rem 1fr 4rem; }
    .vbar-label { font-size: 0.6rem; }
}
