:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1b1f24;
  --muted: #69707a;
  --accent: #2f6fed;
  --accent-soft: #e6eefe;
  --ok: #2e9d5b;
  --redir: #8b95a3;
  --warn: #d68a12;
  --err: #d63b3b;
  --err-soft: #fdecec;
  --warn-soft: #fdf3e2;
  --ok-soft: #e7f6ed;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --border: #2a3039;
    --text: #e6e9ee;
    --muted: #8d96a3;
    --accent: #5b8ff9;
    --accent-soft: #1c2a45;
    --ok: #43b874;
    --redir: #6b7480;
    --warn: #e5a23a;
    --err: #ef5f5f;
    --err-soft: #3a1d1f;
    --warn-soft: #3a2d16;
    --ok-soft: #173023;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }
.small-text { font-size: 12px; }
h3 { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
input, select, button { font: inherit; color: inherit; }
input, select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input.small { width: 220px; padding: 5px 9px; }
input.tiny { width: 76px; padding: 5px 8px; }

.btn { border: 1px solid var(--border); background: var(--surface); padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--border)); }
.btn.danger:hover { background: var(--err-soft); }
.btn.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
.btn.warn:hover { background: var(--warn-soft); }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 4px 10px; cursor: pointer; font-size: 12px; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.row-gap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.end { justify-content: flex-end; }
.error-text { color: var(--err); min-height: 1.2em; margin: 8px 0 0; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.login-card label { font-size: 12px; color: var(--muted); }
.login-card input { font-family: var(--mono); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

/* Topbar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.tabs button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.range { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.presets { display: flex; gap: 4px; }

main { padding: 20px; max-width: 1500px; margin: 0 auto; display: block; }
.tab { display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h3 { margin: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.toggle-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; padding: 3px 0; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.kpi.err .value { color: var(--err); }
.kpi.warn .value { color: var(--warn); }
.kpi.clickable { cursor: pointer; }
.kpi.clickable:hover { border-color: var(--accent); }

/* Timeline */
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.timeline { position: relative; }
.timeline svg { width: 100%; height: 200px; display: block; }
.timeline .bar:hover { opacity: .8; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; padding: 6px 8px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -110%); z-index: 5; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text); }
td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.ep { font-family: var(--mono); font-size: 12px; word-break: break-all; max-width: 520px; }
td.msg { max-width: 360px; }
td.nowrap { white-space: nowrap; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.s2 { background: var(--ok-soft); color: var(--ok); }
.s3 { background: var(--surface-2); color: var(--redir); }
.s4 { background: var(--warn-soft); color: var(--warn); }
.s5 { background: var(--err-soft); color: var(--err); }
.m { font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--muted); }
.slow { color: var(--warn); font-weight: 600; }
.very-slow { color: var(--err); font-weight: 600; }
.ratebar { display: inline-block; width: 50px; height: 6px; border-radius: 3px; background: var(--surface-2); vertical-align: middle; margin-left: 6px; overflow: hidden; }
.ratebar span { display: block; height: 100%; background: var(--err); }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters .f { display: flex; flex-direction: column; gap: 4px; min-width: 120px; }
.filters .f.grow { flex: 1 1 200px; }
.filters .f label { font-size: 11px; color: var(--muted); }
.filters .actions { flex-direction: row; gap: 6px; }
.filters .check-f { justify-content: flex-end; padding-bottom: 6px; }
.pager { display: flex; gap: 6px; align-items: center; }
.pager.end { justify-content: flex-end; margin-top: 10px; }

/* Files */
.usage-bar { height: 12px; background: var(--surface-2); border-radius: 6px; overflow: hidden; margin: 8px 0; }
.usage-bar span { display: block; height: 100%; background: var(--accent); }
.usage-bar.warn span { background: var(--warn); }
.usage-bar.err span { background: var(--err); }
.sizebar { display: inline-block; height: 6px; border-radius: 3px; background: var(--accent); vertical-align: middle; opacity: .7; }
.clean-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; }

/* Drawer */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 40; }
.drawer { position: fixed; inset: 0; background: var(--surface); z-index: 50; display: flex; flex-direction: column; }
body.drawer-open { overflow: hidden; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.drawer-head h3 { margin: 0; }
.drawer-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); }
.drawer-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.drawer-meta { margin: 0; padding: 16px 20px; display: grid; grid-template-columns: auto 1fr; align-content: start; gap: 8px 14px; font-size: 13px; border-right: 1px solid var(--border); overflow-y: auto; }
.drawer-meta dt { color: var(--muted); }
.drawer-meta dd { margin: 0; font-family: var(--mono); font-size: 12px; word-break: break-all; }
@media (max-width: 900px) {
  .drawer-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .drawer-meta { border-right: 0; border-bottom: 1px solid var(--border); max-height: 35vh; padding: 12px 16px; }
  .drawer-head { padding: 12px 16px; }
}
.drawer-tabs { display: flex; gap: 4px; padding: 8px 16px 0; border-bottom: 1px solid var(--border); }
.drawer-tabs button { border: 0; background: none; padding: 6px 10px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.drawer-tabs button.active { color: var(--text); border-color: var(--accent); }
.json { flex: 1; overflow: auto; margin: 0; padding: 14px 16px; font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; background: var(--surface-2); }
.json .k { color: var(--accent); }
.json .s { color: var(--ok); }
.json .n { color: var(--warn); }
.json .b { color: var(--err); }
.json .z { color: var(--muted); }

dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); max-width: 440px; width: calc(100% - 32px); padding: 20px; }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 100; max-width: calc(100% - 32px); }
.toast.err { background: var(--err); color: #fff; }
.alert { border: 1px solid color-mix(in srgb, var(--err) 40%, var(--border)); background: var(--err-soft); border-radius: 12px; padding: 12px 16px; }
.loading { opacity: .5; pointer-events: none; transition: opacity .15s; }

@media (max-width: 900px) {
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  main { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .range { margin-left: 0; }
}
