*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:     #050818;
  --navy-2:   #0a102a;
  --navy-3:   #111836;
  --teal:     #00d9c0;
  --teal-dim: #00d9c018;
  --teal-mid: #00d9c055;
  --teal-hi:  #00f5d4;
  --amber:    #f5a623;
  --rose:     #ff5c72;
  --violet:   #8c6fff;
  --text:     #e8eaf6;
  --muted:    #7b84ab;
  --border:   #1a2248;
  --border-hi:#242e5e;
  --card-bg:  #0c1130;
  --radius:   10px;
  --sidebar-w: 260px;
  --font-mono: 'DM Mono', monospace;
  --font-disp: 'Epilogue', sans-serif;
}

html { scroll-behavior: smooth; }

body {
  background: var(--navy);
  color: var(--text);
  font-family: var(--font-disp);
  line-height: 1.65;
  overflow-x: hidden;
  min-height: 100vh;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 56px 56px;
  opacity: 0.25;
  pointer-events: none;
  z-index: 0;
}

/* ── TOP NAV ── */
.top-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  background: rgba(5,8,24,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  gap: 24px;
}

.nav-logo {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 500;
  color: var(--teal);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.nav-logo span { color: var(--text); }

.nav-logo-icon {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--teal-dim);
  border: 1px solid var(--teal-mid);
  display: flex; align-items: center; justify-content: center;
}

.nav-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
}

.nav-breadcrumb a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s;
}

.nav-breadcrumb a:hover { color: var(--text); }

.nav-breadcrumb .sep { color: var(--border-hi); }

.nav-breadcrumb .current { color: var(--text); }

.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.nav-right a {
  color: var(--muted);
  font-size: 0.82rem;
  text-decoration: none;
  font-weight: 600;
  transition: color 0.2s;
}

.nav-right a:hover { color: var(--text); }

.nav-right .cta {
  padding: 6px 14px;
  background: var(--teal);
  color: var(--navy) !important;
  border-radius: 6px;
  font-weight: 800 !important;
  font-size: 0.8rem;
}

/* ── LAYOUT ── */
.layout {
  display: flex;
  padding-top: 56px;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* ── SIDEBAR ── */
.sidebar {
  position: fixed;
  top: 56px; left: 0; bottom: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  background: rgba(10,16,42,0.85);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  backdrop-filter: blur(8px);
  z-index: 100;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 4px; }

.sidebar-section-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 16px 20px 6px;
}

.sidebar-section-label:first-child { padding-top: 4px; }

.sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 20px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: color 0.15s, background 0.15s;
  border-left: 2px solid transparent;
  position: relative;
}

.sidebar a:hover {
  color: var(--text);
  background: var(--teal-dim);
}

.sidebar a.active {
  color: var(--teal);
  border-left-color: var(--teal);
  background: var(--teal-dim);
  font-weight: 700;
}

.sidebar a svg { flex-shrink: 0; opacity: 0.7; }
.sidebar a.active svg { opacity: 1; }

/* ── MAIN CONTENT ── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
}

.content {
  max-width: 820px;
  margin: 0 auto;
  padding: 48px 40px 96px;
}

/* ── TYPOGRAPHY ── */
.page-header {
  margin-bottom: 48px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
}

.page-tag {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-tag::before {
  content: '';
  width: 18px; height: 1px;
  background: var(--teal);
}

h1.page-title {
  font-size: 2.4rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: 12px;
}

.page-lead {
  font-size: 1.05rem;
  color: var(--muted);
  line-height: 1.7;
  max-width: 640px;
}

h2 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 40px 0 16px;
  color: var(--text);
}

h3 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 28px 0 10px;
  color: var(--text);
}

p {
  color: var(--muted);
  margin-bottom: 16px;
  font-size: 0.94rem;
  line-height: 1.75;
}

p strong { color: var(--text); font-weight: 700; }

a {
  color: var(--teal);
  text-decoration: none;
}

a:hover { text-decoration: underline; }

