/* ============================================================
   Alur Pelayanan SKTK — Viewer Styles
   Brand tokens selaras dengan sktk.dishubjabar.com
   ============================================================ */

/* ---------- Design Tokens ---------- */
:root {
  /* Brand */
  --navy: #0A1F44;
  --blue: #1E40AF;
  --accent: #F59E0B;
  --amber: #FBBF24;
  --cyan: #06B6D4;
  --green: #10B981;
  --bg: #FAFAF7;
  --dark: #0F172A;

  /* Semantic (light) */
  --text: #0F172A;
  --text-2: #475569;
  --text-3: #64748B;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --surface-3: #F1F5F9;
  --header-bg: #0A1F44;
  --page-bar-bg: rgba(250, 250, 247, 0.88);
  --diagram-bg: #FFFFFF;
  --nav-active-bg: rgba(30, 64, 175, 0.10);

  /* Gradients */
  --grad-brand: linear-gradient(135deg, #1E40AF 0%, #06B6D4 100%);
  --grad-accent: linear-gradient(135deg, #F59E0B 0%, #FBBF24 100%);

  /* Typography */
  --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
  --font-body: 'Plus Jakarta Sans', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', monospace;

  /* Spacing */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px;
  --s6: 32px; --s7: 48px; --s8: 64px;

  /* Radius */
  --r-sm: 8px; --r-md: 14px; --r-lg: 20px; --r-pill: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(10, 31, 68, 0.05);
  --shadow-md: 0 4px 12px rgba(10, 31, 68, 0.08);
  --shadow-lg: 0 16px 40px rgba(10, 31, 68, 0.12);

  /* Layout */
  --container: 1400px;
  --kop-h: 64px;
  --header-h: 128px;
  --sidebar-w: 304px;
}

[data-theme="dark"] {
  --text: #E2E8F0;
  --text-2: #A3B1C6;
  --text-3: #7C8AA0;
  --border: #1E293B;
  --border-strong: #334155;
  --surface: #0F172A;
  --surface-2: #111C33;
  --surface-3: #16233D;
  --header-bg: #070F1F;
  --page-bar-bg: rgba(11, 18, 32, 0.9);
  --bg: #0B1220;
  --nav-active-bg: rgba(6, 182, 212, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.55);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 20px); }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.2; margin: 0; font-weight: 700; }

:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; border-radius: 6px; }

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 200;
  background: var(--navy); color: #fff; padding: 10px 18px; border-radius: var(--r-pill);
  font-weight: 600; font-size: 14px; transition: top .2s ease;
}
.skip-link:focus { top: 12px; }

/* ---------- KOP Bar ---------- */
.app-header { position: sticky; top: 0; z-index: 60; }

.kop-bar {
  position: relative;
  background: linear-gradient(115deg, #0A1F44 0%, #0E2A5C 52%, #0A1F44 100%);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 6px 22px rgba(10, 31, 68, 0.28);
}
.kop-inner {
  max-width: var(--container); margin: 0 auto;
  padding: 0 var(--s5); height: var(--kop-h);
  display: flex; align-items: center; gap: var(--s4);
}
.kop-logo-badge {
  flex-shrink: 0; width: 52px; height: 46px; border-radius: 10px;
  background: #fff; display: grid; place-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
}
.kop-logo { width: 40px; height: 34px; object-fit: contain; }
.kop-text { display: flex; flex-direction: column; line-height: 1.28; min-width: 0; }
.kop-line1 {
  font-size: 10px; font-weight: 600; letter-spacing: 0.18em;
  text-transform: uppercase; color: #93C5FD;
}
.kop-line2 {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(0.8rem, 1.5vw, 1rem); letter-spacing: 0.015em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kop-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  display: inline-grid; place-items: center;
  background: rgba(255, 255, 255, 0.08); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.14);
  transition: background .2s ease, transform .2s ease, border-color .2s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.18); border-color: rgba(255, 255, 255, 0.3); }
.icon-btn:active { transform: scale(0.96); }
.icon-btn svg { width: 20px; height: 20px; }

.menu-toggle { display: none; }

