/* ─── Design System ─────────────────────────────────────────────────────────── */

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #161822;
  --bg-tertiary: #1c1f2e;
  --bg-card: #1a1d2e;
  --bg-hover: #232740;
  --bg-sidebar: #0c0e14;
  --border: #2a2d3e;
  --border-light: #353850;
  --text-primary: #e4e6f0;
  --text-secondary: #9ca0b8;
  --text-muted: #6b6f88;
  --accent: #6c8aff;
  --accent-dim: #4a62cc;
  --accent-glow: rgba(108, 138, 255, 0.15);
  --green: #34d399;
  --green-dim: rgba(52, 211, 153, 0.15);
  --red: #f87171;
  --red-dim: rgba(248, 113, 113, 0.15);
  --orange: #fbbf24;
  --orange-dim: rgba(251, 191, 36, 0.15);
  --purple: #a78bfa;
  --blue: #60a5fa;
  --sidebar-width: 260px;
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 150ms ease;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

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

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.logo svg {
  color: var(--accent);
}

.sidebar-subtitle {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.nav-links {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  transition: all var(--transition);
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--accent-glow);
  color: var(--accent);
}

.nav-link.active svg {
  color: var(--accent);
}

.nav-link svg {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: color var(--transition);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.sidebar-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ─── Main Content ──────────────────────────────────────────────────────────── */

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
}

.content-wrapper {
  max-width: 960px;
  margin: 0 auto;
  padding: 40px 48px 80px;
}

/* ─── Markdown Content ──────────────────────────────────────────────────────── */

.markdown-body {
  line-height: 1.7;
  color: var(--text-primary);
}

.markdown-body h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.markdown-body h2 {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 40px;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.markdown-body h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-top: 28px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.markdown-body h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 20px;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.markdown-body p {
  margin-bottom: 14px;
}

.markdown-body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition);
}

.markdown-body a:hover {
  border-bottom-color: var(--accent);
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 24px;
  margin-bottom: 14px;
}

.markdown-body li {
  margin-bottom: 6px;
}

.markdown-body li > ul,
.markdown-body li > ol {
  margin-top: 4px;
  margin-bottom: 4px;
}

.markdown-body strong {
  font-weight: 600;
  color: var(--text-primary);
}

.markdown-body em {
  color: var(--text-secondary);
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

/* Images */
.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin: 16px 0;
  display: block;
}

/* Tables */
.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0 24px;
  font-size: 0.88rem;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.markdown-body thead {
  background: var(--bg-tertiary);
}

.markdown-body th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.markdown-body td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.markdown-body tr:last-child td {
  border-bottom: none;
}

.markdown-body tbody tr:hover {
  background: var(--bg-hover);
}

/* Code */
.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

.markdown-body pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  margin: 16px 0;
}

.markdown-body pre code {
  background: none;
  padding: 0;
  font-size: 0.85rem;
  color: var(--text-primary);
}

/* Blockquotes */
.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 12px 20px;
  margin: 16px 0;
  background: var(--accent-glow);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-secondary);
}

.markdown-body blockquote p:last-child {
  margin-bottom: 0;
}

.markdown-body blockquote strong {
  color: var(--accent);
}

/* ─── KPI Cards ─────────────────────────────────────────────────────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: border-color var(--transition);
}

.kpi-card:hover {
  border-color: var(--border-light);
}

.kpi-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.kpi-value.green { color: var(--green); }
.kpi-value.red { color: var(--red); }
.kpi-value.orange { color: var(--orange); }
.kpi-value.accent { color: var(--accent); }

.kpi-detail {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: var(--font-mono);
}

/* ─── Chart Containers ──────────────────────────────────────────────────────── */

.chart-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.chart-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.chart-toggle {
  display: flex;
  gap: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.chart-toggle button {
  padding: 6px 14px;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--font-sans);
  border: none;
  cursor: pointer;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  transition: all var(--transition);
}

.chart-toggle button.active {
  background: var(--accent);
  color: #fff;
}

.chart-toggle button:hover:not(.active) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.chart-canvas-wrapper {
  position: relative;
  width: 100%;
  max-height: 420px;
}

.chart-canvas-wrapper canvas {
  width: 100% !important;
  max-height: 400px;
}

.chart-static-img {
  width: 100%;
  border-radius: var(--radius);
}

/* ─── Model Detail Panels (inside chart sections) ──────────────────────────── */

.model-details {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.model-detail-section {
  border: none !important;
  background: transparent !important;
  border-radius: 0 !important;
  margin: 0 !important;
}

.model-detail-section summary {
  padding: 10px 12px !important;
  font-size: 0.82rem !important;
  font-weight: 600 !important;
  color: var(--text-secondary) !important;
  border-radius: var(--radius) !important;
  gap: 8px !important;
}

.model-detail-section summary:hover {
  background: var(--bg-hover) !important;
  color: var(--text-primary) !important;
}

.model-detail-section summary::before {
  border-left-color: var(--text-muted) !important;
}

.model-detail-body {
  padding: 8px 12px 16px 26px;
}

.model-detail-body p {
  font-size: 0.85rem;
  line-height: 1.65;
  color: var(--text-secondary);
  margin-bottom: 0;
}

.model-detail-body code {
  font-family: var(--font-mono);
  font-size: 0.8em;
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

.model-detail-body strong {
  color: var(--text-primary);
  font-weight: 600;
}

.model-detail-body strong.red {
  color: var(--red);
}

.model-detail-body strong.green-text {
  color: var(--green);
}

.model-detail-body strong.blue-text {
  color: var(--blue);
}

.model-detail-body ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.model-detail-body ul li {
  font-size: 0.85rem;
  color: var(--text-secondary);
  padding: 5px 0;
  padding-left: 18px;
  position: relative;
  line-height: 1.5;
}

.model-detail-body ul li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 12px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.6;
}

/* Assumptions table inside model details */
.assumptions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.assumptions-table thead {
  background: var(--bg-tertiary);
}

.assumptions-table th {
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.assumptions-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  line-height: 1.5;
}

.assumptions-table td:first-child {
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  width: 180px;
}

.assumptions-table tr:last-child td {
  border-bottom: none;
}

.assumptions-table tbody tr:hover {
  background: var(--bg-hover);
}

/* ─── Mini Charts (Overview) ────────────────────────────────────────────────── */

.mini-chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 32px;
}

