/* ============================================================================
   CivicBell Developer portal — design system
   Light theme only. Inter. 1px borders, 8px radii, restrained accent use
   (#FF9800 appears only in the logo, the active-nav marker, and focus rings).
   ========================================================================= */

:root {
  --ink:        #0f172a;
  --body:       #334155;
  --muted:      #64748b;
  --faint:      #94a3b8;
  --border:     #e5e7eb;
  --border-soft:#f1f5f9;
  --bg:         #ffffff;
  --bg-subtle:  #f8fafc;
  --accent:     #FF9800;
  --link:       #1e40af;
  --ok:         #16a34a;
  --ok-bg:      #f0fdf4;
  --warn:       #d97706;
  --warn-bg:    #fffbeb;
  --err:        #dc2626;
  --err-bg:     #fef2f2;
  --code-bg:    #0f172a;
  --code-head:  #1e293b;
  --code-ink:   #e2e8f0;
  --radius:     8px;
  --radius-sm:  6px;
  --shadow:     0 1px 2px rgb(15 23 42 / .05);
  --mono:       ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-w:  260px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.65;
  color: var(--body);
  background: var(--bg);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: #ffedd5; }

:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgb(255 152 0 / .28);
  border-radius: var(--radius-sm);
}

/* ── Shell ─────────────────────────────────────────────────────────────── */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  z-index: 40;
}

.content {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  padding: 3rem 3.25rem 5rem;
}

/* ── Sidebar ───────────────────────────────────────────────────────────── */

.brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: 1.35rem 1.4rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.brand img { height: 30px; display: block; }
.brand-sub {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  padding: .14rem .45rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
}
.brand:hover { text-decoration: none; }

