/* ===== Custom Properties ===== */
:root {
  --color-primary: #228be6;
  --color-primary-hover: #1c7ed6;
  --color-primary-dark: #1971c2;
  --color-primary-darkest: #1864ab;
  --color-primary-light: #74c0fc;
  --color-primary-bg: #e7f5ff;
  --color-primary-ring: rgba(34,139,230,0.2);

  --color-text: #1a1a1a;
  --color-text-secondary: #495057;
  --color-text-muted: #868e96;
  --color-text-dim: #adb5bd;

  --color-bg: #f8f9fa;
  --color-surface: #fff;
  --color-surface-hover: #e9ecef;
  --color-surface-alt: #f1f3f5;

  --color-border: #dee2e6;
  --color-border-light: #e9ecef;
  --color-border-input: #ced4da;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.2);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.3);
  --shadow-nav: 0 1px 3px rgba(0,0,0,0.06);
}

/* ===== Accessibility Helpers ===== */
.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;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 110px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial,
    sans-serif;
  font-size: 16px;
  line-height: 1.65;
  color: var(--color-text);
  background: var(--color-bg);
}

/* ===== Top Navigation ===== */
.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-nav);
}

.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  padding: 0 20px;
  height: 56px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 17px;
  color: var(--color-text);
  margin-right: 32px;
  white-space: nowrap;
  text-decoration: none;
}
.nav-logo {
  height: 20px;
  width: auto;
  filter: brightness(0);
}

.nav-tabs {
  display: flex;
  gap: 4px;
  list-style: none;
}

.nav-tab {
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}

.nav-tab:hover {
  background: var(--color-surface-hover);
}

.nav-tab.active {
  background: var(--color-primary);
  color: #fff;
}

/* ===== Nav Icon Buttons (shared base for search, dark toggle, strategy) ===== */
.nav-search-btn,
.dark-toggle,
.nav-strategy-btn {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--color-text-secondary);
  transition: background 0.15s, color 0.15s;
  line-height: 1;
  flex-shrink: 0;
}

.nav-search-btn:hover,
.dark-toggle:hover,
.nav-strategy-btn:hover {
  background: var(--color-surface-hover);
}

.nav-search-btn {
  display: flex;
  align-items: center;
  margin-left: auto;
}

/* ===== Hamburger Menu Button ===== */
.nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 8px;
  cursor: pointer;
  margin-right: 8px;
  flex-shrink: 0;
}

.nav-hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--color-text-secondary);
  border-radius: 1px;
  transition: transform 0.2s, opacity 0.2s;
}

.nav-hamburger.open span:nth-child(1) {
  transform: rotate(45deg) translate(4px, 4px);
}

.nav-hamburger.open span:nth-child(2) {
  opacity: 0;
}

.nav-hamburger.open span:nth-child(3) {
  transform: rotate(-45deg) translate(4px, -4px);
}

/* ===== Report Selector Bar ===== */
.selector-bar {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  z-index: 99;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.selector-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.selector-inner .report-toggle { order: 1; }
.selector-inner .report-dropdown { order: 2; }
.selector-inner .reading-time { order: 3; margin-left: auto; }
.selector-inner .action-btn { order: 4; }

/* Report Toggle */
.report-toggle {
  display: flex;
  flex-shrink: 0;
}

.toggle-btn {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--color-border-input);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.toggle-btn:first-child {
  border-radius: 6px 0 0 6px;
  border-right: none;
}

.toggle-btn:last-child {
  border-radius: 0 6px 6px 0;
}

.toggle-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.toggle-btn:hover:not(.active) {
  background: var(--color-surface-hover);
}

.report-dropdown {
  padding: 6px 12px;
  font-size: 14px;
  border: 1px solid var(--color-border-input);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  min-width: 220px;
}

.report-dropdown:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary-ring);
}

/* ===== Layout ===== */
.page-body {
  margin-top: 110px;
  display: flex;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  padding: 20px;
  gap: 32px;
}

/* ===== Table of Contents Sidebar ===== */
.toc-sidebar {
  width: 240px;
  flex-shrink: 0;
  position: sticky;
  top: 130px;
  align-self: flex-start;
  max-height: calc(100vh - 150px);
  overflow-y: auto;
  background: var(--color-surface);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.toc-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--color-text-muted);
  margin-bottom: 12px;
  padding-left: 12px;
}

