:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --text: #0f172a;
  --text-muted: #475569;
  --border: #e2e8f0;
  --primary: #0369a1;
  --primary-hover: #075985;
  --primary-soft: #e0f2fe;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --amber-soft: #fef3c7;
  --amber-text: #92400e;
  --emerald-soft: #d1fae5;
  --emerald-text: #065f46;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
  --radius: 14px;
}

html.dark {
  --bg: #020617;
  --surface: #0f172a;
  --surface-alt: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #1e293b;
  --primary: #38bdf8;
  --primary-hover: #0ea5e9;
  --primary-soft: rgba(56, 189, 248, 0.16);
  --danger: #f87171;
  --danger-soft: rgba(239, 68, 68, 0.18);
  --amber-soft: rgba(245, 158, 11, 0.18);
  --amber-text: #fcd34d;
  --emerald-soft: rgba(16, 185, 129, 0.18);
  --emerald-text: #6ee7b7;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; overflow-x: clip; }
body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: clip;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.875em;
  background: var(--surface-alt);
  padding: 2px 6px;
  border-radius: 6px;
}

.icon { width: 16px; height: 16px; flex-shrink: 0; }
.icon-lg { width: 22px; height: 22px; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 10px rgba(15, 23, 42, 0.04);
}
.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #0369a1;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand-title { font-weight: 800; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.brand-sub { font-size: 0.78rem; color: var(--text-muted); }
.ver-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
}

