/* ── Reset & tokens ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 260px;
  --topbar-h:  52px;
  --bg:        #ffffff;
  --bg-sidebar:#0f172a;
  --border:    #e2e8f0;
  --text:      #1e293b;
  --text-muted:#64748b;
  --link:      #2563eb;
  --link-hover:#1d4ed8;
  --active-bg: #1e3a5f;
  --active-txt:#60a5fa;
  --section-hdr:#94a3b8;
  --code-bg:   #f1f5f9;
  --code-border:#e2e8f0;
  --accent:    #2563eb;
  --radius:    6px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  display: flex;
}

/* ── Overlay ─────────────────────────────────────────────────────── */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 40;
}
.overlay.visible { display: block; }

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 50;
}

.sidebar-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  text-decoration: none;
}
.logo-img {
  height: 28px;
  width: auto;
  display: block;
  /* Invert to white so logo reads well on the dark sidebar */
  filter: brightness(0) invert(1);
}

/* ── Nav tree ────────────────────────────────────────────────────── */
.nav-tree {
  padding: 12px 0 24px;
  overflow-y: auto;
  flex: 1;
}

.nav-section { margin-bottom: 4px; }

.nav-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--section-hdr);
  cursor: pointer;
  user-select: none;
}
.nav-section-header:hover { color: #cbd5e1; }

.nav-arrow {
  transition: transform .2s;
  flex-shrink: 0;
}
.nav-section-header.open .nav-arrow { transform: rotate(90deg); }

.nav-children { overflow: hidden; }
.nav-children.collapsed { display: none; }

.nav-link {
  display: block;
  padding: 6px 20px 6px 28px;
  font-size: 13px;
  color: #94a3b8;
  text-decoration: none;
  border-radius: 0;
  transition: color .15s, background .15s;
  line-height: 1.4;
}
.nav-link.top-level {
  padding-left: 20px;
  font-size: 13.5px;
  color: #cbd5e1;
}
.nav-link:hover { color: #f1f5f9; background: rgba(255,255,255,.05); }
.nav-link.active {
  color: var(--active-txt);
  background: var(--active-bg);
  font-weight: 600;
}

/* ── Layout ──────────────────────────────────────────────────────── */
.layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

/* ── Topbar ──────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 28px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.menu-btn {
  display: none;
  background: none; border: none;
  font-size: 20px; cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
}
.topbar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Content ─────────────────────────────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
}
.content-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 40px 80px;
}

.loading {
  color: var(--text-muted);
  padding: 40px 0;
  font-size: 14px;
}

.error-msg {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 20px 24px;
  color: #991b1b;
}

/* ── Markdown content ────────────────────────────────────────────── */
.content-inner h1 {
  font-size: 28px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 8px;
  line-height: 1.25;
}
.content-inner h2 {
  font-size: 20px;
  font-weight: 600;
  color: #1e293b;
  margin-top: 36px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.content-inner h3 {
  font-size: 16px;
  font-weight: 600;
  color: #334155;
  margin-top: 24px;
  margin-bottom: 8px;
}
.content-inner h4 {
  font-size: 14px;
  font-weight: 600;
  color: #475569;
  margin-top: 18px;
  margin-bottom: 6px;
}

.content-inner p { margin-bottom: 14px; }

.content-inner ul, .content-inner ol {
  margin: 8px 0 14px 24px;
}
.content-inner li { margin-bottom: 5px; }

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

.content-inner code {
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 13px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  padding: 1px 6px;
  color: #0f172a;
}

.content-inner pre {
  background: #0f172a;
  border-radius: var(--radius);
  padding: 18px 20px;
  overflow-x: auto;
  margin: 14px 0 20px;
}
.content-inner pre code {
  background: none;
  border: none;
  padding: 0;
  color: #e2e8f0;
  font-size: 13px;
  line-height: 1.6;
}

.content-inner table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0 20px;
  font-size: 14px;
}
.content-inner thead tr { background: #f8fafc; }
.content-inner th {
  text-align: left;
  padding: 9px 12px;
  font-weight: 600;
  font-size: 13px;
  color: #475569;
  border-bottom: 2px solid var(--border);
}
.content-inner td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.content-inner tr:last-child td { border-bottom: none; }

/* Home page nav tables — hide the empty header row */
.content-inner table thead tr th:empty,
.content-inner table thead tr:has(th:empty) {
  display: none;
}
.content-inner table thead tr th:empty ~ th {
  display: none;
}

.content-inner blockquote {
  border-left: 3px solid var(--accent);
  background: #eff6ff;
  padding: 12px 16px;
  margin: 14px 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: #1e3a5f;
}

.content-inner hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}

/* ── Documentation flows ────────────────────────────────────────── */
.flow-diagram {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) auto minmax(150px, 1fr) auto minmax(130px, 1fr) auto minmax(130px, 1fr);
  align-items: stretch;
  gap: 10px;
  margin: 20px 0 14px;
}

.flow-step {
  position: relative;
  display: flex;
  min-height: 112px;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  padding: 18px 14px 14px;
  border: 1px solid #dbe4f0;
  border-radius: 10px;
  background: linear-gradient(180deg, #fff 0%, #f8fafc 100%);
  box-shadow: 0 4px 12px rgba(15, 23, 42, .05);
  text-align: center;
}
.flow-step strong { color: #0f172a; font-size: 14px; }
.flow-step small { color: var(--text-muted); line-height: 1.45; }
.flow-step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 25px;
  height: 25px;
  margin: 0 auto 2px;
  border-radius: 50%;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 700;
}
.flow-step-conditional { border-color: #c4b5fd; background: linear-gradient(180deg, #fff 0%, #f5f3ff 100%); }
.flow-step-conditional .flow-step-number { background: #ede9fe; color: #6d28d9; }
.flow-step-active { border-color: #93c5fd; background: linear-gradient(180deg, #fff 0%, #eff6ff 100%); }
.flow-arrow { align-self: center; color: #94a3b8; font-size: 22px; font-weight: 600; }
.flow-note {
  margin: 12px 0 20px;
  padding: 11px 14px;
  border: 1px solid #ddd6fe;
  border-radius: 8px;
  background: #f5f3ff;
  color: #4c1d95;
  font-size: 13px;
}

.status-flow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 18px 0 22px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
}
.status-outcomes { display: flex; flex-wrap: wrap; gap: 8px; }
.status-after { flex-basis: 100%; color: var(--text-muted); font-size: 13px; }
.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 11px;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}
.status-created { background: #e0e7ff; color: #3730a3; }
.status-processing { background: #dbeafe; color: #1d4ed8; }
.status-success { background: #dcfce7; color: #166534; }
.status-danger { background: #fee2e2; color: #991b1b; }
.status-neutral { background: #e2e8f0; color: #475569; }
.status-warning { background: #fef3c7; color: #92400e; }

.flow-decision {
  margin: 20px 0 24px;
  padding: 18px;
  border: 1px solid #dbe4f0;
  border-radius: 12px;
  background: linear-gradient(180deg, #fff 0%, #f8fafc 100%);
  box-shadow: 0 5px 16px rgba(15, 23, 42, .05);
}
.flow-decision-start { display: flex; align-items: center; justify-content: center; gap: 10px; text-align: left; }
.flow-decision-start .flow-step-number { margin: 0; flex: 0 0 auto; }
.flow-decision-start small { display: block; color: var(--text-muted); }
.flow-decision-question {
  width: fit-content;
  margin: 18px auto 14px;
  padding: 8px 14px;
  border-radius: 8px;
  background: #ede9fe;
  color: #5b21b6;
  font-weight: 650;
  text-align: center;
}
.flow-branches { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.flow-branch { padding: 14px; border: 1px solid var(--border); border-radius: 9px; background: #fff; }
.flow-branch strong, .flow-branch small { display: block; }
.flow-branch small { margin-top: 3px; color: var(--text-muted); }
.flow-branch-label { display: inline-block; margin-bottom: 7px; border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.flow-branch-no { background: #e2e8f0; color: #475569; }
.flow-branch-yes { background: #ede9fe; color: #6d28d9; }
.flow-merge { margin-top: 12px; padding: 10px; border-radius: 8px; background: #dbeafe; color: #1e40af; font-weight: 650; text-align: center; }

/* ── API Reference (Redoc full-width mode) ───────────────────────── */
.content-inner.redoc-mode {
  max-width: none;
  padding: 0;
  margin: 0;
}

/* Separator above API Reference nav link */
.nav-link-apiref {
  margin-top: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
  padding-top: 14px !important;
  color: #60a5fa !important;
  font-weight: 600 !important;
}
.nav-link-apiref:hover { color: #93c5fd !important; }

/* ── Country toggle ──────────────────────────────────────────────── */
.country-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 20px;
  min-width: 0;
  overflow-x: auto;
  padding: 4px 0;
  scrollbar-width: thin;
}

.country-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 13px;
  border: 1.5px solid #cbd5e1;
  border-radius: 20px;
  background: #fff;
  color: #475569;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s, background .15s, color .15s;
  font-family: inherit;
}
.country-btn:hover {
  border-color: #2563eb;
  color: #2563eb;
}
.country-btn.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  font-weight: 600;
}

/* ── Mobile ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  body { display: block; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    transform: translateX(-100%);
    transition: transform .25s ease;
    height: 100%;
    z-index: 50;
  }
  .sidebar.open { transform: translateX(0); }

  .layout { min-height: 100vh; }

  .menu-btn { display: block; }

  .topbar { padding: 0 14px; }
  .topbar-title { display: none; }
  .country-toggle { margin-left: 0; flex: 1; }

  .content-inner { padding: 24px 20px 60px; }

  .flow-diagram { grid-template-columns: 1fr; }
  .flow-diagram > .flow-arrow { transform: rotate(90deg); justify-self: center; }
  .flow-step { min-height: 96px; }
  .flow-branches { grid-template-columns: 1fr; }
  .status-flow { align-items: flex-start; }
}
