/* ── Material Design 3 — Personal Finance ── */

/* ── Privacy mode ── */
html[data-privacy="on"] .acc-balance,
html[data-privacy="on"] .stat-tile .value,
html[data-privacy="on"] .ui-amount,
html[data-privacy="on"] td.amount-income,
html[data-privacy="on"] td.amount-expense,
html[data-privacy="on"] td.amount-transfer,
html[data-privacy="on"] .prv {
  filter: blur(8px);
  user-select: none;
  transition: filter .2s;
}

/* ── Dark theme ── */
html[data-theme="dark"] {
  --primary:            #9da2f8;
  --primary-container:  #1e2050;
  --on-primary:         #0d0f1e;
  --surface:            #161828;
  --surface-variant:    #1f2138;
  --bg:                 #0d0f1e;
  --on-surface:         #e2e2f4;
  --on-surface-variant: #9898c0;
  --outline:            #3a3c5c;
  --outline-variant:    #272944;
  --success:            #4caf7d;
  --success-container:  #0a2e1a;
  --danger:             #ef5350;
  --danger-container:   #2e0a0a;
  --warning:            #ffb74d;
  --warning-container:  #2e1a00;
  --transfer:           #64b5f6;
  --transfer-container: #0a1e35;
  --text:               #e2e2f4;
  --text-muted:         #9898c0;
  --border:             #272944;
  --shadow:             0 1px 4px rgba(0,0,0,.35), 0 0 1px rgba(0,0,0,.25);
  --danger-tint:        #2a0808;
}

[data-theme="dark"] #sidebar {
  background: #0a0b18;
}
[data-theme="dark"] #sidebar nav a.active {
  background: #1e2050;
}
[data-theme="dark"] #sidebar nav a:hover {
  background: rgba(255,255,255,.05);
}
[data-theme="dark"] .auth-card {
  background: var(--surface);
  border-color: var(--outline-variant);
}

:root {
  --danger-tint: #fff5f5;
  --primary:            #2d3066;
  --primary-container:  #eef0fb;
  --on-primary:         #ffffff;
  --surface:            #ffffff;
  --surface-variant:    #f3f3fd;
  --bg:                 #f0f0f8;
  --on-surface:         #1a1c3a;
  --on-surface-variant: #6b6b8a;
  --outline:            #c8c8f0;
  --outline-variant:    #e8e8f4;
  --success:            #1a7a4a;
  --success-container:  #e8f5ef;
  --danger:             #b3261e;
  --danger-container:   #fdf0ee;
  --warning:            #b06000;
  --warning-container:  #fff3e0;
  --transfer:           #1565a8;
  --transfer-container: #e3f0fb;

  /* aliases used in JS-generated HTML */
  --text:       #1a1c3a;
  --text-muted: #6b6b8a;
  --border:     #e8e8f4;
  --shadow:     0 1px 3px rgba(45,48,102,.07), 0 0 1px rgba(45,48,102,.05);

  --radius-sm:  8px;
  --radius:     16px;
  --radius-lg:  24px;
  --sidebar-w:  240px;
  --sidebar-collapsed-w: 64px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Google Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--on-surface);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Auth pages ── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.auth-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--outline-variant);
  padding: 40px 36px;
  width: 380px;
  box-shadow: var(--shadow);
}
.auth-card h1 {
  font-size: 1.4rem;
  font-weight: 500;
  margin-bottom: 6px;
  text-align: center;
  color: var(--on-surface);
}
.auth-card .subtitle {
  color: var(--on-surface-variant);
  font-size: .875rem;
  text-align: center;
  margin-bottom: 28px;
}

/* ── Layout ── */
#layout { display: flex; min-height: 100vh; }

#sidebar {
  width: var(--sidebar-w);
  background: #1a1c3a;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: width .2s cubic-bezier(.4,0,.2,1), transform .25s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}

#sidebar .logo {
  padding: 22px 20px 18px;
  font-size: 1rem;
  font-weight: 500;
  color: #c5c7f7;
  letter-spacing: .02em;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 0.5px solid rgba(255,255,255,.08);
}

#sidebar nav { flex: 1; padding: 10px 12px; overflow-y: auto; }

