/* === CSS Variables for consistent theming === */
:root {
  --primary-color: #2c3e50;
  --secondary-color: #3498db;
  --accent-color: #e74c3c;
  --success-color: #27ae60;
  --warning-color: #f39c12;
  --bg-light: #f8f9fa;
  --bg-white: #ffffff;
  --text-dark: #2c3e50;
  --text-light: #7f8c8d;
  --border-color: #e1e8ed;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  --border-radius: 8px;
  --transition: all 0.3s ease;

  /* Typography scale */
  --font-ui: "Inter", system-ui, -apple-system, sans-serif;
  --font-serif: "Source Serif 4", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", monospace; /* For data */

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;
  --text-2xl: 1.75rem;
  --text-3xl: 2.25rem;
  --text-4xl: 3rem;

  /* Line heights */
  --leading-tight: 1.35;
  --leading-normal: 1.5;
  --leading-relaxed: 1.6;

  /* Vertical rhythm */
  --spacing-unit: 24px;
  --spacing-lg: 32px;

  /* Content width - increased for better space usage */
  --content-width: 85ch;

  /* Table-specific variables */
  --table-max-width: 100%;
  --table-font-size: 0.95rem;
  --table-line-height: 1.4;
  --table-bg: #ffffff;
  --table-border: 1px solid #e0e0e0;
  --table-cell-padding-y: 0.75rem;
  --table-cell-padding-x: 1rem;
  --table-header-bg: #2c3e50;
  --table-header-text: #ffffff;
  --table-row-alt-bg: #f9f9f9;
  --table-row-hover-bg: #e3f2fd;
}

/* === Base Styles === */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-dark);
  background-color: var(--bg-light);
}

/* Typography hierarchy with new scale */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: var(--leading-tight);
  margin-bottom: var(--spacing-unit);
}

h1 {
  font-size: var(--text-4xl);
  margin-top: var(--spacing-lg);
}

h2 {
  font-size: var(--text-3xl);
  margin-top: var(--spacing-lg);
}

h3 {
  font-size: var(--text-2xl);
  margin-top: var(--spacing-unit);
}

h4 {
  font-size: var(--text-xl);
  margin-top: var(--spacing-unit);
}

h5 {
  font-size: var(--text-lg);
}

h6 {
  font-size: var(--text-base);
}

p,
ul,
ol {
  max-width: var(--content-width);
  line-height: var(--leading-relaxed);
  margin-bottom: var(--spacing-unit);
}

/* === Header & Navigation === */
.main-header {
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--secondary-color)
  );
  color: white;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.navbar {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.navbar h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: white;
  font-family: var(--font-serif);
  margin: 0;
}

.navbar h1 a {
  color: white !important;
  text-decoration: none;
  transition: var(--transition);
}

.navbar h1 a:hover {
  color: rgba(255, 255, 255, 0.9) !important;
}

.nav-links {
  display: flex;
  list-style: none;
  gap: 1rem;
  align-items: center;
  margin: 0;
  padding: 0;
}

.nav-links a {
  color: white;
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius);
}

.nav-links a:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.nav-links .dropdown-toggle {
  background: transparent;
  border: none;
  color: #fff;
  font-weight: 600;
  font-size: 1.1rem;
  padding: 0.5rem 0.8rem;
  border-radius: var(--border-radius);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.nav-links .dropdown-toggle:hover {
  background: rgba(255, 255, 255, 0.2);
  font-size: 1.15rem;
  transition: var(--transition);
}

.nav-links .dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  min-width: 200px;
  z-index: 200;
  display: none;
  list-style: none;
  padding: 0.5rem 0;
  margin: 0;
}

.nav-links .has-dropdown {
  position: relative;
}

.nav-links .dropdown li {
  margin: 0;
}

.nav-links .dropdown a {
  display: block;
  padding: 0.75rem 1rem;
  color: var(--text-dark);
  text-decoration: none;
  transition: var(--transition);
  border-radius: 0;
}

.nav-links .dropdown a:hover {
  background: var(--bg-light);
  transform: none;
}

.nav-links .has-dropdown:hover .dropdown {
  display: block;
}

.nav-links .has-dropdown.open .dropdown {
  display: block;
}

