:root {
  --bg: #0b0f17;
  --panel: #121826;
  --panel2: #1a2234;
  --border: #243049;
  --text: #e8eefc;
  --muted: #8b9bb8;
  --primary: #ee4d2d;
  --primary2: #ff7a4a;
  --ok: #22c55e;
  --ok-text: #86efac;
  --get: #3b82f6;
  --post: #22c55e;
  --sidebar: #0e1420;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  overflow-x: hidden;
}
a { color: var(--primary2); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88em;
  background: rgba(255,255,255,.06);
  padding: 2px 6px;
  border-radius: 6px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.row { display: flex; flex-wrap: wrap; align-items: center; }
.gap { gap: 8px; }

.layout {
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 18px 14px 32px;
  -webkit-overflow-scrolling: touch;
}
.side-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.side-brand {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
}
.docs-logo {
  height: 42px;
  width: auto;
  max-width: 170px;
  object-fit: contain;
  display: block;
  border-radius: 6px;
}
.docs-logo.sm { height: 32px; max-width: 140px; }

.sidebar-close {
  display: none;
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
}
.sidebar-close:hover { filter: brightness(1.15); }

/* Mobile Sticky Bar */
.mobile-bar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 30;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  min-height: 56px;
  background: var(--sidebar);
  border-bottom: 1px solid var(--border);
}
.mobile-brand { display: flex; align-items: center; text-decoration: none; }
.menu-toggle {
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  border-radius: 10px;
  width: 42px; height: 42px;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.menu-toggle:hover { filter: brightness(1.1); }

.mobile-portal-link {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.mobile-portal-link:hover {
  filter: brightness(1.15);
  text-decoration: none;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 45;
  opacity: 0;
  transition: opacity .25s ease;
  pointer-events: none;
}
.sidebar-backdrop.show {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

.side-nav { display: flex; flex-direction: column; gap: 3px; }
.side-nav a {
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: .92rem;
  font-weight: 500;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
  display: flex;
  align-items: center;
}
.side-nav a:hover { background: var(--panel2); color: var(--text); text-decoration: none; }
.side-nav a.active {
  background: rgba(238, 77, 45, 0.12);
  color: var(--primary2);
  border-left-color: var(--primary);
  font-weight: 700;
}
.nav-group {
  margin: 16px 0 6px;
  padding: 0 10px;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.85;
}

/* Content */
.content {
  max-width: 920px;
  padding: 36px 36px 80px;
  margin: 0 auto;
  width: 100%;
}
.hero { margin-bottom: 36px; }
.pill {
  display: inline-block;
  background: rgba(238,77,45,.12);
  border: 1px solid rgba(238,77,45,.35);
  color: var(--primary2);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: .8rem;
  font-weight: 700;
  margin-bottom: 14px;
}
.hero h1 { margin: 0 0 12px; font-size: 1.95rem; letter-spacing: -.02em; }
.lead { color: var(--muted); font-size: 1.05rem; max-width: 660px; margin: 0 0 20px; }

.base-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.base-box .label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}
.base-box code {
  background: transparent;
  font-size: .94rem;
  color: var(--ok-text);
  word-break: break-all;
}

.doc-section {
  margin-bottom: 48px;
  padding-top: 12px;
  border-top: 1px solid transparent;
  scroll-margin-top: 32px;
}
.doc-section h2 {
  margin: 0 0 12px;
  font-size: 1.38rem;
  letter-spacing: -.01em;
}
.doc-section > p { color: var(--text); opacity: 0.92; }

.cards-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin: 18px 0;
}
.info-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
}
.info-card h3 { margin: 0 0 8px; font-size: .98rem; color: var(--primary2); }
.info-card p { margin: 0; font-size: .88rem; color: var(--muted); line-height: 1.55; }

.note, .warn, .auth-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  margin: 16px 0;
}
.note ol, .note ul, .warn ol { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }
.warn {
  border-color: rgba(245,158,11,.4);
  background: rgba(245,158,11,.08);
}
.auth-panel.ok {
  border-color: rgba(34,197,94,.4);
  background: linear-gradient(180deg, rgba(34,197,94,.08), var(--panel));
}
.label-strong {
  font-weight: 700;
  margin: 18px 0 8px;
  font-size: .95rem;
}
.steps { color: var(--muted); padding-left: 18px; line-height: 1.8; }

.endpoint {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 12px 0;
  flex-wrap: wrap;
}
.endpoint code { background: transparent; font-size: .95rem; color: var(--text); word-break: break-all; }
.method {
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .04em;
  padding: 4px 8px;
  border-radius: 6px;
  color: #fff;
}
.method.get { background: var(--get); }
.method.post { background: var(--post); }