#sidebar nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 28px;
  color: #c5c7f7;
  text-decoration: none;
  font-size: .875rem;
  margin-bottom: 2px;
  transition: background .15s;
}
#sidebar nav a:hover { background: rgba(255,255,255,.07); }
#sidebar nav a.active {
  background: #2d3066;
  color: #e8eaf6;
  font-weight: 500;
}
#sidebar nav a .nav-icon {
  font-size: 20px;
  opacity: .85;
  flex-shrink: 0;
}
#sidebar nav a.active .nav-icon { opacity: 1; }

#sidebar .sidebar-footer {
  padding: 12px;
  border-top: 0.5px solid rgba(255,255,255,.08);
}

#main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  transition: margin-left .2s cubic-bezier(.4,0,.2,1);
  flex-direction: column;
  min-height: 100vh;
}

#topbar {
  background: var(--surface);
  border-bottom: 0.5px solid var(--outline-variant);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
#topbar h2 { font-size: 1.125rem; font-weight: 500; }

#page-content { padding: 24px 28px; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 0.5px solid var(--outline-variant);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: .75rem;
  font-weight: 500;
  margin-bottom: 16px;
  color: var(--on-surface-variant);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ── Grids ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }

/* ── Stat tiles ── */
.stat-tile {
  background: var(--surface);
  border-radius: var(--radius);
  border: 0.5px solid var(--outline-variant);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow);
}
.stat-tile .label { font-size: .75rem; font-weight: 500; color: var(--on-surface-variant); }
.stat-tile .value { font-size: 1.5rem; font-weight: 600; letter-spacing: -.01em; }
.stat-tile .value.income  { color: var(--success); }
.stat-tile .value.expense { color: var(--danger); }
.stat-tile .value.neutral { color: var(--primary); }

/* ── Account tiles ── */
.account-tile {
  background: var(--surface);
  border-radius: var(--radius);
  border: 0.5px solid var(--outline-variant);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  box-shadow: var(--shadow);
  transition: box-shadow .15s;
}
.account-tile:hover { box-shadow: 0 3px 10px rgba(45,48,102,.12); }
.account-tile .acc-name { font-weight: 500; font-size: .9375rem; }
.account-tile .acc-type { font-size: .75rem; color: var(--on-surface-variant); }
.account-tile .acc-balance { font-size: 1.375rem; font-weight: 600; margin-top: 6px; letter-spacing: -.01em; }
.account-tile .acc-balance.positive { color: var(--success); }
.account-tile .acc-balance.negative { color: var(--danger); }
.account-tile .acc-actions {
  position: absolute; top: 12px; right: 12px;
  display: flex; gap: 2px; opacity: 0; transition: opacity .15s;
}
.account-tile:hover .acc-actions { opacity: 1; }

/* ── Tables ── */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  padding: 10px 12px;
  text-align: left;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--on-surface-variant);
  background: var(--surface-variant);
  border-bottom: 1px solid var(--outline-variant);
}
td {
  padding: 11px 12px;
  text-align: left;
  border-bottom: 0.5px solid var(--outline-variant);
  font-size: .875rem;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-variant); }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.badge-income   { background: var(--success-container); color: #145c36; }
.badge-expense  { background: var(--danger-container);  color: #8c1d18; }
.badge-transfer { background: var(--transfer-container); color: #0d4680; }

.amount-income   { color: var(--success); font-weight: 600; }
.amount-expense  { color: var(--danger);  font-weight: 600; }
.amount-transfer { color: var(--transfer); font-weight: 600; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: .75rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--on-surface-variant);
}
.form-group input:not([type="checkbox"]),
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--outline);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-family: inherit;
  color: var(--on-surface);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  appearance: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45,48,102,.1);
}
.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24'%3E%3Cpath fill='%236b6b8a' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}
.form-group small { display: block; margin-top: 4px; font-size: .75rem; color: var(--on-surface-variant); }

.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-size: .875rem;
  font-family: inherit;
  font-weight: 500;
  letter-spacing: .01em;
  transition: filter .15s, transform .1s, box-shadow .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover  { filter: brightness(.92); }
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--outline);
}
.btn-ghost:hover { background: var(--primary-container); filter: none; }

