/* Downlink Docs — shares the Downlink brand token system (see BRANDING.md).
   Light + dark themes; a fixed left sidebar, a readable article column, and
   an "on this page" rail. Docs-specific components: callouts, screenshot
   figures, step lists, nav-path badges, and field-example tables. */

:root {
  --bg: #ffffff;
  --bg-2: #f1f7f8;
  --bg-3: #e8f1f2;
  --panel: #ffffff;
  --panel-2: #eef4f5;
  --line: #e2ebee;
  --line-bright: #cddbe0;
  --text: #13232b;
  --mute: #566873;
  --accent: #0b6d77;
  --accent-2: #159ba0;
  --mint: #0f9b8c;           /* mint, darkened a touch for text-contrast on white */
  --mint-soft: rgba(16, 183, 166, 0.12);
  --mint-line: rgba(16, 183, 166, 0.30);
  --gold: #8a5a0b;
  --ok: #157a4d;
  --danger: #c2453c;
  --ink: #ffffff;
  --code-bg: #f3f7f8;
  --shadow-1: 0 1px 2px rgba(16, 40, 48, 0.05), 0 8px 24px -14px rgba(16, 40, 48, 0.16);
  --shadow-2: 0 2px 8px rgba(16, 40, 48, 0.06), 0 24px 60px -28px rgba(16, 40, 48, 0.24);
  --radius: 14px;
  --sidebar-w: 288px;
  --toc-w: 220px;
  --topbar-h: 60px;
  --font: ui-sans-serif, system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #0a0f14;
  --bg-2: #0e1820;
  --bg-3: #13212b;
  --panel: #101c25;
  --panel-2: #17242e;
  --line: #223541;
  --line-bright: #2c4453;
  --text: #eaf3f5;
  --mute: #93a6b0;
  --accent: #3bbfca;
  --accent-2: #2aa7b1;
  --mint: #2fe0cb;
  --mint-soft: rgba(47, 224, 203, 0.14);
  --mint-line: rgba(47, 224, 203, 0.32);
  --gold: #d9a03d;
  --ok: #34b678;
  --danger: #e26e64;
  --code-bg: #0e1820;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4), 0 10px 26px -16px rgba(0,0,0,.6);
  --shadow-2: 0 2px 8px rgba(0,0,0,.45), 0 26px 64px -30px rgba(0,0,0,.7);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg:#0a0f14;--bg-2:#0e1820;--bg-3:#13212b;--panel:#101c25;--panel-2:#17242e;--line:#223541;--line-bright:#2c4453;
    --text:#eaf3f5;--mute:#93a6b0;--accent:#3bbfca;--accent-2:#2aa7b1;--mint:#2fe0cb;--mint-soft:rgba(47,224,203,.14);
    --mint-line:rgba(47,224,203,.32);--gold:#d9a03d;--ok:#34b678;--danger:#e26e64;--code-bg:#0e1820;color-scheme:dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* overflow-x: clip contains the off-canvas mobile sidebar without breaking the
   sticky topbar/sidebar. */
html { scroll-behavior: smooth; overflow-x: clip; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── top bar ──────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar .logo { font-weight: 850; font-size: 1.1rem; color: var(--text); display: flex; align-items: center; gap: 8px; }
.topbar .logo i.lk { color: var(--accent); font-style: normal; }
.topbar .logo .docs-tag {
  font-size: 0.66rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--mint); border: 1px solid var(--mint-line); background: var(--mint-soft);
  padding: 2px 7px; border-radius: 6px; margin-left: 4px;
}
.topbar .grow { flex: 1; }
.topbar .search {
  width: min(320px, 40vw); display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; color: var(--mute); font-size: 0.9rem;
}
.topbar .search input { border: 0; background: none; outline: none; color: var(--text); font: inherit; width: 100%; }
.topbar .tb-link { color: var(--mute); font-size: 0.9rem; font-weight: 550; }
.topbar .tb-link:hover { color: var(--text); text-decoration: none; }
.topbar .btn-app {
  background: linear-gradient(135deg, #0b6d77, #159ba0); color: #fff; font-weight: 700;
  font-size: 0.86rem; padding: 8px 15px; border-radius: 9px;
}
.topbar .btn-app:hover { text-decoration: none; }
.theme-toggle, .menu-toggle {
  width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--line-bright);
  background: var(--panel); color: var(--mute); cursor: pointer; display: grid; place-items: center;
}
.theme-toggle:hover, .menu-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle .sun { display: none; } .theme-toggle .moon { display: block; }
html[data-theme="dark"] .theme-toggle .sun { display: block; } html[data-theme="dark"] .theme-toggle .moon { display: none; }
.menu-toggle { display: none; }

/* ── layout ───────────────────────────────────────────────────────────────── */
.layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); align-items: start; }