/* ---------- Page Bar ---------- */
.page-bar {
  background: var(--page-bar-bg);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.page-bar-inner {
  max-width: var(--container); margin: 0 auto;
  padding: var(--s4) var(--s5);
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--s4); flex-wrap: wrap;
}
.page-heading h1 { font-size: clamp(1.35rem, 2.6vw, 1.9rem); color: var(--navy); letter-spacing: -0.01em; }
[data-theme="dark"] .page-heading h1 { color: #F1F5F9; }
.page-heading p { margin: 4px 0 0; color: var(--text-2); font-size: 0.95rem; }
.page-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--blue);
  background: rgba(30, 64, 175, 0.08); border: 1px solid rgba(30, 64, 175, 0.16);
  padding: 6px 12px; border-radius: var(--r-pill);
}
[data-theme="dark"] .chip { color: #67E8F9; background: rgba(6, 182, 212, 0.1); border-color: rgba(6, 182, 212, 0.24); }

/* ---------- Layout ---------- */
.layout {
  max-width: var(--container); margin: 0 auto;
  padding: var(--s6) var(--s5) var(--s8);
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: var(--s6);
}
.content { min-width: 0; outline: none; }

/* ---------- Sidebar ---------- */
.sidebar-card {
  position: sticky; top: calc(var(--header-h) + 16px);
  max-height: calc(100vh - var(--header-h) - 32px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--s4);
  box-shadow: var(--shadow-sm);
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sidebar-title {
  font-family: var(--font-display); font-weight: 700; font-size: 0.95rem; color: var(--text);
}
.sidebar-close { display: none; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-pill); padding: 0 14px; color: var(--text-3);
  transition: border-color .2s ease, box-shadow .2s ease;
}
.search-box:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.12); }
.search-box svg { width: 17px; height: 17px; flex-shrink: 0; }
.search-box input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  padding: 10px 0; font: inherit; font-size: 14px; color: var(--text);
}
.search-status { font-size: 12px; color: var(--text-3); margin: 8px 2px 12px; }