.btn-sm { padding: 6px 14px; font-size: .8rem; border-radius: 16px; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: transparent;
  color: var(--on-surface-variant);
  font-size: .9rem;
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--primary-container); color: var(--primary); }
.btn-icon .material-symbols-outlined { font-size: 18px; }
.btn-icon-danger:hover { background: var(--danger-container); color: var(--danger); }

/* ── Category chip picker ── */
.cat-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 150px;
  overflow-y: auto;
  padding: 8px;
  border: 1.5px solid var(--outline);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.cat-picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border: 1.5px solid var(--outline-variant);
  border-radius: 20px;
  background: transparent;
  color: var(--on-surface-variant);
  cursor: pointer;
  font-size: .8rem;
  font-family: inherit;
  white-space: nowrap;
  transition: background .12s, color .12s, border-color .12s;
}
.cat-picker-btn:hover { background: var(--surface-variant); color: var(--on-surface); border-color: var(--outline); }
.cat-picker-btn.selected { background: var(--primary-container); color: var(--primary); border-color: var(--primary); font-weight: 500; }
.cat-picker-btn .material-symbols-outlined { font-size: 15px; }
.cat-picker-group {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  font-size: .7rem;
  font-weight: 700;
  color: var(--on-surface-variant);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 6px 0 2px;
  margin-top: 2px;
}
.cat-picker-group .material-symbols-outlined { font-size: 14px; color: var(--primary); }
.cat-picker-sub { margin-left: 10px; }

/* ── Icon picker ── */
.icon-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
  padding: 8px;
  border: 1.5px solid var(--outline);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.icon-picker-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--on-surface-variant);
  transition: background .12s, color .12s;
  flex-shrink: 0;
}
.icon-picker-btn:hover { background: var(--surface-variant); color: var(--on-surface); }
.icon-picker-btn.selected { background: var(--primary-container); color: var(--primary); }

/* ── Filters bar ── */
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: flex-end;
}
.filters .form-group { margin-bottom: 0; }
.filters select,
.filters input { min-width: 140px; }

/* ── Modal ── */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(26,28,58,.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 40px rgba(26,28,58,.2);
  padding: 28px;
  width: 500px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}
.modal h3 { font-size: 1.125rem; font-weight: 500; margin-bottom: 20px; }
.modal-close {
  position: absolute; top: 16px; right: 16px;
  width: 32px; height: 32px;
  background: none; border: none; cursor: pointer;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--on-surface-variant);
  transition: background .15s;
}
.modal-close:hover { background: var(--surface-variant); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* ── Toast ── */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: #2d2f5a;
  color: #e8eaf6;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: .875rem;
  opacity: 0; transform: translateY(12px);
  transition: opacity .25s, transform .25s;
  z-index: 300; pointer-events: none;
  max-width: 320px;
  box-shadow: 0 4px 16px rgba(26,28,58,.25);
}
#toast.show    { opacity: 1; transform: translateY(0); }
#toast.toast-error   { background: var(--danger); }
#toast.toast-success { background: var(--success); }

/* ── Calendar / Cashflow ── */
.cal-controls { display: flex; gap: 8px; margin-bottom: 16px; }

/* Legacy grid calendar (kept for potential future use) */
.cal-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 4px; }
.cal-header {
  text-align: center;
  font-size: .7rem;
  font-weight: 600;
  color: var(--on-surface-variant);
  padding: 4px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.cal-day {
  background: var(--surface);
  border: 0.5px solid var(--outline-variant);
  border-radius: var(--radius-sm);
  padding: 6px;
  min-height: 80px;
  font-size: .75rem;
}
.cal-day.today { border-color: var(--primary); border-width: 1.5px; }
.cal-day.other-month { opacity: .4; }
.cal-day .day-num { font-weight: 600; margin-bottom: 4px; }
.cal-day .cal-income  { color: var(--success); }
.cal-day .cal-expense { color: var(--danger); }
.cal-day .cal-planned {
  background: var(--primary-container);
  color: var(--primary);
  border-radius: 4px;
  padding: 1px 4px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-day .cal-planned.overdue { background: var(--danger-container); color: var(--danger); }

/* ── Charts ── */
.chart-wrap { position: relative; height: 280px; }

/* ── Upcoming / Cashflow list ── */
.upcoming-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--outline-variant);
}
.upcoming-item:last-child { border-bottom: none; }
.upcoming-item .ui-left  { display: flex; flex-direction: column; gap: 2px; }
.upcoming-item .ui-name  { font-weight: 500; }
.upcoming-item .ui-date  { font-size: .75rem; color: var(--on-surface-variant); }
.upcoming-item .ui-amount { font-weight: 600; }