/* sidebar */
.sidebar {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  border-right: 1px solid var(--line);
  padding: 22px 16px 60px;
  background: var(--bg);
}
.sb-section { margin-bottom: 20px; }
.sb-section > h4 {
  font-size: 0.68rem; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--mute); padding: 0 10px; margin-bottom: 6px;
}
.sb-section a {
  display: block; padding: 7px 10px; border-radius: 8px; color: var(--mute);
  font-size: 0.92rem; font-weight: 500; border-left: 2px solid transparent;
}
.sb-section a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.sb-section a.active {
  color: var(--accent); background: var(--mint-soft); border-left-color: var(--accent); font-weight: 650;
}

/* article */
.article-wrap { display: grid; grid-template-columns: minmax(0, 1fr) var(--toc-w); gap: 40px; padding: 40px 44px 100px; max-width: 1160px; }
.article-wrap.home { grid-template-columns: minmax(0, 1fr); max-width: 1040px; }
article { min-width: 0; }
.breadcrumb { font-size: 0.82rem; color: var(--mute); margin-bottom: 10px; }
.breadcrumb a { color: var(--mute); }
article h1 { font-size: 2.3rem; font-weight: 840; letter-spacing: -0.02em; line-height: 1.12; margin-bottom: 10px; text-wrap: balance; }
article > .lead { font-size: 1.12rem; color: var(--mute); margin-bottom: 26px; text-wrap: pretty; }
article h2 { font-size: 1.5rem; font-weight: 780; letter-spacing: -0.01em; margin: 40px 0 12px; scroll-margin-top: 78px; }
article h3 { font-size: 1.14rem; font-weight: 720; margin: 26px 0 8px; scroll-margin-top: 78px; }
article p { margin: 12px 0; }
article ul, article ol { margin: 12px 0 12px 22px; }
article li { margin: 6px 0; }
article strong { color: var(--text); font-weight: 700; }
.anchor-h { color: var(--mute); opacity: 0; margin-left: 8px; font-weight: 400; text-decoration: none; }
h2:hover .anchor-h, h3:hover .anchor-h { opacity: 1; }

/* nav-path badge: "Sidebar → Clients → New" */
.path { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px 9px; font-size: 0.85rem; font-weight: 600; color: var(--text); vertical-align: middle; }
.path .sep { color: var(--mute); }
kbd { font-family: var(--mono); font-size: 0.82em; background: var(--panel-2); border: 1px solid var(--line-bright); border-bottom-width: 2px; border-radius: 6px; padding: 1px 6px; color: var(--text); }

