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

/* ── Global Tokens ───────────────────────────────────────────────────────── */
:root {
  --accent:       #7C6FFF;
  --accent-soft:  rgba(124,111,255,0.12);
  --income:       #00C896;
  --income-soft:  rgba(0,200,150,0.12);
  --expense:      #FF4D6D;
  --expense-soft: rgba(255,77,109,0.12);
  --savings:      #FFB830;
  --savings-soft: rgba(255,184,48,0.12);

  --radius:    14px;
  --radius-sm: 8px;
  --shadow:    0 4px 24px rgba(0,0,0,0.14);
  --transition: 0.22s ease;

  /* category badge colors */
  --cat-salary:        #7C6FFF;
  --cat-food:          #FF6B6B;
  --cat-transport:     #00BCD4;
  --cat-rent:          #FFC107;
  --cat-entertainment: #FF9800;
  --cat-shopping:      #4CAF50;
  --cat-health:        #E91E8C;
  --cat-utilities:     #2196F3;
  --cat-other:         #90A4AE;
}

/* ── Dark Theme ──────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:       #0D0F1A;
  --surface:  #1A1D30;
  --surface2: #20243A;
  --border:   rgba(255,255,255,0.07);
  --text:     #E8EAFF;
  --text2:    #8B90B8;
  --text3:    #555B80;
}

/* ── Light Theme — Vibrant ───────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:       #EEF0FF;
  --surface:  #FFFFFF;
  --surface2: #F4F5FF;
  --border:   rgba(100,90,220,0.12);
  --text:     #1A1D30;
  --text2:    #5A5F80;
  --text3:    #AAB0CC;
}

/* Light-mode body gets a subtle diagonal gradient */
[data-theme="light"] body {
  background: linear-gradient(145deg, #EEF0FF 0%, #F5F0FF 40%, #EFF8FF 100%);
}

/* ── Base ────────────────────────────────────────────────────────────────── */
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 230px;
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  padding: 28px 16px;
  transition: background var(--transition), border-color var(--transition);
}

/* Light mode sidebar gets a vivid gradient */
[data-theme="light"] .sidebar {
  background: linear-gradient(175deg, #5C4FE0 0%, #7C6FFF 50%, #A78BFA 100%);
  border-right: none;
  box-shadow: 4px 0 20px rgba(92,79,224,0.2);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  margin-bottom: 36px;
}

.brand-logo {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 1rem;
}

[data-theme="light"] .brand-logo {
  background: rgba(255,255,255,0.25);
  backdrop-filter: blur(4px);
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
}

[data-theme="light"] .brand-name { color: #fff; }

.sidebar-nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text2);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
}

[data-theme="light"] .nav-item { color: rgba(255,255,255,0.72); }

.nav-item:hover { background: var(--surface2); color: var(--text); }

[data-theme="light"] .nav-item:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

[data-theme="light"] .nav-item.active {
  background: rgba(255,255,255,0.22);
  color: #fff;
  font-weight: 700;
}

.nav-icon { font-size: 1.1rem; }

.sidebar-footer { padding-top: 16px; border-top: 1px solid var(--border); }

[data-theme="light"] .sidebar-footer { border-top-color: rgba(255,255,255,0.2); }

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

[data-theme="light"] .theme-toggle {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.25);
  color: rgba(255,255,255,0.85);
}

.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }

[data-theme="light"] .theme-toggle:hover {
  background: rgba(255,255,255,0.3);
  color: #fff;
  border-color: rgba(255,255,255,0.5);
}

/* ── Main ────────────────────────────────────────────────────────────────── */
.main {
  margin-left: 230px;
  flex: 1;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.page-title { font-size: 1.5rem; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 0.82rem; color: var(--text2); margin-top: 2px; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  transition: border-color var(--transition);
}

.search-box:focus-within { border-color: var(--accent); }

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  color: var(--text);
  font-size: 0.88rem;
  width: 190px;
}

.search-box input::placeholder { color: var(--text3); }

/* ── Currency Dropdown ───────────────────────────────────────────────────── */
.currency-dropdown {
  position: relative;
}

.currency-trigger {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.currency-trigger:hover,
.currency-dropdown.open .currency-trigger {
  border-color: var(--accent);
  color: var(--accent);
}

.currency-trigger .caret {
  font-size: 0.7rem;
  color: var(--text3);
  transition: transform var(--transition);
}

.currency-dropdown.open .caret { transform: rotate(180deg); }

/* Panel */
.currency-panel {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.22);
  z-index: 500;
  overflow: hidden;
  animation: dropIn 0.18s ease;
}

