:root {
  /* Primary Identity: Trust & Stability (Singapore/Global Banking vibe) */
  --color-primary-navy: #0f172a;
  --color-brand-blue: #0284c7;
  --color-bg-light: #f8fafc;

  /* Secondary/Accent: Growth & Action */
  --color-accent-mint: #10b981;
  --color-accent-glow: rgba(16, 185, 129, 0.15);

  /* Neutral UI Elements */
  --color-surface-white: #ffffff;
  --color-border-subtle: #e2e8f0;
  --color-text-muted-slate: #64748b;

  /* Semantic aliases used throughout the stylesheet */
  --color-bg: var(--color-bg-light);
  --color-surface: var(--color-surface-white);
  --color-border: var(--color-border-subtle);
  --color-text: var(--color-primary-navy);
  --color-muted: var(--color-text-muted-slate);
  --color-primary: var(--color-brand-blue);
  --color-primary-dark: #036aa3;
  --color-accent: var(--color-accent-mint);
  --color-danger: #b6511e;
  --color-blockquote-bg: #e0f2fe;
  --color-code-bg: #eef2f6;

  --category-core: var(--color-brand-blue);
  --category-gov: var(--color-accent-mint);
  --category-hybrid: #b6511e;
  --category-scheme: #8548c7;
  --sidebar-width: 280px;
  --header-height: 60px;
}

[data-theme="dark"] {
  --color-primary-navy: #0f172a;
  --color-bg-light: #0b1220;
  --color-surface-white: #111827;
  --color-border-subtle: #253145;
  --color-text-muted-slate: #94a3b8;
  --color-brand-blue: #38bdf8;
  --color-primary-dark: #7dd3fc;
  --color-accent-mint: #34d399;
  --color-accent-glow: rgba(52, 211, 153, 0.18);

  --color-text: #e2e8f0;
  --color-blockquote-bg: rgba(2, 132, 199, 0.15);
  --color-code-bg: #1a2436;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --color-primary-navy: #0f172a;
    --color-bg-light: #0b1220;
    --color-surface-white: #111827;
    --color-border-subtle: #253145;
    --color-text-muted-slate: #94a3b8;
    --color-brand-blue: #38bdf8;
    --color-primary-dark: #7dd3fc;
    --color-accent-mint: #34d399;
    --color-accent-glow: rgba(52, 211, 153, 0.18);

    --color-text: #e2e8f0;
    --color-blockquote-bg: rgba(2, 132, 199, 0.15);
    --color-code-bg: #1a2436;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
  transition: background 0.2s ease, color 0.2s ease;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.site-header {
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.site-title a {
  color: var(--color-text);
  font-weight: 700;
  font-size: 1.05rem;
}

.search-box {
  position: relative;
  width: 280px;
}

#search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.9rem;
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  list-style: none;
  margin: 0;
  padding: 4px;
  max-height: 320px;
  overflow-y: auto;
}

.theme-toggle {
  flex-shrink: 0;
  margin-left: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:hover { border-color: var(--color-primary); }

.theme-toggle::before {
  content: "\1F319"; /* moon: click to switch to dark */
}

[data-theme="dark"] .theme-toggle::before {
  content: "\2600\FE0F"; /* sun: click to switch to light */
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme]) .theme-toggle::before {
    content: "\2600\FE0F";
  }
}

.search-results.hidden { display: none; }

.search-results li a {
  display: block;
  padding: 8px 10px;
  border-radius: 4px;
  color: var(--color-text);
}

.search-results li a:hover,
.search-results li a.active {
  background: var(--color-bg);
  text-decoration: none;
}

.search-results .result-summary {
  display: block;
  font-size: 0.8rem;
  color: var(--color-muted);
}

.layout {
  display: flex;
  align-items: flex-start;
  min-height: calc(100vh - var(--header-height));
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 16px 8px;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
}

.nav-category {
  margin-bottom: 4px;
}

.nav-category-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--color-text);
  text-align: left;
}

.nav-category-toggle:hover { background: var(--color-bg); }

.nav-category-toggle .chip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.nav-category-toggle .arrow {
  margin-left: auto;
  transition: transform 0.15s ease;
  font-size: 0.75rem;
  color: var(--color-muted);
}

.nav-category.expanded .arrow { transform: rotate(90deg); }

.nav-instrument-list {
  list-style: none;
  margin: 0;
  padding: 2px 0 8px 0;
  display: none;
}

.nav-category.expanded .nav-instrument-list { display: block; }

.nav-instrument-list a {
  display: block;
  padding: 7px 12px 7px 30px;
  border-radius: 6px;
  font-size: 0.88rem;
  color: var(--color-muted);
}

.nav-instrument-list a:hover {
  background: var(--color-bg);
  text-decoration: none;
  color: var(--color-text);
}

.nav-instrument-list a.active {
  background: var(--color-accent-glow);
  color: var(--color-primary-dark);
  font-weight: 600;
}

.nav-overview-link {
  display: block;
  padding: 10px 12px;
  border-radius: 6px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 8px;
}

.nav-overview-link:hover { background: var(--color-bg); text-decoration: none; }
.nav-overview-link.active {
  background: var(--color-accent-glow);
  color: var(--color-primary-dark);
}