.toc-list {
  list-style: none;
}

.toc-item {
  margin-bottom: 2px;
}

.toc-link {
  display: block;
  padding: 5px 12px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--color-text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  border-radius: 0 4px 4px 0;
  transition: all 0.15s;
}

.toc-link:hover {
  color: var(--color-primary);
  background: var(--color-surface-alt);
}

.toc-link.active {
  color: var(--color-primary);
  border-left-color: var(--color-primary);
  background: var(--color-primary-bg);
  font-weight: 600;
}

/* TOC sub-items (h3 headings nested under h2) */
.toc-sub-list {
  list-style: none;
  margin: 2px 0 2px 0;
  padding: 0;
}

.toc-item-sub {
  margin-bottom: 1px;
}

.toc-link-sub {
  padding-left: 24px;
  font-size: 12px;
}

.toc-link-sub.active {
  font-weight: 600;
}

/* Mobile TOC toggle */
.toc-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--color-primary);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  line-height: 1;
}

/* ===== Content Area ===== */
.content-area {
  flex: 1;
  min-width: 0;
  max-width: 800px;
}

/* ===== Content Cards (section blocks) ===== */
.content-card {
  background: var(--color-surface);
  border-radius: 8px;
  padding: 20px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.content-card > h1:first-child,
.content-card > h2:first-child {
  margin-top: 0;
}

.content-card hr:last-child {
  display: none;
}

/* ===== Report Date Subtitle ===== */
.report-date {
  font-size: 20px;
  color: var(--color-text);
  margin-top: -4px;
  margin-bottom: 16px;
}

/* ===== Markdown Rendered Content ===== */
.report-content h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 8px;
}

.report-content h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
  margin-top: 40px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border);
}

.report-content h3 {
  font-size: 17px;
  font-weight: 700;
  color: #343a40;
  margin-top: 28px;
  margin-bottom: 10px;
}

.report-content p {
  margin-bottom: 14px;
}

.report-content strong {
  font-weight: 700;
  color: var(--color-text);
}

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

.report-content li {
  margin-bottom: 6px;
}

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

.report-content hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 32px 0;
}

.report-content a {
  color: var(--color-primary);
  text-decoration: none;
}

.report-content a:hover {
  text-decoration: underline;
}

/* ===== Tables ===== */
.table-wrapper {
  overflow-x: auto;
  margin-bottom: 16px;
  border-radius: 8px;
  border: 1px solid var(--color-border);
}

.report-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.report-content thead th {
  background: var(--color-surface-alt);
  font-weight: 700;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}

.report-content tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--color-border-light);
}

.report-content tbody tr:nth-child(even) {
  background: var(--color-bg);
}

.report-content tbody tr:hover {
  background: var(--color-primary-bg);
}

/* ===== Footer Metadata ===== */
.report-content .report-meta {
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
  font-size: 13px;
  color: var(--color-text-muted);
  font-style: italic;
}

.report-content .report-meta p {
  margin-bottom: 4px;
}

/* ===== TTS Audio Player ===== */
.tts-bar {
  display: none;
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  z-index: 99;
  background: var(--color-primary-bg);
  border-bottom: 1px solid #a5d8ff;
}

.tts-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tts-btn {
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--color-primary);
  border-radius: 6px;
  background: var(--color-primary);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.tts-btn:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.tts-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tts-btn-stop {
  background: var(--color-surface);
  color: var(--color-primary);
}

.tts-btn-stop:hover:not(:disabled) {
  background: var(--color-primary-bg);
}

.tts-status {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-left: 8px;
}

.tts-progress-wrap {
  flex: 1;
  height: 6px;
  background: #c5dff8;
  border-radius: 3px;
  cursor: pointer;
  margin: 0 8px;
  min-width: 80px;
}

.tts-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--color-primary);
  border-radius: 3px;
  transition: width 0.2s linear;
}

