:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #17191c;
  --muted: #5d6673;
  --accent: #3d7bf7;
  --accent-ink: #ffffff;
  --accent-soft: #e6eeff;
  --ok: #18864b;
  --ok-soft: #e2f5ea;
  --err: #c9372c;
  --err-soft: #fdeceb;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --user: #7c4dcc;
  --user-soft: #f1eafd;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --border: #2a2f39;
    --text: #e6e8ec;
    --muted: #9aa3b2;
    --accent: #5b8ff9;
    --accent-ink: #ffffff;
    --accent-soft: #1b2741;
    --ok: #3fbf7a;
    --ok-soft: #13291d;
    --err: #f2685d;
    --err-soft: #331818;
    --warn: #e0b341;
    --warn-soft: #2e2611;
    --user: #b18cf2;
    --user-soft: #261d38;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a20;
  --surface-2: #1e222a;
  --border: #2a2f39;
  --text: #e6e8ec;
  --muted: #9aa3b2;
  --accent: #5b8ff9;
  --accent-ink: #ffffff;
  --accent-soft: #1b2741;
  --ok: #3fbf7a;
  --ok-soft: #13291d;
  --err: #f2685d;
  --err-soft: #331818;
  --warn: #e0b341;
  --warn-soft: #2e2611;
  --user: #b18cf2;
  --user-soft: #261d38;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
code, kbd, pre { font-family: var(--mono); font-size: 12.5px; }
kbd {
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  background: var(--surface);
  font-size: 11px;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 18px; font-weight: 650; }
