:root {
  --bg: #0a0a0c;
  --panel: #121218;
  --border: #24242e;
  --text: #f2f2f5;
  --muted: #8b8b9a;
  --accent: #e8ff47;
  --danger: #ff5c5c;
  --ok: #3dd68c;
  --warn: #f5a524;
  --input: #0e0e14;
  --hover: #1c1c26;
  --sidebar: 240px;
  --font: "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); background: var(--panel); border-right: 1px solid var(--border);
  padding: 1.25rem 1rem; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar h1 { font-size: 1.1rem; margin: 0 0 0.25rem; letter-spacing: 0.04em; }
.sidebar .sub { color: var(--muted); font-size: 0.75rem; margin-bottom: 1.5rem; }
.nav a {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.45rem 0.6rem; border-radius: 6px; color: var(--text);
  font-size: 0.9rem; margin-bottom: 2px;
}
.nav a:hover, .nav a.active { background: var(--hover); text-decoration: none; color: var(--accent); }
.nav .sec {
  display: flex; align-items: center; gap: 0.4rem;
  color: var(--muted); font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.06em; margin: 1rem 0 0.35rem; font-weight: 650;
}
.nav .sec:first-child { margin-top: 0; }
.nav-ico { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.88; }
.nav a.active .nav-ico, .nav a:hover .nav-ico { opacity: 1; }
.nav .sec .nav-ico { width: 13px; height: 13px; opacity: 0.75; }
.theme-toggle { display: flex; align-items: center; justify-content: center; gap: 0.4rem; }
.theme-toggle .nav-ico { width: 14px; height: 14px; }
.main { flex: 1; min-width: 0; padding: 1.5rem 2rem; max-width: 1200px; }

/* Right rail */
.rail {
  width: 300px; flex-shrink: 0; margin-left: auto; padding: 1.5rem 1.25rem 1.5rem 0;
  position: sticky; top: 0; align-self: flex-start; max-height: 100vh; overflow-y: auto;
}
.rail-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.85rem; margin-bottom: 0.85rem;
}
.rail-card h4 {
  margin: 0 0 0.6rem; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
}
.rail-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.rail-stat {
  display: block; background: var(--input); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.55rem 0.65rem; color: var(--text);
}
a.rail-stat:hover { text-decoration: none; border-color: var(--accent); }
.rail-stat b { display: block; font-size: 1.25rem; }
.rail-stat span { color: var(--muted); font-size: 0.72rem; }
.rail-stat.hot b { color: var(--warn); }
.rail-alerts { border-color: var(--warn); }
.rail-list li.alert-critical { border-left: 3px solid #e5484d; padding-left: 0.5rem; }
.rail-list li.alert-warning { border-left: 3px solid var(--warn); padding-left: 0.5rem; }
.rail-list { list-style: none; margin: 0; padding: 0; }
.rail-list li { padding: 0.45rem 0; border-bottom: 1px solid var(--border); font-size: 0.82rem; display: flex; flex-direction: column; gap: 0.1rem; }
.rail-list li:last-child { border-bottom: none; }
.rail-list .muted { font-size: 0.72rem; }
.rail-sub { font-size: 0.78rem; margin: 0.4rem 0; }
.rail-link { display: inline-block; margin-top: 0.5rem; font-size: 0.8rem; }
.rail-ctx { display: flex; align-items: center; gap: 0.5rem; }
.rail-id { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.78rem; }
.rail-copy { padding: 0.25rem 0.5rem; font-size: 0.72rem; }
.rail-kind {
  display: inline-block; font-size: 0.65rem; text-transform: uppercase; color: #111; background: var(--accent);
  border-radius: 4px; padding: 0 0.3rem; margin-right: 0.25rem;
}
@media (max-width: 1400px) {
  .rail { display: none; }
}
h2 { margin: 0 0 1rem; font-size: 1.4rem; }
.flash { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash.err { background: #2a1212; color: var(--danger); border: 1px solid #5a2020; }
.flash.ok { background: #10261c; color: var(--ok); border: 1px solid #1e4a32; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 1rem; margin-bottom: 1rem;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.75rem; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; }
.stat .n { font-size: 1.6rem; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 0.8rem; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.55rem 0.4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; }
input, select, textarea, button {
  font: inherit; border-radius: 6px; border: 1px solid var(--border);
  background: var(--input); color: var(--text); padding: 0.5rem 0.65rem;
}
button, .btn {
  background: var(--accent); color: #111; border: none; font-weight: 600; cursor: pointer;
  display: inline-block; padding: 0.5rem 0.85rem;
}
button.secondary, .btn.secondary { background: var(--hover); color: var(--text); border: 1px solid var(--border); }
button.danger, .btn.danger { background: var(--danger); color: #fff; }
button:hover { filter: brightness(1.05); }
.form-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; align-items: center; }
.form-row label { color: var(--muted); font-size: 0.85rem; min-width: 90px; }
.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(ellipse at top, #1a1a24 0%, var(--bg) 55%);
}
.login-box { width: min(380px, 92vw); }
.login-box h1 { margin: 0 0 0.25rem; }
.oauth-or {
  display: flex; align-items: center; gap: 0.75rem;
  margin: 1.1rem 0 0.85rem; color: var(--muted); font-size: 0.72rem;
  letter-spacing: 0.12em; text-transform: uppercase;
}
.oauth-or::before, .oauth-or::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.oauth-btn {
  display: flex; align-items: center; justify-content: center; gap: 0.6rem;
  width: 100%; margin-top: 0.5rem; padding: 0.55rem 0.85rem;
  background: var(--hover); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; font-weight: 600; text-decoration: none;
}
.oauth-btn:hover { text-decoration: none; border-color: var(--accent); color: var(--text); }
.oauth-btn svg { flex-shrink: 0; display: block; }
.oauth-hint { font-size: 0.75rem; margin: 0.85rem 0 0; }
.muted { color: var(--muted); }
.badge { display: inline-block; padding: 0.15rem 0.45rem; border-radius: 999px; font-size: 0.72rem; background: var(--hover); }
.badge.warn { background: #3a2a10; color: var(--warn); }
.badge.danger { background: #3a1515; color: var(--danger); }
.badge.ok { background: #153a28; color: var(--ok); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.35rem; }
.checks label { display: flex; gap: 0.4rem; align-items: center; font-size: 0.85rem; }
pre.json { background: var(--input); padding: 0.75rem; border-radius: 8px; overflow: auto; font-size: 0.8rem; max-height: 320px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; word-break: break-all; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 1rem; }
.tabs a {
  padding: 0.35rem 0.7rem; border-radius: 6px; background: var(--hover); color: var(--text);
  font-size: 0.82rem; text-decoration: none; border: 1px solid var(--border);
}
.tabs a:hover { border-color: var(--accent); color: var(--accent); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.85rem; }
.kv .muted { display: block; font-size: 0.72rem; margin-bottom: 0.15rem; }
.thread .bubble {
  border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem; margin-bottom: 0.6rem;
  background: var(--input);
}
.thread .bubble.staff { border-color: #3a4a20; }
.thread .bubble.user { border-color: #2a3a5a; }
.thread .meta { color: var(--muted); font-size: 0.75rem; margin-bottom: 0.35rem; }
h3 { margin: 0 0 0.75rem; font-size: 1rem; }

/* Audit side-by-side diff */
.audit-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.audit-entry details { margin-top: 0.75rem; }
.audit-entry summary { cursor: pointer; color: var(--muted); font-size: 0.82rem; margin-bottom: 0.5rem; }
.diff {
  display: grid; grid-template-columns: minmax(120px, 0.6fr) 1fr 1fr;
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
  font-size: 0.82rem;
}
.diff > div { padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); word-break: break-word; }
.diff > div:nth-last-child(-n+3) { border-bottom: none; }
.diff-head { background: var(--hover); color: var(--muted); font-size: 0.7rem; text-transform: uppercase; font-weight: 600; }
.diff-key { color: var(--muted); font-family: ui-monospace, Consolas, monospace; background: var(--input); }
.diff-cell { font-family: ui-monospace, Consolas, monospace; background: var(--input); border-left: 1px solid var(--border); }
.diff-cell.before.chg { background: #2a1212; color: #ff9a9a; }
.diff-cell.after.chg { background: #10261c; color: #7fe3b0; }
.diff-cell.empty { opacity: 0.5; }
.diff-key.chg { color: var(--accent); }
.diff-raw { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.diff-raw pre.json { margin: 0; max-height: 360px; }
@media (max-width: 800px) {
  .diff-raw { grid-template-columns: 1fr; }
}

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; }
}