.overdue-mark { color: var(--danger); font-size: .7rem; margin-left: 6px; }

/* ── Misc utilities ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h3 { font-size: 1rem; font-weight: 500; }

.empty-state {
  text-align: center;
  color: var(--on-surface-variant);
  padding: 48px 20px;
  font-size: .9rem;
}

.text-right { text-align: right; }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
hr { border: none; border-top: 0.5px solid var(--outline-variant); margin: 16px 0; }

/* ── Positive / Negative balance helpers ── */
.positive { color: var(--success); }
.negative { color: var(--danger); }

/* ── Collapsible filter panel ── */
.filter-toggle {
  display: none; /* shown only on mobile via media query below */
  width: 100%;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  margin-bottom: 12px;
  background: none;
  border: none;
  border-bottom: 0.5px solid var(--outline-variant);
  cursor: pointer;
  font-size: .875rem;
  font-weight: 500;
  color: var(--on-surface);
  text-align: left;
}
.filter-chevron { margin-left: auto; transition: transform .2s ease; color: var(--on-surface-variant); }
.filter-panel.open .filter-chevron { transform: rotate(180deg); }

/* ── Budget progress bar ── */
.budget-bar {
  height: 6px;
  background: var(--outline-variant);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
}
.budget-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--success);
  transition: width .4s ease;
}
.budget-bar-fill.warn { background: var(--warning, #f59e0b); }
.budget-bar-fill.over { background: var(--danger); }

/* ── Navigation Drawer + collapsible sidebar ── */
#menu-btn { display: flex; }

@media (min-width: 769px) {
  body.sidebar-collapsed #sidebar { width: var(--sidebar-collapsed-w); }
  body.sidebar-collapsed #main   { margin-left: var(--sidebar-collapsed-w); }

  body.sidebar-collapsed .logo {
    padding: 22px 0 18px;
    justify-content: center;
  }
  body.sidebar-collapsed .sidebar-label { display: none; }

  body.sidebar-collapsed #sidebar nav { padding: 10px 8px; }
  body.sidebar-collapsed #sidebar nav a {
    padding: 10px;
    justify-content: center;
    gap: 0;
    border-radius: 16px;
  }
  body.sidebar-collapsed .sidebar-footer { padding: 12px 8px; }
  body.sidebar-collapsed .sidebar-footer button {
    padding: 10px;
    justify-content: center;
    min-width: 0;
  }
}

#drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 150;
}
body.drawer-open #drawer-overlay { display: block; }
body.drawer-open #sidebar { transform: translateX(0) !important; }

