:root {
    --bg: #0e1014;
    --panel: #161920;
    --panel-2: #1c2029;
    --line: #262b36;
    --text: #e6e8ec;
    --muted: #8d94a3;
    --accent: #e8b23a;
    --accent-ink: #1a1405;
    --blue: #5b8def;
    --green: #3fb27f;
    --red: #e5534b;
    --amber: #d29922;
    --violet: #a371f7;
    --radius: 8px;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Buttons and inputs ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    border: 1px solid transparent; border-radius: var(--radius);
    background: var(--accent); color: var(--accent-ink);
    font: inherit; font-weight: 600; padding: 7px 14px; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: var(--panel-2); filter: none; }
.btn-discord { background: #5865f2; color: #fff; padding: 11px 18px; font-size: 15px; }
.icon-btn { background: none; border: 0; color: var(--text); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--panel-2); }

input, select {
    background: var(--panel-2); color: var(--text);
    border: 1px solid var(--line); border-radius: var(--radius);
    padding: 7px 10px; font: inherit; min-width: 0;
}
input:focus, select:focus, .btn:focus-visible, .nav-item:focus-visible, .log-row:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 1px;
}
input[type="search"] { width: 220px; }

/* ---------- Login ---------- */
.login-page { display: grid; place-items: center; padding: 24px; }
.login-card {
    width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line);
    border-radius: 14px; padding: 32px; text-align: center;
}
.login-logo { width: 96px; height: auto; }
.login-card h1 { margin: 12px 0 6px; font-size: 24px; }
.login-card p { margin: 0 0 20px; }
.login-error {
    background: rgba(229, 83, 75, .12); border: 1px solid rgba(229, 83, 75, .4);
    color: #ffb4ae; border-radius: var(--radius); padding: 10px 12px; text-align: left;
}

/* ---------- Layout ---------- */
.topbar {
    position: sticky; top: 0; z-index: 10; height: 56px;
    display: flex; align-items: center; gap: 12px; padding: 0 16px;
    background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 16px; }