ul, ol {
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.75;
  padding-left: 20px;
  margin-bottom: 16px;
}

li { margin-bottom: 6px; }
li strong { color: var(--text); }

/* ── CALLOUT ── */
.callout {
  display: flex;
  gap: 14px;
  padding: 16px 20px;
  border-radius: var(--radius);
  margin: 24px 0;
  font-size: 0.9rem;
  line-height: 1.65;
}

.callout-icon { flex-shrink: 0; margin-top: 1px; }

.callout.info {
  background: var(--teal-dim);
  border: 1px solid var(--teal-mid);
  color: var(--text);
}

.callout.warning {
  background: rgba(245,166,35,0.08);
  border: 1px solid rgba(245,166,35,0.3);
  color: var(--text);
}

.callout.tip {
  background: rgba(140,111,255,0.08);
  border: 1px solid rgba(140,111,255,0.28);
  color: var(--text);
}

/* ── STEPS ── */
.steps {
  counter-reset: step-counter;
  list-style: none;
  padding-left: 0;
  margin: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.step {
  counter-increment: step-counter;
  display: flex;
  gap: 20px;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
}

.step:last-child { border-bottom: none; }

.step-num {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--teal-mid);
  background: var(--navy-2);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--teal);
  flex-shrink: 0;
}

.step-body h4 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.step-body p {
  margin-bottom: 0;
  font-size: 0.875rem;
}

/* ── CODE ── */
code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: var(--navy-3);
  border: 1px solid var(--border-hi);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--teal-hi);
}

pre {
  background: var(--navy-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  overflow-x: auto;
  margin: 20px 0;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.83rem;
  line-height: 1.7;
  color: var(--text);
}

/* ── TABLE ── */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 0.875rem;
}

th {
  text-align: left;
  padding: 10px 14px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--navy-3);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 11px 14px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

td strong { color: var(--text); }
td code { font-size: 0.8em; }

tr:last-child td { border-bottom: none; }

/* ── BADGES ── */
.badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 10px;
  border-radius: 4px;
}

.badge-teal  { background: rgba(0,217,192,0.12); color: var(--teal); border: 1px solid rgba(0,217,192,0.3); }
.badge-amber { background: rgba(245,166,35,0.12); color: var(--amber); border: 1px solid rgba(245,166,35,0.3); }
.badge-rose  { background: rgba(255,92,114,0.12); color: var(--rose); border: 1px solid rgba(255,92,114,0.3); }
.badge-violet{ background: rgba(140,111,255,0.12); color: var(--violet); border: 1px solid rgba(140,111,255,0.3); }

/* ── CARDS ── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin: 24px 0;
}

.card {
  padding: 24px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card h4 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.card p { margin-bottom: 0; font-size: 0.86rem; }

/* ── ROLE PERMISSION TABLE ── */
.perm-check { color: var(--teal); font-weight: 700; }
.perm-dash  { color: var(--border-hi); }

/* ── MERMAID DIAGRAMS ── */
.diagram-wrap {
  margin: 28px 0;
  background:
    radial-gradient(circle at 50% 0%, rgba(140, 111, 255, 0.08), transparent 45%),
    var(--navy-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  box-shadow: 0 24px 60px rgba(2, 5, 18, 0.28);
}

.diagram-caption {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
  margin-top: 12px;
}

.diagram-image {
  display: block;
  width: 100%;
  min-width: 680px;
  height: auto;
  border-radius: 10px;
  cursor: zoom-in;
  transition:
    transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1),
    filter 220ms ease;
}

.diagram-image:hover {
  transform: translateY(-2px) scale(1.005);
  filter: brightness(1.08);
}

.diagram-image:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 4px;
}

.diagram-lightbox[hidden] {
  display: none;
}

.diagram-lightbox {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 52px 24px 42px;
  background: rgba(2, 4, 16, 0);
  backdrop-filter: blur(0);
  opacity: 0;
  transition:
    opacity 240ms ease,
    background 240ms ease,
    backdrop-filter 240ms ease;
}

