  /* ───────────────────────── Config ─────────────────────────
     SITE_NAME (used for <title>/<h1>, via the {{SITE_TITLE}}/
     {{SITE_NAME}} markers below) is rendered server-side — see
     SITE_NAME in api.py. API_BASE is '' when this file is served
     by the gangtok API itself (StaticFiles at the API's own origin);
     set it to an absolute origin if this page is hosted separately. */

  :root {
    --font-display: 'Fraunces', ui-serif, Georgia, serif;
    --font-body: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  }

  /* Dark = closed ledger cover: warm graphite ink, not navy. */
  :root, [data-theme="dark"] {
    /* Drives native form-control rendering (e.g. the date input's calendar
       icon) from our own toggle, not the OS's prefers-color-scheme — a bare
       `light dark` here follows the OS and can pick a white icon that
       vanishes against the light theme's white input background. */
    color-scheme: dark;
    --bg: #14181A;
    --surface: #1C2124;
    --surface-2: #22282B;
    --border: #333B3E;
    --border-strong: #454F53;
    --text: #EDEAE2;
    --text-muted: #9AA39E;
    --text-dim: #6B7570;
    --brass: #C6A05F;
    --brass-text: #14181A;
    --moss: #6FA57F;
    --rust: #D08674;
    --focus: #D9BC85;
    --shadow: 0 8px 28px rgba(0,0,0,0.35);
  }

  /* Light = open ledger page: unbleached paper, not cream-and-terracotta. */
  [data-theme="light"] {
    color-scheme: light;
    --bg: #F6F3EC;
    --surface: #FFFFFF;
    --surface-2: #EFEBE1;
    --border: #DDD6C7;
    --border-strong: #C9C0AB;
    --text: #201C16;
    --text-muted: #6B6255;
    --text-dim: #9C927F;
    --brass: #8A6A34;
    --brass-text: #FFFFFF;
    --moss: #3E6A4C;
    --rust: #8A3B2E;
    --focus: #8A6A34;
    --shadow: 0 8px 28px rgba(32,28,22,0.10);
  }

  * , *::before, *::after { box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    transition: background .18s ease, color .18s ease;
  }
  ::selection { background: var(--brass); color: var(--brass-text); }
  a { color: var(--brass); }

  :focus { outline: none; }
  :focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
    border-radius: 3px;
  }

  @media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
  }

  main {
    flex: 1 0 auto;
    width: 100%;
    max-width: 1024px;
    margin: 0 auto;
    padding: 44px 24px 64px;
  }

  /* ── Header ───────────────────────────────────────────── */
  .page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 14px;
  }
  .site-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .site-icon {
    width: clamp(30px, 5.2vw, 40px);
    height: clamp(30px, 5.2vw, 40px);
    flex-shrink: 0;
    transform: translateY(5px);
  }
  .site-title {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(28px, 5vw, 38px);
    letter-spacing: -0.01em;
    line-height: 1.05;
  }
  .site-tagline {
    margin-top: 6px;
    font-size: 12.5px;
    color: var(--text-muted);
  }
  .header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    flex-shrink: 0;
  }

  .theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 5px 6px 5px 10px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
  }
  .theme-toggle:hover { border-color: var(--border-strong); }
  .toggle-track {
    width: 30px; height: 17px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    position: relative;
  }
  .toggle-thumb {
    width: 11px; height: 11px;
    background: var(--brass);
    border-radius: 50%;
    position: absolute;
    top: 2px; left: 2px;
    transition: left .16s ease;
  }
  [data-theme="dark"] .toggle-thumb { left: 15px; }

  .as-of-chip {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 10px;
    white-space: nowrap;
  }
  .as-of-chip strong { color: var(--text-muted); font-weight: 500; }

  .ledger-rule {
    height: 1px;
    background: var(--border);
    margin: 18px 0 26px;
    position: relative;
  }
  .ledger-rule::after {
    content: '';
    position: absolute;
    left: 0; right: 0; top: 4px;
    height: 1px;
    background: var(--border);
    opacity: .55;
  }

  /* ── Mode switch ──────────────────────────────────────── */
  .mode-switch-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
  }
  .mode-switch {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3px;
    gap: 2px;
  }
  .mode-tab {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: .03em;
    text-transform: uppercase;
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 7px 14px;
    border-radius: 6px;
    cursor: pointer;
  }
  .mode-tab:hover { color: var(--text); }
  .mode-tab.active { background: var(--brass); color: var(--brass-text); }

  /* ── Search ───────────────────────────────────────────── */
  .search-row { display: flex; gap: 8px; margin-bottom: 10px; }
  .search-input, .date-input {
    flex: 1;
    padding: 12px 14px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14.5px;
  }
  .date-input { font-family: var(--font-mono); }
  .search-input:focus, .date-input:focus { border-color: var(--brass); }
  .search-input::placeholder { color: var(--text-dim); }
  .go-btn {
    font-family: var(--font-mono);
    font-size: 12.5px;
    background: var(--brass);
    color: var(--brass-text);
    border: none;
    border-radius: 8px;
    padding: 0 18px;
    cursor: pointer;
    white-space: nowrap;
  }
  .go-btn:hover { filter: brightness(1.06); }
  .clear-btn {
    flex-shrink: 0;
    width: 42px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    color: var(--text-dim);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
  }
  .clear-btn:hover { border-color: var(--rust); color: var(--rust); }

  /* ── API URL block: the signature element ────────────────
     A labeled, copyable readout of the exact request that would
     fetch the resource currently on screen — shown only against a
     concrete result (a fund, a date), never live during typing. */
  .api-url-block {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--brass);
    border-radius: 0 6px 6px 0;
    padding: 10px 12px;
    margin-bottom: 10px;
  }
  .api-url-label {
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--brass);
    margin-bottom: 2px;
  }
  .api-url-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
  }
  .api-url-row {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .api-url-text {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text);
    flex: 1;
    overflow-x: auto;
    white-space: nowrap;
  }
  .copy-btn {
    flex-shrink: 0;
    font-family: var(--font-mono);
    font-size: 11px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 5px;
    padding: 3px 9px;
    cursor: pointer;
  }
  .copy-btn:hover { border-color: var(--brass); color: var(--text); }
  .copy-btn.copied { border-color: var(--moss); color: var(--moss); }

  /* ── Results ──────────────────────────────────────────── */
  .panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 16px;
  }
  .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 14px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 10.5px;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-dim);
  }

  .result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
  }
  .result-row:last-child { border-bottom: none; }
  .result-row:hover { background: var(--surface-2); }
  .result-name { font-size: 14px; margin-bottom: 2px; }
  .result-sub { font-size: 12px; color: var(--text-muted); }
  .result-code { font-family: var(--font-mono); font-size: 12px; color: var(--text-dim); flex-shrink: 0; }

  .date-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
  }
  .date-row:last-child { border-bottom: none; }
  .date-row:hover { background: var(--surface-2); }
  .date-row-nav { text-align: right; flex-shrink: 0; }
  .date-row-nav .mono { font-size: 13px; margin-bottom: 2px; }

  .mono { font-family: var(--font-mono); }

  .tick {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 12.5px;
  }
  .tick .arrow {
    width: 0; height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
  }
  .tick.up { color: var(--moss); }
  .tick.up .arrow { border-bottom: 6px solid var(--moss); }
  .tick.down { color: var(--rust); }
  .tick.down .arrow { border-top: 6px solid var(--rust); }
  .tick.flat { color: var(--text-dim); }

  .message { padding: 34px 20px; text-align: center; color: var(--text-muted); font-size: 13.5px; }
  .message.error { color: var(--rust); }

  .pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--text-muted);
  }
  .page-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 5px;
    padding: 4px 10px;
    font-family: var(--font-mono);
    font-size: 11.5px;
    cursor: pointer;
  }
  .page-btn:disabled { opacity: .35; cursor: default; }
  .page-btn:not(:disabled):hover { border-color: var(--brass); }

  /* ── Detail card ──────────────────────────────────────── */
  .detail-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 16px;
  }
  .back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    padding: 0;
    margin-bottom: 14px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
  }
  .back-link:hover { color: var(--brass); }
  .detail-top { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
  .detail-name { font-family: var(--font-display); font-size: 19px; font-weight: 600; margin: 0 0 3px; }
  .detail-house { font-size: 13px; color: var(--text-muted); }
  .detail-nav {
    text-align: right;
    flex-shrink: 0;
  }
  .detail-nav .amount {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 21px;
    font-weight: 600;
  }
  .detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; margin-bottom: 14px; }
  .detail-cell { background: var(--surface-2); border-radius: 6px; padding: 10px 12px; }
  .cell-label {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 4px;
  }
  .cell-value { font-size: 13.5px; }
  .cell-value.mono { font-family: var(--font-mono); }

  .related-endpoints { display: flex; flex-direction: column; }

  /* ── Header actions + API docs trigger ───────────────────── */
  .header-actions { display: flex; align-items: center; gap: 8px; }
  .docs-trigger {
    font-family: var(--font-mono);
    font-size: 11px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 20px;
    padding: 6px 12px;
    cursor: pointer;
  }
  .docs-trigger:hover { border-color: var(--brass); color: var(--text); }

  /* ── API reference modal ──────────────────────────────────
     An overlay, not another inline panel, so it never has to
     compete visually with the search/results area for attention. */
  .modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 13, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
  }
  .modal-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    max-width: 640px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
  }
  .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
  }
  .modal-header span {
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 600;
  }
  .modal-close {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
  }
  .modal-close:hover { color: var(--rust); }

  .api-docs-list { padding: 4px 0; }
  .api-docs-note {
    margin: 0;
    padding: 10px 18px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
  }
  .api-docs-row {
    display: grid;
    grid-template-columns: minmax(160px, 240px) 1fr;
    gap: 12px;
    padding: 9px 18px;
    border-bottom: 1px solid var(--border);
  }
  .api-docs-row:last-child { border-bottom: none; }
  .api-docs-row code {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--brass);
  }
  .api-docs-row code a {
    color: inherit;
    text-decoration: none;
  }
  .api-docs-row code a:hover { text-decoration: underline; }
  .api-docs-row span {
    font-size: 12.5px;
    color: var(--text-muted);
  }

  /* ── Idle state: stats strip + hint ──────────────────────── */
  .empty-state { padding: 8px 0 10px; text-align: center; }
  .stats-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    margin-top: 28px;
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 16px;
  }
  .stat-tile { background: var(--surface); padding: 18px 8px; }
  .stat-value {
    font-family: var(--font-display);
    font-size: clamp(19px, 3vw, 27px);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
  }
  .stat-label {
    margin-top: 5px;
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-muted);
  }
  .empty-hint { color: var(--text-muted); font-size: 13px; margin: 0; }

  /* ── About modal body ─────────────────────────────────── */
  .modal-body { padding: 14px 18px; }
  .modal-body p {
    font-size: 13.5px;
    color: var(--text-muted);
    line-height: 1.65;
    margin: 0 0 10px;
  }
  .modal-body p:last-child { margin-bottom: 0; }

  /* ── Footer (sticky to viewport bottom, never overlaps
     content — pinned via flex layout rather than position:fixed,
     so a long date-mode table never hides behind it) ─────── */
  footer {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 14px 24px;
  }
  .footer-inner { max-width: 1024px; margin: 0 auto; text-align: center; }
  .disclaimer-secondary {
    font-size: 11px;
    color: var(--text-dim);
    line-height: 1.5;
    margin-top: 6px;
  }
  .footer-meta {
    font-size: 11px;
    color: var(--text-dim);
  }
  .footer-meta a { color: var(--text-dim); }
  .footer-meta a:hover { color: var(--text); }

  .hidden { display: none !important; }

  @media (max-width: 480px) {
    .detail-top { flex-direction: column; }
    .detail-nav { text-align: left; }
    .detail-grid { grid-template-columns: 1fr; }
    .stats-strip { grid-template-columns: repeat(2, 1fr); }
  }

  /* ── Fund page: server-rendered NAV history table ─────────────────── */
  .detail-history { margin-top: 24px; }