.currency-dropdown.open .currency-panel { display: block; }

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Search inside panel */
.currency-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}

.currency-search-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
}

.currency-search-wrap input::placeholder { color: var(--text3); }

/* Scrollable list */
.currency-list {
  max-height: 280px;
  overflow-y: auto;
  padding: 6px 0;
}

.currency-group-label {
  padding: 8px 14px 4px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text3);
}

.currency-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background var(--transition);
  font-size: 0.875rem;
  color: var(--text);
}

.currency-option:hover { background: var(--surface2); }

.currency-option.selected {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.currency-option .opt-flag  { font-size: 1.1rem; flex-shrink: 0; }
.currency-option .opt-code  { font-weight: 700; min-width: 38px; }
.currency-option .opt-name  { color: var(--text2); font-size: 0.8rem; }

.currency-option.selected .opt-name { color: var(--accent); opacity: 0.8; }

.currency-no-result {
  padding: 20px;
  text-align: center;
  color: var(--text3);
  font-size: 0.85rem;
}

.btn-export {
  padding: 9px 16px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-export:hover { background: var(--accent); color: #fff; }

/* ── Stats Grid ──────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: transform var(--transition), box-shadow var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
}

.stat-balance::before { background: linear-gradient(90deg, #7C6FFF, #A78BFA); }
.stat-income::before  { background: linear-gradient(90deg, #00C896, #00E5B0); }
.stat-expense::before { background: linear-gradient(90deg, #FF4D6D, #FF8FA3); }
.stat-savings::before { background: linear-gradient(90deg, #FFB830, #FFD166); }

.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }

/* Light mode stat cards get gradient backgrounds */
[data-theme="light"] .stat-balance {
  background: linear-gradient(135deg, #EDE9FE 0%, #DDD6FE 100%);
  border-color: rgba(124,111,255,0.2);
}
[data-theme="light"] .stat-income {
  background: linear-gradient(135deg, #DCFCE7 0%, #BBF7D0 100%);
  border-color: rgba(0,200,150,0.2);
}
[data-theme="light"] .stat-expense {
  background: linear-gradient(135deg, #FFE4E6 0%, #FECDD3 100%);
  border-color: rgba(255,77,109,0.2);
}
[data-theme="light"] .stat-savings {
  background: linear-gradient(135deg, #FEF9C3 0%, #FDE68A 100%);
  border-color: rgba(255,184,48,0.2);
}

.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text2);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 6px;
}

.stat-sub { font-size: 0.75rem; color: var(--text3); }

.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.bal-icon { background: var(--accent-soft);  color: var(--accent); }
.inc-icon { background: var(--income-soft);  color: var(--income); }
.exp-icon { background: var(--expense-soft); color: var(--expense); }
.sav-icon { background: var(--savings-soft); color: var(--savings); }

[data-theme="light"] .bal-icon { background: rgba(124,111,255,0.18); }
[data-theme="light"] .inc-icon { background: rgba(0,200,150,0.18); }
[data-theme="light"] .exp-icon { background: rgba(255,77,109,0.18); }
[data-theme="light"] .sav-icon { background: rgba(255,184,48,0.18); }

#balance-card .stat-value,
.stat-balance .stat-value { color: var(--accent); }
.income-val  { color: var(--income); }
.expense-val { color: var(--expense); }
.savings-val { color: var(--savings); }

/* ── Middle Grid ─────────────────────────────────────────────────────────── */
.middle-grid {
  display: grid;
  grid-template-columns: 1fr 1.7fr;
  grid-template-rows: auto auto;
  gap: 20px;
  align-items: start;
}

.middle-grid .chart-card:nth-child(1) { grid-column: 1; grid-row: 1; }
.middle-grid .chart-card:nth-child(2) { grid-column: 1; grid-row: 2; }

.form-card { grid-column: 2; grid-row: 1 / 3; }

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: background var(--transition), border-color var(--transition);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}

.card-header h3 { font-size: 0.95rem; font-weight: 600; color: var(--text); }

/* Form card header gets a gradient in light mode */
[data-theme="light"] .form-card-header {
  background: linear-gradient(135deg, #7C6FFF 0%, #A78BFA 100%);
  border-bottom: none;
}

[data-theme="light"] .form-card-header h3 { color: #fff; }

.form-currency-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  letter-spacing: 0.5px;
}

[data-theme="light"] .form-card .form-currency-badge {
  background: rgba(255,255,255,0.25);
  color: #fff;
}

/* ── Charts ──────────────────────────────────────────────────────────────── */
.donut-wrapper, .bar-wrapper {
  position: relative;
  padding: 16px 20px;
  min-height: 210px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.donut-wrapper canvas, .bar-wrapper canvas { max-height: 190px; }

.chart-empty {
  position: absolute;
  color: var(--text3);
  font-size: 0.85rem;
  display: none;
}

.donut-legend {
  padding: 0 20px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text2);
}

.legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Form ────────────────────────────────────────────────────────────────── */
.form-card form { padding: 18px 22px 22px; }

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.opt { text-transform: none; font-weight: 400; color: var(--text3); }

.form-group input {
  padding: 10px 13px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition), background var(--transition);
}

.form-group input:focus { border-color: var(--accent); background: var(--surface); }
.form-group input::placeholder { color: var(--text3); }

[data-theme="light"] .form-group input {
  background: #F8F7FF;
  border-color: rgba(124,111,255,0.2);
}

[data-theme="light"] .form-group input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(124,111,255,0.1);
}

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

/* Type Toggle */
.type-toggle {
  display: flex;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1.5px solid var(--border);
}

.type-btn {
  flex: 1;
  padding: 9px 4px;
  border: none;
  background: transparent;
  color: var(--text2);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.type-btn.active[data-value="income"]  { background: var(--income);  color: #fff; }
.type-btn.active[data-value="expense"] { background: var(--expense); color: #fff; }
.type-btn:not(.active):hover { background: var(--surface2); }

/* Category Grid */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.cat-btn {
  padding: 8px 4px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.cat-btn:hover  { border-color: var(--accent); color: var(--accent); }
.cat-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }

[data-theme="light"] .cat-btn { background: #F5F4FF; border-color: rgba(124,111,255,0.18); }
[data-theme="light"] .cat-btn:hover { background: #EDE9FE; }
[data-theme="light"] .cat-btn.active { background: #EDE9FE; border-color: var(--accent); }

/* Submit */
.btn-submit {
  width: 100%;
  padding: 13px;
  background: linear-gradient(135deg, var(--accent) 0%, #A78BFA 100%);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition), box-shadow var(--transition);
  margin-top: 4px;
  letter-spacing: 0.3px;
  box-shadow: 0 4px 14px rgba(124,111,255,0.35);
}

.btn-submit:hover  { opacity: 0.92; box-shadow: 0 6px 20px rgba(124,111,255,0.45); }
.btn-submit:active { transform: scale(0.98); }

/* ── History ─────────────────────────────────────────────────────────────── */
.history-card { margin-bottom: 8px; }

/* Light mode history card header gets a subtle tint */
[data-theme="light"] .history-card .card-header {
  background: linear-gradient(90deg, #F8F7FF, #F0EDFF);
}

.history-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.mini-select {
  padding: 7px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
}

.mini-select:focus { border-color: var(--accent); }

[data-theme="light"] .mini-select {
  background: #F5F4FF;
  border-color: rgba(124,111,255,0.2);
}

.btn-danger-outline {
  padding: 7px 14px;
  background: transparent;
  color: var(--expense);
  border: 1px solid var(--expense);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-danger-outline:hover { background: var(--expense); color: #fff; }

/* Table */
.table-wrapper { overflow-x: auto; }

.txn-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.txn-table thead th {
  padding: 12px 20px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface2);
}

[data-theme="light"] .txn-table thead th {
  background: linear-gradient(90deg, #F0EDFF, #F5F4FF);
  color: #7C6FFF;
}

.txn-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.txn-table tbody tr:last-child { border-bottom: none; }
.txn-table tbody tr:hover { background: var(--surface2); }

[data-theme="light"] .txn-table tbody tr:hover { background: #F8F7FF; }

.txn-table tbody td {
  padding: 14px 20px;
  color: var(--text);
  vertical-align: middle;
}

.txn-desc-cell { font-weight: 600; }

/* Category-colored badges */
.txn-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: capitalize;
}

.txn-badge[data-cat="salary"]        { background: rgba(124,111,255,0.13); color: var(--cat-salary); }
.txn-badge[data-cat="food"]          { background: rgba(255,107,107,0.13); color: var(--cat-food); }
.txn-badge[data-cat="transport"]     { background: rgba(0,188,212,0.13);   color: var(--cat-transport); }
.txn-badge[data-cat="rent"]          { background: rgba(255,193,7,0.15);   color: #E6A800; }
.txn-badge[data-cat="entertainment"] { background: rgba(255,152,0,0.13);   color: var(--cat-entertainment); }
.txn-badge[data-cat="shopping"]      { background: rgba(76,175,80,0.13);   color: var(--cat-shopping); }
.txn-badge[data-cat="health"]        { background: rgba(233,30,140,0.12);  color: var(--cat-health); }
.txn-badge[data-cat="utilities"]     { background: rgba(33,150,243,0.13);  color: var(--cat-utilities); }
.txn-badge[data-cat="other"]         { background: rgba(144,164,174,0.15); color: var(--cat-other); }

.txn-date { color: var(--text2); white-space: nowrap; }
.txn-note { color: var(--text3); font-size: 0.82rem; font-style: italic; }

.txn-amount { font-weight: 700; font-size: 0.95rem; white-space: nowrap; }
.txn-amount.income  { color: var(--income); }
.txn-amount.expense { color: var(--expense); }

.btn-del {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text3);
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all var(--transition);
}

.btn-del:hover { background: var(--expense-soft); color: var(--expense); }

/* Empty State */
.empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text3);
  gap: 10px;
}

.empty-state .empty-icon { font-size: 2.5rem; }
.empty-state p  { font-size: 1rem; font-weight: 600; color: var(--text2); }
.empty-state span { font-size: 0.85rem; }

.table-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text3);
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 28px;
  right: 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
  min-width: 260px;
  animation: slideIn 0.3s ease;
}

[data-theme="light"] .toast {
  box-shadow: 0 8px 30px rgba(92,79,224,0.18);
  border-color: rgba(124,111,255,0.15);
}

.toast.success .toast-dot { background: var(--income); }
.toast.error   .toast-dot { background: var(--expense); }
.toast.info    .toast-dot { background: var(--accent); }

.toast-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateX(40px); }
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(124,111,255,0.3); }

/* ── Hamburger (hidden on desktop) ───────────────────────────────────────── */
.hamburger {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.2rem;
  width: 40px; height: 40px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
}
.hamburger:hover { border-color: var(--accent); color: var(--accent); }

/* Sidebar overlay backdrop */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.visible { display: block; }

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   BREAKPOINT 1 — Large tablet / small desktop  (max 1280px)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
@media (max-width: 1280px) {
  .stats-grid  { grid-template-columns: repeat(2, 1fr); }
  .middle-grid { grid-template-columns: 1fr 1.4fr; }
  .stat-value  { font-size: 1.35rem; }
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   BREAKPOINT 2 — Tablet landscape  (max 1024px)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
@media (max-width: 1024px) {
  /* Collapse sidebar to icon rail */
  .sidebar {
    width: 64px;
    padding: 20px 10px;
    overflow: hidden;
  }
  .brand-name,
  .nav-item span:not(.nav-icon),
  #theme-label { display: none; }
  .brand-logo  { margin: 0 auto; }
  .sidebar-brand { justify-content: center; padding: 0; }
  .nav-item    { justify-content: center; padding: 12px; }
  .theme-toggle { justify-content: center; padding: 10px; }

  .main { margin-left: 64px; padding: 24px 20px; gap: 20px; }

  .middle-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
  }
  .middle-grid .chart-card:nth-child(1) { grid-column: 1; grid-row: 1; }
  .middle-grid .chart-card:nth-child(2) { grid-column: 2; grid-row: 1; }
  .form-card { grid-column: 1 / -1; grid-row: 2; }
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   BREAKPOINT 3 — Tablet portrait  (max 768px)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
@media (max-width: 768px) {
  /* Sidebar becomes off-canvas overlay */
  .hamburger { display: flex; }

  .sidebar {
    width: 230px;
    transform: translateX(-230px);
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1),
                background var(--transition);
    padding: 28px 16px;
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0); }

  /* Restore collapsed items now that sidebar is full width again */
  .brand-name,
  .nav-item span:not(.nav-icon),
  #theme-label { display: inline; }
  .brand-logo  { margin: 0; }
  .sidebar-brand { justify-content: flex-start; padding: 0 8px; }
  .nav-item    { justify-content: flex-start; padding: 11px 14px; }
  .theme-toggle { justify-content: flex-start; padding: 10px 14px; }

  .main { margin-left: 0; padding: 16px 16px 80px; }

  /* Topbar */
  .topbar { gap: 10px; }
  .topbar-left { display: flex; align-items: center; gap: 10px; }
  .topbar-right { width: 100%; gap: 8px; }
  .search-box { flex: 1; min-width: 0; }
  .search-box input { width: 100%; min-width: 0; }
  .btn-export span { display: none; }

  /* Stats */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .stat-card  { padding: 16px 14px; }
  .stat-value { font-size: 1.2rem; }
  .stat-icon  { width: 40px; height: 40px; font-size: 1.1rem; }

  /* Middle */
  .middle-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
  .middle-grid .chart-card:nth-child(1),
  .middle-grid .chart-card:nth-child(2) { grid-column: 1; grid-row: auto; }
  .form-card { grid-column: 1; grid-row: auto; }

  /* History header stacks */
  .card-header { flex-wrap: wrap; gap: 10px; }
  .history-controls { width: 100%; overflow-x: auto; padding-bottom: 4px; }

  /* Currency panel — expand left instead of right */
  .currency-panel { right: auto; left: 0; width: 260px; }
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   BREAKPOINT 4 — Mobile  (max 480px)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
@media (max-width: 480px) {
  .main { padding: 12px 12px 80px; gap: 14px; }

  .page-title    { font-size: 1.15rem; }
  .page-subtitle { display: none; }

  /* Topbar: search takes full row */
  .topbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .topbar-left { display: flex; align-items: center; gap: 10px; }
  .topbar-right {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 8px;
    width: 100%;
  }
  .search-box { grid-column: 1 / -1; }
  .btn-export { padding: 8px 10px; font-size: 0.8rem; }

  /* Stats: 2-col compact */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card  { padding: 14px 12px; flex-direction: column; align-items: flex-start; gap: 8px; }
  .stat-icon  { display: none; }
  .stat-value { font-size: 1.1rem; }
  .stat-label { font-size: 0.7rem; margin-bottom: 4px; }

  /* Form */
  .form-card form { padding: 14px 14px 18px; }
  .form-row-2 { grid-template-columns: 1fr; }
  .cat-grid   { grid-template-columns: repeat(3, 1fr); }

  /* History table → card list */
  .txn-table thead { display: none; }

  .txn-table tbody tr {
    display: block;
    background: var(--surface2);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-left: 3px solid transparent;
  }
  .txn-table tbody tr.income-row  { border-left-color: var(--income); }
  .txn-table tbody tr.expense-row { border-left-color: var(--expense); }

  .txn-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border: none;
    font-size: 0.85rem;
  }

  /* Hide note cell on mobile to save space */
  .txn-table tbody td.txn-note-cell { display: none; }

  /* Label prefix via data-label */
  .txn-table tbody td[data-label]::before {
    content: attr(data-label);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text3);
  }

  /* First cell (description) = full row header */
  .txn-table tbody td.txn-desc-cell {
    font-size: 0.92rem;
    font-weight: 700;
    justify-content: flex-start;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
  }
  .txn-table tbody td.txn-desc-cell::before { display: none; }

  /* Delete button row */
  .txn-table tbody td.del-cell {
    justify-content: flex-end;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
  }
  .txn-table tbody td.del-cell::before { display: none; }

  .btn-del { padding: 5px 10px; }

  /* Currency panel full-width on small screens */
  .currency-dropdown { position: static; }
  .currency-panel {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 70vh;
    overflow-y: auto;
    border-left: none; border-right: none; border-bottom: none;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.3);
  }
  .currency-list { max-height: 55vh; }

  /* Toast stacks at bottom, full-width */
  #toast-container { right: 12px; left: 12px; bottom: 16px; }
  .toast { min-width: 0; width: 100%; }
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   BREAKPOINT 5 — Very small phones  (max 360px)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
@media (max-width: 360px) {
  .stats-grid { grid-template-columns: 1fr; }
  .cat-grid   { grid-template-columns: repeat(2, 1fr); }
  .stat-card  { flex-direction: row; align-items: center; }
  .topbar-right { grid-template-columns: 1fr auto; }
  .currency-trigger { padding: 8px; }
  #currency-code { display: none; }
}