@media (max-width: 768px) {
  /* ── Collapsible filters ── */
  .filter-toggle { display: flex; }
  .filter-panel:not(.open) .filters { display: none; }

  /* ── Drawer ── */
  #sidebar {
    transform: translateX(-100%);
    z-index: 200;
  }

  #main { margin-left: 0; }
  #topbar { padding: 12px 16px; }
  #page-content { padding: 16px; }

  /* ── Grids & forms ── */
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }

  /* Account tile actions always visible (no hover on touch) */
  .account-tile .acc-actions { opacity: 1; }

  /* ── Bottom Sheet modal ── */
  .modal-backdrop { align-items: flex-end; }

  .modal {
    width: 100%;
    max-width: 100%;
    border-radius: 28px 28px 0 0;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
  }

  /* Drag handle indicator */
  .modal::before {
    content: '';
    display: block;
    width: 32px;
    height: 4px;
    background: var(--outline-variant);
    border-radius: 2px;
    margin: 12px auto 0;
    flex-shrink: 0;
  }

  .modal h3 {
    padding: 10px 52px 10px 24px;
    margin-bottom: 0;
    flex-shrink: 0;
    border-bottom: 0.5px solid var(--outline-variant);
    font-size: 1rem;
  }

  .modal-body {
    overflow-y: auto;
    flex: 1;
    padding: 16px 24px;
    -webkit-overflow-scrolling: touch;
  }

  .modal-actions {
    padding: 12px 24px 24px;
    margin-top: 0;
    border-top: 0.5px solid var(--outline-variant);
    flex-shrink: 0;
    background: var(--surface);
  }

  .modal-close { top: 8px; right: 16px; }

  /* ── Card layout: transactions ── */
  #tx-table-wrap table,
  #tx-table-wrap tbody { display: block; }
  #tx-table-wrap thead { display: none; }

  #tx-table-wrap tr {
    display: flex;
    flex-direction: column;
    padding: 10px 12px;
    border-bottom: 0.5px solid var(--outline-variant);
    position: relative;
  }

  #tx-table-wrap td { border: none; padding: 0; }

  /* Amount — pinned top-right */
  #tx-table-wrap td:nth-child(7) {
    position: absolute; top: 10px; right: 12px;
    font-weight: 600;
  }

  /* Category — main title */
  #tx-table-wrap td:nth-child(4) {
    order: 1;
    font-weight: 500;
    padding-right: 90px;
    margin-bottom: 2px;
  }

  /* Date */
  #tx-table-wrap td:nth-child(1) {
    order: 2;
    font-size: .75rem;
    color: var(--on-surface-variant);
  }

  /* Account */
  #tx-table-wrap td:nth-child(3) {
    order: 3;
    font-size: .75rem;
    color: var(--on-surface-variant);
  }

  /* Actions */
  #tx-table-wrap td:nth-child(8) {
    order: 4;
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
  }

  /* Hidden: Type badge(2), Label(5), Description(6) */
  #tx-table-wrap td:nth-child(2),
  #tx-table-wrap td:nth-child(5),
  #tx-table-wrap td:nth-child(6) { display: none; }

  /* ── Card layout: planned templates ── */
  #planned-templates-wrap table,
  #planned-templates-wrap tbody { display: block; }
  #planned-templates-wrap thead { display: none; }

  #planned-templates-wrap tr {
    display: flex;
    flex-direction: column;
    padding: 10px 12px;
    border-bottom: 0.5px solid var(--outline-variant);
    position: relative;
  }

  #planned-templates-wrap td { border: none; padding: 0; }

  /* Amount(5) — pinned top-right */
  #planned-templates-wrap td:nth-child(5) {
    position: absolute; top: 10px; right: 12px;
    font-weight: 600;
  }

  /* Category(4) — main */
  #planned-templates-wrap td:nth-child(4) {
    order: 1;
    font-weight: 500;
    padding-right: 90px;
    margin-bottom: 2px;
  }

  /* Account(2) */
  #planned-templates-wrap td:nth-child(2) {
    order: 2;
    font-size: .75rem;
    color: var(--on-surface-variant);
  }

  /* Date(6) */
  #planned-templates-wrap td:nth-child(6) {
    order: 3;
    font-size: .75rem;
    color: var(--on-surface-variant);
  }

  /* Periodicity(7) */
  #planned-templates-wrap td:nth-child(7) {
    order: 4;
    font-size: .75rem;
    color: var(--on-surface-variant);
  }

  /* Actions(9) */
  #planned-templates-wrap td:nth-child(9) {
    order: 5;
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
  }

  /* Hidden: Type(1), Description(3), Status(8) */
  #planned-templates-wrap td:nth-child(1),
  #planned-templates-wrap td:nth-child(3),
  #planned-templates-wrap td:nth-child(8) { display: none; }

  /* ── Card layout: planned occurrences ── */
  #planned-occurrences-wrap table,
  #planned-occurrences-wrap tbody { display: block; }
  #planned-occurrences-wrap thead { display: none; }

  #planned-occurrences-wrap tr {
    display: flex;
    flex-direction: column;
    padding: 10px 12px;
    border-bottom: 0.5px solid var(--outline-variant);
    position: relative;
  }

  #planned-occurrences-wrap td { border: none; padding: 0; }

  /* Amount(5) — pinned top-right */
  #planned-occurrences-wrap td:nth-child(5) {
    position: absolute; top: 10px; right: 12px;
    font-weight: 600;
  }

  /* Description/category(4) — main */
  #planned-occurrences-wrap td:nth-child(4) {
    order: 1;
    font-weight: 500;
    padding-right: 90px;
    margin-bottom: 2px;
  }

  /* Date(1) with overdue mark */
  #planned-occurrences-wrap td:nth-child(1) {
    order: 2;
    font-size: .75rem;
    color: var(--on-surface-variant);
  }

  /* Account(3) */
  #planned-occurrences-wrap td:nth-child(3) {
    order: 3;
    font-size: .75rem;
    color: var(--on-surface-variant);
  }

  /* Execute button(7) */
  #planned-occurrences-wrap td:nth-child(7) {
    order: 4;
    margin-top: 6px;
  }

  /* Hidden: Type(2), Status(6) */
  #planned-occurrences-wrap td:nth-child(2),
  #planned-occurrences-wrap td:nth-child(6) { display: none; }

  /* ── Card layout: cashflow table ── */
  #cashflow-wrap .tbl-wrap { overflow-x: visible; }
  #cashflow-wrap .tbl-wrap table,
  #cashflow-wrap .tbl-wrap tbody { display: block; width: 100%; }
  #cashflow-wrap .tbl-wrap thead { display: none; }

  #cashflow-wrap .tbl-wrap tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto auto;
    column-gap: 12px;
    padding: 10px 0;
    border-bottom: 0.5px solid var(--outline-variant);
    width: 100%;
    box-sizing: border-box;
  }

  #cashflow-wrap .tbl-wrap td { border: none; padding: 0; }

  /* Description (col 2) — left col, row 1 */
  #cashflow-wrap .tbl-wrap td:nth-child(2) {
    grid-column: 1; grid-row: 1;
    font-weight: 500;
  }

  /* Date (col 1) — left col, row 2 */
  #cashflow-wrap .tbl-wrap td:nth-child(1) {
    grid-column: 1; grid-row: 2;
    font-size: .75rem;
    color: var(--on-surface-variant);
  }

  /* Account (col 3) — left col, row 3 */
  #cashflow-wrap .tbl-wrap td:nth-child(3) {
    grid-column: 1; grid-row: 3;
    font-size: .75rem;
    color: var(--on-surface-variant);
  }

  /* Amount (col 5) — right col, row 1 */
  #cashflow-wrap .tbl-wrap td:nth-child(5) {
    grid-column: 2; grid-row: 1;
    font-weight: 600;
    text-align: right;
    white-space: nowrap;
  }

  /* Running balance (col 6) — right col, rows 2-3 */
  #cashflow-wrap .tbl-wrap td:nth-child(6) {
    grid-column: 2; grid-row: 2 / 4;
    font-size: .8rem;
    font-weight: 600;
    text-align: right;
    white-space: nowrap;
    align-self: end;
  }
  #cashflow-wrap .tbl-wrap td:nth-child(6):not(:empty)::before {
    content: '→ ';
    font-weight: 400;
    color: var(--on-surface-variant);
  }

  /* Hide category (col 4) */
  #cashflow-wrap .tbl-wrap td:nth-child(4) { display: none; }

  /* ── Card layout: budgets table ── */
  #budgets-list { overflow-x: hidden; }
  #budgets-list table,
  #budgets-list tbody { display: block; width: 100%; }
  #budgets-list thead { display: none; }

  #budgets-list tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 10px 0;
    border-bottom: 0.5px solid var(--outline-variant);
    width: 100%;
    box-sizing: border-box;
  }
  #budgets-list td { border: none; padding: 0; }

  /* Icon */
  #budgets-list td:nth-child(1) { flex: 0 0 auto; margin-right: 8px; align-self: flex-start; padding-top: 2px; }
  /* Category + progress bar */
  #budgets-list td:nth-child(2) { flex: 1 1 0; min-width: 0; }
  /* Edit/delete buttons */
  #budgets-list td:nth-child(6) { flex: 0 0 auto; align-self: flex-start; }

  /* Flex line break before amounts */
  #budgets-list tr::after { content: ''; display: block; flex: 0 0 100%; height: 0; order: 5; }

  /* Amounts: потрачено · лимит · остаток — on second row */
  #budgets-list td:nth-child(3),
  #budgets-list td:nth-child(4),
  #budgets-list td:nth-child(5) {
    flex: 1 1 0;
    order: 10;
    text-align: left !important;
    font-size: .75rem;
    padding-top: 4px;
  }
}