.diagram-lightbox.is-open {
  background: rgba(2, 4, 16, 0.88);
  backdrop-filter: blur(14px);
  opacity: 1;
}

.diagram-lightbox-stage {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.diagram-lightbox-image {
  display: block;
  max-width: min(96vw, 1600px);
  max-height: 86vh;
  width: auto;
  height: auto;
  border: 1px solid var(--border-hi);
  border-radius: 16px;
  box-shadow:
    0 40px 100px rgba(0, 0, 0, 0.6),
    0 0 80px rgba(0, 217, 192, 0.08);
  opacity: 0;
  transform: translateY(24px) scale(0.86);
  transition:
    transform 420ms cubic-bezier(0.16, 1, 0.3, 1),
    opacity 220ms ease;
}

.diagram-lightbox.is-open .diagram-lightbox-image {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.diagram-lightbox-close {
  position: fixed;
  z-index: 1;
  top: 18px;
  right: 20px;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: var(--text);
  background: rgba(12, 17, 48, 0.9);
  border: 1px solid var(--border-hi);
  border-radius: 50%;
  cursor: pointer;
  opacity: 0;
  transform: rotate(-45deg) scale(0.7);
  transition:
    color 180ms ease,
    border-color 180ms ease,
    transform 360ms cubic-bezier(0.16, 1, 0.3, 1),
    opacity 180ms ease;
}

.diagram-lightbox.is-open .diagram-lightbox-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

.diagram-lightbox-close:hover,
.diagram-lightbox-close:focus-visible {
  color: var(--teal);
  border-color: var(--teal);
  outline: none;
}

.diagram-lightbox-close svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.diagram-lightbox-hint {
  position: fixed;
  bottom: 16px;
  margin: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 240ms ease 120ms,
    transform 240ms ease 120ms;
}

.diagram-lightbox.is-open .diagram-lightbox-hint {
  opacity: 1;
  transform: translateY(0);
}

body.diagram-lightbox-open {
  overflow: hidden;
}

@media (max-width: 760px) {
  .diagram-wrap {
    padding: 10px;
  }

  .diagram-image {
    min-width: 620px;
  }

  .diagram-lightbox {
    padding: 56px 10px 44px;
    overflow: auto;
  }

  .diagram-lightbox-image {
    max-width: none;
    width: max-content;
    min-width: 960px;
    max-height: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .diagram-image,
  .diagram-lightbox,
  .diagram-lightbox-image,
  .diagram-lightbox-close,
  .diagram-lightbox-hint {
    transition-duration: 1ms;
  }
}

/* ── DIVIDER ── */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 40px 0;
}

/* ── NEXT/PREV ── */
.page-nav {
  display: flex;
  gap: 16px;
  margin-top: 64px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.page-nav-link {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 20px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color 0.2s, background 0.2s;
}

.page-nav-link:hover {
  border-color: var(--teal-mid);
  background: var(--teal-dim);
  text-decoration: none;
}

.page-nav-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.page-nav-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.page-nav-link.next { text-align: right; }

/* ── FOOTER ── */
.doc-footer {
  border-top: 1px solid var(--border);
  padding: 36px 48px;
  position: relative;
  z-index: 1;
}

.doc-footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.doc-footer .footer-logo {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--teal);
  text-decoration: none;
}

.doc-footer .footer-links {
  display: flex;
  gap: 24px;
  list-style: none;
  padding: 0;
  flex-wrap: wrap;
}

.doc-footer .footer-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.82rem;
  transition: color 0.2s;
}

.doc-footer .footer-links a:hover { color: var(--text); text-decoration: none; }

.doc-footer p {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  margin: 0;
}

.doc-footer a { color: var(--teal); text-decoration: none; }
.doc-footer a:hover { text-decoration: underline; }

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .content { padding: 32px 20px 64px; }
  .card-grid { grid-template-columns: 1fr; }
  h1.page-title { font-size: 1.8rem; }
  .doc-footer { padding: 28px 20px; }
  .doc-footer-inner { justify-content: center; text-align: center; }
}