.nav-overview-link.nav-sublink {
  margin-top: -4px;
  margin-left: 12px;
  padding: 6px 12px;
  font-weight: 500;
  font-size: 0.9em;
  color: var(--color-muted);
}

.content {
  flex: 1;
  min-width: 0;
  padding: 28px 40px 60px;
  max-width: 900px;
  margin: 0 auto;
}

.breadcrumb {
  font-size: 0.85rem;
  color: var(--color-muted);
  margin-bottom: 18px;
}

.breadcrumb a { color: var(--color-muted); }
.breadcrumb .sep { margin: 0 6px; }
.breadcrumb .current { color: var(--color-text); font-weight: 600; }

.page-content h1 {
  font-size: 1.9rem;
  margin: 0 0 6px;
}

.page-content .summary {
  font-size: 1.05rem;
  color: var(--color-muted);
  margin: 0 0 24px;
}

.page-content h2 {
  font-size: 1.25rem;
  margin: 28px 0 10px;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 6px;
}

.page-content h3 {
  font-size: 1.05rem;
  margin: 18px 0 8px;
}

.page-content p { line-height: 1.65; margin: 0 0 12px; }
.page-content ul { line-height: 1.65; padding-left: 22px; margin: 0 0 16px; }
.page-content li { margin-bottom: 6px; }

.page-content blockquote {
  margin: 16px 0;
  padding: 10px 16px;
  border-left: 4px solid var(--color-primary);
  background: var(--color-blockquote-bg);
  border-radius: 0 6px 6px 0;
  color: var(--color-muted);
}

.page-content code {
  background: var(--color-code-bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

.page-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 20px;
  font-size: 0.92rem;
}

.page-content th,
.page-content td {
  border: 1px solid var(--color-border);
  padding: 8px 12px;
  text-align: left;
}

.page-content thead th {
  background: var(--color-bg);
  font-weight: 700;
}

.category-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 14px;
  color: #fff;
}

.source-link {
  margin-top: 28px;
  padding-top: 14px;
  border-top: 1px solid var(--color-border);
  font-size: 0.85rem;
  color: var(--color-muted);
}

.category-instrument-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 20px;
}

.instrument-card {
  display: block;
  padding: 14px 16px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
}

.instrument-card:hover {
  border-color: var(--color-primary);
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
}

.instrument-card .card-title { font-weight: 700; margin-bottom: 4px; }
.instrument-card .card-summary { font-size: 0.85rem; color: var(--color-muted); }

.allocation-widget {
  margin-top: 32px;
  padding: 20px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-surface);
}

.allocation-widget h2 {
  margin-top: 0;
}

.allocation-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.allocation-tab {
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.allocation-tab:hover { border-color: var(--color-primary); }

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

.allocation-blurb {
  margin: 0 0 12px;
  color: var(--color-muted);
  font-size: 0.9rem;
}

.allocation-bar {
  display: flex;
  width: 100%;
  height: 40px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--color-border);
}

.allocation-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: width 0.35s ease;
  min-width: 0;
}

.allocation-segment .segment-pct {
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  white-space: nowrap;
  overflow: hidden;
}

.allocation-legend {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  font-size: 0.88rem;
}

.allocation-legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.allocation-disclaimer {
  margin: 16px 0 0;
  font-size: 0.78rem;
  color: var(--color-muted);
  font-style: italic;
}

.goal-checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.goal-input-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border);
}

.goal-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  min-width: 220px;
}

.goal-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--color-muted);
}

.goal-field input {
  width: 100px;
  padding: 4px 6px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.85rem;
  background: var(--color-bg);
  color: var(--color-text);
}

.goals-cards {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}

.goal-card {
  padding: 14px 16px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg);
}

.goal-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.goal-card-title {
  font-weight: 700;
}

.goal-card-detail {
  margin: 0 0 12px;
  color: var(--color-muted);
  font-size: 0.85rem;
}

.goals-empty {
  color: var(--color-muted);
  font-style: italic;
}

#goals-combined h3 {
  margin-bottom: 4px;
}

.budget-input-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
  font-weight: 600;
  max-width: 220px;
  margin-bottom: 16px;
}

.budget-input-label input {
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.95rem;
  background: var(--color-bg);
  color: var(--color-text);
}

.budget-input-label select {
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.95rem;
  background: var(--color-bg);
  color: var(--color-text);
}

.priority-input {
  width: 44px;
  margin-left: 6px;
  padding: 2px 6px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.85rem;
}

.priority-input.hidden {
  display: none;
}

.goal-order {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--color-primary);
  color: #fff;
  white-space: nowrap;
}

.goal-shortfall {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: #b6511e;
  color: #fff;
  white-space: nowrap;
}

.goal-shortfall.goal-fully-funded {
  background: var(--color-accent-mint);
}

.budget-shortfall { color: var(--color-danger); }
.budget-surplus { color: var(--color-accent-mint); }

#budget-summary h3 {
  margin-bottom: 4px;
}

@media (max-width: 780px) {
  .layout { flex-direction: column; }
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }
  .content { padding: 20px; }
  .search-box { width: 160px; }
}
