@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

:root {
 --bg: #0c0f14;
 --bg-card: #141820;
 --bg-sidebar: #10141a;
 --bg-hover: #1a1f2a;
 --border: #1e2530;
 --border-active: #3b82f6;
 --text: #e2e8f0;
 --text-dim: #8896ab;
 --text-muted: #556070;
 --accent: #3b82f6;
 --accent-glow: rgba(59,130,246,.15);
 --green: #22c55e;
 --orange: #f59e0b;
 --red: #ef4444;
 --olive: #6b7a2f;
 --radius: 12px;
 --sidebar-w: 300px;
 --header-h: 64px;
}

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

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 20px); }

body {
 font-family: 'Inter', -apple-system, sans-serif;
 background: var(--bg);
 color: var(--text);
 line-height: 1.7;
 font-size: 15px;
}

/* HEADER */
.header {
 position: fixed; top:0; left:0; right:0;
 height: var(--header-h);
 background: rgba(12,15,20,.85);
 backdrop-filter: blur(20px);
 border-bottom: 1px solid var(--border);
 z-index: 100;
 display: flex; align-items: center; padding: 0 24px;
 gap: 16px;
}
.header-flag { font-size: 28px; }
.header-title { font-size: 16px; font-weight: 700; letter-spacing: -.02em; }
.header-subtitle { font-size: 12px; color: var(--text-dim); font-weight: 400; }
.header-version {
 font-size: 11px;
 color: var(--text-muted);
 background: var(--bg-card);
 padding: 4px 12px;
 border-radius: 100px;
 border: 1px solid var(--border);
 white-space: nowrap;
}
.header-text { min-width: 0; }
.header-actions {
 display: flex; align-items: center; gap: 12px;
 margin-left: auto; flex-shrink: 0;
}
.logout-btn {
 background: rgba(239,68,68,.15);
 border: 1px solid rgba(239,68,68,.3);
 color: #f87171;
 padding: 6px 16px;
 border-radius: 8px;
 font-size: 13px;
 font-family: inherit;
 cursor: pointer;
 transition: all .2s;
 font-weight: 500;
 white-space: nowrap;
}
.logout-btn:hover { background: rgba(239,68,68,.25); }
.menu-toggle {
 display: none;
 background: none; border: none;
 color: var(--text); font-size: 24px; cursor: pointer;
}