/* callouts */
.callout { border: 1px solid var(--line); border-left-width: 3px; border-radius: 10px; background: var(--panel); padding: 14px 16px; margin: 18px 0; font-size: 0.96rem; box-shadow: var(--shadow-1); }
.callout .c-title { font-weight: 750; display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.callout p { margin: 4px 0; }
.callout.note { border-left-color: var(--accent); }
.callout.note .c-title { color: var(--accent); }
.callout.tip { border-left-color: var(--mint); }
.callout.tip .c-title { color: var(--mint); }
.callout.warn { border-left-color: var(--gold); }
.callout.warn .c-title { color: var(--gold); }
.callout.example { border-left-color: var(--accent-2); background: var(--bg-2); }
.callout.example .c-title { color: var(--accent-2); }

/* steps */
ol.steps { list-style: none; margin: 20px 0; counter-reset: step; }
ol.steps > li { position: relative; padding: 4px 0 18px 46px; counter-increment: step; }
ol.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: 0; width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, #0b6d77, #159ba0); color: #fff; font-weight: 800; font-size: 0.9rem;
  display: grid; place-items: center;
}
ol.steps > li::after { content: ""; position: absolute; left: 14px; top: 34px; bottom: 4px; width: 2px; background: var(--line); }
ol.steps > li:last-child::after { display: none; }
ol.steps > li > strong:first-child { display: block; margin-bottom: 2px; }

/* field-example table */
.fields { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 0.92rem; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.fields th, .fields td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.fields thead th { background: var(--panel-2); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--mute); }
.fields tbody tr:last-child td { border-bottom: 0; }
.fields td.f-name { font-weight: 650; color: var(--text); white-space: nowrap; }
.fields td.f-val { font-family: var(--mono); font-size: 0.86rem; color: var(--accent); }
.fields td.f-note { color: var(--mute); }

/* generic table */
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 0.92rem; }
table.data th, table.data td { text-align: left; padding: 9px 13px; border-bottom: 1px solid var(--line); }
table.data thead th { color: var(--text); font-weight: 700; border-bottom: 2px solid var(--line-bright); }
table.data td { color: var(--mute); }

/* code */
code { font-family: var(--mono); font-size: 0.88em; background: var(--code-bg); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; color: var(--text); overflow-wrap: anywhere; }
article { overflow-wrap: break-word; }
/* long monospace example values (emails, addresses) must break, not overflow */
.fields td.f-val { overflow-wrap: anywhere; }
pre { background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; overflow-x: auto; margin: 16px 0; }
pre code { background: none; border: 0; padding: 0; font-size: 0.85rem; line-height: 1.55; }

/* screenshot figure */
figure.shot { margin: 22px 0; }
figure.shot .frame {
  border: 1px solid var(--line-bright); border-radius: var(--radius); overflow: hidden; background: var(--panel);
  box-shadow: var(--shadow-2);
}
figure.shot .frame.chrome::before {
  content: ""; display: block; height: 32px; background: var(--panel-2); border-bottom: 1px solid var(--line);
  background-image: radial-gradient(circle 4.5px at 18px 16px, #ef4444 4.5px, transparent 5px),
    radial-gradient(circle 4.5px at 36px 16px, #fbbf24 4.5px, transparent 5px),
    radial-gradient(circle 4.5px at 54px 16px, #34d399 4.5px, transparent 5px);
}
figure.shot img { width: 100%; display: block; }
figure.shot figcaption { font-size: 0.84rem; color: var(--mute); margin-top: 9px; text-align: center; }

/* feature-card grid (docs home) */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin: 24px 0; }
.doc-card { display: block; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; background: var(--panel); box-shadow: var(--shadow-1); transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
.doc-card:hover { transform: translateY(-3px); border-color: var(--mint-line); box-shadow: var(--shadow-2); text-decoration: none; }
.doc-card .ico { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; font-size: 1.3rem; background: var(--mint-soft); border: 1px solid var(--mint-line); margin-bottom: 12px; }
.doc-card h3 { margin: 0 0 4px; font-size: 1.02rem; color: var(--text); }
.doc-card p { margin: 0; font-size: 0.9rem; color: var(--mute); }

/* prev / next */
.pager { display: flex; justify-content: space-between; gap: 16px; margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--line); }
.pager a { flex: 1; border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; box-shadow: var(--shadow-1); }
.pager a:hover { border-color: var(--mint-line); text-decoration: none; }
.pager .dir { font-size: 0.74rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--mute); }
.pager .ttl { font-weight: 700; color: var(--text); }
.pager a.next { text-align: right; }

/* on-this-page (toc) */
.toc { position: sticky; top: calc(var(--topbar-h) + 24px); align-self: start; font-size: 0.86rem; }
.toc .toc-title { font-size: 0.7rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--mute); margin-bottom: 10px; }
.toc a { display: block; color: var(--mute); padding: 4px 0 4px 12px; border-left: 2px solid var(--line); }
.toc a:hover { color: var(--text); text-decoration: none; }
.toc a.h3 { padding-left: 24px; font-size: 0.82rem; }
.toc a.active { color: var(--accent); border-left-color: var(--accent); }