.mini-chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.mini-chart-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.mini-chart-wrapper {
  height: 160px;
}

/* ─── Checkbox Styling (Info Gaps) ──────────────────────────────────────────── */

.markdown-body input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-light);
  border-radius: 4px;
  background: var(--bg-tertiary);
  cursor: pointer;
  position: relative;
  top: 3px;
  margin-right: 8px;
  transition: all var(--transition);
}

.markdown-body input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.markdown-body input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 6px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.markdown-body input[type="checkbox"]:hover {
  border-color: var(--accent-dim);
}

/* ─── Collapsible Details (Playbook) ────────────────────────────────────────── */

.markdown-body details {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 12px 0;
  overflow: hidden;
}

.markdown-body details summary {
  padding: 14px 18px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-primary);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background var(--transition);
}

.markdown-body details summary:hover {
  background: var(--bg-hover);
}

.markdown-body details summary::before {
  content: '';
  width: 0;
  height: 0;
  border-left: 6px solid var(--text-muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform var(--transition);
  flex-shrink: 0;
}

.markdown-body details[open] summary::before {
  transform: rotate(90deg);
}

.markdown-body details summary::-webkit-details-marker {
  display: none;
}

.markdown-body details > :not(summary) {
  padding: 0 18px;
}

.markdown-body details > p:last-child,
.markdown-body details > ul:last-child,
.markdown-body details > ol:last-child {
  padding-bottom: 14px;
}

/* ─── Section Dividers ──────────────────────────────────────────────────────── */

.section-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 16px;
  margin-top: 40px;
}

.section-label:first-child {
  margin-top: 0;
}

/* ─── Page Title ────────────────────────────────────────────────────────────── */

.page-title {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.page-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 32px;
}

/* ─── Loading ───────────────────────────────────────────────────────────────── */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.loading::after {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin-left: 10px;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Scrollbar ─────────────────────────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* ─── Equity Mechanics — Comparison Cards ──────────────────────────────────── */

.iso-nso-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.comparison-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.comparison-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.comparison-card.iso::before { background: var(--green); }
.comparison-card.nso::before { background: var(--orange); }

.comparison-card-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.comparison-card-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.comparison-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.comparison-row:last-child { border-bottom: none; }

.comparison-row-label {
  color: var(--text-muted);
  font-weight: 500;
}

.comparison-row-value {
  color: var(--text-primary);
  font-weight: 600;
  text-align: right;
  max-width: 60%;
}

.comparison-row-value.green { color: var(--green); }
.comparison-row-value.red { color: var(--red); }
.comparison-row-value.orange { color: var(--orange); }

.tax-savings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}

.tax-savings-table thead { background: var(--bg-tertiary); }

.tax-savings-table th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tax-savings-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.tax-savings-table tr:last-child td { border-bottom: none; }
.tax-savings-table tbody tr:hover { background: var(--bg-hover); }

/* Protection cards */
.protection-cards {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.protection-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.protection-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.protection-card-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.protection-card-icon.blue { background: rgba(96, 165, 250, 0.15); color: var(--blue); }
.protection-card-icon.purple { background: rgba(167, 139, 250, 0.15); color: var(--purple); }
.protection-card-icon.green { background: rgba(52, 211, 153, 0.15); color: var(--green); }

.protection-card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.protection-card-body {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.65;
}

.protection-card-body p { margin-bottom: 8px; }
.protection-card-body p:last-child { margin-bottom: 0; }

.protection-card-body strong { color: var(--text-primary); }

.protection-example {
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 10px 0;
  font-size: 0.82rem;
  font-family: var(--font-mono);
  line-height: 1.7;
  color: var(--text-secondary);
}

.protection-example strong { color: var(--text-primary); }
.protection-example .green { color: var(--green); }
.protection-example .red { color: var(--red); }
.protection-example .orange { color: var(--orange); }

/* Action callouts */
.action-callout {
  background: var(--accent-glow);
  border: 1px solid rgba(108, 138, 255, 0.25);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 12px 16px;
  margin: 12px 0;
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 500;
}

/* Scenario toggle for equity mechanics */
.scenario-toggle {
  display: flex;
  gap: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.scenario-toggle button {
  padding: 6px 14px;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--font-sans);
  border: none;
  cursor: pointer;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  transition: all var(--transition);
}

.scenario-toggle button.active {
  background: var(--accent);
  color: #fff;
}

.scenario-toggle button:hover:not(.active) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Key insight box */
.key-insight {
  background: var(--green-dim);
  border: 1px solid rgba(52, 211, 153, 0.25);
  border-left: 3px solid var(--green);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 14px 18px;
  margin: 16px 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.key-insight strong { color: var(--green); }

/* ─── Responsive ────────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .sidebar {
    width: 220px;
  }
  .main-content {
    margin-left: 220px;
  }
  .content-wrapper {
    padding: 24px;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .mini-chart-grid {
    grid-template-columns: 1fr;
  }
  .iso-nso-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .sidebar {
    display: none;
  }
  .main-content {
    margin-left: 0;
  }
}
