:root {
  --bg: #0e0f12;
  --panel: #16181d;
  --panel2: #1c1f26;
  --line: #2a2e37;
  --text: #e7e9ee;
  --muted: #9aa1ad;
  --orange: #c14a2c;
  --slate: #6b7280;
  --good: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
a { color: #8ab4ff; text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand svg { width: 22px; height: 22px; }
.brand .tag { color: var(--muted); font-weight: 400; font-size: 13px; }
.topbar .spacer { flex: 1; }
.whoami { color: var(--muted); font-size: 13px; }

.tabs { display: flex; gap: 4px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tab {
  padding: 7px 14px; border-radius: 8px; cursor: pointer; color: var(--muted);
  border: 1px solid transparent; background: none; font-size: 14px;
}
.tab:hover { color: var(--text); background: var(--panel2); }
.tab.on { color: var(--text); background: var(--panel2); border-color: var(--line); }

main { padding: 20px; max-width: 1200px; margin: 0 auto; }
section.view { display: none; }
section.view.on { display: block; }

h2 { font-size: 18px; margin: 0 0 14px; }
.muted { color: var(--muted); }
.right { text-align: right; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px;
}
.card .k { color: var(--muted); font-size: 13px; }
.card .v { font-size: 28px; font-weight: 700; margin-top: 4px; }
.card .v small { font-size: 14px; color: var(--muted); font-weight: 400; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 20px; }
.panel h3 { margin: 0 0 12px; font-size: 15px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
tr:hover td { background: var(--panel2); }
td.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); }
.pill.good { color: var(--good); border-color: #24422c; }
.pill.warn { color: var(--warn); border-color: #4a3d16; }
.pill.bad { color: var(--bad); border-color: #4a1f1e; }

button.btn, a.btn {
  display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); cursor: pointer; font-size: 14px;
}
button.btn:hover, a.btn:hover { border-color: var(--orange); text-decoration: none; }
button.btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; }

.bars { display: flex; flex-direction: column; gap: 6px; }
.bar { display: grid; grid-template-columns: 220px 1fr 60px; gap: 10px; align-items: center; }
.bar .lab { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .track { background: var(--panel2); border-radius: 6px; height: 16px; overflow: hidden; }
.bar .fill { background: var(--orange); height: 100%; }
.bar .num { text-align: right; color: var(--muted); }

.spark { display: flex; align-items: flex-end; gap: 2px; height: 60px; }
.spark span { flex: 1; background: var(--orange); border-radius: 2px 2px 0 0; min-height: 2px; }

pre.json {
  background: #0a0b0e; border: 1px solid var(--line); border-radius: 10px; padding: 14px;
  overflow: auto; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; color: #cdd3dd; max-height: 60vh;
}
.err { color: var(--bad); margin: 10px 0; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
input.text { background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 14px; min-width: 260px; }
.loading { color: var(--muted); padding: 20px 0; }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 40px; text-align: center; width: 360px; }
.login-box svg { width: 44px; height: 44px; margin-bottom: 8px; }
.login-box h1 { font-size: 20px; margin: 6px 0 4px; }
.login-box p { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.gh {
  display: inline-flex; align-items: center; gap: 10px; padding: 11px 18px; border-radius: 10px;
  background: #1f6feb; color: #fff; font-weight: 600;
}
.gh:hover { text-decoration: none; background: #388bfd; }

/* Safe-area top padding so the bar clears the notch in standalone mode. */
.topbar { padding-top: max(12px, env(safe-area-inset-top)); }

/* ---------- phones: responsive layout + native-style bottom tab bar ---------- */
@media (max-width: 640px) {
  .topbar { gap: 10px; padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .brand .tag { display: none; }
  .whoami { font-size: 12px; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  main { padding: 14px; }
  /* Room for the fixed bottom tab bar. */
  body { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }

  /* Move the tab strip to a fixed bottom bar. */
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    border-top: 1px solid var(--line); border-bottom: none;
    background: rgba(22, 24, 29, 0.94); backdrop-filter: blur(10px);
    display: flex; gap: 0; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    flex-wrap: nowrap; overflow-x: auto; z-index: 50;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    flex: 1 0 auto; min-width: 60px; min-height: 48px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 10px; font-size: 12px; padding: 6px 8px; white-space: nowrap;
  }
  .tab.on { background: var(--panel2); color: var(--text); }

  h2 { font-size: 17px; }

  /* Cards two-up. */
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
  .card { padding: 13px 14px; }
  .card .v { font-size: 22px; }

  /* Tables scroll sideways inside their panel, never break the page. */
  .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 560px; }

  /* Research bars: tighter label column. */
  .bar { grid-template-columns: 110px 1fr 40px; }

  /* Toolbars stack, controls go full width and stay tap-friendly. */
  .toolbar { flex-direction: column; align-items: stretch; }
  input.text { min-width: 0; width: 100%; }
  button.btn, a.btn { min-height: 44px; }
  .toolbar button.btn, .toolbar a.btn { width: 100%; text-align: center; }

  pre.json { font-size: 11.5px; max-height: 55vh; }

  /* Login box fits small screens. */
  .login-box { width: min(360px, 88vw); padding: 32px 24px; }
}
