:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #17202b;
  --muted: #5d6877;
  --brand: #0e7c6b;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3ef;
  --bar: #0f1b26;
  --bar-text: #d5dde6;
  --ok: #157f3c;
  --ok-soft: #e3f4e8;
  --warn: #a15c00;
  --warn-soft: #fdf1dc;
  --bad: #b42318;
  --bad-soft: #fde7e5;
  --info: #1d5fbf;
  --info-soft: #e5eefb;
  --c1: #1d5fbf;
  --c2: #0e7c6b;
  --c3: #7a4cc2;
  --c4: #d1453b;
  --c5: #c98400;
  --c6: #c2477f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1319;
    --surface: #161d25;
    --surface-2: #1c2530;
    --border: #2a3542;
    --text: #e6ebf0;
    --muted: #96a3b2;
    --brand: #2bb39b;
    --brand-ink: #062a24;
    --brand-soft: #11332d;
    --bar: #0a0f14;
    --ok: #4cc27a;
    --ok-soft: #12301f;
    --warn: #e8a645;
    --warn-soft: #33270f;
    --bad: #f0776c;
    --bad-soft: #3a1916;
    --info: #7aa7f0;
    --info-soft: #15233a;
    --c1: #7aa7f0;
    --c2: #2bb39b;
    --c3: #b08ef0;
    --c4: #f0776c;
    --c5: #e8a645;
    --c6: #ec86b5;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

.topbar {
  background: var(--bar);
  color: var(--bar-text);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 18px;
}
.logo { display: flex; align-items: center; gap: 9px; color: #fff; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.logo:hover { text-decoration: none; }
.logo-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, #19a68e, #0e7c6b);
  display: grid; place-items: center; color: #fff; font-size: 14px; font-weight: 800;
}
.nav { display: flex; gap: 2px; flex: 1; }
.nav-item { position: relative; }
.nav-link {
  display: block; padding: 8px 12px; border-radius: 8px; color: var(--bar-text);
  font-weight: 500; background: none; border: 0; font: inherit; cursor: pointer;
}
.nav-link:hover, .nav-item:focus-within > .nav-link, .nav-item.active > .nav-link { background: rgba(255, 255, 255, .09); color: #fff; text-decoration: none; }
.nav-menu {
  display: none; position: absolute; top: 100%; left: 0; min-width: 220px; margin-top: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .18); padding: 6px;
}
.nav-item:hover > .nav-menu, .nav-item:focus-within > .nav-menu { display: block; }
.nav-item::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 8px; }
.nav-menu a { display: block; padding: 8px 10px; border-radius: 7px; color: var(--text); }
.nav-menu a:hover, .nav-menu a.on { background: var(--surface-2); text-decoration: none; }
.nav-menu .desc { display: block; color: var(--muted); font-size: 12px; }
.nav-right { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; }
.nav-right .nav-menu { left: auto; right: 0; }
.acct-chip { font-size: 12px; color: var(--bar-text); opacity: .85; }

.page { max-width: 1320px; margin: 0 auto; padding: 24px 20px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }

.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: center; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.flush { padding: 0; overflow: hidden; }
.flush .card-head { padding: 16px 18px 0; }

.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1fr) 340px; }
.stack > * + * { margin-top: 16px; }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.kpi .rate { font-size: 12.5px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.chart { width: 100%; height: 240px; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

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; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.table-wrap { overflow-x: auto; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-info { background: var(--info-soft); color: var(--info); }
.b-brand { background: var(--brand-soft); color: var(--brand); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--brand) 88%, #000); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-danger { color: var(--bad); }
.inline { display: inline; }

.field { margin-bottom: 14px; }
.field label, .label-row { display: block; font-weight: 600; margin-bottom: 5px; }
.field .hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
input:not([type]), input[type=text], input[type=search], input[type=url], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); border-color: var(--brand); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.checks label { font-weight: 400; display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin: 0; min-width: 150px; }

.seg { display: inline-flex; flex-wrap: wrap; max-width: 100%; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg a { padding: 7px 12px; color: var(--muted); font-weight: 600; font-size: 13px; border-right: 1px solid var(--border); }
.seg a:last-child { border-right: 0; }
.seg a.on { background: var(--brand-soft); color: var(--brand); }
.seg a:hover { text-decoration: none; background: var(--surface-2); }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); }
.tabs a:hover { text-decoration: none; color: var(--text); }

.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-warn { background: var(--warn-soft); color: var(--warn); }
.flash-bad { background: var(--bad-soft); color: var(--bad); }
.secret { border: 2px solid var(--brand); background: var(--brand-soft); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.secret .kv { display: grid; grid-template-columns: 110px 1fr auto; gap: 8px 12px; align-items: center; margin-top: 10px; }
.secret code { background: var(--surface); padding: 6px 9px; border-radius: 6px; border: 1px solid var(--border); word-break: break-all; }

.kv-grid { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 8px 16px; }
.kv-grid dt { color: var(--muted); font-size: 13px; }
.kv-grid dd { margin: 0; word-break: break-word; }

.checklist .row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.checklist .row:last-child { border-bottom: 0; }
.tick { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 800; flex: none; }
.tick.done { background: var(--ok); color: #fff; }
.tick.todo { border: 2px solid var(--border); }

.meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 8px 0 4px; }
.meter > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }

.timeline { position: relative; }
.timeline a { display: flex; gap: 12px; padding: 10px 12px; border-radius: 8px; color: var(--text); align-items: center; }
.timeline a:hover { background: var(--surface-2); text-decoration: none; }
.timeline a.on { background: var(--brand-soft); }
.tl-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }

.records td { word-break: break-all; }
.records td:nth-child(3) { min-width: 260px; word-break: break-word; }
.records td:nth-child(1) { word-break: normal; }
.copy { cursor: pointer; }
pre.raw { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow: auto; max-height: 360px; margin: 0; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.pager .links { display: flex; gap: 6px; }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .logo { color: var(--text); justify-content: center; margin-bottom: 18px; font-size: 20px; }
.danger-zone { border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .g-main { grid-template-columns: minmax(0, 1fr); }
}
.card-head { flex-wrap: wrap; }
@media (max-width: 760px) {
  .topbar-inner { padding: 0 16px; gap: 10px; overflow-x: auto; }
  .nav-link { padding: 8px 8px; white-space: nowrap; }
  .nav-menu, .nav-right .nav-menu { position: fixed; top: 52px; left: 16px; right: 16px; min-width: 0; }
  .grid[style*="300px"] { grid-template-columns: minmax(0, 1fr) !important; }
  .acct-chip { display: none; }
  .page { padding: 18px 16px 48px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-2, .g-3 { grid-template-columns: minmax(0, 1fr); }
  .kv-grid { grid-template-columns: 1fr; }
  .secret .kv { grid-template-columns: 1fr; }
}