.menu-toggle {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  display: none;
  font-size: 1.25rem;
  min-width: 48px;
  min-height: 48px;
  transition: var(--transition);
}

.menu-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.6);
}

.menu-toggle.active {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.8);
  transform: rotate(90deg);
}

/* === Hero Section === */
.hero {
  background: linear-gradient(135deg, var(--bg-white), var(--bg-light));
  text-align: center;
  padding: 2.5rem 1.5rem; /* Reduced from 4rem 2rem */
  margin-bottom: var(--spacing-unit); /* Reduced from spacing-lg */
}

.hero h2 {
  font-size: var(--text-2xl); /* Reduced from text-3xl */
  margin-bottom: 0.75rem; /* Reduced */
  color: var(--primary-color);
  font-family: var(--font-serif);
  line-height: var(--leading-tight);
}

.hero-description {
  font-size: var(--text-base); /* Reduced from text-lg */
  line-height: var(--leading-relaxed);
  color: var(--text-light);
  max-width: var(--content-width);
  margin: 0 auto;
}

.hero .btn {
  display: inline-block;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  text-decoration: none;
}

.btn-primary {
  background: var(--secondary-color);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-color);
}

.btn-secondary {
  background: #fff;
  color: var(--primary-color);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-light);
}

.hero-cta {
  margin-top: 1rem;
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

/* === Content Sections === */
.content-section {
  max-width: 1400px; /* Increased from 1200px */
  margin: 0 auto var(--spacing-unit) auto; /* Reduced bottom margin */
  padding: 0 1rem; /* Reduced from 2rem */
}

.content-section h2 {
  font-size: var(--text-2xl); /* Slightly smaller */
  font-family: var(--font-serif);
  line-height: var(--leading-tight);
  color: var(--primary-color);
  margin-bottom: var(--spacing-unit); /* Reduced from spacing-lg */
  text-align: center;
  position: relative;
}

.content-section h2::after {
  content: "";
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 3px;
  background: var(--secondary-color);
  border-radius: 2px;
}

/* === Image Sections === */
.image-section {
  background: var(--bg-white);
  border-radius: var(--border-radius);
  padding: 1rem; /* Reduced from 2rem */
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem; /* Reduced from 2rem */
  min-height: 150px; /* Reduced from 200px */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 1rem; /* Reduced from 2rem */
}

img {
  max-width: 100%;
  width: 100%;
  height: auto;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  transition: var(--transition);
  margin-bottom: 0.5rem; /* Reduced from 1rem */
}

img:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.image-card {
  width: 100%;
}

.image-card img {
  width: 100%;
  height: auto;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  cursor: zoom-in;
  transition: var(--transition);
}

.image-card img:hover {
  transform: scale(1.01);
}

.image-card figcaption {
  margin-top: 0.5rem;
  color: var(--text-light);
  font-size: 0.9rem;
  text-align: center;
}

/* === TABLE STYLES - INDEPENDENT SECTION === */
/* All table-related styles are contained here and use table-specific CSS variables */

.table-container {
  background: var(--bg-white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1.5rem; /* Reduced from 2rem */
  overflow-x: auto;
  border: 1px solid var(--border-color);
  width: 100%; /* Ensure full width */
}

/* Base table styles */
table {
  width: 100%;
  max-width: 100%; /* Changed from var(--table-max-width) */
  margin: 1rem auto; /* Reduced from 2rem */
  border-collapse: collapse;
  font-size: var(--table-font-size);
  line-height: var(--table-line-height);
  background: var(--table-bg);
  border: var(--table-border);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

/* Table cells - tighter padding */
table th,
table td {
  padding: 0.5rem 0.75rem; /* Reduced from var(--table-cell-padding-y) var(--table-cell-padding-x) */
  border: 1px solid #ddd;
  vertical-align: top;
  transition: background 0.2s ease;
}

/* Table headers */
table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--table-header-bg) !important;
  color: var(--table-header-text) !important;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
}

table th {
  background: var(--table-header-bg) !important;
  color: var(--table-header-text) !important;
  text-align: left;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
}

/* Rounded header corners */
table th:first-child {
  border-top-left-radius: 4px;
}

table th:last-child {
  border-top-right-radius: 4px;
}

/* Zebra striping for table rows - applies to ALL cells uniformly */
table tbody tr:nth-child(odd) td {
  background: var(--table-bg) !important;
}

table tbody tr:nth-child(even) td {
  background: var(--table-row-alt-bg) !important;
}

/* Hover effect for table rows - applies to ALL cells uniformly */
table tbody tr:hover td {
  background: var(--table-row-hover-bg) !important;
  cursor: pointer;
}

table tbody tr:hover {
  transform: translateX(2px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Table links */
table tbody td a {
  color: var(--secondary-color);
  text-decoration: none;
  font-weight: 600;
  transition: var(--transition);
}

table tbody td a:hover {
  color: var(--primary-color);
  text-decoration: underline;
}

/* Sortable header style */
th.sortable {
  cursor: pointer;
}

th.sortable::after {
  content: " ⇅";
  font-weight: 400;
}

/* Specific table styles */
#rank-table {
  max-width: 100% !important;
}

#rank-table th {
  text-transform: capitalize;
  font-size: 0.9rem;
}

#rank-table tbody tr {
  transition: all 0.2s ease;
}

