  :root {
    --ink: #1B2A4A;
    --ink-soft: #243456;
    --gold: #C9A961;
    --gold-soft: #E4D5AC;
    --paper: #FAF7F0;
    --paper-dim: #F1ECE0;
    --slate: #5A6478;
    --line: #E2DCCB;
    --up: #B8533E;
    --down: #4A7C59;
    --shadow: 0 4px 24px rgba(27,42,74,0.07);
    --cb: #3B6FDB;
    --db: #B8962E;
    --fc: #C05A3A;
  }

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

  body {
    font-family: 'Inter', sans-serif;
    background: var(--paper);
    color: var(--ink);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
  }

  /* ========= HEADER / NAV ========= */
  header {
    position: sticky;
    top: 0;
    z-index: 200;
  }

  .main-nav {
    background: rgba(27,42,74,0.97);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-bottom: 1px solid rgba(255,255,255,0.07);
  }

  .nav-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 28px;
    height: 64px;
    display: flex;
    align-items: center;
    position: relative;
  }

  .nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    cursor: pointer;
    text-decoration: none;
  }

  .brand-mark {
    font-family: 'Fraunces', serif;
    font-size: 22px;
    font-weight: 600;
    color: var(--paper);
    letter-spacing: 0.01em;
    white-space: nowrap;
  }

  .brand-mark .accent { color: var(--gold); font-style: italic; }

  .nav-links {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
  }

  .nav-link {
    background: none;
    border: none;
    color: rgba(250,247,240,0.6);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 500;
    padding: 8px 15px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.16s;
    white-space: nowrap;
    letter-spacing: 0.01em;
    position: relative;
  }

  .nav-link:hover { color: var(--paper); background: rgba(255,255,255,0.06); }

  .nav-link.active { color: var(--paper); font-weight: 600; }

  .nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 15px;
    right: 15px;
    height: 2px;
    background: var(--gold);
    border-radius: 2px 2px 0 0;
  }

  .nav-link.coming-soon {
    opacity: 0.35;
    cursor: default;
  }
  .nav-link.coming-soon:hover {
    color: rgba(250,247,240,0.6);
    background: transparent;
  }

  .cs-badge {
    display: inline-block;
    font-size: 8px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gold);
    border: 1px solid rgba(201,169,97,0.4);
    border-radius: 4px;
    padding: 1px 4px;
    margin-left: 4px;
    vertical-align: middle;
  }

  /* ========= CATEGORY SEGMENTED CONTROL ========= */
  .sub-nav-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 26px;
  }

  .sub-nav-row .data-asof { margin-bottom: 0; }

  .sub-nav {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 4px;
    box-shadow: var(--shadow);
  }

  .cat-pill-btn {
    background: transparent;
    border: none;
    color: var(--slate);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 18px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.16s;
    white-space: nowrap;
  }

  .cat-pill-btn:hover:not(:disabled):not(.active) {
    color: var(--ink);
    background: var(--paper-dim);
  }

  .cat-pill-btn.active {
    background: var(--gold);
    color: var(--ink);
  }

  .cat-pill-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
  }

  .cat-count {
    font-family: 'Space Mono', monospace;
    font-size: 10.5px;
    opacity: 0.65;
    margin-left: 3px;
  }

  /* ========= MAIN ========= */
  main { max-width: 1180px; margin: 0 auto; padding: 40px 28px 80px; }

  .page { display: none; }
  .page.active { display: block; }

  /* ========= DASHBOARD ========= */
  .data-asof {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 7px;
    font-family: 'Space Mono', monospace;
    font-size: 11.5px;
    color: var(--slate);
    margin-bottom: 14px;
  }

  .data-asof .asof-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--down);
    flex-shrink: 0;
  }

  .data-asof .asof-dot.pending { background: var(--gold); }

  .dash-stat-grid {
    display: grid;
    grid-template-columns: 3fr 1fr 1fr;
    gap: 16px;
    margin-bottom: 28px;
  }

  .stat-delta {
    font-family: 'Space Mono', monospace;
    font-size: 12px;
    font-weight: 700;
    margin-left: 7px;
    vertical-align: 2px;
  }

  .stat-card-combined {
    display: flex;
    align-items: stretch;
    gap: 24px;
  }

  .stat-card-combined .stat-group { flex: 1; }

  .stat-divider {
    width: 1px;
    background: var(--line);
    flex-shrink: 0;
  }

  .stat-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 22px 24px;
    box-shadow: var(--shadow);
  }

  .stat-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--slate);
    margin-bottom: 10px;
  }

  .stat-value {
    font-family: 'Space Mono', monospace;
    font-size: 26px;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.1;
  }

  .stat-sub {
    font-size: 11.5px;
    color: var(--slate);
    margin-top: 5px;
  }

  .stat-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    flex-shrink: 0;
    vertical-align: middle;
    position: relative;
    top: -1px;
  }

  .dash-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 26px 28px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
  }

  .dash-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 18px;
  }

  .dash-card-title {
    font-family: 'Fraunces', serif;
    font-size: 18px;
    font-weight: 600;
    color: var(--ink);
  }

  .dash-card-sub {
    font-size: 12px;
    color: var(--slate);
    margin-top: 3px;
  }

  .dash-legend {
    display: flex;
    gap: 20px;
    margin-bottom: 16px;
    flex-wrap: wrap;
  }

  .dash-leg {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    color: var(--slate);
  }

  .dash-leg-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  .dash-cat-pills {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }

  .dash-cat-pill {
    background: transparent;
    border: 1.5px solid var(--line);
    color: var(--slate);
    font-family: 'Inter', sans-serif;
    font-size: 12.5px;
    font-weight: 600;
    padding: 5px 14px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.15s;
  }

  .dash-cat-pill:hover:not(:disabled) { border-color: var(--gold); color: var(--ink); }
  .dash-cat-pill:disabled { opacity: 0.3; cursor: not-allowed; }
  .dash-cat-pill.active-cb { background: var(--cb); border-color: var(--cb); color: #fff; }
  .dash-cat-pill.active-db { background: var(--db); border-color: var(--db); color: #fff; }
  .dash-cat-pill.active-fc { background: var(--fc); border-color: var(--fc); color: #fff; }

  /* ========= COMING SOON ========= */
  .coming-soon-page {
    text-align: center;
    padding: 100px 20px 120px;
  }

  .cs-glyph {
    width: 64px;
    height: 64px;
    margin: 0 auto 22px;
    border-radius: 18px;
    background: var(--paper-dim);
    border: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
  }

  .cs-title {
    font-family: 'Fraunces', serif;
    font-size: 30px;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 10px;
  }

  .cs-sub {
    font-size: 15px;
    color: var(--slate);
    max-width: 440px;
    margin: 0 auto 28px;
    line-height: 1.65;
  }

  .cs-back-btn {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 11px 22px;
    cursor: pointer;
    transition: all 0.18s;
  }
  .cs-back-btn:hover { background: var(--ink); color: var(--gold); border-color: var(--ink); }

  /* ========= DATA PAGE — table, search, etc. ========= */
  .section-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
  }

  .section-head h1 { font-family: 'Fraunces', serif; font-size: 32px; font-weight: 600; }
  .section-sub { font-size: 13.5px; color: var(--slate); margin-top: 4px; }

  .search-box { position: relative; }
  .search-box input {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 10px;
    padding: 11px 16px 11px 38px;
    width: 260px;
    color: var(--ink);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
  }
  .search-box input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,169,97,0.15); }
  .search-box::before { content: ''; position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 13px; height: 13px; border: 1.5px solid var(--slate); border-radius: 50%; }
  .search-box::after { content: ''; position: absolute; left: 24px; top: 64%; width: 6px; height: 1.5px; background: var(--slate); transform: rotate(45deg); }

  /* ========= TABLE ========= */
  .rate-table-wrap { background: #fff; border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; border: 1px solid var(--line); }
  table.rate-table { width: 100%; border-collapse: collapse; }

  .rate-table thead th {
    text-align: left; font-size: 11px; text-transform: uppercase;
    letter-spacing: 0.1em; color: var(--slate); font-weight: 600;
    padding: 16px 24px; background: var(--paper-dim); border-bottom: 1px solid var(--line);
  }

  .sortable-th { cursor: pointer; user-select: none; white-space: nowrap; transition: color 0.15s; }
  .sortable-th:hover { color: var(--ink); }
  .sort-active { color: var(--ink) !important; }
  .sort-arrow { margin-left: 5px; opacity: 0.4; font-size: 10px; }
  .sort-active .sort-arrow { opacity: 1; }

  .rate-table thead th.num, .rate-table tbody td.num { text-align: right; }
  .rate-table tbody tr { border-bottom: 1px solid var(--line); transition: background 0.15s; }
  .rate-table tbody tr:last-child { border-bottom: none; }
  .rate-table tbody tr:hover { background: var(--paper-dim); }
  .rate-table td { padding: 18px 24px; font-size: 15px; vertical-align: middle; }

  .inst-name { font-weight: 600; font-family: 'Fraunces', serif; font-size: 17px; }
  .rate-value { font-family: 'Space Mono', monospace; font-size: 19px; font-weight: 700; color: var(--ink); }
  .rate-date { font-family: 'Space Mono', monospace; font-size: 12.5px; color: var(--slate); }

  .trend-chip { display: inline-flex; align-items: center; gap: 4px; font-family: 'Space Mono', monospace; font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 6px; margin-left: 10px; }
  .trend-chip.up { color: var(--up); background: rgba(184,83,62,0.08); }
  .trend-chip.down { color: var(--down); background: rgba(74,124,89,0.08); }
  .trend-chip.flat { color: var(--slate); background: rgba(90,100,120,0.08); }

  .pending-badge { display: inline-block; font-family: 'Inter', sans-serif; font-size: 10.5px; font-weight: 700; letter-spacing: 0.03em; color: var(--gold); background: rgba(201,169,97,0.12); border: 1px solid rgba(201,169,97,0.35); border-radius: 6px; padding: 2px 7px; margin-left: 8px; text-transform: uppercase; vertical-align: middle; }

  .history-btn { font-family: 'Inter', sans-serif; font-size: 13px; font-weight: 600; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 9px; padding: 9px 18px; cursor: pointer; transition: all 0.18s; white-space: nowrap; }
  .history-btn:hover { background: var(--ink); color: var(--gold); border-color: var(--ink); }

  /* ========= MOBILE CARDS ========= */
  .rate-cards { display: none; }
  .rate-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; margin-bottom: 12px; box-shadow: var(--shadow); }
  .rate-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; gap: 12px; }
  .rate-card .inst-name { font-size: 16px; }

  /* ========= HISTORY VIEW ========= */
  .history-view { display: none; }
  .history-view.active { display: block; }
  .tab-view { display: none; }
  .tab-view.active { display: block; }

  .back-link { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600; color: var(--slate); background: none; border: none; cursor: pointer; margin-bottom: 18px; padding: 0; transition: color 0.15s; }
  .back-link:hover { color: var(--ink); }
  .back-link::before { content: '←'; font-size: 16px; }

  .history-grid { display: grid; grid-template-columns: 360px 1fr; gap: 20px; align-items: start; }

  .history-topbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
  .inst-selectors { display: flex; gap: 10px; flex-wrap: wrap; }
  .selector-wrap { position: relative; }
  .selector-wrap select { font-family: 'Inter', sans-serif; font-size: 13.5px; font-weight: 600; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 36px 10px 16px; cursor: pointer; appearance: none; -webkit-appearance: none; outline: none; transition: border-color 0.15s, box-shadow 0.15s; min-width: 160px; }
  .selector-wrap select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,169,97,0.15); }
  .selector-wrap::after { content: ''; position: absolute; right: 14px; top: 50%; width: 8px; height: 8px; border-right: 1.5px solid var(--slate); border-bottom: 1.5px solid var(--slate); transform: translateY(-65%) rotate(45deg); pointer-events: none; }
  #instSelect { min-width: 240px; }

  .detail-col { background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 26px 24px; max-height: calc(100vh - 150px); overflow-y: auto; position: sticky; top: 130px; }
  .detail-col .category-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--gold); font-weight: 700; margin-bottom: 6px; display: block; }
  .detail-col h1 { font-family: 'Fraunces', serif; font-size: 24px; font-weight: 600; line-height: 1.25; margin-bottom: 20px; }
  .detail-col h1 .pending-badge { display: block; width: fit-content; margin: 8px 0 0; }

  .chart-extra-stats { font-family: 'Space Mono', monospace; font-size: 11.5px; color: var(--slate); margin-top: 4px; line-height: 1.6; }
  .chart-extra-stats b { color: var(--ink); }

  .detail-history h2 { font-family: 'Fraunces', serif; font-size: 15px; font-weight: 600; margin-top: 0; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }

  .hist-entry { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
  .hist-entry:last-child { border-bottom: none; }
  .hist-entry-header { padding: 4px 0 6px; }
  .hist-entry .he-date { font-family: 'Space Mono', monospace; font-size: 11.5px; color: var(--slate); flex-shrink: 0; min-width: 90px; }
  .hist-entry .he-right { display: flex; align-items: center; gap: 12px; }
  .hist-entry .he-rate { font-family: 'Space Mono', monospace; font-size: 13px; font-weight: 700; min-width: 80px; text-align: right; }
  .hist-entry .he-applicable { font-family: 'Space Mono', monospace; font-size: 12.5px; font-weight: 700; color: var(--ink); background: rgba(201,169,97,0.1); border: 1px solid rgba(201,169,97,0.25); border-radius: 5px; padding: 2px 7px; min-width: 64px; text-align: center; cursor: help; }

  .chart-col { background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 22px 24px; }
  .chart-col-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; margin-bottom: 4px; }
  .chart-price { font-family: 'Space Mono', monospace; font-size: 32px; font-weight: 700; line-height: 1.1; }
  .chart-price-change { font-family: 'Space Mono', monospace; font-size: 13px; font-weight: 700; margin-top: 4px; }
  .chart-price-change.pos { color: var(--up); }
  .chart-price-change.neg { color: var(--down); }
  .chart-price-change.flat { color: var(--slate); }
  .chart-hover-date { font-family: 'Space Mono', monospace; font-size: 12px; color: var(--slate); text-align: right; }
  #robinhoodChart { margin: 14px 0; }

  .range-pills { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
  .range-pill { background: var(--paper-dim); border: 1px solid var(--line); border-radius: 999px; font-family: 'Inter', sans-serif; font-size: 12.5px; font-weight: 700; color: var(--slate); padding: 7px 16px; cursor: pointer; transition: all 0.15s; }
  .range-pill:hover { color: var(--ink); border-color: var(--gold); }
  .range-pill.active { background: var(--ink); color: var(--gold); border-color: var(--ink); }

  /* ========= TOOLTIP ========= */
  .tip {
    position: fixed;
    pointer-events: none;
    display: none;
    background: var(--ink);
    color: var(--paper);
    font-size: 11.5px;
    line-height: 1.5;
    padding: 7px 11px;
    border-radius: 8px;
    white-space: nowrap;
    z-index: 400;
    box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  }

  /* ========= FOOTER ========= */
  footer { border-top: 1px solid var(--line); padding: 28px; text-align: center; font-size: 12.5px; color: var(--slate); }
  footer .disclaimer { max-width: 640px; margin: 0 auto 8px; line-height: 1.6; }

  /* ========= MISC ========= */
  .empty-state { text-align: center; padding: 60px 20px; color: var(--slate); font-size: 14px; }
  ::placeholder { color: #B5AF9E; }

  /* ========= RESPONSIVE ========= */
  @media (max-width: 960px) {
    .dash-stat-grid { grid-template-columns: 1fr; }
    .nav-links { gap: 0; }
    .nav-link { padding: 7px 11px; font-size: 13px; }
    .dash-two-col { grid-template-columns: 1fr !important; }
  }

  @media (max-width: 760px) {
    .rate-table-wrap { display: none; }
    .rate-cards { display: block; }
    .section-head h1 { font-size: 26px; }
    .search-box input { width: 100%; }
    .search-box { width: 100%; }
    .history-grid { grid-template-columns: 1fr; }
    .detail-col { position: static; max-height: none; }
    .detail-col h1 { font-size: 20px; }
    .chart-col, .detail-col { padding: 18px; }
    .chart-price { font-size: 28px; }
  }

  @media (max-width: 600px) {
    .history-topbar { flex-direction: column; align-items: stretch; }
    .inst-selectors { flex-direction: column; }
    .selector-wrap select, #instSelect { width: 100%; min-width: 0; }
    .dash-stat-grid { grid-template-columns: 1fr; }
    .stat-card-combined { flex-direction: column; gap: 16px; }
    .stat-divider { width: auto; height: 1px; }
  }

  @media (max-width: 480px) {
    .nav-inner { padding: 0 14px; }
    main { padding: 24px 16px 60px; }
    .brand-mark { font-size: 18px; }
    .nav-link { padding: 6px 8px; font-size: 12px; }
  }