.tts-time {
  font-size: 12px;
  color: var(--color-text-secondary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ===== Loading / Empty State ===== */
.loading-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-text-muted);
  font-size: 15px;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .page-body {
    flex-direction: column;
    padding: 16px;
  }

  .toc-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 300;
    background: var(--color-surface);
    padding: 20px 16px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
    max-height: 100vh;
    overflow-y: auto;
  }

  .toc-sidebar.open {
    transform: translateX(0);
  }

  .toc-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 250;
  }

  .toc-overlay.open {
    display: block;
  }

  .toc-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .tts-bar {
    top: 56px;
  }

  .content-area {
    max-width: 100%;
  }

  .nav-brand {
    font-size: 15px;
    margin-right: auto;
  }

  .nav-hamburger {
    display: flex;
  }

  .nav-tabs {
    display: none;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    padding: 8px 0;
    gap: 0;
  }

  .nav-tabs.open {
    display: flex;
  }

  .nav-tab {
    padding: 12px 24px;
    font-size: 15px;
    border-radius: 0;
  }

  .nav-tab:hover {
    background: var(--color-surface-alt);
  }

  .nav-tab.active {
    border-radius: 0;
  }
}

@media (max-width: 500px) {
  .report-content h1 {
    font-size: 22px;
  }
  .report-content h2 {
    font-size: 18px;
  }
  .selector-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .report-dropdown {
    width: 100%;
  }
}

/* ===== Dark Mode Toggle ===== */
.dark-toggle {
  margin-left: 4px;
  font-size: 18px;
}

/* ===== Dark Mode ===== */
body.dark {
  --color-text: #dee2e6;
  --color-text-secondary: #adb5bd;
  --color-text-muted: #868e96;
  --color-text-dim: #868e96;

  --color-bg: #1a1b1e;
  --color-surface: #25262b;
  --color-surface-hover: #373a40;
  --color-surface-alt: #2c2e33;

  --color-border: #373a40;
  --color-border-light: #373a40;
  --color-border-input: #373a40;

  --color-primary-bg: #1b2838;
  --color-primary-ring: rgba(34,139,230,0.3);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-nav: 0 1px 3px rgba(0,0,0,0.3);
}

body.dark .nav-logo {
  filter: none;
}

body.dark .nav-brand {
  color: #e9ecef;
}

body.dark .dark-toggle {
  color: #fcc419;
}

body.dark .nav-search-btn,
body.dark .nav-strategy-btn {
  color: var(--color-text-secondary);
}

body.dark .toggle-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

body.dark .report-dropdown:focus {
  border-color: var(--color-primary);
}

body.dark .tts-bar {
  background: #1b2838;
  border-bottom-color: #2c3e50;
}

body.dark .tts-btn {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
}

body.dark .tts-btn:hover:not(:disabled) {
  background: var(--color-primary-darkest);
}

body.dark .tts-btn-stop {
  background: var(--color-surface-alt);
  color: var(--color-primary-light);
  border-color: var(--color-primary-dark);
}

body.dark .tts-btn-stop:hover:not(:disabled) {
  background: #1b2838;
}

body.dark .tts-progress-wrap {
  background: #2c3e50;
}

body.dark .toc-link:hover,
body.dark .toc-link-sub:hover {
  color: var(--color-primary-light);
}

body.dark .toc-link.active,
body.dark .toc-link-sub.active {
  color: var(--color-primary-light);
  border-left-color: var(--color-primary);
}

body.dark .toc-link-sub {
  color: #909296;
}

body.dark .report-content h1,
body.dark .report-content h2 {
  color: #e9ecef;
}

body.dark .report-content h3 {
  color: var(--color-text);
}

body.dark .report-content strong {
  color: #f1f3f5;
}

body.dark .report-content a {
  color: var(--color-primary-light);
}

body.dark .report-content thead th {
  color: var(--color-text);
  border-bottom-color: var(--color-text-secondary);
}

body.dark .toc-toggle {
  background: var(--color-primary-dark);
}

/* Dark mode mobile sidebar & menu */
@media (max-width: 900px) {
  body.dark .toc-sidebar {
    box-shadow: 2px 0 12px rgba(0,0,0,0.4);
  }

  body.dark .toc-overlay {
    background: rgba(0,0,0,0.5);
  }

  body.dark .nav-tabs {
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  }
}