#rank-table tbody td {
  font-size: 0.9rem;
}

#rank-table tbody td:first-child {
  font-weight: 600;
  color: var(--primary-color);
}

#rank-table tbody tr:hover td:first-child,
#historical-analysis-table tbody tr:hover td:first-child {
  border-left: 3px solid var(--secondary-color);
}

/* Historical analysis table specific - only header styling */
#historical-analysis-table th {
  min-width: 80px;
  max-width: 120px;
  white-space: normal !important;
  text-align: center !important;
  vertical-align: middle !important;
  line-height: 1.2 !important;
  font-size: 0.85rem !important;
}

/* Remove special background for is-stat columns - use uniform zebra striping */
#historical-analysis-table td.is-stat {
  font-weight: 600;
  /* Removed: background-color rules to use uniform zebra striping */
}

/* === END OF TABLE STYLES === */

/* === Resources Section === */
.resources-section {
  background: var(--bg-white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 2rem 1.5rem; /* Reduced from 3rem 2rem */
}

.resource-category h3 {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  line-height: var(--leading-tight);
  color: var(--secondary-color);
  margin-bottom: var(--spacing-unit);
  text-align: left;
}

.resource-card {
  background: var(--bg-light);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  transition: var(--transition);
  margin-bottom: 1rem;
}

.resource-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow);
  border-color: var(--secondary-color);
}

.resource-card a {
  text-decoration: none;
  color: inherit;
  display: block;
}

.resource-card h4 {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  line-height: var(--leading-tight);
  color: var(--primary-color);
  margin-bottom: 0.5rem;
}

.resource-card p {
  color: var(--text-light);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  text-align: left;
}

/* === Footer === */
footer {
  background: var(--primary-color);
  color: white;
  text-align: center;
  padding: 1.5rem; /* Reduced from 2rem */
  margin-top: 2rem; /* Reduced from 4rem */
}

/* === Loading States === */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
  color: var(--text-light);
}

.loading::after {
  content: "";
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top: 3px solid var(--secondary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-left: 1rem;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* === Scroll to Top Button === */
.scroll-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--secondary-color);
  color: white;
  border: none;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: var(--transition);
  opacity: 0;
  visibility: hidden;
}

.scroll-to-top.visible {
  opacity: 1;
  visibility: visible;
}

.scroll-to-top:hover {
  background: var(--primary-color);
  transform: translateY(-3px);
}

/* === Utilities === */
.text-center {
  text-align: center !important;
}

.muted {
  color: var(--text-light) !important;
}

.heading-spaced-lg {
  margin-top: 40px;
  margin-bottom: 20px;
}

.heading-spaced-md {
  margin-top: 30px;
  margin-bottom: 15px;
}

.section-spaced {
  margin-bottom: 40px;
}

