/* ============================================================
   AI Through Dragonfly Eyes — Shared Design System v2
   Matching Iran Crisis briefing aesthetic
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400&display=swap');

/* ---- CSS Custom Properties ---- */
:root {
  /* Narrative Colors */
  --n-builders: #10B981;
  --n-displaced: #F59E0B;
  --n-hawks: #3B82F6;
  --n-power-critics: #8B5CF6;
  --n-disruptors: #EF4444;
  --n-truth-crisis: #F97316;
  --n-environmental: #22C55E;
  --n-safety: #EC4899;
  --n-humanists: #6366F1;

  /* Pair Colors */
  --pair-work: #D97706;
  --pair-power: #7C3AED;
  --pair-information: #DC2626;
  --unmirrored: #475569;

  /* Edge / Relationship Semantics */
  --edge-convergence: #10B981;
  --edge-tension: #EF4444;
  --edge-mirror: #3B82F6;
  --edge-switching: #F59E0B;
  --edge-source: #94A3B8;

  /* Neutral Palette (Tailwind Slate) */
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --slate-950: #020617;

  /* Semantic */
  --text-heading: var(--slate-900);
  --text-body: var(--slate-800);
  --text-secondary: var(--slate-600);
  --text-muted: var(--slate-400);
  --text-label: var(--slate-700);
  --border: var(--slate-200);
  --border-strong: var(--slate-300);
  --surface: #ffffff;
  --surface-raised: #f8f9fb;
  --surface-dark: var(--slate-900);
  --accent-blue: #2563eb;
  --accent-blue-dim: rgba(37, 99, 235, 0.06);

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-subtle: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.15);

  /* Transitions */
  --ease-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;

  /* Layout */
  --sidebar-width: 280px;
  --detail-width: 340px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

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

/* ---- Base Typography ---- */
html { scroll-behavior: smooth; }

body {
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.7;
  color: var(--text-body);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { color: var(--text-heading); line-height: 1.3; }

h1 { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 22px; font-weight: 700; }
h3 { font-size: 17px; font-weight: 600; }
h4 { font-size: 15px; font-weight: 600; }

p { margin-bottom: 14px; color: var(--text-body); }
strong { font-weight: 600; color: var(--text-heading); }

/* ---- Links ---- */
a { color: var(--slate-600); text-decoration: none; transition: color var(--duration-fast) var(--ease-out); }
a:hover { color: var(--text-heading); }


/* ============================================================
   LAYOUT SYSTEM
   ============================================================ */

/* ---- Left Sidebar (fixed, always visible) ---- */
.sidebar-left {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--surface-raised);
  border-right: 1px solid var(--border);
  padding: 32px 24px 24px;
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

/* ---- Main Visualization Area (fixed, for SVG pages) ---- */
.main-viz {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  bottom: 0;
  overflow: hidden;
  transition: right 300ms var(--ease-out);
}

/* When detail panel is open, shrink main viz */
.main-viz.detail-open {
  right: var(--detail-width);
}

/* ---- Main Content Area (scrollable, for content pages) ---- */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  padding: 48px 56px 80px;
  transition: margin-right var(--duration-slow) var(--ease-out);
}

.main-content.detail-open {
  margin-right: var(--detail-width);
}

.main-content {
  transition: margin-right 300ms var(--ease-out);
}

.content-inner {
  max-width: 768px;
  width: 100%;
  margin: 0 auto;
}

/* ---- Detail Panel (slides in from right) ---- */
.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--detail-width);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 500;
  overflow-y: auto;
  transform: translateX(100%);
  opacity: 0;
  transition: transform var(--duration-slow) var(--ease-out),
              opacity var(--duration-normal) var(--ease-out);
}

.detail-panel.open {
  transform: translateX(0);
  opacity: 1;
  box-shadow: var(--shadow-md);
}


/* ============================================================
   LEFT SIDEBAR COMPONENTS
   ============================================================ */

/* Logo */
.sidebar-logo {
  display: block;
  width: 180px;
  height: auto;
  padding-bottom: 18px;
  margin-bottom: 14px;
}

/* Site Navigation */
.sidebar-nav-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2.5px;
  color: var(--text-label);
  margin-bottom: 8px;
}

.sidebar-nav-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-bottom: 0;
  border-left: 1px solid var(--border);
  padding-left: 0;
}

.sidebar-nav-item {
  display: block;
  padding: 5px 10px 5px 14px;
  font-size: 13px;
  font-weight: 400;
  color: var(--slate-600);
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -1px;
  line-height: 1.45;
  transition: color var(--duration-fast) ease, border-color var(--duration-fast) ease, background var(--duration-fast) ease;
}

.sidebar-nav-item:hover {
  color: var(--text-heading);
  background: rgba(15, 23, 42, 0.03);
}

.sidebar-nav-item.active {
  color: var(--accent-blue);
  border-left-color: var(--accent-blue);
  background: var(--accent-blue-dim);
  font-weight: 500;
}

/* Divider */
.sidebar-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0 20px;
}

/* Page context */
.sidebar-classification {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2.5px;
  color: var(--text-label);
  margin-bottom: 28px;
}

.sidebar-page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-heading);
  line-height: 1.3;
  margin-bottom: 4px;
}

.sidebar-page-subtitle {
  font-size: 13px;
  color: var(--slate-500);
  margin-bottom: 4px;
}

.sidebar-framing {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 10px 0 0 0;
  font-style: italic;
}

.sidebar-page-date {
  font-size: 13px;
  color: var(--slate-500);
  margin-bottom: 16px;
}

.sidebar-page-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.55;
  margin-bottom: 16px;
}

