/* ============================================
   WIKI DESIGN SYSTEM — Notion/shadcn inspired
   bw/grey, max content area, clean nav
   ============================================ */

:root {
  /* Greys — Notion/shadcn palette */
  --bg:          #ffffff;
  --bg-secondary:#f7f7f8;
  --bg-hover:    #f0f0f2;
  --bg-active:   #e8e8ec;
  --border:      #e4e4e7;
  --border-heavy:#d4d4d8;
  --text:        #18181b;
  --text-secondary:#71717a;
  --text-muted:  #a1a1aa;
  --accent:      #18181b;
  --accent-light:#f4f4f5;
  --tag-bg:      #f4f4f5;
  --tag-text:    #3f3f46;
  --code-bg:     #f4f4f5;
  --sidebar-w:   260px;
  --header-h:    52px;
  --radius:      6px;
  --radius-lg:   10px;
  --shadow-sm:   0 1px 2px rgba(0,0,0,.04);
  --shadow:      0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg:   0 4px 12px rgba(0,0,0,.08);
  --transition:  150ms cubic-bezier(.4,0,.2,1);
  --font:        -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono:   "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
}

/* ---- Dark mode ---- */
[data-theme="dark"] {
  --bg:          #09090b;
  --bg-secondary:#18181b;
  --bg-hover:    #27272a;
  --bg-active:   #3f3f46;
  --border:      #27272a;
  --border-heavy:#3f3f46;
  --text:        #fafafa;
  --text-secondary:#a1a1aa;
  --text-muted:  #71717a;
  --accent:      #fafafa;
  --accent-light:#27272a;
  --tag-bg:      #27272a;
  --tag-text:    #d4d4d8;
  --code-bg:     #1c1c1f;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
img, svg { max-width: 100%; display: block; }

/* ---- Layout ---- */
.wiki-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-areas:
    "sidebar header"
    "sidebar main";
  min-height: 100vh;
}

/* ---- Header ---- */
.wiki-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
}
.wiki-header .breadcrumb {
  font-size: 0.875rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.wiki-header .breadcrumb .sep { color: var(--text-muted); }
.wiki-header .breadcrumb .current { color: var(--text); font-weight: 500; }

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

/* ---- Search ---- */
.search-wrapper {
  position: relative;
  width: 260px;
}
.search-wrapper input {
  width: 100%;
  padding: 7px 12px 7px 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  font-size: 0.8125rem;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-wrapper input::placeholder { color: var(--text-muted); }
.search-wrapper input:focus {
  border-color: var(--border-heavy);
  box-shadow: 0 0 0 3px rgba(0,0,0,.04);
}
[data-theme="dark"] .search-wrapper input:focus {
  box-shadow: 0 0 0 3px rgba(255,255,255,.06);
}
.search-wrapper .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 16px;
  height: 16px;
}
.search-results {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 320px;
  overflow-y: auto;
  z-index: 200;
}
.search-results.active { display: block; }
.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg-hover); }
.search-result-item .result-title { font-size: 0.875rem; font-weight: 500; }
.search-result-item .result-excerpt {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---- Theme toggle ---- */
.theme-toggle {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}
.theme-toggle:hover { background: var(--bg-hover); color: var(--text); }

/* ---- Sidebar ---- */
.wiki-sidebar {
  grid-area: sidebar;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  padding: 0 20px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.sidebar-brand h1 {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.sidebar-brand .subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.nav-section {
  padding: 0 12px;
  margin-bottom: 8px;
}
.nav-section-title {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 8px 8px 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--bg-active); color: var(--text); font-weight: 500; }
.nav-item .nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.6;
}
.nav-item.active .nav-icon { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 0.6875rem;
  color: var(--text-muted);
}

/* ---- Main content ---- */
.wiki-main {
  grid-area: main;
  padding: 40px 48px 80px;
  max-width: 900px;
  width: 100%;
}

/* ---- Typography ---- */
.wiki-main h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
  margin-bottom: 8px;
}
.wiki-main .page-description {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 32px;
  line-height: 1.6;
}
.wiki-main h2 {
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.wiki-main h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 12px;
}
.wiki-main p {
  margin-bottom: 16px;
  color: var(--text);
}
.wiki-main ul, .wiki-main ol {
  margin-bottom: 16px;
  padding-left: 24px;
}
.wiki-main li { margin-bottom: 6px; }