.side-nav { display: flex; flex-direction: column; gap: var(--s4); }
.nav-group-title {
  margin: 0 0 6px; padding-left: 10px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-3);
}
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 8px 10px; border-radius: 10px;
  color: var(--text-2); font-size: 13.5px; line-height: 1.35;
  border-left: 3px solid transparent;
  transition: background .18s ease, color .18s ease, border-color .18s ease;
}
.nav-num {
  flex-shrink: 0; margin-top: 1px;
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  color: var(--blue); background: rgba(30, 64, 175, 0.08);
  padding: 1px 6px; border-radius: 6px;
}
[data-theme="dark"] .nav-num { color: #67E8F9; background: rgba(6, 182, 212, 0.12); }
.nav-link:hover { background: var(--surface-3); color: var(--text); }
.nav-link.active {
  background: var(--nav-active-bg); color: var(--blue);
  border-left-color: var(--blue); font-weight: 600;
}
[data-theme="dark"] .nav-link.active { color: #67E8F9; border-left-color: var(--cyan); }

/* ---------- Diagram sections ---------- */
.diagram-section { margin-bottom: var(--s7); }
.section-heading {
  display: flex; align-items: center; gap: 10px;
  font-size: 1.05rem; color: var(--text); margin-bottom: var(--s4);
}
.section-heading::before {
  content: ""; width: 5px; height: 22px; border-radius: 3px;
  background: var(--grad-brand); flex-shrink: 0;
}

/* ---------- Card ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
  margin-bottom: var(--s5); overflow: hidden;
  transition: box-shadow .25s ease, border-color .25s ease;
}
.card:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.card:target { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.14), var(--shadow-md); }

.card-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--s4); flex-wrap: wrap;
  padding: var(--s5); border-bottom: 1px solid var(--border);
}
.card-title-group { display: flex; gap: var(--s4); min-width: 0; flex: 1; }
.card-num {
  flex-shrink: 0; width: 46px; height: 46px; border-radius: 13px;
  display: grid; place-items: center; background: var(--grad-brand);
  color: #fff; font-family: var(--font-display); font-weight: 700;
  font-size: 1.15rem; box-shadow: var(--shadow-sm);
}
.card-titles { min-width: 0; }
.card-title { font-size: 1.12rem; color: var(--text); }
.card-ref { display: inline-flex; align-items: center; gap: 8px; margin-top: 7px; flex-wrap: wrap; }
.ref-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-3);
}
.ref-text {
  font-family: var(--font-mono); font-size: 12px; font-weight: 500;
  color: var(--blue); background: rgba(30, 64, 175, 0.08);
  border: 1px solid rgba(30, 64, 175, 0.16);
  padding: 2px 10px; border-radius: var(--r-pill);
}
[data-theme="dark"] .ref-text { color: #67E8F9; background: rgba(6, 182, 212, 0.1); border-color: rgba(6, 182, 212, 0.24); }

.card-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 600; padding: 9px 14px;
  border-radius: var(--r-pill); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-2);
  transition: transform .2s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease, background .2s ease;
}
.tool-btn svg { width: 15px; height: 15px; }
.tool-btn:hover { border-color: var(--blue); color: var(--blue); background: var(--surface); }
.tool-btn.primary { background: var(--grad-brand); color: #fff; border-color: transparent; }
.tool-btn.primary:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); color: #fff; }
.tool-btn.copy.copied { color: var(--green); border-color: var(--green); background: var(--surface); }

/* ---------- Diagram surface ---------- */
.diagram-surface {
  position: relative; background: var(--diagram-bg); color: #0F172A;
  padding: var(--s6) var(--s5); overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.diagram-surface svg { display: block; margin: 0 auto; height: auto; max-width: 100%; }
.diagram-surface.is-scrollable { cursor: grab; }
.diagram-surface.is-scrollable::-webkit-scrollbar { height: 10px; }
.diagram-surface::-webkit-scrollbar { height: 10px; }
.diagram-surface::-webkit-scrollbar-thumb { background: rgba(10, 31, 68, 0.2); border-radius: 999px; }
.diagram-surface::-webkit-scrollbar-track { background: rgba(10, 31, 68, 0.05); }

.diagram-loading {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  min-height: 220px; color: #64748B; font-size: 0.92rem; font-weight: 500;
}
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid #E2E8F0; border-top-color: #1E40AF;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.diagram-error { max-width: 720px; margin: 0 auto; }
.diagram-error .err-title { margin: 0 0 6px; font-family: var(--font-display); font-weight: 700; color: #B91C1C; font-size: 1rem; }
.diagram-error .err-msg { margin: 0 0 6px; color: #475569; font-size: 0.9rem; }
.diagram-error .err-detail { margin: 0 0 14px; color: #64748B; font-size: 0.82rem; font-family: var(--font-mono); word-break: break-word; }
.diagram-error details { border: 1px solid #E2E8F0; border-radius: var(--r-md); overflow: hidden; }
.diagram-error summary { padding: 10px 14px; cursor: pointer; font-weight: 600; font-size: 0.85rem; color: #1E40AF; background: #F8FAFC; }
.diagram-error pre {
  margin: 0; padding: 14px; overflow: auto; max-height: 340px;
  background: #0F172A; color: #E2E8F0; font-family: var(--font-mono);
  font-size: 12px; line-height: 1.55;
}
.diagram-error code { font-family: inherit; white-space: pre; }

.card-foot {
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px var(--s5); border-top: 1px solid var(--border);
  color: var(--text-3); font-size: 12px;
}

/* ---------- Empty / Fatal states ---------- */
.empty-state, .fatal {
  background: var(--surface); border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg); padding: var(--s7) var(--s5); text-align: center;
  color: var(--text-2); font-size: 1.02rem;
}
.fatal { border-color: #FCA5A5; color: #B91C1C; }

/* ---------- Footer ---------- */
.app-footer { background: var(--dark); color: #94A3B8; margin-top: var(--s6); }
[data-theme="dark"] .app-footer { background: #070F1F; }
.footer-inner {
  max-width: var(--container); margin: 0 auto; padding: var(--s6) var(--s5);
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; font-size: 0.85rem;
}
.footer-main { margin: 0; color: #CBD5E1; font-weight: 600; }
.footer-note { margin: 0; opacity: 0.8; }

/* ---------- Scrim (mobile drawer) ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(10, 31, 68, 0.5);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  opacity: 0; transition: opacity .25s ease;
}
.scrim.show { opacity: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 300;
  transform: translateX(-50%) translateY(16px);
  background: var(--navy); color: #fff;
  padding: 12px 22px; border-radius: var(--r-pill);
  box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 600;
  max-width: min(92vw, 560px); text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 80;
    width: min(340px, 88vw); background: var(--surface);
    transform: translateX(-102%);
    transition: transform .3s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .sidebar-card {
    position: static; max-height: none; height: 100%;
    border-radius: 0; border: 0; box-shadow: none;
    overflow-y: auto; padding: var(--s5);
  }
  .sidebar-close { display: inline-grid; }
  .menu-toggle { display: inline-grid; }
}

@media (max-width: 720px) {
  .kop-inner { padding: 0 var(--s4); gap: 10px; }
  .kop-logo-badge { width: 44px; height: 40px; }
  .kop-logo { width: 34px; height: 30px; }
  .kop-line1 { font-size: 9px; letter-spacing: 0.12em; }
  .kop-line2 { font-size: 0.78rem; }
  .icon-btn { width: 38px; height: 38px; }

  .page-bar-inner { padding: var(--s4); }
  .page-heading p { font-size: 0.88rem; }

  .layout { padding: var(--s5) var(--s4) var(--s7); gap: var(--s5); }
  .card-head { padding: var(--s4); gap: var(--s3); }
  .card-num { width: 40px; height: 40px; border-radius: 11px; font-size: 1rem; }
  .card-title { font-size: 1.02rem; }
  .card-tools { width: 100%; }
  .tool-btn { flex: 1 1 auto; justify-content: center; font-size: 12.5px; padding: 9px 12px; }
  .diagram-surface { padding: var(--s5) var(--s3); }
  .card-foot { padding: 10px var(--s4); }
  .footer-inner { flex-direction: column; text-align: center; }
}

@media (max-width: 380px) {
  .tool-btn span { font-size: 12px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   Print — bersih, tanpa sidebar/tombol, jeda halaman antar kartu
   ============================================================ */
@media print {
  :root,
  [data-theme="dark"] {
    --bg: #FFFFFF; --surface: #FFFFFF; --surface-2: #FFFFFF; --surface-3: #FFFFFF;
    --text: #000000; --text-2: #333333; --text-3: #555555;
    --border: #BBBBBB; --border-strong: #999999; --diagram-bg: #FFFFFF;
    --page-bar-bg: #FFFFFF;
  }
  html, body { background: #fff !important; color: #000 !important; }
  .skip-link, .sidebar, .scrim, .app-footer, .card-tools,
  .search-box, .search-status, .page-meta, .kop-actions, .toast { display: none !important; }

  .kop-bar { position: static; background: #fff !important; color: #000 !important; border-bottom: 2px solid #000; box-shadow: none; }
  .kop-line1 { color: #333 !important; }
  .kop-logo-badge { box-shadow: none; border: 1px solid #ccc; }
  .page-bar { border-bottom: 1px solid #999; }

  .layout { display: block; max-width: none; padding: 0; }
  .diagram-section { margin-bottom: 0; }
  .section-heading { break-after: avoid; page-break-after: avoid; }
  .card {
    border: 1px solid #999; box-shadow: none; border-radius: 0;
    break-inside: avoid; page-break-inside: avoid;
    break-before: page; page-break-before: always;
    margin-bottom: 0;
  }
  .diagram-section:first-of-type .card:first-of-type { break-before: auto; page-break-before: auto; }
  .diagram-surface { overflow: visible; padding: 12px 0; }
  .diagram-surface svg { max-width: 100% !important; width: auto !important; }
  .card-head { padding: 12px 0; border-bottom: 1px solid #ccc; }
  .card-title { color: #000; }
  .ref-text { color: #000; border-color: #999; background: #fff; }
  .card-foot { display: none; }
}