/* Table of Contents / Section label */
.sidebar-section-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2.5px;
  color: var(--text-label);
  margin-bottom: 10px;
  margin-top: 4px;
}

/* TOC items */
.toc-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.toc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--slate-600);
  cursor: pointer;
  transition: background var(--duration-fast) ease, color var(--duration-fast) ease;
  line-height: 1.45;
}

.toc-item:hover {
  background: var(--slate-100);
  color: var(--text-heading);
}

.toc-item.active {
  background: var(--accent-blue-dim);
  color: var(--text-heading);
}

.toc-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.toc-number {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  width: 18px;
  flex-shrink: 0;
}

.toc-text {
  font-size: 13px;
  font-weight: 400;
  color: inherit;
}

.toc-section-header {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-top: 14px;
  margin-bottom: 6px;
  padding-left: 2px;
}


/* ============================================================
   DETAIL PANEL CONTENT
   ============================================================ */

.detail-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--surface-raised);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  z-index: 10;
  transition: background var(--duration-fast);
}
.detail-close:hover { background: var(--slate-200); }

.detail-header {
  padding: 24px 48px 18px 24px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.detail-body {
  padding: 20px 24px 32px;
}

.detail-section {
  margin-bottom: 24px;
}

.detail-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.detail-text {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-body);
}

.detail-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}


/* ============================================================
   REUSABLE COMPONENTS
   ============================================================ */

/* ---- Page Header ---- */
.page-header {
  margin-bottom: 48px;
}

.page-header h1 {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-heading);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.page-header .subtitle {
  font-size: 14px;
  font-weight: 300;
  color: var(--slate-500);
}

.page-header .meta-line {
  font-size: 13px;
  color: var(--slate-500);
  margin-top: 4px;
}

/* ---- Section Labels ---- */
.section-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-muted);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: box-shadow var(--duration-normal) var(--ease-out), border-color var(--duration-fast);
}

.card:hover {
  box-shadow: var(--shadow-subtle);
}

.card-accent {
  border-left: 3px solid var(--accent-color, var(--slate-400));
}

/* ---- Callout ---- */
.callout {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid #002D9C;
  padding: 16px 20px;
  border-radius: 0 8px 8px 0;
  margin: 18px 0 22px;
}

.callout p { margin-bottom: 6px; color: var(--text-body); }
.callout p:last-child { margin-bottom: 0; }

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-narrative {
  color: white;
  background: var(--badge-color, var(--slate-500));
}

.badge-outline {
  color: var(--badge-color, var(--slate-500));
  background: transparent;
  border: 1px solid currentColor;
}

.badge-gain { background: rgba(16, 185, 129, 0.1); color: #059669; border: 1px solid rgba(5, 150, 105, 0.2); }
.badge-loss { background: rgba(239, 68, 68, 0.1); color: #dc2626; border: 1px solid rgba(220, 38, 38, 0.2); }
.badge-unmirrored { background: rgba(71, 85, 105, 0.1); color: #475569; border: 1px solid rgba(71, 85, 105, 0.2); }

/* ---- Filter Buttons ---- */
.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  font-family: inherit;
}

.filter-btn:hover {
  border-color: var(--border-strong);
  color: var(--text-body);
}

.filter-btn.active {
  background: var(--slate-800);
  color: white;
  border-color: var(--slate-800);
}

.filter-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---- Tooltip ---- */
.tooltip {
  position: fixed;
  pointer-events: none;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  box-shadow: var(--shadow-lg);
  max-width: 320px;
  z-index: 2000;
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-out);
  font-size: 13px;
  line-height: 1.5;
}

.tooltip.visible { opacity: 1; }
.tooltip-title { font-weight: 600; margin-bottom: 4px; color: var(--text-heading); }
.tooltip-subtitle { font-size: 12px; color: var(--text-secondary); }

/* ---- Search Box ---- */
.search-box {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--text-body);
  background: var(--surface);
  transition: border-color var(--duration-fast);
  margin-bottom: 16px;
}
.search-box:focus {
  outline: none;
  border-color: var(--slate-400);
}
.search-box::placeholder { color: var(--text-muted); }

/* ---- Legend ---- */
.legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-body);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-line {
  width: 24px;
  height: 2px;
  flex-shrink: 0;
}

.legend-line-dashed {
  background: repeating-linear-gradient(
    90deg, currentColor 0, currentColor 4px, transparent 4px, transparent 8px
  );
  height: 2px;
  width: 24px;
}

/* ---- Stats Row ---- */
.stats-row {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.stat-item {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  text-align: center;
  flex: 1;
  min-width: 80px;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-heading);
  line-height: 1.2;
}

.stat-label {
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-top: 2px;
}


/* ============================================================
   ANIMATIONS
   ============================================================ */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.animate-in {
  animation: fadeIn var(--duration-normal) var(--ease-out) forwards;
}


/* ============================================================
   SCROLLBAR
   ============================================================ */

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(15, 23, 42, 0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(15, 23, 42, 0.2); }


/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Sidebar toggle (mobile) */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-body);
  box-shadow: var(--shadow-sm);
  font-family: inherit;
}

@media (max-width: 1400px) {
  /* Detail panel overlays instead of pushing */
  .main-viz.detail-open {
    right: 0;
  }
  .main-content.detail-open {
    margin-right: 0;
  }
  .detail-panel.open {
    box-shadow: var(--shadow-xl);
  }
}

@media (max-width: 1000px) {
  .sidebar-left {
    transform: translateX(-100%);
  }
  .sidebar-left.open {
    transform: translateX(0);
  }
  .sidebar-toggle {
    display: flex;
  }
  .main-viz {
    left: 0;
  }
  .main-content {
    margin-left: 0;
    padding: 48px 24px;
  }
}