.list-unstyled {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.link-clean {
  text-decoration: none;
}

.link-clean:hover {
  text-decoration: underline;
}

.list-center li {
  text-align: center;
}

.p-center {
  text-align: center;
}

.image-section.section-spaced {
  margin-bottom: 40px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.show-more-btn {
  background: var(--secondary-color);
  color: #fff;
  border: none;
  padding: 0.55rem 1rem;
  border-radius: var(--border-radius);
  cursor: pointer;
  margin-top: 0.5rem;
  align-self: stretch;
  font-size: 0.9rem;
}

.show-more-btn:hover {
  background: var(--primary-color);
}

/* === Chart Explainer === */
.chart-explainer {
  width: 100%;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.chart-explainer summary {
  cursor: pointer;
  user-select: none;
  outline: none;
  font-size: 0.85rem;
}

.chart-explainer[open] summary {
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
}

.chart-explainer summary::marker {
  content: "▶ ";
}

.chart-explainer[open] summary::marker {
  content: "▼ ";
}

.chart-explainer .explainer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  padding: 0.75rem;
}

.chart-explainer .explainer-item h5 {
  margin: 0 0 0.25rem 0;
  font-size: 0.8rem;
  color: var(--secondary-color);
}

.chart-explainer .explainer-item p {
  font-size: 0.75rem;
  line-height: 1.4;
  margin: 0;
}

/* === Callouts & Grid === */
.callout {
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1rem;
  box-shadow: var(--shadow);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.bullet-tight {
  margin: 0.5rem 0 0;
  padding-left: 1rem;
}

.bullet-tight li {
  margin: 0.25rem 0;
}

/* === Compounding Effect Insight Section === */
.insight-container {
  display: flex;
  flex-direction: column;
  gap: 1rem; /* Reduced from 1.5rem */
  background: var(--bg-white);
  border-radius: var(--border-radius);
  padding: 1.5rem; /* Reduced from 2rem */
  box-shadow: var(--shadow);
  max-width: 1400px; /* Increased from 1200px */
  margin: 0 auto;
}

.insight-image {
  position: relative;
  width: 100%;
  margin: 0;
}

.insight-image img {
  width: 100%;
  height: auto;
  border-radius: var(--border-radius);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  transition: var(--transition);
  cursor: zoom-in;
  display: block;
}

.insight-image img:hover {
  transform: scale(1.01);
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.18);
}

.insight-image figcaption {
  margin-top: 0.5rem;
  color: var(--text-light);
  font-size: 0.9rem;
  text-align: center;
}

.insight-text {
  padding: 0 0.5rem; /* Reduced from 0 1rem */
  text-align: center;
}

.insight-text p {
  font-size: 0.85rem; /* Slightly larger for readability */
  line-height: 1.6; /* Reduced from 1.7 */
  color: var(--text-light);
  margin: 0 auto;
  max-width: 1000px; /* Increased from 900px */
}

/* === Lightbox === */
.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 2rem;
}

.lightbox-backdrop.open {
  display: flex;
}

.lightbox-image {
  max-width: 95vw;
  max-height: 80vh;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  background: #fff;
}

.lightbox-caption {
  margin-top: 0.75rem;
  color: #f0f0f0;
  text-align: center;
}

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: transparent;
  color: #fff;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
}

/* === Superinvestors Page === */
.superinvestors-page #si-metrics {
  display: block !important;
  grid-template-columns: none !important;
}

.superinvestors-page #si-metrics .si-card {
  display: block;
  width: 100%;
  margin: 0 0 1rem 0;
}

.superinvestors-page #si-metrics .si-card img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  object-fit: contain;
}

.superinvestors-page #superinvestor-gallery {
  display: block !important;
}

.superinvestors-page #superinvestor-gallery img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  object-fit: contain;
}

/* === Macro Page === */
.macro-page .macro-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 auto 1rem auto;
  max-width: 1200px;
  padding: 0 2rem;
}

.macro-page .macro-info {
  color: var(--text-light);
  font-size: 0.95rem;
}

.macro-page .macro-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.macro-page .chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  color: var(--text-dark);
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.9rem;
}

.macro-page .chip:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.macro-page .chip.active {
  background: var(--secondary-color);
  color: #fff;
  border-color: var(--secondary-color);
}

.macro-page .image-card {
  width: 100%;
}

.macro-page .image-card figure {
  width: 100%;
}

.macro-page .image-card figcaption {
  margin-top: 0.5rem;
  color: var(--text-light);
  font-size: 0.9rem;
  text-align: center;
}

/* === Stock Details Page Styles === */
body {
  background-color: #f4f7f6;
  color: #333;
  line-height: 1.6;
}

header {
  background-color: #2c3e50;
  color: white;
  padding: 15px 0;
  margin-bottom: 25px;
  text-align: center;
}

