:root {
  --bg: #f4f6fa; --panel: #ffffff; --ink: #111827; --muted: #5b6475; --line: #e3e8f0;
  --accent: #2563eb; --accent-dark: #1d4ed8; --accent-soft: #e8f0ff;
  --good: #15803d; --good-bg: #dcfce7; --warn: #b45309; --warn-bg: #fef3c7; --bad: #b91c1c; --bad-bg: #fee2e2; --grey-bg: #eceff4;
  --side: #0f172a; --side-ink: #cbd5e1; --radius: 12px; --shadow: 0 8px 24px rgba(15,23,42,.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020; --panel: #121a33; --ink: #eef2fb; --muted: #a3adc4; --line: #232c48;
    --accent: #4d86ff; --accent-dark: #6b9bff; --accent-soft: #16244d;
    --good: #4ade80; --good-bg: #12301d; --warn: #fcd34d; --warn-bg: #2f2710; --bad: #fca5a5; --bad-bg: #3a1717; --grey-bg: #1b2440;
    --side: #070b17; --shadow: 0 8px 24px rgba(0,0,0,.5);
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0 0 10px; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
a { color: var(--accent); }
.muted { color: var(--muted); } .small { font-size: 12px; } .mono { font-family: ui-monospace, Consolas, monospace; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.noscript { padding: 24px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login .logo { width: 40px; height: 40px; margin-bottom: 12px; }

/* shell */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 16px; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 700; }
.nav-item { all: unset; box-sizing: border-box; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--side-ink); }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item[aria-current="page"] { background: var(--accent); color: #fff; }
.nav-item:focus-visible { outline: 3px solid #93c5fd; }
.badge-count { background: #ef4444; color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.side .spacer { flex: 1; }
.side .who { padding: 10px 12px; font-size: 12px; color: #94a3b8; word-break: break-all; }
.main { padding: 24px 28px 48px; min-width: 0; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* controls */
button, input, select, textarea { font: inherit; color: inherit; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 14px; cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--grey-bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.sm { padding: 3px 10px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
.tools input, .tools select { width: auto; min-width: 180px; }
textarea { min-height: 90px; resize: vertical; }
label.field { display: grid; gap: 4px; font-weight: 600; font-size: 13px; margin-bottom: 12px; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* cards, stats, tables */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .num { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; margin-bottom: 14px; }
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
td.wrap { white-space: normal; min-width: 220px; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--bg); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--accent-soft); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--grey-bg); color: var(--muted); }
.pill.good { background: var(--good-bg); color: var(--good); } .pill.warn { background: var(--warn-bg); color: var(--warn); } .pill.bad { background: var(--bad-bg); color: var(--bad); }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.bars i { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.bars i.zero { background: var(--line); }
.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 4px; }
dl.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0 0 12px; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; word-break: break-word; }
.list-item { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; }
.list-item:last-child { border-bottom: 0; }
.msg-body { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }

/* dialog + toast */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(640px, 94vw); max-height: 90vh; background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(8, 12, 24, .55); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dlg-body { padding: 18px 20px; overflow-y: auto; max-height: calc(90vh - 130px); }
.dlg-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.x { all: unset; cursor: pointer; font-size: 22px; line-height: 1; padding: 0 6px; color: var(--muted); }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 360px; }
.toast.error { background: var(--bad); color: #fff; }
.error-text { color: var(--bad); margin: 0 0 10px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .brand { padding: 4px 10px; } .side .spacer, .side .who { display: none; }
  .main { padding: 18px 14px 40px; }
  .grid2, .row2 { grid-template-columns: 1fr; }
}