/* ---- Callout boxes ---- */
.callout {
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  border-left: 3px solid;
  font-size: 0.875rem;
}
.callout-info { background: #f0f4ff; border-color: #6366f1; }
.callout-warn { background: #fffbeb; border-color: #f59e0b; }
.callout-success { background: #f0fdf4; border-color: #22c55e; }
.callout-neutral { background: var(--bg-secondary); border-color: var(--border-heavy); }
[data-theme="dark"] .callout-info { background: #1e1b4b22; }
[data-theme="dark"] .callout-warn { background: #45340122; }
[data-theme="dark"] .callout-success { background: #05290e22; }

/* ---- Code ---- */
code {
  font-family: var(--font-mono);
  font-size: 0.8125em;
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
}
pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  overflow-x: auto;
  margin-bottom: 20px;
  font-size: 0.8125rem;
  line-height: 1.6;
}
pre code { background: none; padding: 0; }

/* ---- Tables ---- */
.wiki-main table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
  font-size: 0.875rem;
}
.wiki-main th {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border-heavy);
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.wiki-main td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.wiki-main tr:hover td { background: var(--bg-hover); }

/* ---- Tags ---- */
.tag {
  display: inline-block;
  padding: 2px 10px;
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}
.tag.gap-ok { background: #dcfce7; color: #166534; }
.tag.gap-warn { background: #fef9c3; color: #854d0e; }
.tag.gap-crit { background: #fef2f2; color: #991b1b; }

/* ---- Cards grid ---- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: box-shadow var(--transition), border-color var(--transition);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.card:hover {
  box-shadow: var(--shadow);
  border-color: var(--border-heavy);
}
.card .card-icon {
  width: 36px;
  height: 36px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  font-size: 1.25rem;
}
.card .card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.card .card-desc {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ---- Stat cards ---- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.stat-card .stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.stat-card .stat-change {
  font-size: 0.75rem;
  margin-top: 4px;
}
.stat-card .stat-change.positive { color: #22c55e; }
.stat-card .stat-change.negative { color: #ef4444; }

/* ---- Infographic / Chart containers ---- */
.chart-container {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
}
.chart-container .chart-title {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 16px;
}

/* Bar chart (pure CSS) */
.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 200px; padding-top: 8px; }
.bar-chart .bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: flex-end;
}
.bar-chart .bar {
  width: 100%;
  max-width: 48px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  transition: height 0.6s cubic-bezier(.4,0,.2,1);
  min-height: 4px;
}
.bar-chart .bar-label {
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-align: center;
}
.bar-chart .bar-value {
  font-size: 0.6875rem;
  font-weight: 600;
}

/* Progress bars */
.progress-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.progress-row .progress-label {
  width: 120px;
  font-size: 0.8125rem;
  flex-shrink: 0;
}
.progress-row .progress-track {
  flex: 1;
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 99px;
  overflow: hidden;
}
.progress-row .progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.8s cubic-bezier(.4,0,.2,1);
}
.progress-row .progress-value {
  width: 48px;
  text-align: right;
  font-size: 0.8125rem;
  font-weight: 600;
}

/* Timeline */
.timeline { position: relative; padding-left: 24px; margin-bottom: 24px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--border);
}
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-item::before {
  content: '';
  position: absolute;
  left: -20px;
  top: 6px;
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid var(--bg);
}
.timeline-item .timeline-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.timeline-item .timeline-title {
  font-size: 0.875rem;
  font-weight: 600;
}
.timeline-item .timeline-desc {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

/* ---- Responsive ---- */
@media (max-width: 860px) {
  .wiki-layout {
    grid-template-columns: 1fr;
    grid-template-areas: "header" "main";
  }
  .wiki-sidebar { display: none; }
  .wiki-main { padding: 24px 20px 60px; }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-heavy); }

/* ---- Print ---- */
@media print {
  .wiki-sidebar, .wiki-header { display: none; }
  .wiki-layout { grid-template-columns: 1fr; }
  .wiki-main { max-width: 100%; padding: 0; }
}
