    :root {
      --bg: #f4f1eb;
      --paper: rgba(255, 255, 255, 0.82);
      --surface: rgba(255, 255, 255, 0.82);
      --surface-strong: rgba(255, 255, 255, 0.94);
      --surface-soft: rgba(248, 246, 242, 0.82);
      --ink: #18212b;
      --muted: #5d6872;
      --line: rgba(24, 33, 43, 0.1);
      --line-strong: rgba(24, 33, 43, 0.16);
      --accent: #23425e;
      --accent-soft: #e6eef5;
      --success: #24664a;
      --success-soft: #e4f3ea;
      --warning: #9a6a20;
      --warning-soft: #fbf2df;
      --danger: #a14842;
      --shadow: 0 24px 60px rgba(24, 33, 43, 0.08);
      --sans: "Segoe UI Variable Text", "SF Pro Text", "Helvetica Neue", sans-serif;
      --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
    }

    html {
      scrollbar-gutter: stable;
    }

    * { box-sizing: border-box; margin: 0; padding: 0; }
    body {
      font-family: var(--sans);
      background:
        radial-gradient(circle at top left, rgba(255,255,255,0.92), rgba(255,255,255,0) 38%),
        linear-gradient(180deg, #fbfaf7 0%, var(--bg) 100%);
      color: var(--ink);
      min-height: 100vh;
      padding: 24px;
    }
    a { color: inherit; text-decoration: none; }
    button,
    input,
    select { font: inherit; }
    button { cursor: pointer; }

    .page {
      max-width: 1180px;
      margin: 0 auto;
    }
    .frame {
      background: var(--paper);
      border: 1px solid rgba(255,255,255,0.7);
      box-shadow: var(--shadow);
      border-radius: 36px;
      backdrop-filter: blur(18px);
      overflow: hidden;
    }
    .nav {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 16px;
      padding: 22px 26px;
      border-bottom: 1px solid var(--line);
    }
    .brand {
      display: inline-flex;
      align-items: center;
      gap: 12px;
      font-weight: 700;
      letter-spacing: 0.02em;
    }
    .brand-mark {
      width: 24px;
      height: 24px;
      flex-shrink: 0;
      display: block;
      filter: drop-shadow(0 2px 5px rgba(35, 66, 94, 0.22));
    }
    .nav-actions {
      display: flex;
      align-items: center;
      gap: 10px;
      flex-wrap: wrap;
    }
    .nav-link,
    .nav-pill,
    .filter-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      border-radius: 999px;
      padding: 12px 18px;
      font-size: 0.9rem;
      font-weight: 700;
      border: 1px solid var(--line-strong);
      background: rgba(255,255,255,0.8);
      transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
    }
    .nav-link:hover,
    .filter-btn:hover {
      transform: translateY(-1px);
    }
    .nav-pill {
      color: var(--ink);
      cursor: default;
    }
    .nav-danger {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      border-radius: 999px;
      padding: 12px 18px;
      font-size: 0.9rem;
      font-weight: 700;
      border: 1px solid rgba(161, 72, 66, 0.18);
      background: rgba(255, 255, 255, 0.8);
      color: var(--danger);
      cursor: pointer;
      transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
    }
    .nav-danger:hover {
      transform: translateY(-1px);
    }

    .content {
      padding: 24px;
      display: grid;
      gap: 18px;
    }
    .panel {
      background: var(--surface);
      border: 1px solid var(--line);
      border-radius: 30px;
      padding: 28px;
    }
    .panel-soft {
      background: var(--surface-soft);
    }
    .headline {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      gap: 18px;
      background:
        linear-gradient(180deg, rgba(255,255,255,0.96), rgba(255,255,255,0.86)),
        linear-gradient(135deg, rgba(230,238,245,0.3), rgba(255,255,255,0));
    }
    .headline h1 {
      font-family: var(--serif);
      font-size: clamp(2.4rem, 4vw, 3.5rem);
      font-weight: 600;
      letter-spacing: -0.05em;
      line-height: 0.96;
      margin-bottom: 12px;
    }
    .scope-bar {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 14px;
      flex-wrap: wrap;
    }
    .scope-summary {
      color: var(--muted);
      font-size: 0.92rem;
      line-height: 1.6;
    }
    .clear-link {
      display: none;
      align-items: center;
      justify-content: center;
      border-radius: 999px;
      padding: 10px 14px;
      border: 1px solid var(--line-strong);
      background: rgba(255,255,255,0.84);
      color: var(--ink);
      font-size: 0.84rem;
      font-weight: 700;
      transition: transform 0.16s ease, border-color 0.16s ease;
    }
    .clear-link:hover {
      transform: translateY(-1px);
    }

    .state-panel {
      text-align: center;
      padding: 72px 24px;
    }
    .state-panel h2 {
      font-size: 1.2rem;
      letter-spacing: -0.02em;
      margin-bottom: 8px;
    }
    .state-panel p {
      color: var(--muted);
      line-height: 1.68;
    }
    .state-panel a {
      color: var(--accent);
      font-weight: 700;
    }
    .spinner {
      width: 30px;
      height: 30px;
      border: 3px solid rgba(24, 33, 43, 0.12);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: spin 0.7s linear infinite;
      display: inline-block;
      margin-bottom: 18px;
    }
    @keyframes spin { to { transform: rotate(360deg); } }

    .dashboard {
      display: grid;
      gap: 18px;
    }
    .metrics-grid {
      display: grid;
      grid-template-columns: repeat(4, minmax(0, 1fr));
      gap: 12px;
    }
    .metric-card {
      background: var(--surface-strong);
      border: 1px solid var(--line);
      border-radius: 24px;
      padding: 18px;
      display: grid;
      gap: 10px;
    }
    /* Same family as workspace “Analysis summary” metrics (index): green → amber → navy → purple */
    .metric-card.success {
      background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.5) 0%, transparent 42%),
        linear-gradient(180deg, rgba(36, 102, 74, 0.2) 0%, rgba(36, 102, 74, 0.09) 100%);
      border-color: rgba(36, 102, 74, 0.34);
    }
    .metric-card.warning {
      background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.45) 0%, transparent 42%),
        linear-gradient(180deg, rgba(154, 106, 32, 0.2) 0%, rgba(154, 106, 32, 0.09) 100%);
      border-color: rgba(154, 106, 32, 0.32);
    }
    .metric-card.neutral {
      background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.45) 0%, transparent 42%),
        linear-gradient(180deg, rgba(53, 98, 146, 0.2) 0%, rgba(53, 98, 146, 0.09) 100%);
      border-color: rgba(53, 98, 146, 0.3);
    }
    .metric-card.accent {
      background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.45) 0%, transparent 42%),
        linear-gradient(180deg, rgba(99, 84, 167, 0.2) 0%, rgba(99, 84, 167, 0.09) 100%);
      border-color: rgba(99, 84, 167, 0.3);
    }
    .metric-label {
      font-size: 0.78rem;
      text-transform: uppercase;
      letter-spacing: 0.12em;
      color: #000;
      font-weight: 700;
    }
    .metric-value {
      font-size: clamp(1.5rem, 2.3vw, 2rem);
      font-weight: 800;
      letter-spacing: -0.05em;
      line-height: 1;
    }
    .metric-card-editable {
      position: relative;
    }
    .metric-label-row {
      display: flex;
      align-items: center;
      gap: 6px;
    }
    .metric-edit-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 18px;
      height: 18px;
      padding: 0;
      border: none;
      background: transparent;
      color: #000;
      border-radius: 6px;
      cursor: pointer;
      transition: background 120ms ease, color 120ms ease;
    }
    .metric-edit-btn:hover,
    .metric-edit-btn[aria-expanded="true"] {
      background: rgba(35, 66, 94, 0.08);
      color: var(--accent);
    }
    .metric-popover {
      position: absolute;
      top: calc(100% + 6px);
      left: 14px;
      right: 14px;
      z-index: 40;
      background: #fff;
      border: 1px solid var(--line);
      border-radius: 16px;
      box-shadow: 0 14px 32px rgba(35, 66, 94, 0.14);
      padding: 12px;
      display: grid;
      gap: 10px;
    }
    .metric-popover[hidden] {
      display: none;
    }
    .metric-popover-label {
      font-size: 0.7rem;
      text-transform: uppercase;
      letter-spacing: 0.12em;
      color: #7a8390;
      font-weight: 700;
    }
    .rolling-presets {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
    }
    .rolling-preset {
      flex: 1 1 auto;
      min-width: 38px;
      padding: 6px 8px;
      border-radius: 999px;
      border: 1px solid var(--line);
      background: #fff;
      font-size: 0.8rem;
      font-weight: 700;
      color: var(--accent);
      cursor: pointer;
      transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
    }
    .rolling-preset:hover {
      border-color: var(--accent);
    }
    .rolling-preset.active {
      background: var(--accent);
      border-color: var(--accent);
      color: #fff;
    }
    .rolling-custom {
      display: flex;
      gap: 6px;
      align-items: center;
    }
    .rolling-custom input {
      flex: 1;
      min-width: 0;
      padding: 6px 10px;
      border-radius: 10px;
      border: 1px solid var(--line);
      font-size: 0.85rem;
      background: #fff;
      color: var(--accent);
      font-weight: 600;
    }
    .rolling-custom input:focus {
      outline: none;
      border-color: var(--accent);
    }
    .rolling-ok {
      padding: 6px 12px;
      border-radius: 10px;
      border: 1px solid var(--accent);
      background: var(--accent);
      color: #fff;
      font-size: 0.8rem;
      font-weight: 700;
      cursor: pointer;
      transition: opacity 120ms ease;
    }
    .rolling-ok:hover {
      opacity: 0.88;
    }
    /* Spend Trend | Compare — column mix shifts with month count (see --density classes). */
    .insight-grid {
      display: grid;
      gap: 18px;
      align-items: stretch;
    }
    .insight-grid--density-a {
      grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }
    .insight-grid--density-b {
      grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
    }
    .insight-grid--density-c {
      grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.18fr);
    }
    .insight-aside {
      min-height: 0;
      display: flex;
      flex-direction: column;
    }
    .insight-compare-inner {
      display: flex;
      flex-direction: column;
      flex: 1;
      min-height: 0;
    }
    .compare-head-tools {
      display: flex;
      align-items: center;
      flex-shrink: 0;
    }
    .compare-mode-pills {
      display: inline-flex;
      gap: 3px;
      padding: 4px;
      background: var(--surface-soft);
      border: 1px solid var(--line);
      border-radius: 999px;
    }
    .compare-mode-pill {
      border: none;
      border-radius: 999px;
      padding: 7px 14px;
      font-size: 0.76rem;
      font-weight: 800;
      letter-spacing: 0.06em;
      text-transform: uppercase;
      color: var(--muted);
      background: transparent;
      cursor: pointer;
    }
    .compare-mode-pill:hover {
      color: var(--ink);
    }
    .compare-mode-pill.active {
      background: var(--accent);
      color: #fff;
    }
    .compare-chart-shell {
      display: grid;
      grid-template-columns: minmax(20px, 26px) 50px minmax(0, 1fr);
      gap: 6px 10px;
      align-items: stretch;
      flex: 1;
      min-height: 200px;
    }
    .compare-y-axis-label {
      display: flex;
      align-items: center;
      justify-content: center;
      padding-bottom: 26px;
      border-right: 1px solid rgba(24, 33, 43, 0.08);
    }
    .compare-y-axis-label-text {
      writing-mode: vertical-rl;
      text-orientation: mixed;
      transform: rotate(180deg);
      font-size: 0.58rem;
      font-weight: 800;
      letter-spacing: 0.11em;
      text-transform: uppercase;
      color: #5c6570;
      line-height: 1.2;
      max-height: 100%;
    }
    .compare-y-axis {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      font-size: 0.65rem;
      letter-spacing: 0.02em;
      color: #7a8390;
      font-weight: 700;
      text-align: right;
      padding-bottom: 26px;
      line-height: 1.2;
      border-right: 1px solid rgba(24, 33, 43, 0.1);
      padding-right: 4px;
    }
    .compare-plot {
      display: flex;
      flex-direction: column;
      min-width: 0;
      flex: 1;
    }
    .compare-bars {
      flex: 1;
      display: flex;
      align-items: stretch;
      justify-content: stretch;
      min-height: 156px;
      border-bottom: 1px solid rgba(24, 33, 43, 0.12);
      padding-bottom: 0;
    }
    .compare-bar-col {
      flex: 1 1 0;
      min-width: 0;
      min-height: 0;
      display: flex;
      flex-direction: column;
      align-items: stretch;
      justify-content: flex-end;
    }
    /* Label anchored just above the bar; fill height stays h% of track (y-axis accurate). */
    .compare-bar-stack {
      --compare-h-pct: 0%;
      position: relative;
      width: 100%;
      max-width: 56px;
      margin: 0 auto;
      min-height: 0;
      flex: 1 1 auto;
    }
    .compare-bar-value {
      position: absolute;
      left: 0;
      right: 0;
      bottom: calc(var(--compare-h-pct) + 3px);
      z-index: 1;
      font-size: 0.68rem;
      font-weight: 800;
      color: var(--accent);
      letter-spacing: -0.02em;
      text-align: center;
      white-space: nowrap;
      max-width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .compare-bar-track {
      flex: 1 1 auto;
      width: 100%;
      margin: 0 auto;
      min-height: 104px;
      display: flex;
      align-items: stretch;
      justify-content: center;
      border-radius: 12px 12px 0 0;
      background: transparent;
    }
    .compare-bar-fill {
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      width: 100%;
      height: var(--compare-h-pct);
      min-height: 3px;
      border-radius: 12px 12px 0 0;
    }
    .compare-x-labels {
      display: flex;
      justify-content: stretch;
      padding-top: 10px;
      gap: inherit;
    }
    .compare-x-labels span {
      flex: 1 1 0;
      min-width: 0;
      text-align: center;
      font-size: 0.72rem;
      font-weight: 800;
      color: var(--muted);
      letter-spacing: 0.04em;
      text-transform: uppercase;
    }
    .compare-footnote {
      margin-top: 12px;
      font-size: 0.74rem;
      line-height: 1.45;
      color: var(--muted);
      font-weight: 600;
    }
    .compare-empty {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      min-height: 140px;
      color: var(--muted);
      font-size: 0.88rem;
      text-align: center;
      padding: 16px 8px;
    }
    .trend-head-wrap {
      position: relative;
      flex-shrink: 0;
    }
    .trend-month-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 34px;
      height: 34px;
      padding: 0;
      border: 1px solid var(--line);
      border-radius: 12px;
      background: rgba(255, 255, 255, 0.9);
      color: var(--accent);
      cursor: pointer;
      transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
    }
    .trend-month-btn:hover,
    .trend-month-btn[aria-expanded="true"] {
      border-color: rgba(35, 66, 94, 0.28);
      background: rgba(35, 66, 94, 0.05);
    }
    .trend-month-popover {
      position: absolute;
      top: calc(100% + 8px);
      right: 0;
      left: auto;
      min-width: 240px;
      max-width: min(320px, calc(100vw - 48px));
      z-index: 50;
    }
    .trend-month-popover[hidden] {
      display: none;
    }
    .trend-month-checks {
      display: flex;
      flex-direction: column;
      gap: 4px;
      max-height: min(280px, 42vh);
      overflow-y: auto;
    }
    .trend-month-option {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 8px 10px;
      border-radius: 10px;
      cursor: pointer;
      font-size: 0.88rem;
      font-weight: 600;
      color: var(--accent);
      transition: background 120ms ease;
    }
    .trend-month-option:hover {
      background: rgba(35, 66, 94, 0.06);
    }
    .trend-month-option input {
      width: 16px;
      height: 16px;
      accent-color: var(--accent);
      flex-shrink: 0;
    }
    .trend-month-option input:disabled {
      opacity: 0.45;
      cursor: not-allowed;
    }
    .trend-month-cap-note {
      margin: 10px 0 0;
      padding-top: 10px;
      border-top: 1px solid var(--line);
      font-size: 0.74rem;
      line-height: 1.45;
      color: var(--muted);
      font-weight: 600;
    }
    .trend-month-cap-note strong {
      color: var(--ink);
      font-weight: 800;
    }
    .section-head {
      display: flex;
      justify-content: space-between;
      align-items: flex-end;
      gap: 14px;
      margin-bottom: 18px;
    }
    .section-head h2 {
      font-size: 1.1rem;
      letter-spacing: -0.02em;
    }
    .section-head span {
      color: var(--muted);
      font-size: 0.82rem;
      font-weight: 700;
      white-space: nowrap;
    }

    .trend-list,
    .merchant-list,
    .card-list {
      display: grid;
      gap: 12px;
    }
    .interactive-row {
      width: 100%;
      border: 1px solid transparent;
      background: transparent;
      text-align: left;
      padding: 12px 14px;
      border-radius: 18px;
      transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
    }
    .interactive-row:hover {
      background: rgba(255,255,255,0.7);
      border-color: var(--line);
      transform: translateY(-1px);
    }
    /* Active filter: thin accent bar + tint. Cards & merchants only (Spend
       Trend months are chosen via the header popover, not row clicks). */
    .interactive-row.active {
      background: rgba(35, 66, 94, 0.04);
      border-color: transparent;
      box-shadow: inset 3px 0 0 var(--accent);
    }
    .trend-row,
    .merchant-row,
    .card-row {
      display: grid;
      gap: 10px;
      align-items: center;
    }
    .trend-row {
      grid-template-columns: 98px minmax(0, 1fr) auto;
      padding: 12px 14px;
      border-radius: 18px;
      border: 1px solid transparent;
      background: rgba(255, 255, 255, 0.45);
    }
    .trend-label,
    .merchant-label,
    .card-label {
      font-size: 0.9rem;
      font-weight: 700;
      letter-spacing: -0.01em;
    }
    .trend-track,
    .share-track {
      position: relative;
      height: 10px;
      border-radius: 999px;
      background: rgba(24, 33, 43, 0.08);
      overflow: hidden;
    }
    .trend-fill,
    .share-fill {
      position: absolute;
      inset: 0 auto 0 0;
      border-radius: 999px;
      background: linear-gradient(90deg, #2b5376, #7f9cb8);
    }
    .trend-value,
    .merchant-value,
    .card-value {
      font-size: 0.92rem;
      font-weight: 700;
      white-space: nowrap;
    }
    .card-row {
      grid-template-columns: minmax(0, 1fr) auto;
      padding: 14px 0;
      border-top: 1px solid var(--line);
    }
    .card-row:first-child {
      border-top: none;
      padding-top: 0;
    }
    .card-meta,
    .merchant-meta {
      color: var(--muted);
      font-size: 0.82rem;
      line-height: 1.5;
    }
    /* --- "Top X" table shell ---------------------------------------------
       Shared table-style container used by Top Cards and Top Merchants.
       Tinted header strip matches the Transactions `thead` aesthetic; row
       delineation is by border-bottom (not gap) so the contents read as a
       proper table. */
    .top-table {
      border: 1px solid var(--line);
      border-radius: 18px;
      overflow: hidden;
      background: rgba(255,255,255,0.6);
    }
    .top-thead {
      display: grid;
      grid-template-columns: minmax(0, 1.7fr) minmax(140px, 1.3fr) auto;
      gap: 14px;
      padding: 12px 20px;
      background: rgba(248,246,242,0.7);
      border-bottom: 1px solid var(--line);
      font-size: 0.74rem;
      text-transform: uppercase;
      letter-spacing: 0.12em;
      color: #7a8390;
      font-weight: 700;
      align-items: center;
    }
    .top-thead span:last-child { text-align: right; }

    /* The list ditches gap-based layout and uses row borders. Applies to
       both the merchants list and the cards list when they're inside a
       .top-table shell. */
    .top-table .merchant-list,
    .top-table .card-list { display: block; }
    .top-table .merchant-row,
    .top-table .card-row {
      /* Two-row grid: bar + $ share the first data row (centered together);
         "% of spend" sits below spanning Share+Total columns. */
      grid-template-columns: minmax(0, 1.7fr) minmax(140px, 1.3fr) auto;
      grid-template-rows: auto auto;
      grid-template-areas:
        "top-name share-track top-value"
        "top-name share-meta share-meta";
      gap: 6px 14px;
      padding: 14px 20px;
      border: none;
      border-bottom: 1px solid var(--line);
      border-radius: 0;
      align-items: center;
    }
    .top-table .merchant-row:last-child,
    .top-table .card-row:last-child { border-bottom: none; }
    /* Flatten the default interactive-row hover lift inside the table so
       rows don't detach from their neighbors. */
    .top-table .merchant-row:hover,
    .top-table .card-row:hover {
      transform: none;
      background: rgba(255,255,255,0.85);
      border-color: transparent;
      border-bottom-color: var(--line);
    }
    .top-table .merchant-row:last-child:hover,
    .top-table .card-row:last-child:hover { border-bottom-color: transparent; }

    .top-table .top-name-col {
      grid-area: top-name;
      min-width: 0;
      align-self: start;
    }
    .top-table .share-track {
      grid-area: share-track;
      align-self: center;
      min-width: 0;
    }
    .top-table .top-value-col {
      grid-area: top-value;
      align-self: center;
    }
    .top-table .top-share-label {
      grid-area: share-meta;
      color: var(--muted);
      font-size: 0.78rem;
    }
    .top-value-col {
      font-size: 0.95rem;
      font-weight: 700;
      white-space: nowrap;
      text-align: right;
    }
    .mini-empty {
      color: var(--muted);
      font-size: 0.9rem;
      line-height: 1.65;
      padding: 10px 0 2px;
    }

    .ledger-panel {
      padding: 0;
      overflow: hidden;
    }
    .ledger-top {
      /* The `padding` bottom (3rd value) controls the gap between the
         last filter row and the ledger table. The grid `gap` controls the
         spacing between the H2 and row 1, AND between row 1 and row 2.
         See also `.ledger-tools + .ledger-tools` below for the extra
         tightening between row 1 and row 2 only. */
      padding: 24px 24px 28px;
      border-bottom: 1px solid var(--line);
      background: rgba(255,255,255,0.9);
      display: grid;
      gap: 16px;
    }
    .ledger-head {
      display: flex;
      justify-content: space-between;
      align-items: flex-end;
      gap: 14px;
    }
    .ledger-head h2 {
      font-size: 1.1rem;
      letter-spacing: -0.02em;
    }
    .ledger-count {
      color: var(--muted);
      font-size: 0.82rem;
      font-weight: 700;
      white-space: nowrap;
    }
    .ledger-count-group {
      display: flex;
      align-items: center;
      gap: 12px;
      flex-wrap: wrap;
    }
    .ledger-tools {
      display: grid;
      grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(190px, 0.8fr);
      gap: 12px;
      align-items: end;
    }
    .control {
      display: grid;
      gap: 8px;
    }
    .control label {
      font-size: 0.74rem;
      text-transform: uppercase;
      letter-spacing: 0.12em;
      color: #7a8390;
      font-weight: 700;
    }
    .search-input,
    .card-select {
      width: 100%;
      min-height: 48px;
      padding: 0 15px;
      border-radius: 16px;
      border: 1px solid var(--line-strong);
      background: rgba(255,255,255,0.96);
      color: var(--ink);
      outline: none;
    }
    .search-input:focus,
    .card-select:focus {
      border-color: rgba(35, 66, 94, 0.42);
      box-shadow: 0 0 0 4px rgba(35, 66, 94, 0.08);
    }
    .filter-row {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
    }
    .filter-btn {
      padding: 11px 14px;
      font-size: 0.84rem;
      min-height: 48px;
    }
    .filter-btn.active {
      background: var(--accent);
      color: #ffffff;
      border-color: transparent;
      box-shadow: 0 14px 28px rgba(35, 66, 94, 0.16);
    }

    .ledger-tools + .ledger-tools {
      /* Negative margin pulls row 2 (Month/Amount) closer to row 1
         (Search/Status/Card). The `.ledger-top` grid gap is 16px, so the
         effective spacing here is (16 + this value). Use 0 for 16px,
         -6 for 10px, -10 for 6px, etc. */
      margin-top: -6px;
    }
    .amount-row {
      display: grid;
      grid-template-columns: minmax(0, 110px) minmax(0, 1fr);
      gap: 8px;
      align-items: stretch;
    }
    .amount-op {
      width: 100%;
      min-height: 48px;
      padding: 0 12px;
      border-radius: 16px;
      border: 1px solid var(--line-strong);
      background: rgba(255,255,255,0.96);
      color: var(--ink);
      font: inherit;
      outline: none;
      transition: border-color 0.16s ease, box-shadow 0.16s ease;
    }
    .amount-op:focus {
      border-color: rgba(35, 66, 94, 0.42);
      box-shadow: 0 0 0 4px rgba(35, 66, 94, 0.08);
    }
    .amount-input-wrap {
      display: flex;
      align-items: center;
      min-height: 48px;
      padding: 0 14px;
      border-radius: 16px;
      border: 1px solid var(--line-strong);
      background: rgba(255,255,255,0.96);
      transition: border-color 0.16s ease, box-shadow 0.16s ease;
    }
    .amount-input-wrap:focus-within {
      border-color: rgba(35, 66, 94, 0.42);
      box-shadow: 0 0 0 4px rgba(35, 66, 94, 0.08);
    }
    .amount-prefix {
      color: var(--muted);
      font-weight: 700;
      margin-right: 6px;
    }
    .amount-input {
      flex: 1;
      min-width: 0;
      border: none;
      background: transparent;
      padding: 0;
      font: inherit;
      color: var(--ink);
      outline: none;
      min-height: 44px;
      appearance: textfield;
    }
    .amount-input::-webkit-outer-spin-button,
    .amount-input::-webkit-inner-spin-button {
      -webkit-appearance: none;
      margin: 0;
    }

    .batches-tools {
      padding: 18px 28px;
      border-bottom: 1px solid var(--line);
      background: rgba(255,255,255,0.9);
    }
    .batches-count-group {
      display: flex;
      align-items: center;
      gap: 12px;
      flex-wrap: wrap;
      justify-content: flex-end;
    }

    .table-wrap {
      overflow-x: auto;
    }
    table {
      width: 100%;
      border-collapse: collapse;
    }
    thead th {
      text-align: left;
      padding: 15px 24px;
      font-size: 0.74rem;
      text-transform: uppercase;
      letter-spacing: 0.12em;
      color: #7a8390;
      font-weight: 700;
      border-bottom: 1px solid var(--line);
      background: rgba(248,246,242,0.7);
    }
    tbody td {
      padding: 18px 24px;
      border-bottom: 1px solid var(--line);
      vertical-align: top;
      font-size: 0.94rem;
    }
    tbody tr:last-child td {
      border-bottom: none;
    }
    .merchant-cell {
      display: grid;
      gap: 4px;
    }
    .merchant-name {
      font-weight: 700;
      letter-spacing: -0.01em;
    }
    .merchant-sub {
      color: var(--muted);
      font-size: 0.82rem;
      line-height: 1.45;
    }
    .amount-cell {
      font-weight: 700;
      letter-spacing: -0.01em;
      white-space: nowrap;
      text-align: right;
    }
    .status-pill {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      padding: 8px 11px;
      border-radius: 999px;
      font-size: 0.76rem;
      font-weight: 700;
      border: 1px solid var(--line);
      background: rgba(255,255,255,0.82);
      white-space: nowrap;
    }
    .status-pill::before {
      content: "";
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: var(--success);
    }
    .status-pill.pending {
      background: var(--warning-soft);
      color: var(--warning);
      border-color: rgba(154, 106, 32, 0.18);
    }
    .status-pill.pending::before {
      background: var(--warning);
    }

    tbody tr.ledger-row-pending {
      box-shadow: inset 3px 0 0 var(--warning);
    }
    .status-cell-inner {
      display: inline-flex;
      align-items: center;
      flex-wrap: wrap;
      gap: 8px 10px;
    }
    .mark-settled-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 30px;
      height: 30px;
      padding: 0;
      border-radius: 999px;
      border: 1px solid rgba(35, 66, 94, 0.18);
      background: rgba(255, 255, 255, 0.95);
      color: var(--accent);
      cursor: pointer;
      flex-shrink: 0;
      transition: background 120ms ease, border-color 120ms ease, transform 120ms ease, opacity 120ms ease;
    }
    .mark-settled-btn:hover:not(:disabled) {
      border-color: var(--accent);
      background: rgba(35, 66, 94, 0.06);
    }
    .mark-settled-btn:active:not(:disabled) {
      transform: scale(0.96);
    }
    .mark-settled-btn:disabled {
      opacity: 0.55;
      cursor: default;
    }
    .mark-settled-btn svg {
      display: block;
    }

    .ledger-empty {
      padding: 48px 24px 52px;
      text-align: center;
      color: var(--muted);
      line-height: 1.65;
    }

    @media (max-width: 1180px) {
      .metrics-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }
      .insight-grid.insight-grid--density-a,
      .insight-grid.insight-grid--density-b,
      .insight-grid.insight-grid--density-c {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }
      .insight-grid > .insight-aside {
        grid-column: 1 / -1;
      }
      .ledger-tools {
        grid-template-columns: 1fr;
      }
    }

    .view-switcher {
      display: flex;
      align-items: center;
      gap: 14px;
      flex-wrap: wrap;
      margin-top: 18px;
    }
    .view-tabs {
      display: inline-flex;
      gap: 6px;
      padding: 5px;
      background: var(--surface-soft);
      border: 1px solid rgba(24, 33, 43, 0.06);
      border-radius: 999px;
    }
    .view-tab {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      border: none;
      border-radius: 999px;
      padding: 9px 18px;
      font-size: 0.88rem;
      font-weight: 700;
      letter-spacing: 0.01em;
      color: var(--muted);
      background: transparent;
      transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
    }
    .view-tab:hover {
      color: var(--ink);
    }
    .view-tab.active {
      background: var(--accent);
      color: #ffffff;
      box-shadow: 0 10px 22px rgba(35, 66, 94, 0.18);
    }
    .help-link {
      margin-left: auto;
      background: transparent;
      border: none;
      padding: 4px 2px;
      color: var(--muted);
      font-size: 0.82rem;
      font-weight: 600;
      letter-spacing: 0.01em;
      text-decoration: underline dashed rgba(24, 33, 43, 0.28);
      text-underline-offset: 4px;
      text-decoration-thickness: 1px;
      transition: color 0.16s ease, text-decoration-color 0.16s ease;
    }
    .help-link:hover {
      color: var(--accent);
      text-decoration-color: rgba(35, 66, 94, 0.5);
    }

    .view-section {
      display: grid;
      gap: 18px;
    }
    .view-section[hidden] {
      display: none;
    }

    .batches-panel {
      padding: 0;
      overflow: hidden;
    }
    .batches-top {
      padding: 26px 28px 18px;
      display: flex;
      justify-content: space-between;
      align-items: flex-end;
      gap: 14px;
      border-bottom: 1px solid var(--line);
    }
    .batches-top h2 {
      font-size: 1.1rem;
      letter-spacing: -0.02em;
      margin-bottom: 4px;
    }
    .batches-top p {
      color: var(--muted);
      font-size: 0.86rem;
      line-height: 1.55;
    }
    .batches-count {
      color: var(--muted);
      font-size: 0.82rem;
      font-weight: 700;
      white-space: nowrap;
    }
    .batches-list {
      display: grid;
      gap: 0;
    }
    .batch-row {
      width: 100%;
      display: grid;
      grid-template-columns: minmax(180px, 1.3fr) 90px 110px 110px minmax(0, 1.4fr) 44px;
      gap: 18px;
      align-items: center;
      padding: 18px 28px;
      border: none;
      background: transparent;
      border-bottom: 1px solid var(--line);
      text-align: left;
      transition: background 0.16s ease;
    }
    .batch-row:last-child {
      border-bottom: none;
    }
    .batch-row:hover {
      background: rgba(35, 66, 94, 0.035);
    }
    .batch-cell-primary strong {
      display: block;
      font-size: 0.96rem;
      letter-spacing: -0.01em;
      margin-bottom: 3px;
    }
    .batch-cell-primary span {
      color: var(--muted);
      font-size: 0.82rem;
    }
    .batch-cell-number {
      font-weight: 700;
      letter-spacing: -0.02em;
      font-size: 0.96rem;
    }
    .batch-cell-sub {
      color: var(--muted);
      font-size: 0.78rem;
      margin-top: 2px;
    }
    .batch-cell-card {
      color: var(--ink);
      font-size: 0.88rem;
      line-height: 1.4;
    }
    .batch-cell-card .mixed-flag {
      display: inline-block;
      margin-left: 6px;
      font-size: 0.72rem;
      color: var(--warning);
      font-weight: 700;
    }
    .batch-chevron {
      width: 34px;
      height: 34px;
      border-radius: 999px;
      border: 1px solid var(--line);
      background: rgba(255,255,255,0.8);
      color: var(--muted);
      display: inline-flex;
      align-items: center;
      justify-content: center;
      transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
    }
    .batch-row:hover .batch-chevron {
      color: var(--accent);
      border-color: rgba(35, 66, 94, 0.28);
      transform: translateX(1px);
    }
    .batch-chevron svg {
      width: 14px;
      height: 14px;
    }

    .modal-overlay {
      position: fixed;
      inset: 0;
      background: rgba(24, 33, 43, 0.38);
      backdrop-filter: blur(6px);
      display: none;
      align-items: center;
      justify-content: center;
      z-index: 50;
      padding: 24px;
    }
    .modal-overlay.visible {
      display: flex;
      animation: modal-fade 0.18s ease-out;
    }
    @keyframes modal-fade {
      from { opacity: 0; }
      to { opacity: 1; }
    }
    .modal-card {
      width: min(560px, 100%);
      max-height: calc(100vh - 48px);
      overflow-y: auto;
      background: #ffffff;
      border: 1px solid var(--line);
      border-radius: 28px;
      box-shadow: 0 40px 100px rgba(24, 33, 43, 0.28);
      padding: 28px;
      animation: modal-pop 0.2s ease-out;
    }
    @keyframes modal-pop {
      from { opacity: 0; transform: translateY(6px) scale(0.98); }
      to   { opacity: 1; transform: translateY(0) scale(1); }
    }
    .modal-title {
      font-family: var(--serif);
      font-size: 1.6rem;
      font-weight: 600;
      letter-spacing: -0.03em;
      margin-bottom: 8px;
    }
    .modal-subtitle {
      color: var(--muted);
      font-size: 0.92rem;
      line-height: 1.6;
      margin-bottom: 22px;
    }
    .modal-section {
      border-top: 1px solid var(--line);
      padding-top: 16px;
      margin-top: 16px;
    }
    .modal-section:first-of-type {
      border-top: none;
      padding-top: 0;
      margin-top: 0;
    }
    .modal-section h3 {
      font-size: 0.76rem;
      text-transform: uppercase;
      letter-spacing: 0.12em;
      color: #7a8390;
      font-weight: 700;
      margin-bottom: 10px;
    }
    .modal-stats {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 10px;
    }
    .modal-stat {
      background: var(--surface-soft);
      border: 1px solid rgba(24, 33, 43, 0.06);
      border-radius: 16px;
      padding: 12px 14px;
    }
    .modal-stat span {
      display: block;
      font-size: 0.72rem;
      text-transform: uppercase;
      letter-spacing: 0.1em;
      color: #7a8390;
      font-weight: 700;
      margin-bottom: 3px;
    }
    .modal-stat strong {
      font-size: 1.05rem;
      letter-spacing: -0.02em;
    }
    .modal-tx-list {
      display: grid;
      gap: 8px;
      max-height: 220px;
      overflow-y: auto;
      padding-right: 4px;
    }
    .modal-tx-row {
      display: flex;
      justify-content: space-between;
      gap: 14px;
      padding: 10px 12px;
      border-radius: 14px;
      background: rgba(255,255,255,0.76);
      border: 1px solid var(--line);
      font-size: 0.88rem;
    }
    .modal-tx-row .tx-vendor {
      font-weight: 700;
      letter-spacing: -0.01em;
    }
    .modal-tx-row .tx-meta {
      color: var(--muted);
      font-size: 0.76rem;
      margin-top: 2px;
    }
    .modal-tx-row .tx-amount {
      font-weight: 700;
      white-space: nowrap;
    }
    .modal-actions {
      display: flex;
      justify-content: space-between;
      gap: 12px;
      margin-top: 24px;
      flex-wrap: wrap;
    }
    .modal-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      border-radius: 999px;
      padding: 12px 20px;
      font-size: 0.9rem;
      font-weight: 700;
      letter-spacing: 0.01em;
      border: 1px solid transparent;
      transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
    }
    .modal-btn:hover:not(:disabled) {
      transform: translateY(-1px);
    }
    .modal-btn:disabled {
      opacity: 0.55;
      cursor: not-allowed;
    }
    .modal-btn-secondary {
      background: rgba(255,255,255,0.9);
      color: var(--ink);
      border-color: var(--line-strong);
    }
    .modal-btn-danger {
      background: var(--danger);
      color: #ffffff;
      box-shadow: 0 12px 28px rgba(161, 72, 66, 0.22);
    }
    .modal-btn .spinner {
      width: 14px;
      height: 14px;
      border-width: 2px;
      margin-bottom: 0;
      border-color: rgba(255,255,255,0.35);
      border-top-color: #ffffff;
    }

    .help-copy p + p {
      margin-top: 12px;
    }
    .help-copy strong {
      color: var(--ink);
    }
    .help-copy {
      color: var(--muted);
      line-height: 1.68;
      font-size: 0.95rem;
    }

    .toast {
      position: fixed;
      left: 50%;
      bottom: 28px;
      transform: translateX(-50%);
      background: rgba(24, 33, 43, 0.92);
      color: #ffffff;
      padding: 14px 20px;
      border-radius: 999px;
      font-size: 0.88rem;
      opacity: 0;
      transition: opacity 0.24s ease, transform 0.24s ease;
      pointer-events: none;
      box-shadow: 0 18px 40px rgba(24, 33, 43, 0.22);
      white-space: nowrap;
      z-index: 60;
    }
    .toast.show {
      opacity: 1;
      transform: translateX(-50%) translateY(-2px);
    }

    @media (max-width: 980px) {
      .nav {
        flex-direction: column;
        align-items: stretch;
      }
      .nav-actions {
        width: 100%;
      }
      .nav-link,
      .nav-pill {
        flex: 1;
      }
      .batch-row {
        grid-template-columns: 1fr auto;
        row-gap: 10px;
        column-gap: 14px;
      }
      .batch-row > *:nth-child(2),
      .batch-row > *:nth-child(3),
      .batch-row > *:nth-child(4),
      .batch-row > *:nth-child(5) {
        grid-column: 1;
      }
      .batch-chevron {
        grid-column: 2;
        grid-row: 1 / span 5;
        align-self: center;
      }
      .batches-top {
        flex-direction: column;
        align-items: flex-start;
      }
    }

    @media (max-width: 860px) {
      body { padding: 16px; }
      .metrics-grid {
        grid-template-columns: 1fr 1fr;
      }
      .insight-grid.insight-grid--density-a,
      .insight-grid.insight-grid--density-b,
      .insight-grid.insight-grid--density-c {
        grid-template-columns: 1fr;
      }
      .insight-grid > .insight-aside {
        grid-column: auto;
      }
      .trend-row {
        grid-template-columns: 82px minmax(0, 1fr) auto;
      }
    }

    @media (max-width: 640px) {
      .content {
        padding: 18px;
      }
      .panel {
        padding: 20px;
        border-radius: 24px;
      }
      .metrics-grid {
        grid-template-columns: 1fr;
      }
      .ledger-top {
        padding: 20px 20px 16px;
      }
      .ledger-head {
        flex-direction: column;
        align-items: flex-start;
      }
      thead {
        display: none;
      }
      table,
      tbody,
      tr,
      td {
        display: block;
        width: 100%;
      }
      tbody tr {
        padding: 18px 20px;
        border-bottom: 1px solid var(--line);
      }
      tbody td {
        padding: 0;
        border-bottom: none;
        margin-top: 12px;
      }
      tbody td:first-child {
        margin-top: 0;
      }
      tbody td::before {
        content: attr(data-label);
        display: block;
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.12em;
        color: #7a8390;
        font-weight: 700;
        margin-bottom: 6px;
      }
      .amount-cell {
        text-align: left;
      }
      .trend-row {
        grid-template-columns: 1fr;
      }
      .trend-track {
        order: 3;
      }
      .trend-value {
        order: 2;
      }
      /* Top-X tables collapse to stacked cards on narrow screens. */
      .top-thead { display: none; }
      .top-table .merchant-row,
      .top-table .card-row {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-rows: auto auto auto;
        grid-template-areas:
          "top-name top-value"
          "share-track share-track"
          "share-meta share-meta";
        gap: 8px 14px;
        padding: 14px 18px;
      }
      .top-table .top-name-col {
        align-self: start;
      }
    }