h2 { font-size: 20px; font-weight: 650; margin-top: 6px; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 4px 0 0; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand-name span { color: var(--accent); }
.brand-sub { color: var(--muted); font-size: 12px; }
.install-bar { display: flex; align-items: center; gap: 10px; flex: 1; flex-wrap: wrap; min-width: 0; }
.top-actions { display: flex; align-items: center; gap: 6px; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.compact { flex-direction: row; align-items: center; gap: 8px; }
.field-label { font-size: 12px; color: var(--muted); font-weight: 500; white-space: nowrap; }
select, input[type="text"], input[type="search"], input[type="number"], input[type="date"] {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
  width: 100%;
}
.install-bar select { width: auto; max-width: min(360px, 60vw); }
select:focus, input:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-weight: 500; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { width: 34px; height: 20px; border-radius: 99px; background: var(--border); position: relative; transition: background .15s; }
.toggle-thumb { position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: var(--shadow); }
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(14px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-weight: 550;
  border: 1px solid transparent; border-radius: 8px;
  padding: 7px 14px; cursor: pointer;
  text-decoration: none; color: inherit; background: none;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.primary:disabled { opacity: .65; cursor: progress; }
.btn.ghost { border-color: var(--border); background: var(--surface); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn.icon-only { padding: 6px 8px; }
.count { background: var(--surface-2); border-radius: 99px; padding: 0 7px; font-size: 11.5px; color: var(--muted); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .01em;
  padding: 2px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted);
  white-space: nowrap;
}
.badge.mock { background: var(--warn-soft); color: var(--warn); }
.badge.anonymous { background: var(--accent-soft); color: var(--accent); }
.badge.signed, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.user-scope, .badge.user { background: var(--user-soft); color: var(--user); }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: calc(100vh - 58px);
}
.layout.with-history { grid-template-columns: 260px minmax(0, 1fr) 320px; }

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex; flex-direction: column;
  position: sticky; top: 58px; height: calc(100vh - 58px);
  overflow: hidden;
}
.sidebar-search { padding: 12px; border-bottom: 1px solid var(--border); }
#endpointNav { overflow-y: auto; flex: 1; padding: 6px 8px 12px; }
.nav-group { margin-top: 10px; }
.nav-group-title {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 4px 8px;
}
.nav-group-title code { text-transform: none; letter-spacing: 0; font-size: 11px; font-weight: 400; }
.nav-item {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  width: 100%; text-align: left;
  font: inherit; color: var(--text);
  background: none; border: 0; border-radius: 7px;
  padding: 6px 8px; cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .badge { font-size: 10.5px; padding: 0 6px; }
.sidebar-foot { padding: 10px 12px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--border); }

.main { padding: 18px 20px 40px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.intro {
  display: flex; gap: 16px; align-items: flex-start; justify-content: space-between;
  padding: 16px 18px;
  border-radius: var(--radius);
  background: linear-gradient(120deg, var(--accent-soft), var(--surface) 70%);
  border: 1px solid var(--border);
}
.intro p { color: var(--muted); max-width: 820px; }

.endpoint-card, .snippet-card, .result-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.endpoint-card { padding: 16px 18px; }
.crumbs { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.crumbs code { color: var(--muted); }
.service-chip { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 8px; border-radius: 6px; }

.params { margin-top: 14px; }
.params-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.params-grid:empty { display: none; }
.param-hint { font-size: 11.5px; color: var(--muted); }
.run-row { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 12px; }

/* ---------- results ---------- */
.results { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.results.compare { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.result-col { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.result-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.result-head .inst { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 160px; }
.metric { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.metric b { color: var(--text); font-weight: 500; }
.result-url {
  font-family: var(--mono); font-size: 11.5px; color: var(--muted);
  padding: 6px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap; overflow-x: auto;
  background: var(--surface-2);
}
.result-url .verb { color: var(--ok); font-weight: 600; margin-right: 6px; }
.panes { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 0; }
.panes.single { grid-template-columns: minmax(0, 1fr); }
.pane { min-width: 0; display: flex; flex-direction: column; }
.pane + .pane { border-left: 1px solid var(--border); }
.pane-title {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 14px; font-size: 12px; font-weight: 600; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.pane-title code { color: var(--accent); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-host { height: 420px; position: relative; }
.snippet-host { height: 300px; }
.editor-host pre.fallback {
  margin: 0; height: 100%; overflow: auto; padding: 10px 14px;
  background: var(--surface); color: var(--text); white-space: pre;
}
.error-box {
  margin: 14px; padding: 12px 14px; border-radius: 8px;
  background: var(--err-soft); color: var(--err);
  font-size: 13px; overflow-wrap: anywhere;
}
.error-box.login { background: var(--user-soft); color: var(--user); }
.error-box .btn { margin-top: 8px; }
.empty-result {
  padding: 36px 18px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius);
}
.skeleton { height: 420px; display: grid; place-items: center; color: var(--muted); }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.seg-btn { font: inherit; font-size: 12px; font-weight: 550; border: 0; background: none; color: var(--muted); padding: 3px 10px; border-radius: 6px; cursor: pointer; }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- history ---------- */
.history-panel {
  border-left: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 58px; height: calc(100vh - 58px);
  display: flex; flex-direction: column; overflow: hidden;
}
.history-stats { padding: 8px 16px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); }
.history-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.history-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 2px 8px; align-items: center;
  width: 100%; text-align: left; font: inherit; color: inherit;
  background: none; border: 0; border-radius: 8px; padding: 8px 10px; cursor: pointer;
}
.history-item:hover { background: var(--surface-2); }
.history-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.history-item.failed .dot { background: var(--err); }
.history-item .title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .ms { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.history-item .sub { grid-column: 2 / 4; font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timing-bar { grid-column: 2 / 4; height: 3px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.timing-bar span { display: block; height: 100%; background: var(--accent); opacity: .7; }
.history-empty { padding: 24px 16px; color: var(--muted); text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg);
  padding: 8px 14px; border-radius: 8px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.results.compare .panes { grid-template-columns: minmax(0, 1fr); }
.results.compare .pane + .pane { border-left: 0; border-top: 1px solid var(--border); }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .layout.with-history { grid-template-columns: 240px minmax(0, 1fr); }
  .layout.with-history .history-panel {
    position: fixed; right: 0; top: 0; bottom: 0; height: 100vh; width: min(340px, 92vw);
    z-index: 40; box-shadow: -8px 0 24px rgba(0, 0, 0, .18);
  }
  .layout { grid-template-columns: 240px minmax(0, 1fr); }
  .results.compare .panes { grid-template-columns: minmax(0, 1fr); }
  .results.compare .pane + .pane { border-left: 0; border-top: 1px solid var(--border); }
}
@media (max-width: 860px) {
  .layout, .layout.with-history { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; max-height: 260px; border-right: 0; border-bottom: 1px solid var(--border); }
  .main { padding: 16px; }
  .panes { grid-template-columns: minmax(0, 1fr); }
  .pane + .pane { border-left: 0; border-top: 1px solid var(--border); }
  .results.compare { grid-template-columns: minmax(0, 1fr); }
  .editor-host { height: 320px; }
  .install-bar { flex-basis: 100%; order: 3; }
  .install-bar .field.compact { flex: 1 1 100%; }
  .install-bar select { max-width: none; width: 100%; }
  .brand { flex: 1; }
  .topbar { position: static; }
  .brand-sub { display: none; }
}
