  :root {
    color-scheme: dark;
    --bg: #0b0e13;
    --surface: #141820;
    --surface-2: #1b212b;
    --surface-3: #252d3a;
    --border: rgba(255, 255, 255, 0.12);
    --border-hover: rgba(255, 255, 255, 0.22);
    --text: #edf3fb;
    --muted: #9aa6b5;
    --faint: #566174;
    --accent: #4f9a94;
    --accent-strong: #3f817c;
    --accent-soft: rgba(79, 154, 148, 0.14);
    --accent-border: rgba(79, 154, 148, 0.34);
    --pin: #f59e0b;
    --pin-soft: rgba(245, 158, 11, 0.12);
    --special: #d6b45f;
    --special-soft: rgba(214, 180, 95, 0.14);
    --special-border: rgba(214, 180, 95, 0.4);
    --success: #20b486;
    --danger: #f05262;
    --warning: #eab308;
    --radius: 8px;
    font-family: "Noto Sans Thai", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  }

  body.light {
    color-scheme: light;
    --bg: #f5efe4;
    --surface: #fffaf1;
    --surface-2: #f7efdf;
    --surface-3: #efe4d0;
    --border: rgba(89, 67, 41, 0.14);
    --border-hover: rgba(89, 67, 41, 0.24);
    --text: #2f271d;
    --muted: #746653;
    --faint: #b8aa94;
    --accent-soft: rgba(79, 154, 148, 0.1);
    --accent-border: rgba(79, 154, 148, 0.24);
    --pin-soft: rgba(245, 158, 11, 0.1);
    --special-soft: rgba(181, 134, 39, 0.12);
    --special-border: rgba(181, 134, 39, 0.32);
  }

  * { box-sizing: border-box; letter-spacing: 0; }
  html { width: 100%; overflow-x: hidden; }
  body {
    min-height: 100vh;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    overflow-x: hidden;
    transition: background 0.25s ease, color 0.25s ease;
  }
  button, input, textarea, select { font: inherit; }
  button { cursor: pointer; }
  button:active { transform: scale(0.98); }

  /* ── Top projects bar ── */
  .top-projects {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto 18px;
    animation: fadeUp 0.35s ease both;
  }

  .top-projects-inner {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
  }

  .top-project {
    min-width: 0;
    min-height: 58px;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    padding: 10px;
    text-align: left;
    text-decoration: none;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.18);
    transition: 0.15s ease;
  }

  .top-project:hover {
    border-color: var(--accent-border);
    background: var(--surface-2);
    transform: translateY(-1px);
  }

  .top-project.active {
    border-color: var(--accent-border);
    background: var(--accent-soft);
  }

  .top-project.disabled {
    opacity: 0.72;
    border-style: dashed;
    cursor: not-allowed;
  }

  .top-project-icon {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--accent);
    font-size: 1rem;
  }

  .top-project-text {
    min-width: 0;
    display: grid;
    gap: 2px;
  }

  .top-project-name {
    font-size: 0.82rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .top-project-desc {
    color: var(--muted);
    font-size: 0.68rem;
  }

  .top-project-pill {
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    padding: 3px 7px;
    font-size: 0.62rem;
    font-weight: 700;
    white-space: nowrap;
  }

  .top-project.active .top-project-pill {
    color: var(--accent);
    border-color: var(--accent-border);
    background: var(--accent-soft);
  }

  @media (max-width: 820px) {
    .top-projects-inner { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .top-project.disabled { display: none; }
  }

  @media (max-width: 520px) {
    .top-projects-inner { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }

  .layout {
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    align-items: start;
    animation: fadeUp 0.35s ease both;
  }

  @media (min-width: 820px) {
    .layout { grid-template-columns: 250px minmax(0, 1fr); }
  }

  @media (min-width: 1140px) {
    .layout {
      grid-template-columns: 230px minmax(0, 1fr) 230px;
      gap: 18px;
    }
  }
  .left-panel, main { min-width: 0; }
  .left-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }
  .left-panel > .card,
  .right-panel > .feature-panel {
    min-width: 0;
    width: 100%;
  }
  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.18);
  }

  .clock-card { text-align: center; }
  #clock {
    font-family: "DM Mono", monospace;
    font-size: 2.65rem;
    font-weight: 500;
    line-height: 1;
    color: var(--accent);
  }
  #clockวันที่ { margin-top: 8px; color: var(--muted); font-size: 0.78rem; }

  .cal-head, .main-header, .summary-line, .sync-row, .action-row, .progress-label, .modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }
  .cal-head { margin-bottom: 14px; font-size: 0.9rem; font-weight: 600; }
  .nav-btn, .icon-btn {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    min-width: 36px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    padding: 0;
    line-height: 1;
    transition: 0.15s ease;
  }
  .nav-btn:hover, .icon-btn:hover {
    border-color: var(--accent-border);
    color: var(--accent);
    background: var(--accent-soft);
  }
  .today-btn {
    border: 1px solid var(--accent-border);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 3px 10px;
    font-size: 0.72rem;
    font-weight: 700;
    transition: 0.15s ease;
  }
  .today-btn:hover { background: var(--accent); color: #fff; }

  .cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    text-align: center;
  }
  .day-name { padding-bottom: 6px; color: var(--faint); font-size: 0.64rem; font-weight: 600; }
  .cal-day {
    position: relative;
    min-height: 32px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    font-size: 0.78rem;
    cursor: pointer;
    transition: 0.15s ease;
  }
  .cal-day:hover { background: var(--surface-2); color: var(--accent); }
  .cal-day.holiday { color: var(--danger); font-weight: 700; }
  .cal-day.holiday:hover { color: var(--danger); background: rgba(240, 82, 98, 0.1); }
  .cal-day.special-day { color: var(--special); font-weight: 700; }
  .cal-day.special-day:hover { color: var(--special); background: var(--special-soft); }
  .cal-day.today { color: var(--accent); font-weight: 700; }
  .cal-day.today.holiday { color: var(--danger); }
  .cal-day.today.special-day { color: var(--special); }
  .cal-day.today::before {
    content: "";
    position: absolute;
    inset: 0;
    border: 1px solid var(--accent-border);
    border-radius: inherit;
  }
  .cal-day.today.holiday::before { border-color: rgba(240, 82, 98, 0.42); }
  .cal-day.today.special-day::before { border-color: var(--special-border); }
  .cal-day.selected { background: var(--accent); color: #fff; font-weight: 700; }
  .cal-day.selected.holiday { background: var(--danger); color: #fff; }
  .cal-day.selected.special-day { background: var(--special); color: #111318; }
  .cal-day.has-income::after, .cal-day.has-expense::before {
    content: "";
    position: absolute;
    bottom: 4px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
  }
  .cal-day.has-income::after { left: calc(50% + 4px); background: var(--success); }
  .cal-day.has-expense::before { left: calc(50% - 8px); background: var(--danger); }
  .cal-day.has-income::after, .cal-day.has-expense::before { display: none; }
  .cal-dots {
    position: absolute;
    left: 50%;
    bottom: 4px;
    display: flex;
    gap: 3px;
    transform: translateX(-50%);
  }
  .cal-dots span {
    width: 4px;
    height: 4px;
    border-radius: 50%;
  }
  .cal-dots .income { background: var(--success); }
  .cal-dots .expense { background: var(--danger); }
  .cal-dots .bill { background: var(--warning); }
  .cal-hint { margin: 12px 0 0; color: var(--faint); text-align: center; font-size: 0.72rem; }

  /* ── Calendar dot legend ── */
  .cal-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }

  .cal-legend span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--muted);
    font-size: 0.64rem;
    font-weight: 600;
  }

  .dot-income, .dot-expense, .dot-bill {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
  }
  .dot-income  { background: var(--success); }
  .dot-expense { background: var(--danger); }
  .dot-bill    { background: var(--warning); }

  /* ── Cal dot tooltip ── */
  .cal-dot-tooltip {
    position: fixed;
    z-index: 2100;
    pointer-events: none;
    display: none;
    max-width: 180px;
    background: var(--surface-2);
    border: 1px solid var(--border-hover);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.28);
    padding: 8px 10px;
    font-size: 0.72rem;
    line-height: 1.6;
  }
  .cal-dot-tooltip.show { display: block; }
  .cal-dot-tooltip-row { display: flex; align-items: center; gap: 6px; }
  .cal-dot-tooltip-row i {
    width: 6px; height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
  }

  .main-header { margin-bottom: 14px; }
  .main-header h1 {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
    font-size: 1.22rem;
    line-height: 1.25;
    font-weight: 700;
  }
  .date-badge {
    border: 1px solid var(--accent-border);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 4px 10px;
    font-family: "DM Mono", monospace;
    font-size: 0.68rem;
    font-weight: 500;
  }
  .main-header.special-day h1 { color: var(--special); }
  .date-badge.special-day {
    border-color: var(--special-border);
    background: var(--special-soft);
    color: var(--special);
  }
  .date-event {
    display: none;
    align-items: center;
    min-height: 26px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    padding: 4px 10px;
    font-size: 0.72rem;
    font-weight: 800;
  }
  .date-event.show { display: inline-flex; }
  .date-event.holiday {
    border-color: rgba(240, 82, 98, 0.34);
    background: rgba(240, 82, 98, 0.11);
    color: var(--danger);
  }
  .date-event.special-day {
    border-color: var(--special-border);
    background: var(--special-soft);
    color: var(--special);
  }

  .theme-btn, .btn {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    min-height: 40px;
    padding: 0 14px;
    transition: 0.15s ease;
  }
  .theme-btn:hover, .btn-secondary:hover {
    border-color: var(--border-hover);
    color: var(--text);
    background: var(--surface-2);
  }
  .btn-primary {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
    font-weight: 700;
  }
  .btn-primary:hover { border-color: var(--accent-strong); background: var(--accent-strong); }

  .app-actions, .tool-row { display: grid; gap: 8px; margin-bottom: 14px; }
  .mode-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }
  .type-toggle {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .type-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--muted);
    padding: 0 12px;
    font-size: 0.78rem;
    font-weight: 800;
    transition: 0.15s ease;
  }
  .type-toggle-btn::before {
    content: "";
    width: 14px;
    height: 14px;
    border: 1px solid currentColor;
    border-radius: 50%;
  }
  .type-toggle-btn.active::before {
    background: currentColor;
    box-shadow: inset 0 0 0 3px var(--surface-2);
  }
  .type-toggle-btn.income.active {
    border-color: rgba(32, 180, 134, 0.35);
    background: rgba(32, 180, 134, 0.12);
    color: var(--success);
  }
  .type-toggle-btn.expense.active {
    border-color: rgba(240, 82, 98, 0.35);
    background: rgba(240, 82, 98, 0.12);
    color: var(--danger);
  }
  .mode-row .btn-active {
    border-color: var(--pin);
    background: var(--pin-soft);
    color: var(--pin);
  }
  .sync-row { flex-wrap: wrap; }
  .action-row { justify-content: flex-start; flex-wrap: wrap; }

  .status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    padding: 3px 10px;
    font-size: 0.72rem;
    font-weight: 700;
  }
  .status-pill.online { border-color: var(--accent-border); background: var(--accent-soft); color: var(--accent); }
  #exportDataBtn,
  #importDataBtn,
  #importDataInput {
    display: none !important;
  }

  .summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 16px;
  }
  .summary-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    padding: 16px 18px;
  }
  .summary-card.wide { grid-column: span 2; }
  body.light .summary-card { background: rgba(89, 67, 41, 0.04); }
  .summary-card span { display: block; color: var(--muted); font-size: 0.65rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em; }
  .summary-card strong { display: block; margin-top: 10px; font-family: "DM Mono", monospace; font-size: 1.42rem; color: var(--accent); letter-spacing: -0.5px; }
  .summary-card small { display: block; margin-top: 5px; color: var(--faint); font-size: 0.64rem; font-weight: 600; line-height: 1.35; }
  .summary-card.danger strong { color: var(--danger); }
  .summary-card.success strong { color: var(--success); }

  .input-row { display: grid; grid-template-columns: 1fr 150px minmax(160px, 190px) auto; gap: 8px; margin-bottom: 14px; }
  .tool-row { grid-template-columns: 1fr 148px 128px; gap: 8px; }
  select, input[type="number"], input[type="text"], input[type="search"], input[type="date"], textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    outline: none;
    min-height: 42px;
    padding: 0 12px;
    transition: 0.15s ease;
  }
  select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%237d8795' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    background-size: 14px;
    padding-right: 38px;
  }
  input[type="number"], input[type="text"], input[type="search"], input[type="date"], textarea { padding: 12px 14px; }
  textarea { min-height: 90px; padding: 12px; resize: vertical; }
  select:focus, input:focus, textarea:focus { border-color: var(--accent-border); background: var(--surface-3); }
  input::placeholder { color: var(--faint); }

  .progress-label { color: var(--muted); font-size: 0.72rem; margin-bottom: 5px; }
  .progress-wrap { height: 4px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-bottom: 14px; }
  .progress-bar { height: 100%; width: 0; border-radius: inherit; background: var(--accent); }
  .all-transactions-launch {
    display: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    padding: 18px;
    margin-top: 6px;
  }
  .all-transactions-launch.show {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
  }
  .all-transactions-launch strong {
    display: block;
    font-size: 0.92rem;
  }
  .all-transactions-launch span {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.76rem;
  }

  .finance-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
  }
  .finance-table-wrap.hidden { display: none; }
  body.light .finance-table-wrap { background: #fffaf1; }
  table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    min-width: min(100%, 640px);
  }
  th, td {
    min-width: 0;
    padding: 12px 10px;
    border-top: 1px solid var(--border);
    text-align: left;
    font-size: 0.78rem;
    overflow-wrap: anywhere;
  }
  thead th { border-top: 0; color: var(--muted); font-size: 0.68rem; text-transform: uppercase; }
  th:first-child,
  td:first-child { width: 28%; }
  th:nth-child(2),
  td:nth-child(2) { width: 17%; }
  th:nth-child(3),
  td:nth-child(3) { width: 16%; }
  th:nth-child(4),
  td:nth-child(4) { width: 18%; }
  th:nth-child(5),
  td:nth-child(5) { width: 11%; }
  th:nth-child(6),
  td:nth-child(6) { width: 10%; }
  .tx-name { min-width: 0; display: flex; align-items: center; gap: 10px; }
  .tx-icon { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; }
  .badge { display: inline-flex; border-radius: 999px; padding: 4px 8px; font-size: 0.68rem; font-weight: 700; }
  .badge-income { color: var(--success); background: rgba(32,180,134,.12); border: 1px solid rgba(32,180,134,.22); }
  .badge-expense { color: var(--danger); background: rgba(240,82,98,.12); border: 1px solid rgba(240,82,98,.22); }
  .amount-income { color: var(--success); font-weight: 700; }
  .amount-expense { color: var(--danger); font-weight: 700; }
  .row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
  .row-btn {
    min-width: 68px;
    min-height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    padding: 0 10px;
    font-size: 0.72rem;
    font-weight: 800;
    transition: 0.15s ease;
  }
  .row-btn:hover { border-color: var(--border-hover); color: var(--text); background: var(--surface-2); }

  @media (max-width: 720px) {
    .finance-table-wrap {
      overflow-x: hidden;
    }

    table {
      min-width: 0;
    }

    th, td {
      padding: 10px 6px;
      font-size: 0.7rem;
      line-height: 1.35;
    }

    thead th {
      font-size: 0.58rem;
    }

    th:first-child,
    td:first-child { width: 30%; }
    th:nth-child(2),
    td:nth-child(2) { width: 15%; }
    th:nth-child(3),
    td:nth-child(3) { width: 16%; }
    th:nth-child(4),
    td:nth-child(4) { width: 18%; }
    th:nth-child(5),
    td:nth-child(5) { width: 11%; }
    th:nth-child(6),
    td:nth-child(6) { width: 10%; }

    .tx-name {
      gap: 6px;
    }

    .tx-icon {
      width: 24px;
      height: 24px;
      flex: 0 0 24px;
      font-size: 0.68rem;
    }

    .badge {
      padding: 3px 5px;
      font-size: 0.58rem;
    }

    .row-actions {
      gap: 4px;
    }

    .row-btn {
      min-width: 0;
      width: 100%;
      min-height: 28px;
      padding: 0 4px;
      font-size: 0.62rem;
    }
  }

  .mini-card h2 { margin: 0 0 12px; font-size: 0.92rem; }
  .quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .quick-tile {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    min-height: 42px;
    padding: 8px;
    font-size: 0.74rem;
    transition: 0.15s ease;
  }
  .quick-tile:hover { border-color: var(--border-hover); background: var(--surface-3); }
  .budget-list { display: grid; gap: 10px; }
  .budget-row { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); padding: 11px; }
  body.light .budget-row { background: rgba(89, 67, 41, 0.04); }
  .budget-title-line { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; font-size: 0.72rem; }
  .budget-name { color: var(--text); font-weight: 800; }
  .budget-status { color: var(--muted); font-size: 0.68rem; font-weight: 700; text-align: right; }
  .budget-status.good { color: var(--success); }
  .budget-status.warn { color: var(--warning); }
  .budget-status.over { color: var(--danger); }
  .budget-amounts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 9px;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
  }
  .budget-amounts strong { display: block; margin-top: 2px; color: var(--text); font-family: "DM Mono", monospace; font-size: 0.82rem; }
  .budget-amounts .remaining strong { color: var(--success); }
  .budget-amounts .remaining.over strong { color: var(--danger); }
  .progress-track { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin-top: 8px; }
  .progress-fill { height: 100%; border-radius: inherit; }
  .progress-fill.teal { background: var(--accent); }
  .progress-fill.blue { background: #6aa3ff; }
  .progress-fill.purple { background: #8b7bff; }
  .progress-fill.green { background: var(--success); }
  .progress-fill.red { background: var(--danger); }
  .progress-fill.budget-good { background: var(--success); }
  .progress-fill.budget-warn { background: var(--warning); }
  .progress-fill.budget-over { background: var(--danger); }
  .feature-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 10px;
    margin-bottom: 0;
  }
  .right-panel {
    display: grid;
    gap: 12px;
    align-content: start;
  }
  .feature-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
  }
  .feature-head h2 { margin: 0; font-size: 0.74rem; line-height: 1.25; }
  .feature-head span { color: var(--muted); font-size: 0.58rem; line-height: 1.25; }
  .feature-head .btn {
    min-height: 30px;
    padding: 0 9px;
    font-size: 0.66rem;
  }
  /* ═══════════════════════════════════════════════
     Recurring / Subscription card — redesign
  ═══════════════════════════════════════════════ */
  .recurring-grid,
  .envelope-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .mini-finance-card {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    padding: 0;
    transition: border-color 0.15s ease, background 0.15s ease;
    cursor: pointer;
  }

  .mini-finance-card:hover { border-color: var(--border-hover); }

  /* ── Status accent stripe on left edge ── */
  .mini-finance-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 3px;
    border-radius: 10px 0 0 10px;
    background: var(--border);
    transition: background 0.15s ease;
  }
  .mini-finance-card.warn::before  { background: var(--warning); }
  .mini-finance-card.over::before  { background: var(--danger); }
  .mini-finance-card.paid::before  { background: var(--success); }

  /* Remove the old ribbon ::after */
  .mini-finance-card.paid::after { display: none !important; }

  /* ── Main body layout ── */
  .mini-finance-top {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px 0 14px;
  }

  /* ── Title + meta ── */
  .mini-finance-info {
    flex: 1;
    min-width: 0;
  }

  .mini-finance-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
    font-size: 0.82rem;
    line-height: 1.3;
    color: var(--text);
    padding-right: 0;
  }

  .mini-finance-meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
    font-size: 0.66rem;
    line-height: 1.5;
    margin-top: 1px;
  }

  /* ── Amount (right side) ── */
  .mini-finance-amount {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.92rem;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .mini-finance-card.paid .mini-finance-amount { padding-right: 0; }

  /* ── Bottom row: status + actions ── */
  .mini-finance-status {
    padding: 6px 10px 0 14px;
  }

  .mini-finance-actions {
    display: flex;
    gap: 0;
    margin-top: 8px;
    border-top: 1px solid var(--border);
  }

  .mini-finance-actions .btn {
    flex: 1;
    min-height: 32px;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    font-size: 0.72rem !important;
    font-weight: 700;
    color: var(--muted);
    padding: 0 !important;
  }

  .mini-finance-actions .btn:first-child {
    border-right: 1px solid var(--border) !important;
    border-radius: 0 0 0 10px !important;
  }
  .mini-finance-actions .btn:last-child {
    border-radius: 0 0 10px 0 !important;
  }

  .mini-finance-actions .btn:hover {
    background: var(--surface-3) !important;
    color: var(--text);
  }

  /* Pay/done button color */
  .mini-finance-actions .btn-secondary:not(.btn-complete):first-child {
    color: var(--accent);
  }
  .mini-finance-actions .btn-secondary:not(.btn-complete):first-child:hover {
    background: var(--accent-soft) !important;
    color: var(--accent);
  }

  .mini-finance-actions .btn-complete {
    color: var(--success) !important;
    opacity: 1 !important;
  }
  .cal-day.has-bill { font-weight: 800; }
  .day-total-chip {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    padding: 3px 8px;
    font-size: 0.68rem;
    font-weight: 800;
  }

  .finance-graph-card { margin-bottom: 16px; }
  .graph-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
  }
  .graph-head h2 { margin: 0; font-size: 0.88rem; font-weight: 700; }
  .graph-head span { color: var(--muted); font-size: 0.68rem; }
  .graph-controls {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .graph-range-btn {
    min-height: 28px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    padding: 0 9px;
    font-size: 0.66rem;
    font-weight: 700;
    transition: 0.15s ease;
  }
  .graph-range-btn.active {
    border-color: var(--accent-border);
    background: var(--accent-soft);
    color: var(--accent);
  }
  .graph-legend {
    display: flex;
    gap: 14px;
    color: var(--muted);
    font-size: 0.68rem;
    margin-bottom: 10px;
  }
  .graph-legend span { display: inline-flex; align-items: center; gap: 5px; }
  .graph-legend i { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
  .chart-shell {
    height: 180px;
    display: block;
  }
  #spendingChart { width: 100%; height: 100%; display: block; }
  .chart-labels {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
    color: var(--faint);
    font-size: 0.64rem;
  }
  .hidden-support { display: none !important; }

  .modal-overlay {
    position: fixed; inset: 0; z-index: 1000; display: none; align-items: center; justify-content: center;
    background: rgba(0,0,0,.62); backdrop-filter: blur(6px); padding: 18px;
  }
  .modal-overlay.show { display: flex; }
  .modal {
    width: min(620px, 100%);
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: 0 22px 60px rgba(0,0,0,.42);
    overflow: hidden;
    animation: popIn 0.2s ease both;
  }
  .modal.wide {
    width: min(980px, 100%);
  }
  .modal-head, .modal-actions {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 16px 18px; border-bottom: 1px solid var(--border);
  }
  .modal-actions { justify-content: flex-end; border-bottom: 0; border-top: 1px solid var(--border); }
  .modal-body { padding: 18px; display: grid; gap: 14px; }
  .modal-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .field { display: grid; gap: 6px; }
  .field label { color: var(--muted); font-size: 0.74rem; font-weight: 700; }
  .toast {
    position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 2200; display: none; max-width: min(360px, calc(100vw - 32px));
    border: 1px solid var(--border-hover); border-radius: var(--radius); background: var(--surface-2);
    color: var(--text); box-shadow: 0 14px 34px rgba(0,0,0,.3); padding: 12px 14px; font-size: .84rem;
  }
  .toast.show { display: block; }

  @media (max-width: 900px) {
    .summary-grid { grid-template-columns: repeat(2, 1fr); }
    .input-row, .tool-row { grid-template-columns: 1fr; }
  }
  @media (max-width: 640px) {
    body { padding: 12px; }
    .card { padding: 12px 14px; }

    /* ── Top nav ── */
    .top-project.disabled { display: none; }
    .top-projects-inner { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
    .top-project { min-height: 44px !important; }
    .top-project-desc { display: none; }

    /* ── Layout ── */
    .layout { gap: 10px !important; }

    /* ── Header ── */
    .main-header {
      flex-direction: column;
      align-items: flex-start;
      gap: 8px;
    }
    .main-header > div { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

    /* ── Buttons ── */
    .btn, select, input { width: 100%; }
    .btn { min-height: 36px !important; }

    /* ── Summary cards: 2-column ── */
    .summary-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
    .summary-card.wide { grid-column: span 1; }
    .summary-card strong { font-size: 1.08rem !important; }

    /* ── Dashboard strip: 2-column ── */
    .dashboard-strip { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }

    /* ── Input / tool ── */
    .input-row { grid-template-columns: 1fr !important; gap: 6px; }
    .tool-row { grid-template-columns: 1fr !important; gap: 6px; }
    .type-toggle { grid-template-columns: 1fr 1fr; }

    /* ── Action row ── */
    .action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
    .mode-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
    .mode-row .btn { font-size: 0.7rem !important; padding: 0 6px !important; }

    /* ── Right panel ── */
    .right-panel { grid-column: 1 / -1; }

    /* ── Modal ── */
    .modal-grid { grid-template-columns: 1fr; }
  }
  @keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
  @keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

  /* Phase 6: finance card and table polish */
  .summary-grid {
    gap: 12px;
  }

  .summary-card {
    min-height: 118px;
    display: grid;
    align-content: center;
    border-color: color-mix(in srgb, var(--border) 80%, var(--accent-border));
  }

  .summary-card strong {
    font-size: 1.5rem;
  }

  .mode-row,
  .input-row,
  .tool-row {
    align-items: stretch;
  }

  .input-row {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--surface-2) 72%, transparent);
    padding: 10px;
  }

  .finance-table-wrap {
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.16);
  }

  thead th {
    background: var(--surface-2);
    position: sticky;
    top: 0;
    z-index: 1;
  }

  tbody tr {
    transition: background 0.15s ease;
  }

  tbody tr:hover {
    background: color-mix(in srgb, var(--surface-2) 78%, transparent);
  }

  .quick-grid {
    gap: 10px;
  }

  .quick-tile {
    min-height: 48px;
    font-weight: 800;
  }

  .mini-finance-card {
    border-radius: var(--radius);
  }

  .mini-finance-top {
    padding-top: 12px;
  }

  .modal {
    border-radius: var(--radius);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  }

  .modal-head {
    background: color-mix(in srgb, var(--surface-2) 78%, transparent);
  }

  @media (max-width: 640px) {
    .summary-card {
      min-height: 98px;
    }

    .input-row,
    .tool-row {
      padding: 8px;
    }

    .quick-grid {
      grid-template-columns: 1fr;
    }
  }