.code-block {
  background: #0a0e16;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin: 12px 0 18px;
}
.code-head {
  display: flex;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(255,255,255,.03);
  border-bottom: 1px solid var(--border);
  font-size: .75rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.code-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .82rem;
  line-height: 1.55;
  color: #d1dcec;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Table Responsive Wrappers */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 14px 0 20px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
}
.table-wrap table {
  margin: 0;
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
  font-size: .9rem;
}
th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  color: var(--muted);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 700;
  background: rgba(255,255,255,.02);
}
td { color: var(--text); }
.req {
  background: rgba(238,77,45,.15);
  color: #ffb4a0;
  font-size: .7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}
.tags { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 16px; }
.tag {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
}
.tag.ok { color: #86efac; border-color: rgba(34,197,94,.35); }
.tag.bad { color: #fecaca; border-color: rgba(239,68,68,.35); }

.key-box {
  background: #0a0e16;
  border: 1px solid rgba(34,197,94,.4);
  color: #86efac;
  border-radius: 10px;
  padding: 12px 14px;
  word-break: break-all;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .9rem;
  margin: 8px 0 14px;
}

.btn, .btn-sm {
  display: inline-block;
  background: linear-gradient(135deg, var(--primary), #ff7a3c);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  font-size: .9rem;
  text-align: center;
}
.btn:hover, .btn-sm:hover { filter: brightness(1.06); text-decoration: none; }
.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-sm {
  padding: 7px 12px;
  font-size: .82rem;
  border-radius: 8px;
}

.footer {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .88rem;
}

/* ==============================================================================
   MOBILE & TABLET RESPONSIVE OVERHAUL (max-width: 900px)
   ============================================================================== */
@media (max-width: 900px) {
  .mobile-bar { display: flex; }
  .sidebar-close { display: inline-flex; }
  .layout { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(320px, 86vw);
    height: 100vh;
    height: 100dvh;
    z-index: 50;
    transform: translateX(-105%);
    transition: transform .26s cubic-bezier(0.4, 0, 0.2, 1);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: none;
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 16px 0 48px rgba(0, 0, 0, .55);
  }
  body.sidebar-open { overflow: hidden; }

  .side-nav {
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 3px;
  }
  .side-nav a {
    min-height: 44px;
    padding: 10px 14px;
    font-size: .94rem;
    display: flex;
    align-items: center;
  }

  .content {
    padding: 20px 16px 64px;
    max-width: 100%;
    overflow-x: hidden;
  }
  .hero h1 { font-size: 1.55rem; word-break: break-word; }
  .lead { font-size: .98rem; }
  .cards-3 { grid-template-columns: 1fr; gap: 12px; }

  .endpoint { gap: 8px; padding: 10px 12px; }
  .endpoint code { font-size: .86rem; word-break: break-all; }

  .code-block pre {
    font-size: .78rem;
    padding: 12px;
    white-space: pre-wrap;
    word-break: break-word;
  }

  .base-box {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
  }
  .base-box code { font-size: .88rem; word-break: break-all; }
  .base-box #btn-copy-base {
    width: 100%;
    min-height: 42px;
    font-size: .9rem;
  }

  #auth-user .row.gap {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  #auth-user .row.gap .btn {
    width: 100%;
    text-align: center;
    justify-content: center;
    display: flex;
    align-items: center;
    min-height: 44px;
  }
}

@media (max-width: 560px) {
  .doc-section h2 { font-size: 1.25rem; }
  .hero h1 { font-size: 1.35rem; }
  .btn, .btn-sm { min-height: 42px; font-size: .9rem; }
  input, textarea, select, button { font-size: 16px; }
  .table-wrap table { min-width: 480px; }
}

@supports (padding: env(safe-area-inset-bottom)) {
  .sidebar { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
  .mobile-bar {
    padding-top: max(10px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
}

/* =========================================================
   SCROLL REVEAL (Cascading & Staggered Animations on Scroll)
   ========================================================= */
.reveal-on-scroll {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.7s cubic-bezier(0.16, 1, 0.3, 1), transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: opacity, transform;
}

.reveal-on-scroll.is-revealed {
  opacity: 1;
  transform: translateY(0);
}

.reveal-on-scroll.reveal-left {
  transform: translateX(-24px);
}
.reveal-on-scroll.reveal-left.is-revealed {
  transform: translateX(0);
}

.reveal-on-scroll.reveal-right {
  transform: translateX(24px);
}
.reveal-on-scroll.reveal-right.is-revealed {
  transform: translateX(0);
}

/* Stagger delays for cascading elements */
.stagger-1 { transition-delay: 0.08s; }
.stagger-2 { transition-delay: 0.16s; }
.stagger-3 { transition-delay: 0.24s; }
.stagger-4 { transition-delay: 0.32s; }
.stagger-5 { transition-delay: 0.40s; }
.stagger-6 { transition-delay: 0.48s; }

@media (prefers-reduced-motion: reduce) {
  .reveal-on-scroll {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
}
