  :root {
    font-family: "Noto Sans Thai", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  }

  body.light {
    --special-soft: rgba(181, 134, 39, 0.12);
    --special-border: rgba(181, 134, 39, 0.32);
  }

  * { letter-spacing: 0; }
  body {
    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));
    transition: background 0.25s ease, color 0.25s ease;
  }

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

  .top-project {
    text-align: left;
  }

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

  .top-project-icon {
    font-size: 1rem;
  }

  @media (max-width: 820px) {
    .top-project.disabled { display: none; }
  }

  .layout {
    margin: 0 auto;
    grid-template-columns: 1fr;
    align-items: start;
    animation: fadeUp 0.35s ease both;
  }

  @media (min-width: 1140px) {
    .layout {
      grid-template-columns: 230px minmax(0, 1fr) 230px;
    }
  }
  .left-panel {
    grid-template-columns: minmax(0, 1fr);
  }
  .left-panel > .card,
  .right-panel > .feature-panel {
    min-width: 0;
    width: 100%;
  }

  .cal-head, .main-header, .sync-row, .progress-label, .modal-actions {
    justify-content: space-between;
  }
  .cal-head { margin-bottom: 14px; font-size: 0.9rem; font-weight: 600; }
  .nav-btn, .icon-btn {
    display: inline-grid;
    place-items: center;
    height: 36px;
  }

  .cal-grid {
    text-align: center;
  }
  .day-name { padding-bottom: 6px; }
  .cal-day {
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: 0.15s ease;
  }
  .cal-day.holiday { font-weight: 700; }
  .cal-day.holiday:hover { color: var(--danger); background: rgba(240, 82, 98, 0.1); }
  .cal-day.special-day { font-weight: 700; }
  .cal-day.special-day:hover { color: var(--special); background: var(--special-soft); }
  .cal-day.today { font-weight: 700; }
  .cal-day.today.holiday { color: var(--danger); }
  .cal-day.today.special-day { color: var(--special); }
  .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 { font-weight: 700; }
  .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 .expense { background: var(--danger); }
  .cal-hint { margin: 12px 0 0; text-align: center; }

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

  .dot-income, .dot-expense, .dot-bill {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  /* ── Cal dot tooltip ── */
  .cal-dot-tooltip {
    position: fixed;
    pointer-events: none;
    display: none;
    max-width: 180px;
    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 h1 {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
  }
  .date-badge {
    font-family: "DM Mono", monospace;
  }
  .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.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);
  }

  .btn-secondary:hover {
    border-color: var(--border-hover);
    color: var(--text);
    background: var(--surface-2);
  }
  .btn-primary {
    font-weight: 700;
  }

  .type-toggle {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .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);
  }
  .mode-row .btn-active {
    border-color: var(--pin);
    background: var(--pin-soft);
    color: var(--pin);
  }

  #exportDataBtn,
  #importDataBtn,
  #importDataInput {
    display: none !important;
  }

  body.light .summary-card { background: rgba(89, 67, 41, 0.04); }
  .summary-card span { display: block; }
  .summary-card strong { margin-top: 10px; }
  .summary-card small { display: block; margin-top: 5px; }

  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;
    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; }

  .progress-label { margin-bottom: 5px; }
  .progress-wrap { margin-bottom: 14px; }
  .progress-bar { width: 0; }
  .all-transactions-launch {
    margin-top: 6px;
  }
  .all-transactions-launch.show {
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
  }
  .all-transactions-launch span {
    display: block;
    margin-top: 4px;
  }

  .finance-table-wrap {
    overflow-x: auto;
  }
  .finance-table-wrap.hidden { display: none; }
  body.light .finance-table-wrap { background: #fffaf1; }
  table {
    table-layout: fixed;
    min-width: min(100%, 640px);
  }
  th, td {
    min-width: 0;
    border-top: 1px solid var(--border);
    text-align: left;
    overflow-wrap: anywhere;
  }
  thead th { border-top: 0; }
  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 { display: flex; align-items: center; gap: 10px; }
  .badge-income { color: var(--success); background: rgba(32,180,134,.12); border: 1px solid rgba(32,180,134,.22); }
  .badge-expense { color: var(--danger); border: 1px solid rgba(240,82,98,.22); }
  .amount-income { font-weight: 700; }
  .amount-expense { font-weight: 700; }
  .row-btn {
    min-width: 68px;
  }

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

    table {
      min-width: 0;
    }

    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 {
      flex: 0 0 24px;
      font-size: 0.68rem;
    }

    .row-btn {
      min-width: 0;
      width: 100%;
    }
  }

  .mini-card h2 { margin: 0 0 12px; font-size: 0.92rem; }
  body.light .budget-row { background: rgba(89, 67, 41, 0.04); }
  .budget-status { text-align: right; }
  .budget-status.good { color: var(--success); }
  .budget-status.warn { color: var(--warning); }
  .budget-status.over { color: var(--danger); }
  .budget-amounts strong { margin-top: 2px; }
  .budget-amounts .remaining strong { color: var(--success); }
  .budget-amounts .remaining.over strong { color: var(--danger); }
  .progress-track { margin-top: 8px; }
  .feature-panel {
    margin-bottom: 0;
  }
  .feature-head h2 { margin: 0; }
  .feature-head .btn {
    padding: 0 9px;
  }
  /* ═══════════════════════════════════════════════
     Recurring / Subscription card — redesign
  ═══════════════════════════════════════════════ */
  .recurring-grid,
  .envelope-grid {
    grid-template-columns: 1fr;
  }

  .mini-finance-card {
    position: relative;
    overflow: hidden;
    transition: border-color 0.15s ease, background 0.15s ease;
    cursor: pointer;
  }

  /* ── 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 {
    padding: 10px 10px 0 14px;
  }

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

  .mini-finance-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 0;
  }

  .mini-finance-meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 1px;
  }

  /* ── Amount (right side) ── */
  .mini-finance-amount {
    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 {
    border-top: 1px solid var(--border);
  }

  .mini-finance-actions .btn {
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    font-size: 0.8rem !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; }

  .graph-head h2 { margin: 0; font-size: 0.88rem; font-weight: 700; }
  .graph-controls {
    justify-content: flex-end;
  }
  .graph-legend {
    margin-bottom: 10px;
  }
  .chart-shell {
    display: block;
  }
  .chart-labels {
    margin-top: 6px;
  }

  .modal-overlay { padding: 18px;
  }
  .modal {
    animation: popIn 0.2s ease both;
  }
  .modal-actions { border-bottom: 0; }
  .field label { color: var(--muted); font-size: 0.74rem; font-weight: 700; }
  .toast { right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom));
  }

  @media (max-width: 640px) {
    body { padding: 12px; }

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

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

    /* ── Buttons ── */
    .btn, select, input { width: 100%; }

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

    .type-toggle { grid-template-columns: 1fr 1fr; }

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

    /* ── Modal ── */
  }
  @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-card {
    min-height: 118px;
    display: grid;
    align-content: center;
  }

  .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;
  }

  tbody tr {
    transition: background 0.15s ease;
  }

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

  .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;
    }

  }