/* SIDEBAR */
.sidebar {
 position: fixed; top: var(--header-h); left: 0;
 width: var(--sidebar-w);
 height: calc(100vh - var(--header-h));
 background: var(--bg-sidebar);
 border-right: 1px solid var(--border);
 overflow-y: auto;
 padding: 16px 0;
 z-index: 90;
 transition: transform .3s ease;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.nav-section {
 padding: 8px 16px 4px;
 font-size: 10px;
 font-weight: 700;
 text-transform: uppercase;
 letter-spacing: .1em;
 color: var(--text-muted);
}
.nav-link {
 display: flex; align-items: center; gap: 10px;
 padding: 8px 16px 8px 20px;
 color: var(--text-dim);
 text-decoration: none;
 font-size: 13px;
 font-weight: 500;
 border-left: 3px solid transparent;
 transition: all .2s;
}
.nav-link:hover { color: var(--text); background: var(--bg-hover); }
.nav-link.active {
 color: var(--accent);
 border-left-color: var(--accent);
 background: var(--accent-glow);
}
.nav-link .nav-icon { font-size: 16px; width: 22px; text-align: center; flex-shrink: 0; }
.nav-link .nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-sub { padding-left: 32px; }
.nav-sub .nav-link { font-size: 12px; padding: 5px 16px 5px 20px; }

/* MAIN */
.main {
 margin-left: var(--sidebar-w);
 margin-top: var(--header-h);
 padding: 40px 48px 80px;
 max-width: 960px;
}

/* SECTIONS */
section { margin-bottom: 48px; }
section h2 {
 font-size: 26px; font-weight: 800;
 letter-spacing: -.03em;
 margin-bottom: 8px;
 display: flex; align-items: center; gap: 12px;
 padding-bottom: 12px;
 border-bottom: 1px solid var(--border);
}
section h2 .sec-icon { font-size: 28px; }
section h3 {
 font-size: 18px; font-weight: 700;
 margin: 28px 0 12px;
 color: var(--text);
 display: flex; align-items: center; gap: 8px;
}
section h4 {
 font-size: 14px; font-weight: 600;
 margin: 16px 0 8px;
 color: var(--text-dim);
}
p { margin-bottom: 12px; color: var(--text-dim); }

/* STAT GRID */
.stat-grid {
 display: grid;
 grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
 gap: 12px;
 margin: 16px 0;
}
.stat-card {
 background: var(--bg-card);
 border: 1px solid var(--border);
 border-radius: var(--radius);
 padding: 16px;
 text-align: center;
}
.stat-card .stat-value {
 font-size: 28px; font-weight: 800;
 background: linear-gradient(135deg, var(--accent), #818cf8);
 -webkit-background-clip: text; -webkit-text-fill-color: transparent;
 background-clip: text;
}
.stat-card .stat-label {
 font-size: 11px; color: var(--text-muted);
 margin-top: 4px; text-transform: uppercase; letter-spacing: .05em;
}

/* TABLES */
.table-wrap { overflow-x: auto; margin: 16px 0; }
table {
 width: 100%; border-collapse: collapse;
 font-size: 13px;
}
th {
 text-align: left; padding: 10px 14px;
 background: var(--bg-card);
 color: var(--text-dim);
 font-weight: 600; font-size: 11px;
 text-transform: uppercase; letter-spacing: .05em;
 border-bottom: 2px solid var(--border);
}
td {
 padding: 10px 14px;
 border-bottom: 1px solid var(--border);
 color: var(--text-dim);
}
td strong { color: var(--text); font-weight: 600; }
tr:hover td { background: var(--bg-hover); }

/* CODE */
pre {
 background: var(--bg-card);
 border: 1px solid var(--border);
 border-radius: var(--radius);
 padding: 16px 20px;
 overflow-x: auto;
 font-family: 'SF Mono', 'Fira Code', monospace;
 font-size: 13px;
 line-height: 1.6;
 margin: 12px 0;
 color: var(--accent);
}
code {
 font-family: 'SF Mono', 'Fira Code', monospace;
 font-size: 12px;
 background: var(--bg-card);
 padding: 2px 6px;
 border-radius: 4px;
 color: var(--orange);
}

/* LISTS */
ul, ol { padding-left: 20px; margin: 8px 0 16px; }
li { margin-bottom: 6px; color: var(--text-dim); }
li strong { color: var(--text); }

/* MERMAID */
.mermaid-wrap {
 background: var(--bg-card);
 border: 1px solid var(--border);
 border-radius: var(--radius);
 padding: 24px;
 margin: 16px 0;
 overflow-x: auto;
 text-align: center;
 cursor: zoom-in;
 position: relative;
 transition: border-color .2s;
}
.mermaid-wrap:hover { border-color: var(--accent); }
.mermaid-wrap::after {
 content: 'Натисніть для збільшення';
 position: absolute;
 bottom: 8px; right: 12px;
 font-size: 11px;
 color: var(--text-muted);
 background: var(--bg);
 padding: 3px 10px;
 border-radius: 6px;
 border: 1px solid var(--border);
 opacity: 0;
 transition: opacity .25s;
 pointer-events: none;
}
.mermaid-wrap:hover::after { opacity: 1; }
.mermaid { display: inline-block; text-align: center; }

/* LIGHTBOX */
.lightbox-overlay {
 position: fixed; inset: 0;
 background: rgba(0,0,0,.88);
 backdrop-filter: blur(12px);
 z-index: 9999;
 display: flex; align-items: center; justify-content: center;
 cursor: zoom-out;
 opacity: 0;
 visibility: hidden;
 transition: opacity .3s, visibility .3s;
}
.lightbox-overlay.open { opacity: 1; visibility: visible; }
.lightbox-content {
 background: var(--bg-card);
 border: 1px solid var(--border);
 border-radius: 16px;
 padding: 32px;
 max-width: 92vw;
 max-height: 92vh;
 overflow: auto;
 transform: scale(.92);
 transition: transform .3s ease;
 cursor: default;
}
.lightbox-overlay.open .lightbox-content { transform: scale(1); }
.lightbox-close {
 position: fixed; top: 20px; right: 28px;
 background: var(--bg-card);
 border: 1px solid var(--border);
 color: var(--text);
 width: 42px; height: 42px;
 border-radius: 50%;
 font-size: 20px;
 cursor: pointer;
 display: flex; align-items: center; justify-content: center;
 z-index: 10000;
 transition: border-color .2s, transform .2s;
}
.lightbox-close:hover { border-color: var(--accent); transform: scale(1.1); }
.lightbox-hint {
 position: fixed; bottom: 24px; left: 50%;
 transform: translateX(-50%);
 font-size: 12px; color: var(--text-muted);
 background: var(--bg);
 padding: 6px 16px;
 border-radius: 100px;
 border: 1px solid var(--border);
 z-index: 10000;
}

/* STATUS BADGES */
.badge {
 display: inline-block;
 font-size: 10px; font-weight: 700;
 padding: 3px 10px;
 border-radius: 100px;
 text-transform: uppercase;
 letter-spacing: .05em;
}
.badge-live { background: rgba(34,197,94,.15); color: var(--green); }
.badge-progress { background: rgba(59,130,246,.15); color: var(--accent); }
.badge-planned { background: rgba(148,163,184,.1); color: var(--text-muted); }
.badge-partial { background: rgba(245,158,11,.15); color: var(--orange); }

/* TIER CARDS */
.tier {
 background: var(--bg-card);
 border: 1px solid var(--border);
 border-radius: var(--radius);
 padding: 20px 24px;
 margin: 12px 0;
 border-left: 4px solid var(--accent);
}
.tier-field { border-left-color: var(--green); }
.tier-ops { border-left-color: var(--accent); }
.tier-admin { border-left-color: var(--orange); }
.tier-int { border-left-color: #a855f7; }
.tier-strat { border-left-color: var(--red); }
.tier h4 { margin-top: 0; color: var(--text); }

/* FORMULA */
.formula {
 background: linear-gradient(135deg, rgba(59,130,246,.08), rgba(168,85,247,.08));
 border: 1px solid rgba(59,130,246,.2);
 border-radius: var(--radius);
 padding: 20px 24px;
 margin: 16px 0;
 text-align: center;
 font-family: 'SF Mono', monospace;
 font-size: 20px;
 font-weight: 700;
 color: var(--accent);
 letter-spacing: .02em;
}

/* FLOW STEPS */
.flow-steps {
 display: flex; flex-wrap: wrap; gap: 8px;
 margin: 16px 0;
}
.flow-step {
 background: var(--bg-card);
 border: 1px solid var(--border);
 border-radius: var(--radius);
 padding: 10px 16px;
 font-size: 12px; font-weight: 600;
 display: flex; align-items: center; gap: 6px;
}
.flow-step .step-num {
 background: var(--accent);
 color: #fff;
 width: 22px; height: 22px;
 border-radius: 6px;
 display: flex; align-items: center; justify-content: center;
 font-size: 11px; font-weight: 800;
 flex-shrink: 0;
}
.flow-arrow { color: var(--text-muted); font-size: 18px; display: flex; align-items: center; }

/* KPI GRID (used in regulatory section) */
.kpi-grid {
 display: flex; gap: 12px; flex-wrap: wrap; margin: 16px 0;
}
.kpi-card {
 background: var(--bg-card);
 border: 1px solid var(--border);
 border-radius: var(--radius);
 padding: 16px 24px;
 text-align: center;
 flex: 1; min-width: 100px;
}
.kpi-value { font-size: 32px; font-weight: 800; }
.kpi-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin-top: 4px; }

/* SIDEBAR OVERLAY (mobile) */
.sidebar-overlay {
 display: none;
 position: fixed; inset: 0;
 background: rgba(0,0,0,.55);
 z-index: 89;
 backdrop-filter: blur(4px);
 -webkit-backdrop-filter: blur(4px);
}
.sidebar-overlay.show { display: block; }

/* ============================================
   RESPONSIVE — TABLET (≤900px)
   ============================================ */
@media (max-width: 900px) {
 .sidebar { transform: translateX(-100%); }
 .sidebar.open { transform: translateX(0); box-shadow: 8px 0 32px rgba(0,0,0,.4); }
 .main { margin-left: 0; padding: 24px 20px 60px; }
 .menu-toggle { display: block; }
 .stat-grid { grid-template-columns: repeat(2, 1fr); }

 /* Shrink header padding */
 .header { padding: 0 12px; gap: 10px; }
 .header-title { font-size: 14px; }
 .header-subtitle { font-size: 11px; }
 .header-version { font-size: 10px; padding: 3px 8px; }

 /* Touch-friendly nav links */
 .nav-link { padding: 10px 16px 10px 20px; font-size: 14px; min-height: 44px; }
 .nav-section { padding: 12px 16px 6px; font-size: 11px; }

 /* Tables: ensure horizontal scroll */
 .table-wrap { margin: 12px -20px; padding: 0 20px; }
 table { min-width: 480px; }

 /* Mermaid diagrams scroll */
 .mermaid-wrap { padding: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
 .mermaid-wrap::after { display: none; }

 /* Lightbox: full-width on tablets+ */
 .lightbox-content { max-width: 96vw; max-height: 94vh; padding: 20px; border-radius: 12px; }
 .lightbox-close { top: 12px; right: 12px; width: 38px; height: 38px; }
}

/* ============================================
   RESPONSIVE — SMARTPHONE (≤600px)
   ============================================ */
@media (max-width: 600px) {
 :root {
  --header-h: 56px;
 }

 body { font-size: 14px; line-height: 1.65; }

 /* Header: compact */
 .header { padding: 0 10px; gap: 8px; }
 .header-flag { font-size: 22px; }
 .header-title { font-size: 13px; line-height: 1.3; }
 .header-subtitle { font-size: 10px; display: none; }
 .header-version { display: none; }

 /* Main content: tight padding */
 .main { padding: 16px 14px 80px; max-width: 100%; }

 /* Sections */
 section { margin-bottom: 32px; }
 section h2 {
  font-size: 19px; gap: 8px;
  padding-bottom: 8px;
  line-height: 1.35;
  flex-wrap: wrap;
 }
 section h3 { font-size: 16px; margin: 20px 0 10px; }
 section h4 { font-size: 13px; }
 p { font-size: 13px; }

 /* Stat grid: 2 columns on phone */
 .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
 .stat-card { padding: 12px 8px; }
 .stat-card .stat-value { font-size: 20px; }
 .stat-card .stat-label { font-size: 9px; }

 /* Tables: scrollable, smaller font */
 .table-wrap {
  margin: 12px -14px; padding: 0 14px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  /* Scroll shadow hints */
  background:
   linear-gradient(90deg, var(--bg) 30%, transparent) left,
   linear-gradient(90deg, transparent, var(--bg) 70%) right;
  background-size: 20px 100%; background-repeat: no-repeat;
  background-attachment: local;
 }
 table { min-width: 420px; font-size: 12px; }
 th { padding: 8px 10px; font-size: 10px; }
 td { padding: 8px 10px; }

 /* Flow steps: wrap nicely */
 .flow-steps { gap: 6px; }
 .flow-step { padding: 8px 10px; font-size: 11px; }
 .flow-step .step-num { width: 20px; height: 20px; font-size: 10px; }
 .flow-arrow { font-size: 14px; }

 /* Tier cards */
 .tier { padding: 14px 16px; }
 .tier h4 { font-size: 13px; }
 .tier p { font-size: 12px; }

 /* Formula */
 .formula { font-size: 15px; padding: 14px 16px; }

 /* Code / Pre */
 pre { font-size: 11px; padding: 12px 14px; }
 code { font-size: 11px; }

 /* Lists */
 ul, ol { padding-left: 16px; }
 li { font-size: 13px; margin-bottom: 4px; }

 /* Mermaid: scrollable, smaller */
 .mermaid-wrap { padding: 12px; margin: 12px 0; }
 .mermaid svg { max-width: 100%; height: auto; }

 /* Lightbox: nearly full screen */
 .lightbox-content {
  max-width: 100vw; max-height: 100vh;
  border-radius: 0; padding: 16px;
  margin: 0;
 }
 .lightbox-close { top: 8px; right: 8px; width: 36px; height: 36px; font-size: 18px; }
 .lightbox-hint { bottom: 12px; font-size: 11px; padding: 4px 12px; }

 /* Badges */
 .badge { font-size: 9px; padding: 2px 8px; }

 /* KPI grid */
 .kpi-grid { gap: 8px; }
 .kpi-card { padding: 12px 16px; min-width: 80px; }
 .kpi-value { font-size: 26px; }
 .kpi-label { font-size: 9px; }

 /* Sidebar: full width overlay */
 .sidebar { width: 85vw; max-width: 320px; }

 /* Logout button: compact */
 .logout-btn { padding: 5px 12px; font-size: 12px; }
 .header-actions { gap: 8px; }
}

/* ============================================
   RESPONSIVE — VERY SMALL PHONES (≤400px)
   ============================================ */
@media (max-width: 400px) {
 .main { padding: 12px 10px 80px; }

 section h2 { font-size: 17px; }
 section h3 { font-size: 15px; }

 .stat-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
 .stat-card .stat-value { font-size: 18px; }
 .stat-card .stat-label { font-size: 8px; }

 .flow-steps { flex-direction: column; align-items: stretch; }
 .flow-arrow { transform: rotate(90deg); align-self: center; font-size: 16px; }
 .flow-step { justify-content: center; }

 .tier p { font-size: 11px; }
 .formula { font-size: 13px; padding: 12px; }

 table { min-width: 360px; }

 .kpi-grid { flex-direction: column; }
 .kpi-card { min-width: unset; }
}