header h1 {
  color: white;
  font-size: 1.8em;
  margin: 0;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 15px;
}

.section-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 0;
  margin: 0 -15px 2rem -15px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.section-nav-scroll {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0 1rem;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.section-nav-scroll::-webkit-scrollbar {
  display: none;
}

.section-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  background: var(--bg-light);
  color: var(--text-dark);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  min-height: 44px;
}

.section-pill:hover {
  background: var(--bg-white);
  border-color: var(--secondary-color);
  transform: translateY(-1px);
}

.section-pill.active {
  background: var(--secondary-color);
  color: white;
  border-color: var(--secondary-color);
}

.comparison-legend {
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 0.75rem 1rem;
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-light);
}

.comparison-legend strong {
  color: var(--text-dark);
  margin-right: 0.5rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-icon {
  font-weight: bold;
  font-size: 1rem;
}

.legend-icon.better {
  color: var(--success-color);
}

.legend-icon.worse {
  color: var(--accent-color);
}

.legend-icon.equal {
  color: var(--text-light);
}

.financial-section {
  background-color: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 25px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  scroll-margin-top: 100px;
}

.financial-section h2 {
  margin-top: 0;
  color: #2c3e50;
  border-bottom: 2px solid #3498db;
  padding-bottom: 10px;
  margin-bottom: 20px;
  text-align: left;
  font-size: 1.5em;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.section-score {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-light);
  color: var(--text-dark);
  border: 1px solid var(--border-color);
}

.section-score.good {
  background: #d4edda;
  color: #155724;
  border-color: #c3e6cb;
}

.section-score.mixed {
  background: #fff3cd;
  color: #856404;
  border-color: #ffeaa7;
}

.section-score.poor {
  background: #f8d7da;
  color: #721c24;
  border-color: #f5c6cb;
}

.metrics-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 15px;
}

.metric {
  background-color: #f9f9f9;
  border: 1px solid #dcdcdc;
  border-radius: 6px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
  position: relative;
}

.metric-label {
  font-weight: bold;
  color: #555;
  margin-bottom: 8px;
  font-size: 0.9em;
}

.metric-value-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

.metric-indicator {
  font-size: 1.2rem;
  font-weight: bold;
  line-height: 1;
  flex-shrink: 0;
}

.metric-indicator.better {
  color: var(--success-color);
}

.metric-indicator.worse {
  color: var(--accent-color);
}

.metric-indicator.equal {
  color: var(--text-light);
}

.metric-value {
  font-family: "Consolas", "Courier New", Courier, monospace;
  color: #333;
  background-color: #eef1f5;
  padding: 6px 10px;
  border-radius: 4px;
  font-weight: bold;
  font-size: 1.1em;
  flex: 1;
}

.metric-median-container {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 0.5rem;
  font-style: italic;
}

.metric-value-median {
  font-family: "Consolas", "Courier New", Courier, monospace;
  font-weight: 500;
  color: #666;
}

.metric-better {
  background-color: #d4edda;
  color: #155724;
}

.metric-worse {
  background-color: #f8d7da;
  color: #721c24;
}

.navigation-links {
  text-align: center;
  margin-top: 30px;
  margin-bottom: 30px;
}

.navigation-links a {
  display: inline-block;
  padding: 12px 25px;
  background-color: #3498db;
  color: white;
  text-decoration: none;
  border-radius: 5px;
  transition: background-color 0.2s ease-in-out;
  font-weight: bold;
  min-height: 44px;
}

.navigation-links a:hover {
  background-color: #2980b9;
}