.search-box {
  position: relative;
  flex: 1 1 280px;
  max-width: 460px;
  display: flex;
  align-items: center;
}
.search-icon { position: absolute; left: 12px; color: var(--text-muted); pointer-events: none; }
.search-box input {
  width: 100%;
  min-height: 44px;
  padding: 8px 66px 8px 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.9rem;
}
.search-box input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  background: var(--surface);
}
.kbd-hint {
  position: absolute;
  right: 10px;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  text-decoration: none !important;
  white-space: nowrap;
}
.btn-primary { background: #0369a1; color: #ffffff; }
.btn-primary:hover { background: #075985; color: #ffffff; }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary-soft); }
.btn-ghost { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

/* Layout Shell */
.shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 20px 64px;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.sidebar { position: sticky; top: 82px; max-height: calc(100vh - 100px); overflow-y: auto; }
.sidebar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.toc-section-title {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.toc-group { margin-top: 12px; }
.toc-group-title { font-size: 0.76rem; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.toc-link {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.toc-link:hover, .toc-link.active {
  background: var(--primary-soft);
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}
.toc-code { font-family: monospace; font-size: 0.76rem; font-weight: 700; flex-shrink: 0; }
.toc-divider { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }

/* Hero */
.hero {
  background: linear-gradient(135deg, #0369a1 0%, #1e3a8a 100%);
  color: #ffffff;
  border-radius: 18px;
  padding: 28px 32px;
  margin-bottom: 28px;
  box-shadow: var(--shadow);
}
.hero-kicker { font-size: 0.78rem; font-weight: 700; opacity: 0.9; letter-spacing: 0.04em; text-transform: uppercase; }
.hero h1 { margin: 8px 0 10px; font-size: 1.75rem; line-height: 1.25; }
.hero p { margin: 0 0 20px; max-width: 780px; opacity: 0.95; font-size: 0.96rem; }
.hero-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat-box {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  padding: 12px 14px;
}
.stat-box strong { display: block; font-size: 1.45rem; line-height: 1.1; }
.stat-box span { font-size: 0.8rem; opacity: 0.92; }

/* Sections */
.section { margin-bottom: 36px; scroll-margin-top: 86px; }
.section-head { margin-bottom: 16px; }
.section-head h2 { margin: 0 0 4px; font-size: 1.35rem; }
.section-head p { margin: 0; color: var(--text-muted); font-size: 0.92rem; }

/* Quick Start */
.qs-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.qs-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.qs-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.qs-step { font-size: 0.78rem; font-weight: 800; color: var(--primary); text-transform: uppercase; }
.qs-card h3 { margin: 0 0 6px; font-size: 0.98rem; }
.qs-card p { margin: 0 0 12px; font-size: 0.84rem; color: var(--text-muted); flex: 1; }
.qs-link { font-size: 0.82rem; font-weight: 700; }

/* SVG Workflow */
.svg-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.workflow-svg { width: 100%; min-width: 780px; height: auto; color: var(--text-muted); }
.wf-node { stroke-width: 2; }
.wf-blue { fill: #e0f2fe; stroke: #0284c7; }
.wf-indigo { fill: #e0e7ff; stroke: #4f46e5; }
.wf-emerald { fill: #d1fae5; stroke: #059669; }
.wf-amber { fill: #fef3c7; stroke: #d97706; }
.wf-rose { fill: #ffe4e6; stroke: #e11d48; }
html.dark .wf-blue { fill: #0c4a6e; stroke: #38bdf8; }
html.dark .wf-indigo { fill: #312e81; stroke: #818cf8; }
html.dark .wf-emerald { fill: #064e3b; stroke: #34d399; }
html.dark .wf-amber { fill: #78350f; stroke: #fbbf24; }
html.dark .wf-rose { fill: #881337; stroke: #fb7185; }
.wf-code { font-size: 11px; font-weight: 800; fill: #0369a1; }
html.dark .wf-code { fill: #bae6fd; }
.wf-title { font-size: 14px; font-weight: 800; fill: #0f172a; }
html.dark .wf-title { fill: #f8fafc; }
.wf-sub { font-size: 11px; fill: #334155; }
html.dark .wf-sub { fill: #e2e8f0; }
.wf-edge { stroke: currentColor; stroke-width: 2.2; }
.wf-bar { fill: #0f172a; }
html.dark .wf-bar { fill: #1e293b; stroke: #334155; }
.wf-bar-title { font-size: 12px; font-weight: 700; fill: #f8fafc; }
.wf-bar-sub { font-size: 11px; fill: #bae6fd; }

/* Badges */
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
}
.badge-code { background: #0f172a; color: #ffffff; font-family: monospace; }
html.dark .badge-code { background: #38bdf8; color: #020617; }
.badge-portal { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
.badge-role { background: var(--emerald-soft); color: var(--emerald-text); }
.badge-sop { background: var(--primary-soft); color: var(--primary); }
.badge-sla { background: var(--amber-soft); color: var(--amber-text); }
.badge-ex { background: var(--danger-soft); color: var(--danger); font-family: monospace; }

/* SOP Grid */
.sop-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; }
.sop-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  scroll-margin-top: 86px;
}
.sop-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.sop-owner { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.sop-card h3 { margin: 0 0 12px; font-size: 1.02rem; }
.raci-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
  font-size: 0.8rem;
  background: var(--surface-alt);
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 10px;
}
.checkpoint-box {
  font-size: 0.82rem;
  background: var(--amber-soft);
  color: var(--amber-text);
  padding: 9px 12px;
  border-radius: 10px;
  margin-bottom: 10px;
}
.sop-steps { margin: 0; padding-left: 18px; font-size: 0.85rem; color: var(--text-muted); }
.sop-steps li { margin-bottom: 4px; }

/* Filter Bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.role-pill {
  min-height: 44px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.role-pill.active { background: #0369a1; color: #ffffff; border-color: #0369a1; }
.pill-count {
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.12);
}
.role-pill.active .pill-count { background: rgba(255, 255, 255, 0.25); }
.filter-status { margin-left: auto; font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }

/* Screen Cards */
.screen-list { display: flex; flex-direction: column; gap: 22px; }
.screen-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  box-shadow: var(--shadow);
  scroll-margin-top: 86px;
}
.screen-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.screen-meta { flex: 1 1 360px; }
.screen-meta h3 { margin: 0 0 6px; font-size: 1.2rem; }
.screen-route { margin: 0 0 6px; font-size: 0.84rem; color: var(--text-muted); }
.screen-summary { margin: 0; font-size: 0.9rem; color: var(--text-muted); }
.screen-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.shot-figure { margin: 0 0 16px; }
.shot-trigger {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-alt);
  cursor: zoom-in;
}
.shot-trigger img { display: block; width: 100%; height: auto; }
.zoom-hint {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.82);
  color: #ffffff;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
}

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
.guide-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; background: var(--surface); }
.guide-table th, .guide-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.guide-table th {
  background: var(--surface-alt);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.guide-table tr:last-child td { border-bottom: 0; }
.marker-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  border-radius: 999px;
  background: #dc2626;
  color: #ffffff;
  font-weight: 800;
  font-size: 0.95rem;
}

/* FAQ */
.faq-list { display: flex; flex-direction: column; gap: 10px; }
.faq-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.faq-item summary { font-weight: 700; cursor: pointer; font-size: 0.94rem; }
.faq-item p { margin: 10px 0 0; font-size: 0.88rem; color: var(--text-muted); }

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  color: var(--text-muted);
}

.footer {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.lightbox[hidden] { display: none; }
.lightbox-backdrop { position: absolute; inset: 0; background: rgba(2, 6, 23, 0.85); }
.lightbox-dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1320px;
  max-height: 92vh;
  background: var(--surface);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}
.lightbox-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
  font-size: 0.9rem;
}
.lightbox-body { overflow: auto; padding: 14px; text-align: center; background: #0f172a; }
.lightbox-body img { max-width: 100%; max-height: 80vh; height: auto; border-radius: 8px; }

.content, .sidebar, .section, .screen-card, .sop-card, .hero, .filter-bar { min-width: 0; max-width: 100%; }
.svg-wrap, .table-wrap { width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.guide-table { min-width: 560px; }

/* Responsive */
@media (max-width: 1024px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; max-height: none; }
  .hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .topbar-inner { padding: 10px 14px; }
  .shell { display: flex; flex-direction: column; padding: 16px 12px 48px; gap: 18px; width: 100%; max-width: 100vw; overflow-x: hidden; }
  .content, .sidebar { width: 100%; max-width: 100%; }
  .hero { padding: 20px 16px; }
  .hero h1 { font-size: 1.35rem; }
  .screen-card { padding: 14px; overflow: hidden; }
  .svg-wrap { padding: 10px; max-width: calc(100vw - 24px); }
  .table-wrap { max-width: calc(100vw - 54px); }
  #exceptions .table-wrap { max-width: calc(100vw - 24px); }
  .screen-meta { flex: 1 1 100%; min-width: 0; }
  .screen-actions { width: 100%; }
  .screen-actions .btn { flex: 1 1 auto; white-space: normal; text-align: center; }
  .btn-label { display: none; }
  .sop-grid { grid-template-columns: minmax(0, 1fr); }
  .raci-grid { grid-template-columns: minmax(0, 1fr); }
  .filter-status { margin-left: 0; width: 100%; }
}

/* Print / PDF */
@media print {
  .topbar, .sidebar, .filter-bar, .screen-actions, .zoom-hint, .lightbox { display: none !important; }
  body { background: #ffffff; color: #000000; }
  .shell { display: block; padding: 0; }
  .screen-card, .sop-card { break-inside: avoid; box-shadow: none; border: 1px solid #cbd5e1; margin-bottom: 16px; }
  .hero { background: #0369a1 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
