:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #5b4ce0;
  --accent-soft: #eeebff;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --err: #c2410c;
  --err-soft: #ffedd5;
  --info: #0e7490;
  --info-soft: #cffafe;
  --hot: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2a2f3a;
    --text: #e8eaef;
    --muted: #9aa1ad;
    --accent: #8b7fff;
    --accent-soft: #2a2550;
    --ok: #4ade80;
    --ok-soft: #12301f;
    --warn: #fbbf24;
    --warn-soft: #362a0d;
    --err: #fb923c;
    --err-soft: #3a1f10;
    --info: #22d3ee;
    --info-soft: #0c2e35;
    --hot: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
code, pre, .mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 12.5px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--err); min-height: 1em; margin: 0; }

/* Layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 20px;
  padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent-soft); font-size: 18px;
}
nav { display: flex; flex-direction: column; gap: 2px; }
nav a {
  padding: 8px 10px; border-radius: 8px; color: var(--muted); font-weight: 500;
  display: flex; justify-content: space-between; align-items: center;
}
nav a:hover { background: var(--surface-2); color: var(--text); }
nav a.active { background: var(--accent-soft); color: var(--accent); }
.logout { margin-top: auto; }
main { padding: 28px 32px 60px; min-width: 0; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin: 14px 0; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12px; }
.stat.bad b { color: var(--err); }

.tempbar { display: flex; height: 8px; border-radius: 99px; overflow: hidden; background: var(--surface-2); margin: 6px 0 4px; }
.tempbar i { display: block; height: 100%; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }

.copy-row {
  display: flex; align-items: center; gap: 8px; background: var(--surface-2);
  border-radius: 8px; padding: 6px 6px 6px 10px; margin-top: 6px;
}
.copy-row code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 80px; line-height: 1.45; }
textarea.code { font-family: 'JetBrains Mono', monospace; font-size: 12.5px; min-height: 220px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; font-weight: 500; margin-bottom: 4px; font-size: 13px; }
.field { margin-bottom: 12px; }
.field small { color: var(--muted); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters > * { width: auto; min-width: 160px; }
.filters input[type=search] { min-width: 240px; flex: 1; }
.switch { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.switch input { width: auto; }

/* Table */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }
td.num { font-variant-numeric: tabular-nums; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px;
  font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.plain::before { display: none; }

.score { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.score b { font-variant-numeric: tabular-nums; width: 26px; }
.score .bar { flex: 1; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.score .bar i { display: block; height: 100%; background: var(--accent); }

/* Drawer */
.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer-backdrop, .modal-backdrop { position: absolute; inset: 0; background: rgba(10, 12, 16, .45); }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(760px, 100%);
  background: var(--bg); overflow-y: auto; padding: 24px; box-shadow: -8px 0 30px rgba(0,0,0,.15);
}
.drawer-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 18px; }
.drawer-head .big-score { font-size: 34px; font-weight: 700; line-height: 1; text-align: right; }
.section-title { margin: 22px 0 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.status-box { border: 1px solid var(--border); border-radius: 10px; padding: 14px; background: var(--surface); }
.status-box .err-text { color: var(--err); font-size: 12.5px; white-space: pre-wrap; margin: 8px 0 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 118px 80px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.timeline li:last-child { border-bottom: 0; }
details { margin-top: 4px; }
details summary { cursor: pointer; color: var(--muted); font-size: 12px; }
pre {
  background: var(--surface-2); padding: 10px 12px; border-radius: 8px; overflow: auto;
  max-height: 320px; margin: 6px 0 0; white-space: pre-wrap; word-break: break-word;
}
.msg-preview { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; font-size: 13px; margin-bottom: 8px; }
.msg-preview b { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-panel {
  position: relative; background: var(--surface); border-radius: 14px; padding: 22px;
  width: min(640px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25);
}

/* Toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px;
  max-width: 380px; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-weight: 500;
}
.toast.err { background: var(--err); color: #fff; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 12px; text-align: center;
  box-shadow: var(--shadow);
}
.login-card .brand-mark { margin: 0 auto; width: 46px; height: 46px; font-size: 24px; }
.login-card p { margin: 0; }

.steps { margin: 0; padding-left: 18px; }
.steps li { margin-bottom: 6px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; gap: 10px; }
  nav { flex-direction: row; overflow-x: auto; flex: 1 1 100%; order: 3; }
  .logout { margin-top: 0; margin-left: auto; }
  main { padding: 20px 16px 48px; }
  .grid.two { grid-template-columns: 1fr; }
  .timeline li { grid-template-columns: 1fr; gap: 2px; }
  .kv { grid-template-columns: 1fr; }
  .drawer-panel { padding: 16px; }
}