/* === Responsive Design === */
@media (max-width: 768px) {
  .navbar {
    flex-direction: column;
    gap: 1rem;
  }

  .nav-links {
    width: 100%;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    margin-top: 0;
    transition: max-height 0.3s ease, opacity 0.3s ease, margin-top 0.3s ease;
  }

  .nav-links.open {
    max-height: 600px;
    opacity: 1;
    margin-top: 0.5rem;
  }

  .nav-links > li {
    width: 100%;
  }

  .nav-links .dropdown-toggle {
    width: 100%;
    text-align: left;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.75rem 1rem;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 6px;
    transition: var(--transition);
  }

  .nav-links .dropdown-toggle::after {
    content: "▼";
    font-size: 0.8rem;
    transition: transform 0.2s ease;
    margin-left: auto;
  }

  .nav-links .has-dropdown.open .dropdown-toggle::after {
    transform: rotate(180deg);
  }

  .nav-links .dropdown-toggle:hover,
  .nav-links .dropdown-toggle:focus {
    background: rgba(255, 255, 255, 0.2);
  }

  .nav-links .dropdown {
    position: static;
    border: 1px solid rgba(255, 255, 255, 0.2);
    margin-top: 0.25rem;
    background: rgba(255, 255, 255, 0.05);
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
  }

  .nav-links .has-dropdown.open .dropdown {
    max-height: 400px;
    opacity: 1;
  }

  .nav-links .dropdown a {
    padding: 0.875rem 1.25rem;
    min-height: 48px;
    display: flex;
    align-items: center;
    color: white;
    background: transparent;
    transition: var(--transition);
  }

  .nav-links .dropdown a:hover,
  .nav-links .dropdown a:active {
    background: rgba(255, 255, 255, 0.15);
  }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .image-card figcaption {
    font-size: 0.75rem !important;
  }

  .insight-image figcaption {
    font-size: 0.75rem !important;
  }

  .chart-explainer summary {
    font-size: 0.8rem !important;
  }

  .chart-explainer .explainer-item h5 {
    font-size: 0.75rem !important;
  }

  .chart-explainer .explainer-item p {
    font-size: 0.7rem !important;
    line-height: 1.3 !important;
  }

  .chart-explainer .explainer-grid {
    padding: 0.5rem !important;
    gap: 0.5rem !important;
  }

  .section-nav {
    top: 0;
    margin: 0 -15px 1.5rem -15px;
  }

  .content-section {
    padding: 0 0.75rem; /* Even tighter on mobile */
  }

  .image-section {
    padding: 0.75rem;
  }

  .insight-container {
    padding: 1rem;
    gap: 0.75rem;
  }

  .metrics-container {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .metric {
    padding: 12px;
  }

  .metric-label {
    font-size: 0.85rem;
    margin-bottom: 6px;
    display: block;
    width: 100%;
  }

  .metric-value-wrapper {
    margin-bottom: 6px;
    width: 100%;
  }

  .metric-indicator {
    font-size: 1.1rem;
  }

  .metric-value {
    font-size: 1rem;
    padding: 8px 12px;
  }

  .metric-median-container {
    font-size: 0.7rem;
    margin-top: 4px;
    display: block;
    width: 100%;
  }

  .financial-section {
    padding: 15px;
    margin-bottom: 20px;
    scroll-margin-top: 70px;
  }

  .financial-section h2 {
    font-size: 1.25em;
    padding-bottom: 8px;
    margin-bottom: 15px;
    gap: 0.5rem;
  }

  .section-score {
    font-size: 0.7rem;
    padding: 0.3rem 0.5rem;
  }

  .comparison-legend {
    padding: 0.5rem 0.75rem;
    gap: 1rem;
    font-size: 0.8rem;
  }

  .legend-icon {
    font-size: 0.9rem;
  }

  .section-pill {
    min-height: 44px;
    min-width: 44px;
    padding: 0.5rem 0.875rem;
    font-size: 0.85rem;
  }

  .navigation-links a {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  header h1 {
    font-size: 1.4em;
    padding: 0 10px;
  }

  main {
    padding: 0 10px;
  }

  .insight-container {
    padding: 1.5rem;
    gap: 1rem;
  }

  .insight-text {
    padding: 0 0.5rem;
  }

  .insight-text p {
    font-size: 0.8rem;
  }

  .hidden-mobile {
    display: none !important;
  }

  .chart-explainer[open] summary {
    font-weight: 600;
  }

  .chart-explainer summary {
    font-size: 0.95rem;
  }
}

@media (max-width: 480px) {
  .section-pill {
    font-size: 0.8rem;
    padding: 0.45rem 0.75rem;
  }

  .financial-section h2 {
    font-size: 1.1em;
  }

  .metric-value {
    font-size: 0.95rem;
  }

  header h1 {
    font-size: 1.2em;
  }
}

/* Apply mono font to data elements */
.cagr-value,
.drawdown-stat,
table td {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums; /* Aligns numbers vertically */
}