.brand img { height: 32px; width: auto; }
.spacer { flex: 1; }
.user { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.user img { width: 28px; height: 28px; border-radius: 50%; }
.menu-btn { display: none; }

.layout { display: grid; grid-template-columns: 250px 1fr; height: calc(100% - 56px); }
.sidebar { border-right: 1px solid var(--line); overflow-y: auto; padding: 12px 8px 24px; background: var(--panel); }
.nav-group { margin-top: 16px; }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 10px 6px; }
.nav-item {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    padding: 6px 10px; border-radius: 6px; text-decoration: none; color: var(--text);
}
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: rgba(232, 178, 58, .14); color: var(--accent); }
.nav-empty { color: var(--muted); padding: 4px 10px; font-size: 13px; }
.count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.main { overflow-y: auto; padding: 20px 24px 40px; min-width: 0; }
.view-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.view-head h1 { margin: 0; font-size: 20px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.toggle { display: flex; align-items: center; gap: 6px; padding: 7px 4px; cursor: pointer; }
.toggle input { accent-color: var(--accent); }

/* ---------- Tables ---------- */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
.log-table { width: 100%; border-collapse: collapse; }
.log-table th, .log-table td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.log-table th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel-2); position: sticky; top: 0; }
.log-table tbody tr:last-child td { border-bottom: 0; }
.log-row { cursor: pointer; }
.log-row:hover td { background: var(--panel-2); }
.log-row.fresh td { animation: flash 2.5s ease-out; }
@keyframes flash { from { background: rgba(232, 178, 58, .18); } to { background: transparent; } }
.warn-row td { color: #ffb4ae; }
.c-time { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.c-cat { white-space: nowrap; }
.c-title { font-weight: 600; }
.c-msg { color: var(--muted); max-width: 520px; overflow-wrap: anywhere; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; border: 1px solid; }
.src-server { color: var(--blue); border-color: rgba(91, 141, 239, .45); }
.src-admin { color: var(--violet); border-color: rgba(163, 113, 247, .45); }
.src-heists { color: var(--amber); border-color: rgba(210, 153, 34, .45); }
.empty { color: var(--muted); padding: 24px; text-align: center; margin: 0; }
.more { display: flex; justify-content: center; margin: 12px 0; }
.more:empty { display: none; }

/* ---------- Console ---------- */
.console {
    background: #0a0b0e; border: 1px solid var(--line); border-radius: var(--radius);
    font: 12.5px/1.5 var(--mono); height: calc(100vh - 250px); min-height: 300px; overflow: auto; padding: 8px 0;
}
.line { display: flex; gap: 10px; padding: 0 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.line:hover { background: #14161b; }
.ln { color: #4b5263; min-width: 52px; text-align: right; user-select: none; flex: none; }
.ch { color: #6cb6ff; flex: none; }
.tx { flex: 1; }
.lv-error { background: rgba(229, 83, 75, .09); }
.lv-error .tx { color: #ff9b94; }
.lv-warn .tx { color: #e3b341; }

/* ---------- Detail dialog ---------- */
.detail {
    width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 64px);
    background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 0;
}
.detail::backdrop { background: rgba(0, 0, 0, .6); }
.detail-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.detail-head h2 { margin: 0; font-size: 16px; }
.detail dl { display: grid; grid-template-columns: 170px 1fr; gap: 8px 16px; margin: 0; padding: 16px 18px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; overflow-wrap: anywhere; }
.detail pre { margin: 0; font: 12.5px/1.5 var(--mono); background: #0a0b0e; padding: 10px; border-radius: 6px; white-space: pre-wrap; }

/* ---------- Screenshots ---------- */
.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.shot {
    display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 0 0 10px; overflow: hidden;
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    color: var(--text); font: inherit; cursor: pointer;
}
.shot:hover { border-color: var(--accent); }
.shot img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #0a0b0e; display: block; margin-bottom: 4px; }
.shot-name { font-weight: 600; padding: 0 10px; }
.shot-meta { color: var(--muted); font-size: 12px; padding: 0 10px; }
.detail-shot { max-width: 100%; border-radius: 6px; display: block; }
.viewer { width: min(1280px, calc(100vw - 32px)); }
.viewer img { display: block; width: 100%; height: auto; background: #0a0b0e; }
.viewer-meta { margin: 0; padding: 10px 18px 14px; }

.error-bar {
    position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
    background: #3a1714; border: 1px solid rgba(229, 83, 75, .5); color: #ffb4ae;
    padding: 10px 16px; border-radius: var(--radius); margin: 0; z-index: 20;
}

/* ---------- Small screens ---------- */
@media (max-width: 860px) {
    .menu-btn { display: inline-block; }
    .user span { display: none; }
    .layout { grid-template-columns: 1fr; }
    .sidebar { position: fixed; top: 56px; bottom: 0; left: 0; width: 270px; z-index: 9; transform: translateX(-100%); transition: transform .2s; }
    .nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .5); }
    .main { padding: 16px 12px 32px; }
    input[type="search"] { width: 100%; }
    .detail dl { grid-template-columns: 1fr; }
}

/* ---------- Sidebar: sub-categories and empty sources ---------- */
.nav-sub { margin: 0 0 4px 12px; border-left: 1px solid var(--line); padding-left: 4px; }
.nav-sub .nav-item { padding: 4px 10px; font-size: 13px; }
.nav-emptylist summary { color: var(--muted); font-size: 12px; padding: 4px 10px; cursor: pointer; list-style: none; }
.nav-emptylist summary::before { content: '▸ '; }
.nav-emptylist[open] summary::before { content: '▾ '; }
.nav-emptylist .nav-item { color: var(--muted); font-size: 13px; }
.badge { color: var(--muted); border-color: var(--line); }
.badge.src-server { color: var(--blue); border-color: rgba(91, 141, 239, .45); }
.badge.src-admin { color: var(--violet); border-color: rgba(163, 113, 247, .45); }
.badge.src-heists, .badge.src-pettycrimes, .badge.src-gangseller, .badge.src-opcrime, .badge.src-shredder { color: var(--amber); border-color: rgba(210, 153, 34, .45); }
.badge.src-oxlog { color: var(--green); border-color: rgba(63, 178, 127, .45); }
.badge.src-hooks { color: #39c5cf; border-color: rgba(57, 197, 207, .45); }
