  :root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --surface-2: #f1f3f6;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --text: #111827;
    --text-2: #374151;
    --muted: #6b7280;
    --pos: #059669;
    --pos-soft: #ecfdf5;
    --neg: #dc2626;
    --neg-soft: #fef2f2;
    --accent: #2563eb;
    --accent-soft: #eff6ff;
    --warn: #b45309;
    --warn-soft: #fffbeb;
    --grid: #eef0f3;
    --shadow: 0 1px 2px rgba(17,24,39,0.04), 0 1px 3px rgba(17,24,39,0.06);
  }
  html, body { background: var(--bg); color: var(--text); }
  body {
    font-family: ui-sans-serif, system-ui, -apple-system, "SF Pro Text", Inter, sans-serif;
    font-feature-settings: "tnum", "ss01";
    -webkit-font-smoothing: antialiased;
  }
  .num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
  }
  .label {
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
  }
  .pos { color: var(--pos); }
  .neg { color: var(--neg); }
  .muted { color: var(--muted); }
  .accent { color: var(--accent); }
  .pos-bg { background: var(--pos-soft); color: var(--pos); }
  .neg-bg { background: var(--neg-soft); color: var(--neg); }
  .warn-bg { background: var(--warn-soft); color: var(--warn); }
  .accent-bg { background: var(--accent-soft); color: var(--accent); }

  /* Tabs.
     Desktop: inline-flex pill bar. Mobile: horizontally-scrollable strip
     with momentum scrolling and snap so each tab settles cleanly under the
     finger. Without this the 7-tab nav (~600px) overflows a 390px viewport
     and forces the whole document to scroll horizontally. */
  nav.tabs {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px;
    box-shadow: var(--shadow);
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }
  nav.tabs::-webkit-scrollbar { display: none; }
  nav.tabs button {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 7px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.12s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    scroll-snap-align: start;
  }
  nav.tabs button:hover { color: var(--text); background: var(--surface-2); }
  nav.tabs button.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 1px 2px rgba(37,99,235,0.25);
  }
  nav.tabs button.active:hover { background: var(--accent); color: white; }

  /* Range toggle */
  .range {
    display: inline-flex;
    background: var(--surface-2);
    border-radius: 8px;
    padding: 3px;
  }
  .range button {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
  }
  .range button:hover { color: var(--text); }
  .range button.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
  }

  .hidden { display: none !important; }

  /* Tables */
  table.holdings { width: 100%; border-collapse: collapse; }
  table.holdings th, table.holdings td {
    padding: 0.7rem 0.85rem;
    border-bottom: 1px solid var(--border);
    text-align: right;
    font-size: 0.875rem;
    color: var(--text-2);
  }
  table.holdings th {
    color: var(--muted);
    font-weight: 600;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
  }
  table.holdings th:first-child, table.holdings td:first-child { text-align: left; }
  table.holdings tr:last-child td { border-bottom: 0; }
  table.holdings tr:hover td { background: rgba(37,99,235,0.03); }
  table.holdings tr.closed td { color: var(--muted); }
  table.holdings tr.closed td:first-child div:first-child { color: var(--text-2); }

  .pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 500;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
  }
  .pill.open { background: var(--pos-soft); color: var(--pos); border-color: rgba(5,150,105,0.2); }
  .pill.closed { background: var(--surface-2); color: var(--muted); }

  /* Charts */
  .chart { width: 100%; }
  .h-180 { height: 180px; }
  .h-260 { height: 260px; }
  .h-320 { height: 320px; }
  .h-380 { height: 380px; }

  .insight {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
  }
  .insight .icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
  }
  .insight .body { flex: 1; min-width: 0; }
  .insight .body .title { font-size: 0.875rem; font-weight: 600; color: var(--text); margin-bottom: 2px; }
  .insight .body .desc { font-size: 0.8rem; color: var(--muted); line-height: 1.45; }

  .progress {
    height: 6px;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
  }
  .progress > div { height: 100%; border-radius: 999px; }

  .scroll-x { overflow-x: auto; }
  .kbd {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 0.72rem;
    color: var(--text-2);
    font-family: ui-monospace, monospace;
  }

  /* TWR/XIRR explainer card on Performance */
  .explainer { font-size: 0.8rem; color: var(--muted); line-height: 1.5; }

  /* '?' help tooltip — pure CSS, position via JS only when too close to viewport edges */
  .help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    color: var(--muted);
    font-size: 9px;
    font-weight: 700;
    cursor: help;
    margin-left: 4px;
    vertical-align: middle;
    user-select: none;
    background: var(--surface);
    transition: all 0.12s ease;
    position: relative;
    text-transform: none;
    letter-spacing: 0;
  }
  .help:hover, .help:focus {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    outline: none;
  }
  .help::before {
    content: attr(data-tip);
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: white;
    color: var(--text-2);
    border: 1px solid var(--border);
    box-shadow: 0 6px 20px rgba(17,24,39,0.10);
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 400;
    line-height: 1.5;
    white-space: normal;
    width: 260px;
    text-align: left;
    z-index: 100;
    pointer-events: none;
  }
  .help::after {
    content: '';
    display: none;
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: white;
    z-index: 101;
    filter: drop-shadow(0 1px 0 rgba(229,231,235,1));
  }
  .help:hover::before, .help:focus::before,
  .help:hover::after, .help:focus::after { display: block; }
  .help.right::before { left: auto; right: 0; transform: none; }
  .help.right::after { left: auto; right: 8px; transform: none; }
  .help.left::before { left: 0; right: auto; transform: none; }
  .help.left::after { left: 8px; right: auto; transform: none; }

  /* ------ Welcome modal (first-visit landing) ------
   * The overall layout (asymmetric grid, padding, typography) is Tailwind
   * utilities in the markup. CSS here covers only the parts Tailwind can't
   * express compactly: the layered radial-gradient backdrop, the headline
   * gradient text, the preview tile's subtle gradient background, and the
   * trust-strip chips.
   */
  #welcome-overlay {
    position: fixed; inset: 0; z-index: 60;
    /* Topographic SVG backdrop + a faint colour wash over it. The SVG already
     * carries the gradient mesh — these CSS layers just deepen the corners. */
    background:
      radial-gradient(ellipse at top left,    rgba(37,99,235,0.05),  transparent 55%),
      radial-gradient(ellipse at bottom right, rgba(124,58,237,0.04), transparent 55%),
      url('bg-welcome.svg') center/cover no-repeat,
      #f8fafc;
    display: none;
    align-items: center; justify-content: center;
    padding: 24px;
    overflow-y: auto;
  }
  #welcome-overlay.show { display: flex; }

  /* Gradient text on the headline emphasis. Tailwind can do this via
   * bg-clip-text but the CDN build doesn't ship arbitrary-stop gradients
   * cleanly, so we do it by hand. */
  .welcome-gradient-text {
    background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }

  /* Trust-strip chips. Pure utility classes in markup would be 8+ classes
   * each; reusable component-class keeps the markup clean. */
  .welcome-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 12px; border-radius: 999px;
    font-size: 0.78rem; font-weight: 500;
    color: var(--text-2);
    background: var(--surface-2);
    border: 1px solid var(--border);
  }

  /* Preview tile — subtle light backdrop so the mock chart pops. */
  .welcome-preview {
    background:
      radial-gradient(ellipse at top, rgba(37,99,235,0.06), transparent 70%),
      var(--surface);
  }
  .welcome-features-ribbon { border-top: 1px solid var(--border); }

  /* ------ Upload modal ------ */
  #upload-overlay {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(17, 24, 39, 0.45);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center; justify-content: center;
    padding: 20px;
  }
  #upload-overlay.show { display: flex; }
  #upload-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(17,24,39,0.18), 0 4px 12px rgba(17,24,39,0.08);
    width: 100%; max-width: 520px;
    padding: 28px;
  }
  #upload-card h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
    letter-spacing: -0.01em;
  }
  #upload-dropzone, #upload-dropzone-tx {
    display: block;             /* <label> is inline by default — that collapses the dashed border */
    border: 1.5px dashed var(--border-strong);
    border-radius: 12px;
    padding: 22px 20px;
    text-align: center;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--surface-2);
  }
  #upload-dropzone:hover, #upload-dropzone.dragging,
  #upload-dropzone-tx:hover, #upload-dropzone-tx.dragging {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
  }
  #upload-dropzone .filename, #upload-dropzone-tx .filename {
    color: var(--text);
    font-weight: 500;
    margin-top: 6px;
  }
  .upload-label {
    font-size: 0.78rem;
    color: var(--text-2);
    font-weight: 600;
    margin-bottom: 6px;
  }
  .upload-label-2 { margin-top: 16px; }
  .open-degiro {
    float: right;
    font-size: 0.74rem;
    font-weight: 500;
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-thickness: 1px;
  }
  .open-degiro:hover {
    text-decoration-thickness: 2px;
  }
  #upload-card .row {
    display: flex; align-items: center; gap: 10px;
    margin-top: 16px;
    font-size: 0.825rem;
  }
  #upload-card select {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.825rem;
  }
  #upload-card .actions {
    display: flex; gap: 10px;
    margin-top: 18px;
    align-items: center;
  }
  #upload-submit {
    background: var(--accent); color: white;
    border: 0; border-radius: 10px;
    padding: 10px 18px;
    font-size: 0.875rem; font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s ease;
  }
  #upload-submit:hover { opacity: 0.92; }
  #upload-submit:disabled { opacity: 0.5; cursor: not-allowed; }
  #upload-cancel {
    background: transparent; color: var(--muted);
    border: 0; padding: 10px 12px;
    font-size: 0.825rem; cursor: pointer;
  }
  #upload-cancel:hover { color: var(--text); }
  #upload-status { font-size: 0.825rem; margin-left: auto; }
  #upload-status.info { color: var(--muted); }
  /* Error state: occupies its own block under the action row so the
     "Send error report" button can sit below the message comfortably
     instead of crowding the inline status span. */
  #upload-status.error {
    color: var(--neg);
    margin: 12px 0 0 0;
    background: var(--neg-soft);
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 10px 12px;
    width: 100%;
    line-height: 1.45;
  }
  #upload-status.error .report-msg { color: var(--neg); font-size: 0.84rem; }
  #upload-status.error .report-ref {
    font-size: 0.74rem;
    margin-top: 4px;
    word-break: break-all;
  }
  #upload-status.error .report-ref code {
    background: var(--surface);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.74rem;
  }
  #upload-status.error .report-actions {
    display: flex; align-items: center; gap: 10px;
    margin-top: 8px;
    flex-wrap: wrap;
  }
  #upload-status.error #report-error-btn {
    background: var(--surface); color: var(--neg);
    border: 1px solid #fecaca;
    border-radius: 7px;
    padding: 5px 12px;
    font-size: 0.78rem; font-weight: 500;
    cursor: pointer;
    transition: all 0.12s ease;
  }
  #upload-status.error #report-error-btn:hover {
    background: var(--neg); color: #fff; border-color: var(--neg);
  }
  #upload-status.error #report-error-btn:disabled {
    opacity: 0.5; cursor: not-allowed;
  }
  #upload-status.error #report-error-status { font-size: 0.78rem; }
  #upload-status.error #report-error-status.pos { color: var(--pos); }
  #upload-status.error #report-error-status code {
    background: var(--surface);
    padding: 1px 6px; border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.74rem;
  }

  /* ------ Header data controls (visible after data is loaded) ------ */
  .data-ctl {
    display: inline-flex; gap: 6px; align-items: center;
    margin-top: 6px; flex-wrap: wrap;
  }
  .data-ctl button,
  .data-ctl a {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 7px;
    padding: 3px 9px;
    font-size: 0.72rem;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.12s ease;
    text-decoration: none;
  }
  .data-ctl button:hover,
  .data-ctl a:hover { color: var(--text); border-color: var(--border-strong); }
  .data-ctl button.danger:hover { color: var(--neg); border-color: var(--neg); }
  .data-ctl .sep { color: var(--border-strong); }
  .data-source {
    display: inline-flex; align-items: center; gap: 5px;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 3px 9px;
    font-size: 0.72rem;
    color: var(--muted);
    cursor: help;
  }
  .data-source.full { color: var(--pos); border-color: #bbf7d0; background: var(--pos-soft); }
  .data-source.partial { color: var(--warn); border-color: #fde68a; background: var(--warn-soft); }
  .data-source::before {
    content: "●";
    font-size: 0.6rem;
    line-height: 1;
  }

  /* ------ Context tab cards ------ */
  .ctx-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 18px 18px 14px;
    display: flex; flex-direction: column;
  }
  .ctx-question { font-size: 0.78rem; color: var(--muted); }
  .ctx-headline {
    margin: 6px 0 4px;
    display: baseline;
    font-feature-settings: "tnum";
  }
  .ctx-headline-num {
    font-size: 1.65rem;
    font-weight: 600;
    letter-spacing: -0.01em;
  }
  .ctx-headline-unit {
    font-size: 0.85rem;
    color: var(--muted);
    margin-left: 6px;
  }
  .ctx-verdict {
    font-size: 0.85rem;
    font-weight: 500;
    margin: 4px 0 10px;
  }
  .ctx-verdict.pos { color: var(--pos); }
  .ctx-verdict.neutral { color: var(--text-2); }
  .ctx-verdict.warn { color: var(--warn); }
  .ctx-verdict.neg { color: var(--neg); }
  .ctx-bench {
    list-style: none; padding: 0; margin: 0 0 10px;
    border-top: 1px dashed var(--border);
    padding-top: 10px;
  }
  .ctx-bench li {
    display: flex; justify-content: space-between;
    padding: 3px 0;
    font-size: 0.82rem;
    color: var(--text-2);
  }
  .ctx-bench li.you {
    color: var(--text);
    font-weight: 600;
  }
  .ctx-bench li.you .ctx-bench-label::before {
    content: "→ ";
    color: var(--accent);
  }
  .ctx-bench-label { flex: 1; }
  .ctx-bench-value {
    font-feature-settings: "tnum";
    text-align: right;
    min-width: 80px;
    padding-left: 12px;
  }
  .ctx-nudge {
    font-size: 0.82rem;
    color: var(--accent);
    background: var(--accent-soft);
    border-left: 3px solid var(--accent);
    padding: 8px 12px;
    border-radius: 0 6px 6px 0;
    margin: 6px 0 12px;
    line-height: 1.4;
  }
  .ctx-detail {
    font-size: 0.82rem;
    color: var(--text-2);
    line-height: 1.5;
    margin-top: auto;     /* push to the bottom regardless of content above */
    padding-top: 6px;
  }
  .ctx-summary-chip {
    display: inline-flex; align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 500;
    margin-right: 6px;
    border: 1px solid var(--border);
  }
  .ctx-summary-chip.pos     { color: var(--pos);     background: var(--pos-soft);     border-color: #bbf7d0; }
  .ctx-summary-chip.neutral { color: var(--text-2);  background: var(--surface-2); }
  .ctx-summary-chip.warn    { color: var(--warn);    background: var(--warn-soft);    border-color: #fde68a; }
  .ctx-summary-chip.neg     { color: var(--neg);     background: var(--neg-soft);     border-color: #fecaca; }
  .ctx-footnote {
    font-size: 0.7rem;
    color: var(--muted);
    margin-top: 8px;
    font-style: italic;
  }
  @media (max-width: 760px) {
    #ctx-grid { grid-template-columns: 1fr; }
  }

  /* =========================================================
     Diagnostics banner — appears above the tabs whenever the
     pipeline emitted warnings/errors. The banner colour reflects
     the highest-severity item.
     ========================================================= */
  #diagnostics.diag-banner {
    margin: -8px 0 18px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    overflow: hidden;
  }
  #diagnostics.diag-tone-error   { border-color: #fecaca; background: var(--neg-soft); }
  #diagnostics.diag-tone-warn    { border-color: #fde68a; background: var(--warn-soft); }
  #diagnostics.diag-tone-info    { border-color: var(--border); background: var(--surface-2); }

  #diagnostics summary {
    list-style: none;
    cursor: pointer;
    padding: 10px 14px;
    display: flex; align-items: center; gap: 8px;
    font-size: 0.88rem;
    user-select: none;
  }
  #diagnostics summary::-webkit-details-marker { display: none; }
  #diagnostics .diag-icon { font-size: 1rem; line-height: 1; }
  #diagnostics .diag-headline { flex: 1; font-weight: 500; color: var(--text); }
  #diagnostics .diag-cta { font-size: 0.74rem; }
  #diagnostics details[open] summary .diag-cta::after { content: " ▾"; }
  #diagnostics details:not([open]) summary .diag-cta::after { content: " ▸"; }

  #diagnostics .diag-list {
    list-style: none;
    margin: 0; padding: 0;
    border-top: 1px solid var(--border);
    background: var(--surface);
  }
  #diagnostics .diag-row {
    display: grid;
    grid-template-columns: 24px 1fr;
    gap: 10px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    align-items: start;
  }
  #diagnostics .diag-row:first-child { border-top: 0; }
  #diagnostics .diag-row .diag-icon { padding-top: 1px; }
  #diagnostics .diag-msg { font-size: 0.86rem; color: var(--text); line-height: 1.45; }
  #diagnostics .diag-detail {
    font-size: 0.78rem;
    margin-top: 3px;
    word-break: break-word;
  }
  #diagnostics .diag-error .diag-msg   { color: var(--neg); }
  #diagnostics .diag-warning .diag-msg { color: var(--warn); }

  /* Share link sits inside the <summary> next to the headline so users
     don't need to expand the banner to see they can report it. We
     stopPropagation() on click so navigation works even though the
     parent <summary> is a toggle target. */
  #diagnostics .diag-share-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 500;
    text-decoration: none;
    padding: 3px 10px;
    border-radius: 999px;
    white-space: nowrap;
    transition: all 0.12s ease;
  }
  #diagnostics .diag-share-link:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
  }

  /* =========================================================
     Mobile breakpoint (<= 640px).

     Strategy: keep desktop layout intact, override only the hot spots that
     break under 390-640px viewports. Anything that was a 12-col grid with
     fixed col-spans gets collapsed to a single column or a 2-col fallback;
     KPI cards shrink one tier; tab pills auto-scroll horizontally; charts
     and treemaps drop to a usable height.
     ========================================================= */
  @media (max-width: 640px) {
    /* Tighten body padding so cards aren't squeezed by the page gutter. */
    #app { padding-left: 12px; padding-right: 12px; padding-top: 16px; }

    /* Active tab auto-centers itself in the scrollable strip when the user
       switches tabs — they shouldn't have to swipe to find the current one. */
    nav.tabs button { padding: 6px 10px; font-size: 0.84rem; }
    nav.tabs button.active { scroll-snap-align: center; }

    /* Header — stack neatly, smaller subtitle. The 960px media query
       above already stretches .header-right to full width when wrapped,
       so we only adjust the title-side stuff here. */
    header.flex { gap: 12px !important; }
    #subtitle { font-size: 0.78rem; line-height: 1.45; }

    /* Diagnostics banner — slimmer padding, smaller chevron text. */
    #diagnostics summary { padding: 8px 12px; font-size: 0.82rem; }
    #diagnostics .diag-cta { display: none; }

    /* Force every responsive grid we authored to single column at this
       breakpoint. The Tailwind `sm:` prefix is at 640px, so we only need
       this fallback for grids written without sm:-prefixed classes. */
    section[data-section] .grid.grid-cols-12 {
      grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
      gap: 12px !important;
    }
    /* Spans 4-12 collapse to full width; spans 1-3 stay 1-col (so 4-up
       KPI strips become 2x2). */
    section[data-section] [class*="col-span-"] { grid-column: span 2 !important; }
    section[data-section] .col-span-3,
    section[data-section] .col-span-2 { grid-column: span 1 !important; }

    /* The Overview hero needs the headline KPI (Portfolio value) full
       width, then the four small KPIs in a 2x2 below. */
    section[data-section="overview"] .card .col-span-4 { grid-column: span 2 !important; }

    /* Cards: tighter padding so numbers fit. */
    section[data-section] .card.p-6 { padding: 16px !important; }
    section[data-section] .card.p-5 { padding: 14px !important; }

    /* KPI numbers — drop one type tier so 6-digit base-currency values fit
       within a half-width card without being chopped. */
    section[data-section] .num.text-4xl { font-size: 1.75rem !important; }
    section[data-section] .num.text-3xl { font-size: 1.5rem !important; }
    section[data-section] .num.text-2xl { font-size: 1.35rem !important; }
    section[data-section] .num.text-xl  { font-size: 1.15rem !important; }

    /* Charts: cap heights so tabs aren't a scroll marathon. */
    .chart.h-380 { height: 280px !important; }
    .chart.h-320 { height: 240px !important; }
    .chart.h-260 { height: 220px !important; }
    #chart-holdings-treemap { height: 360px !important; }

    /* Insights / Spotlight: 3-col grid → single column. */
    #insights-overview.grid-cols-3 { grid-template-columns: 1fr !important; }

    /* Holdings legend chips — wrap, slightly smaller. */
    section[data-section="holdings"] .text-xs.muted .inline-flex { font-size: 0.72rem; }

    /* Yearly returns table: scroll horizontally inside its card rather
       than overflowing the viewport. */
    table.holdings { font-size: 0.78rem; }
    #yr-returns-table { display: block; overflow-x: auto; max-width: 100%; }

    /* Modals: leave a touch of breathing room rather than full-bleed. */
    #welcome-card, #upload-card { margin: 12px; }

    footer { font-size: 0.72rem; padding: 0 8px; }
  }

  /* Very small phones (<= 360px, e.g. iPhone SE). One more notch tighter. */
  @media (max-width: 360px) {
    section[data-section] .num.text-4xl { font-size: 1.55rem !important; }
    section[data-section] .num.text-3xl { font-size: 1.3rem !important; }
    nav.tabs button { padding: 5px 8px; font-size: 0.8rem; }
  }