/* footer */
.doc-footer { border-top: 1px solid var(--line); padding: 24px 44px; color: var(--mute); font-size: 0.85rem; display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.doc-footer a { color: var(--mute); }

/* sidebar backdrop (mobile) */
.sb-backdrop { display: none; }

@media (max-width: 1080px) {
  .article-wrap { grid-template-columns: minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 860px) {
  .menu-toggle { display: grid; }
  .topbar .search { display: none; }
  .topbar .tb-link { display: none; } /* free up room so the CTA button fits */
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: 300px; max-width: 86vw; z-index: 45;
    transform: translateX(-100%); visibility: hidden;
    transition: transform .26s cubic-bezier(.16,1,.3,1), visibility .26s;
  }
  .sidebar.open { transform: none; visibility: visible; box-shadow: var(--shadow-2); }
  .sb-backdrop { position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(6,12,18,.5); z-index: 44; }
  .sb-backdrop.open { display: block; }
  .article-wrap { padding: 28px 20px 80px; }
  article h1 { font-size: 1.9rem; }
  .doc-footer { padding: 24px 20px; }
  /* keep wide field/data tables from forcing horizontal page overflow:
     fixed layout + wrapping cells so they fit the phone width. */
  .fields, table.data { table-layout: fixed; width: 100%; }
  .fields th, .fields td, table.data th, table.data td { overflow-wrap: anywhere; word-break: break-word; white-space: normal; }
  .fields td.f-name { white-space: normal; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } .sidebar { transition: none; } }

/* ── admin docs gate (admin.html / managed.html sign-in shell) ─────────────── */
.admin-gate { max-width: 420px; margin: 36px auto; text-align: center; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow-1); padding: 34px 28px; }
.admin-gate .gate-lock { font-size: 2rem; line-height: 1; margin-bottom: 10px; }
.admin-gate h2 { margin: 0 0 6px; border: 0; padding: 0; font-size: 1.2rem; }
.admin-gate > p { color: var(--mute); font-size: 0.94rem; margin: 0 0 18px; }
.gate-form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.gate-form input { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; padding: 11px 13px; outline: none; }
.gate-form input:focus { border-color: var(--accent); }
.gate-form button { margin-top: 4px; border: 0; border-radius: 10px; background: var(--accent); color: var(--ink); font: inherit; font-weight: 600; padding: 11px 14px; cursor: pointer; }
.gate-form button:disabled { opacity: .6; cursor: default; }
.gate-error { color: var(--danger); font-size: 0.88rem; margin: 12px 0 0; }
.gate-signout { display: inline-block; margin: 36px 0 0; border: 1px solid var(--line); border-radius: 10px; background: none; color: var(--mute); font: inherit; font-size: 0.85rem; padding: 8px 12px; cursor: pointer; }
.gate-signout:hover { border-color: var(--accent); color: var(--accent); }
.sidebar .sb-lock { font-size: 0.72rem; opacity: .65; }
.card-lock { display: inline-block; margin-top: 12px; font-size: 0.72rem; color: var(--gold); background: rgba(138,90,11,0.08); border: 1px solid rgba(138,90,11,0.22); border-radius: 999px; padding: 2px 9px; }