.nav { flex: 1; overflow-y: auto; padding: 1.1rem .9rem 1.5rem; }
.nav-group + .nav-group { margin-top: 1.35rem; }
.nav-group-label {
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 0 .55rem .35rem;
}
.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .38rem .55rem;
  margin: 1px 0;
  border-radius: var(--radius-sm);
  border-left: 3px solid transparent;
  font-size: .885rem;
  font-weight: 500;
  color: var(--muted);
}
.nav-link:hover { color: var(--ink); background: #eef2f6; text-decoration: none; }
.nav-link.active {
  color: var(--ink);
  background: var(--bg);
  border-left-color: var(--accent);
  border-top: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .85rem 1.15rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.user-meta { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.user-name { font-size: .82rem; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-org  { font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.signout { color: var(--muted); font-size: 1rem; padding: .3rem .4rem; border-radius: var(--radius-sm); }
.signout:hover { color: var(--err); background: var(--err-bg); text-decoration: none; }

/* ── Typography ────────────────────────────────────────────────────────── */

h1 {
  font-size: 1.85rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -.02em;
  margin: 0 0 .55rem;
  line-height: 1.25;
}
h2 {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -.01em;
  margin: 2.6rem 0 .8rem;
  padding-top: 1.6rem;
  border-top: 1px solid var(--border);
}
h2:first-of-type { margin-top: 2rem; }
h3 { font-size: 1.02rem; font-weight: 600; color: var(--ink); margin: 1.9rem 0 .55rem; }
p  { margin: 0 0 1rem; }
.lead { font-size: 1.02rem; color: var(--muted); max-width: 46rem; margin-bottom: 1.6rem; }
.page { max-width: 760px; }
ul, ol { padding-left: 1.3rem; margin: 0 0 1rem; }
li { margin-bottom: .3rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }
strong { color: var(--ink); font-weight: 600; }

code {
  font-family: var(--mono);
  font-size: .82rem;
  background: var(--border-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .1rem .34rem;
  color: var(--ink);
  white-space: nowrap;
}

/* ── Endpoint hero (method + path) ─────────────────────────────────────── */

.endpoint {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  padding: .5rem .85rem;
  margin: .35rem 0 1.4rem;
}
.endpoint code { background: none; border: 0; padding: 0; font-size: .92rem; font-weight: 500; }

.mbadge {
  display: inline-block;
  font-size: .66rem;
  font-weight: 700;
  letter-spacing: .07em;
  padding: .18rem .5rem;
  border-radius: 5px;
  line-height: 1.2;
}
.mbadge-post { color: #166534; background: #dcfce7; }
.mbadge-get  { color: #1e40af; background: #dbeafe; }

/* ── Reference grid (prose left, sticky code right) ────────────────────── */

.ref {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 2.75rem;
  align-items: start;
  max-width: 1240px;
}
.ref-main { min-width: 0; max-width: 760px; }
.ref-code { position: sticky; top: 2rem; min-width: 0; display: flex; flex-direction: column; gap: 1.1rem; }

/* ── Code panels ───────────────────────────────────────────────────────── */

.code-panel {
  background: var(--code-bg);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid #1e293b;
  margin: 0 0 1.2rem;
}
.ref-code .code-panel { margin: 0; }
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem .55rem .5rem .95rem;
  background: var(--code-head);
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: #94a3b8;
}
.code-panel pre {
  margin: 0;
  padding: .95rem 1rem;
  overflow-x: auto;
  max-height: 520px;
}
.code-panel code {
  background: none;
  border: 0;
  padding: 0;
  color: var(--code-ink);
  font-size: .8rem;
  line-height: 1.6;
  white-space: pre;
}
.copy-btn {
  font: 600 .7rem/1 "Inter", sans-serif;
  letter-spacing: .04em;
  color: #cbd5e1;
  background: transparent;
  border: 1px solid #334155;
  border-radius: 5px;
  padding: .32rem .55rem;
  cursor: pointer;
}
.copy-btn:hover { background: #334155; color: #fff; }
.copy-btn.copied { color: #86efac; border-color: #14532d; }

/* ── Tables ────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; margin: 0 0 1.4rem; border: 1px solid var(--border); border-radius: var(--radius); }
.doc-table { width: 100%; border-collapse: collapse; font-size: .865rem; background: var(--bg); }
.doc-table th {
  text-align: left;
  font-size: .67rem;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--bg-subtle);
  padding: .55rem .85rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.doc-table td {
  padding: .55rem .85rem;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}
.doc-table tr:last-child td { border-bottom: 0; }
.doc-table td code { font-size: .78rem; }

/* ── Callouts ──────────────────────────────────────────────────────────── */

.callout {
  display: flex;
  gap: .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  padding: .85rem 1rem;
  margin: 0 0 1.3rem;
  font-size: .89rem;
}
.callout i { flex: 0 0 auto; margin-top: .1rem; color: var(--muted); }
.callout p { margin: 0; }
.callout p + p { margin-top: .4rem; }
.callout-info { border-color: #bfdbfe; background: #eff6ff; }
.callout-info i { color: var(--link); }
.callout-warn { border-color: #fde68a; background: var(--warn-bg); }
.callout-warn i { color: var(--warn); }
.callout-ok { border-color: #bbf7d0; background: var(--ok-bg); }
.callout-ok i { color: var(--ok); }

/* ── Buttons & forms ───────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font: 600 .875rem/1 "Inter", sans-serif;
  color: #fff;
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  padding: .58rem 1.05rem;
  cursor: pointer;
  transition: background .12s ease;
}
.btn:hover { background: #1e293b; text-decoration: none; color: #fff; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-secondary { color: var(--ink); background: var(--bg); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-subtle); color: var(--ink); }

.btn-danger-ghost { color: var(--err); background: transparent; border: 1px solid transparent; padding: .35rem .6rem; font-size: .8rem; }
.btn-danger-ghost:hover { background: var(--err-bg); border-color: #fecaca; }

.btn-sm { padding: .4rem .75rem; font-size: .8rem; }

label { display: block; font-size: .8rem; font-weight: 600; color: var(--ink); margin: 0 0 .3rem; }
.hint { font-size: .76rem; color: var(--muted); margin-top: .25rem; }

input[type="text"], input[type="password"], input[type="email"], select, textarea {
  width: 100%;
  font: 400 .89rem/1.4 "Inter", sans-serif;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .5rem .7rem;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #fb923c;
  box-shadow: 0 0 0 3px rgb(255 152 0 / .16);
}
input::placeholder { color: var(--faint); }

.field { margin-bottom: .95rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }

/* ── Cards ─────────────────────────────────────────────────────────────── */

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.4rem 1.5rem;
  margin: 0 0 1.3rem;
}
.card-title { font-size: .95rem; font-weight: 600; color: var(--ink); margin: 0 0 .9rem; }

/* ── Pills / status ────────────────────────────────────────────────────── */

.pill {
  display: inline-block;
  font-size: .72rem;
  font-weight: 600;
  padding: .18rem .6rem;
  border-radius: 999px;
  border: 1px solid transparent;
  line-height: 1.5;
}
.pill-ok    { color: var(--ok);   background: var(--ok-bg);   border-color: #bbf7d0; }
.pill-warn  { color: var(--warn); background: var(--warn-bg); border-color: #fde68a; }
.pill-err   { color: var(--err);  background: var(--err-bg);  border-color: #fecaca; }
.pill-muted { color: var(--muted); background: var(--bg-subtle); border-color: var(--border); }

/* ── API keys page ─────────────────────────────────────────────────────── */

.keys-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.6rem 0 1rem; }
.keys-table td { vertical-align: middle; }
.key-mono { font-family: var(--mono); font-size: .8rem; color: var(--ink); white-space: nowrap; }
.key-name { font-weight: 600; color: var(--ink); }
.keys-empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.4rem 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
  margin-bottom: 1.3rem;
}

/* Modal (show-once key reveal + create form) */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgb(15 23 42 / .45);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 1rem 1rem;
  z-index: 90;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgb(15 23 42 / .18);
  width: 100%;
  max-width: 34rem;
  padding: 1.6rem 1.7rem;
}
.modal h3 { margin: 0 0 .9rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.2rem; }

.key-reveal {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-family: var(--mono);
  font-size: .82rem;
  color: var(--ink);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .65rem .8rem;
  word-break: break-all;
}
.key-reveal code { background: none; border: 0; padding: 0; white-space: normal; }

/* ── Test console ──────────────────────────────────────────────────────── */

.console {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.6rem;
  align-items: start;
  max-width: 1240px;
  margin-top: 1.4rem;
}
.console-pane { min-width: 0; }
.resp-meta { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; font-size: .8rem; color: var(--muted); margin-bottom: .7rem; }
.resp-status { font-weight: 700; font-family: var(--mono); font-size: .85rem; }
.resp-status.s2 { color: var(--ok); }
.resp-status.s4 { color: var(--warn); }
.resp-status.s5, .resp-status.s0 { color: var(--err); }
.console .code-panel pre { max-height: 640px; }
.console-placeholder {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--faint);
  font-size: .88rem;
  text-align: center;
  padding: 3.2rem 1rem;
}
.con-spinner {
  width: 26px; height: 26px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: con-spin .8s linear infinite;
}
@keyframes con-spin { to { transform: rotate(360deg); } }
.demo-row {
  display: flex; align-items: center; gap: .55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  padding: .6rem .8rem;
  margin-bottom: .95rem;
  font-size: .84rem;
}
.demo-row select { width: auto; flex: 1; }
.switch { position: relative; width: 34px; height: 20px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 2; }
.switch .track {
  position: absolute; inset: 0;
  background: #cbd5e1; border-radius: 999px; transition: background .15s ease;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: var(--shadow); transition: transform .15s ease;
}
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(14px); }

/* ── Misc ──────────────────────────────────────────────────────────────── */

.crumb { font-size: .74rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); margin-bottom: .4rem; }
.toast {
  position: fixed; bottom: 1.4rem; right: 1.4rem;
  background: var(--ink); color: #fff;
  border-radius: var(--radius);
  padding: .65rem 1rem;
  font-size: .85rem;
  box-shadow: 0 6px 18px rgb(15 23 42 / .25);
  opacity: 0; transform: translateY(8px);
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
  z-index: 99;
}
.toast.show { opacity: 1; transform: none; }

.menu-btn { display: none; }

/* ── Responsive ────────────────────────────────────────────────────────── */

@media (max-width: 1180px) {
  .ref { grid-template-columns: 1fr; }
  .ref-code { position: static; max-width: 760px; }
  .console { grid-template-columns: 1fr; }
}

@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .18s ease;
    box-shadow: 0 0 30px rgb(15 23 42 / .15);
  }
  .sidebar.open { transform: none; }
  .content { margin-left: 0; padding: 4.4rem 1.4rem 4rem; }
  .menu-btn {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    position: fixed;
    top: .85rem; left: .95rem;
    z-index: 50;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .45rem .7rem;
    font: 600 .8rem/1 "Inter", sans-serif;
    color: var(--ink);
    cursor: pointer;
    box-shadow: var(--shadow);
  }
  .field-row { grid-template-columns: 1fr; }
}

/* ── Test data generator ───────────────────────────────────────────────── */

.td-results { position: relative; }
.td-results .td-hit {
  border: 1px solid var(--border); border-top: 0;
  padding: .45rem .7rem; font-size: .85rem; cursor: pointer;
  display: flex; justify-content: space-between; gap: .8rem; background: var(--bg);
}
.td-results .td-hit:hover { background: var(--bg-subtle); }
.td-results .td-hit:first-child { border-top: 1px solid var(--border); border-radius: 0; }
.td-results .td-hit .hint { white-space: nowrap; }
.td-chips { display: flex; flex-wrap: wrap; gap: .45rem; margin: .6rem 0 .9rem; }
.td-chip {
  display: inline-flex; align-items: center; gap: .45rem;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg-subtle); padding: .28rem .4rem .28rem .75rem;
  font-size: .8rem; font-weight: 500; color: var(--ink);
}
.td-chip button {
  border: 0; background: none; cursor: pointer; color: var(--muted);
  font-size: .9rem; line-height: 1; padding: 0 .25rem;
}
.td-chip button:hover { color: var(--err); }
.chk-line { display: flex; gap: .5rem; align-items: flex-start; font-size: .84rem; font-weight: 400; color: var(--body); margin: .3rem 0 0; }
.chk-line input { width: auto; margin-top: .2rem; }
#tdMixTable input[type=number] { width: 84px; }
.td-total-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: -.6rem 0 1rem; }
.td-set {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .8rem 1rem; margin-bottom: .7rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; background: var(--bg);
}
.td-set b { color: var(--ink); }
.td-set .hint { flex: 1; }

/* Collapsible reference blocks (e.g. the exhaustive document-type catalog). */
.doc-details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  padding: 0;
  margin: 0 0 1.4rem;
}
.doc-details summary {
  cursor: pointer;
  padding: .7rem 1rem;
  font-weight: 600;
  font-size: .9rem;
  list-style: none;
}
.doc-details summary::-webkit-details-marker { display: none; }
.doc-details summary::before { content: "▸ "; color: var(--muted); }
.doc-details[open] summary::before { content: "▾ "; }
.doc-details[open] summary { border-bottom: 1px solid var(--border); }
.doc-details > *:not(summary) { margin-left: 1rem; margin-right: 1rem; }
.doc-details .table-wrap { background: var(--bg); }
