/* ============================================
   FinTrack - Design System & Styles
   ============================================ */

/* ── Google Fonts Fallback ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ══════════════════════════════════════
   1. CSS CUSTOM PROPERTIES (DESIGN TOKENS)
   ══════════════════════════════════════ */

:root {
  /* ── Colors: Dark Mode (Default) ── */
  --bg: #0f1117;
  --bg-rgb: 15, 17, 23;
  --surface: #1a1d28;
  --surface-rgb: 26, 29, 40;
  --surface-elevated: #252836;
  --surface-elevated-rgb: 37, 40, 54;
  --primary: #a29bfe;
  --primary-rgb: 162, 155, 254;
  --accent: #81ecec;
  --accent-rgb: 129, 236, 236;
  --text: #f0f0f0;
  --text-secondary: #a0a0b0;
  --text-tertiary: #6b6b7b;
  --danger: #ff7675;
  --danger-rgb: 255, 118, 117;
  --success: #55efc4;
  --success-rgb: 85, 239, 196;
  --warning: #ffeaa7;
  --warning-rgb: 255, 234, 167;
  --income-color: #55efc4;
  --expense-color: #ff7675;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);

  /* ── Spacing ── */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  /* ── Radius ── */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* ── Typography ── */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* ── Layout ── */
  --nav-height: 64px;
  --fab-size: 56px;
  --max-width: 480px;

  /* ── Transitions ── */
  --transition-fast: 150ms ease;
  --transition: 300ms ease;
  --transition-slow: 500ms ease;
}

/* ── Light Mode ── */
[data-theme="light"] {
  --bg: #f4f5f7;
  --bg-rgb: 244, 245, 247;
  --surface: #ffffff;
  --surface-rgb: 255, 255, 255;
  --surface-elevated: #f0f2f5;
  --surface-elevated-rgb: 240, 242, 245;
  --primary: #6c5ce7;
  --primary-rgb: 108, 92, 231;
  --accent: #00cec9;
  --accent-rgb: 0, 206, 201;
  --text: #2d3436;
  --text-secondary: #636e72;
  --text-tertiary: #b2bec3;
  --danger: #e17055;
  --danger-rgb: 225, 112, 85;
  --success: #00b894;
  --success-rgb: 0, 184, 148;
  --warning: #fdcb6e;
  --warning-rgb: 253, 203, 110;
  --income-color: #00b894;
  --expense-color: #e17055;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.12);
}

/* ══════════════════════════════════════
   2. RESET & BASE
   ══════════════════════════════════════ */

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

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; color: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
img { max-width: 100%; display: block; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-tertiary); border-radius: 4px; }

/* ══════════════════════════════════════
   3. LAYOUT (APP SHELL)
   ══════════════════════════════════════ */

#app {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: var(--max-width);
  margin: 0 auto;
  position: relative;
  overflow-x: hidden;
}

#content {
  flex: 1;
  padding: var(--space-md);
  padding-bottom: calc(var(--nav-height) + var(--space-xl) + 20px);
  overflow-y: auto;
}

.view {
  display: none;
  animation: fadeSlideUp 0.3s ease;
}

.view.active {
  display: block;
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── View Header ── */
.view-header {
  margin-bottom: var(--space-lg);
}

.view-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.view-header p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: var(--space-xs);
}

/* ══════════════════════════════════════
   4. BOTTOM NAVIGATION
   ══════════════════════════════════════ */

#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  height: var(--nav-height);
  background: rgba(var(--surface-rgb), 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding: 0 var(--space-xs);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-sm) var(--space-xs);
  border-radius: var(--radius-md);
  transition: var(--transition-fast);
  flex: 1;
  min-width: 0;
  position: relative;
}

.nav-item svg {
  width: 22px;
  height: 22px;
  stroke: var(--text-secondary);
  stroke-width: 1.8;
  fill: none;
  transition: var(--transition-fast);
}

.nav-item span {
  font-size: 0.625rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: var(--transition-fast);
  white-space: nowrap;
}

.nav-item.active svg {
  stroke: var(--primary);
}

.nav-item.active span {
  color: var(--primary);
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  background: var(--primary);
  border-radius: 0 0 4px 4px;
}

/* ══════════════════════════════════════
   5. FAB (FLOATING ACTION BUTTON)
   ══════════════════════════════════════ */

#fab {
  position: fixed;
  bottom: calc(var(--nav-height) + 20px + env(safe-area-inset-bottom, 0px));
  right: 24px;
  left: auto !important;
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99;
  box-shadow: 0 4px 20px rgba(var(--primary-rgb), 0.4);
  transition: var(--transition);
  animation: fabPulse 3s ease-in-out infinite;
}

#fab svg {
  width: 28px;
  height: 28px;
  stroke: #fff;
  stroke-width: 2.5;
  fill: none;
}

#fab:active {
  transform: scale(0.92);
}

@keyframes fabPulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(var(--primary-rgb), 0.4); }
  50% { box-shadow: 0 4px 30px rgba(var(--primary-rgb), 0.6), 0 0 40px rgba(var(--accent-rgb), 0.2); }
}

/* On larger screens, position FAB relative to max-width container */
@media (min-width: 480px) {
  #fab {
    right: calc(50% - var(--max-width) / 2 + 20px);
  }
}

/* ══════════════════════════════════════
   6. CARDS & GLASSMORPHISM
   ══════════════════════════════════════ */

.card {
  background: rgba(var(--surface-rgb), 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  transition: var(--transition-fast);
}

.card-elevated {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
}

.card-gradient {
  background: linear-gradient(135deg, rgba(var(--primary-rgb), 0.15), rgba(var(--accent-rgb), 0.1));
  border: 1px solid rgba(var(--primary-rgb), 0.2);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
}

/* ══════════════════════════════════════
   7. BUTTONS
   ══════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.875rem;
  transition: var(--transition-fast);
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  box-shadow: 0 4px 16px rgba(var(--primary-rgb), 0.3);
}

.btn-primary:active {
  transform: scale(0.97);
  box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.3);
}

.btn-secondary {
  background: var(--surface-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: rgba(var(--danger-rgb), 0.15);
  color: var(--danger);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.8125rem;
}

/* ══════════════════════════════════════
   8. FORMS & INPUTS
   ══════════════════════════════════════ */

.form-group {
  margin-bottom: var(--space-md);
}

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface-elevated);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 1rem;
  transition: var(--transition-fast);
  outline: none;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
}

.form-input::placeholder {
  color: var(--text-tertiary);
}

.amount-input {
  font-size: 1.75rem;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}

/* ── Toggle Switch ── */
.toggle-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
}

.toggle {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface-elevated);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--text-secondary);
  border-radius: 50%;
  transition: var(--transition);
}

.toggle input:checked + .toggle-slider {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-color: transparent;
}

.toggle input:checked + .toggle-slider::before {
  transform: translateY(-50%) translateX(20px);
  background: #fff;
}

/* ── Type Selector ── */
.type-selector {
  display: flex;
  gap: var(--space-sm);
  padding: 4px;
  background: var(--surface-elevated);
  border-radius: var(--radius-md);
}

.type-btn {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.875rem;
  text-align: center;
  transition: var(--transition-fast);
}

.type-btn.active[data-type="expense"] {
  background: rgba(var(--danger-rgb), 0.2);
  color: var(--danger);
}

.type-btn.active[data-type="income"] {
  background: rgba(var(--success-rgb), 0.2);
  color: var(--success);
}

/* ── Category Grid ── */
.category-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-sm);
}

.category-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: var(--space-sm) var(--space-xs);
  border-radius: var(--radius-md);
  border: 1.5px solid transparent;
  transition: var(--transition-fast);
  cursor: pointer;
  background: var(--surface-elevated);
}

.category-item:active {
  transform: scale(0.95);
}

.category-item.selected {
  border-color: var(--primary);
  background: rgba(var(--primary-rgb), 0.1);
}

.category-item .cat-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.category-item .cat-label {
  font-size: 0.625rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.2;
}

/* ══════════════════════════════════════
   9. MODAL
   ══════════════════════════════════════ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition);
}

.modal-overlay.show {
  display: flex;
  opacity: 1;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: var(--max-width);
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--space-lg);
  transform: translateY(100%);
  transition: transform var(--transition);
}

.modal-overlay.show .modal {
  transform: translateY(0);
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--text-tertiary);
  border-radius: var(--radius-full);
  margin: 0 auto var(--space-md);
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: var(--space-lg);
  text-align: center;
}

/* ── Confirm Modal ── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
}

.confirm-overlay.show {
  display: flex;
}

.confirm-box {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  max-width: 340px;
  width: 100%;
  text-align: center;
}

.confirm-box h3 {
  font-size: 1.125rem;
  margin-bottom: var(--space-sm);
}

.confirm-box p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-lg);
}

.confirm-actions {
  display: flex;
  gap: var(--space-sm);
}

.confirm-actions .btn {
  flex: 1;
}

/* ══════════════════════════════════════
   10. DASHBOARD
   ══════════════════════════════════════ */

.greeting {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.greeting-name {
  font-size: 1.375rem;
  font-weight: 700;
  margin-top: 2px;
}

/* Summary Cards Row */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

.summary-card {
  padding: var(--space-md);
}

.summary-card .label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.summary-card .amount {
  font-size: 1.125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
  color: var(--text);
}

.summary-card.highlight {
  grid-column: 1 / -1;
}

.summary-card.highlight .amount {
  font-size: 1.5rem;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Budget Mini Cards */
.budget-mini-list {
  margin-top: var(--space-md);
}

.budget-mini-card {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
}

.budget-mini-info {
  flex: 1;
  min-width: 0;
}

.budget-mini-label {
  font-size: 0.8125rem;
  font-weight: 600;
}

.budget-mini-amount {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* Progress Bar */
.progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(var(--surface-elevated-rgb), 0.8);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: var(--space-sm);
}

.progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 0;
}

.progress-fill.safe {
  background: linear-gradient(90deg, var(--success), #81ecec);
}

.progress-fill.warning {
  background: linear-gradient(90deg, var(--warning), #e17055);
}

.progress-fill.danger {
  background: linear-gradient(90deg, var(--danger), #d63031);
}

.budget-mini-percent {
  font-size: 1.125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 50px;
  text-align: right;
}

/* Section Title */
.section-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-md);
  margin-top: var(--space-lg);
}

/* ── Chart Container ── */
.chart-container {
  position: relative;
  height: 180px;
  padding: var(--space-md);
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ── Top Categories ── */
.top-category-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 10px 0;
}

.top-category-item + .top-category-item {
  border-top: 1px solid var(--border);
}

.top-cat-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  flex-shrink: 0;
}

.top-cat-info {
  flex: 1;
  min-width: 0;
}

.top-cat-name {
  font-size: 0.875rem;
  font-weight: 600;
}

.top-cat-bar {
  height: 4px;
  background: var(--surface-elevated);
  border-radius: var(--radius-full);
  margin-top: 4px;
  overflow: hidden;
}

.top-cat-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.6s ease;
}

.top-cat-amount {
  font-size: 0.8125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

/* ══════════════════════════════════════
   11. TRANSACTION LIST
   ══════════════════════════════════════ */

.filter-bar {
  display: flex;
  gap: var(--space-sm);
  overflow-x: auto;
  padding-bottom: var(--space-sm);
  margin-bottom: var(--space-md);
  scrollbar-width: none;
}

.filter-bar::-webkit-scrollbar { display: none; }

.filter-chip {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  background: var(--surface-elevated);
  color: var(--text-secondary);
  border: 1.5px solid transparent;
  transition: var(--transition-fast);
  cursor: pointer;
}

.filter-chip.active {
  background: rgba(var(--primary-rgb), 0.15);
  color: var(--primary);
  border-color: rgba(var(--primary-rgb), 0.3);
}

/* Date Group */
.tx-date-group {
  margin-bottom: var(--space-lg);
}

.tx-date-header {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tx-date-total {
  font-variant-numeric: tabular-nums;
  color: var(--expense-color);
}

/* Transaction Item */
.tx-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition-fast);
}

.tx-item:active {
  transform: scale(0.98);
}

.tx-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.tx-info {
  flex: 1;
  min-width: 0;
}

.tx-category {
  font-size: 0.875rem;
  font-weight: 600;
}

.tx-note {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.tx-amount {
  font-size: 0.9375rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tx-amount.expense { color: var(--expense-color); }
.tx-amount.income { color: var(--income-color); }

/* Delete backdrop */
.tx-delete-bg {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 70px;
  background: var(--danger);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: var(--space-xl) var(--space-md);
  color: var(--text-secondary);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: var(--space-md);
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.875rem;
  line-height: 1.6;
}

/* ══════════════════════════════════════
   12. BUDGET PAGE
   ══════════════════════════════════════ */

.budget-card {
  margin-bottom: var(--space-md);
  padding: var(--space-lg);
}

.budget-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.budget-period-label {
  font-weight: 700;
  font-size: 1rem;
}

.budget-period-emoji {
  font-size: 1.25rem;
  margin-right: var(--space-sm);
}

.budget-status {
  display: flex;
  justify-content: space-between;
  margin-top: var(--space-sm);
  font-size: 0.8125rem;
}

.budget-status .spent {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.budget-status .remaining {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.remaining.safe { color: var(--success); }
.remaining.warning { color: var(--warning); }
.remaining.danger { color: var(--danger); }

.budget-input-row {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

.budget-input-row .form-input {
  flex: 1;
}

.budget-reset-info {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: var(--space-sm);
  font-style: italic;
}

/* ══════════════════════════════════════
   13. STATISTICS
   ══════════════════════════════════════ */

.period-tabs {
  display: flex;
  gap: var(--space-sm);
  padding: 4px;
  background: var(--surface-elevated);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
}

.period-tab {
  flex: 1;
  padding: 8px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 600;
  text-align: center;
  transition: var(--transition-fast);
  color: var(--text-secondary);
  cursor: pointer;
}

.period-tab.active {
  background: var(--primary);
  color: #fff;
}

.stats-total-card {
  text-align: center;
  padding: var(--space-lg);
  margin-bottom: var(--space-md);
}

.stats-total-label {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stats-total-amount {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: var(--space-sm);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stats-comparison {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.stats-comp-card {
  flex: 1;
  text-align: center;
  padding: var(--space-md);
}

.stats-comp-card .label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.stats-comp-card .value {
  font-size: 1.125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}

.stats-comp-card .value.expense { color: var(--expense-color); }
.stats-comp-card .value.income { color: var(--income-color); }

.chart-wrapper {
  padding: var(--space-md);
  margin-bottom: var(--space-md);
}

.chart-wrapper h3 {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: var(--space-md);
}

.chart-box {
  position: relative;
  height: 220px;
}

.chart-box canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Insight Card */
.insight-card {
  padding: var(--space-md);
  display: flex;
  gap: var(--space-md);
  align-items: flex-start;
  margin-bottom: var(--space-md);
}

.insight-card .insight-emoji {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.insight-card .insight-text {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.insight-card .insight-text strong {
  color: var(--text);
}

/* ── Custom Date Range ── */
.stats-custom-range {
  display: none;
  background: var(--surface-elevated);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  border: 1px solid var(--border);
  animation: fadeSlideUp 0.2s ease;
}

.stats-custom-range.show {
  display: block;
}

.custom-range-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.custom-range-field {
  flex: 1;
  min-width: 110px;
}

.custom-range-field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.custom-range-field input[type="date"] {
  width: 100%;
  padding: 8px 10px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
  transition: var(--transition-fast);
}

.custom-range-field input[type="date"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.15);
}

.custom-range-sep {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  padding-bottom: 10px;
  flex-shrink: 0;
}

/* ── Stats Summary Grid ── */
.stats-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.stats-summary-card {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
}

.stats-summary-wide {
  grid-column: 1 / -1;
}

.stats-summary-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  flex-shrink: 0;
}

.expense-bg { background: rgba(var(--danger-rgb), 0.15); }
.income-bg  { background: rgba(var(--success-rgb), 0.15); }

.stats-summary-info {
  flex: 1;
  min-width: 0;
}

.stats-summary-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.stats-summary-value {
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-summary-value.expense { color: var(--expense-color); }
.stats-summary-value.income  { color: var(--income-color); }

/* ── Chart Header with Toggle ── */
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.chart-header h3 {
  margin-bottom: 0;
}

.cat-type-toggle {
  display: flex;
  padding: 3px;
  background: var(--surface-elevated);
  border-radius: var(--radius-sm);
  gap: 2px;
}

.cat-toggle-btn {
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 5px;
  color: var(--text-secondary);
  transition: var(--transition-fast);
  cursor: pointer;
  white-space: nowrap;
}

.cat-toggle-btn.active {
  background: var(--primary);
  color: #fff;
}

/* ── Category Breakdown Bar List ── */
.cat-breakdown-list {
  margin-top: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.cat-breakdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.cat-breakdown-left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 110px;
  flex-shrink: 0;
}

.cat-bd-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.cat-bd-label {
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cat-breakdown-right {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-width: 0;
}

.cat-bd-bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--surface-elevated);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.cat-bd-bar {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 2px;
}

.cat-bd-pct {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 30px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cat-bd-val {
  font-size: 0.8125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--text);
  min-width: 80px;
  text-align: right;
}

.empty-state-inline {
  padding: var(--space-md) 0;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ── Stats Transaction History ── */
.stats-history-section {
  margin-top: var(--space-lg);
}

.stats-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.stats-history-header h3 {
  font-size: 0.875rem;
  font-weight: 600;
}

.stats-history-count {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--surface-elevated);
  padding: 3px 10px;
  border-radius: var(--radius-full);
}

.stats-tx-group {
  margin-bottom: var(--space-lg);
}

.stats-tx-date-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--border);
}

.stats-tx-date-total {
  font-variant-numeric: tabular-nums;
  display: flex;
  gap: var(--space-sm);
}

.stats-tx-date-total .expense { color: var(--expense-color); }
.stats-tx-date-total .income  { color: var(--income-color); }

.stats-tx-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-sm);
  border-radius: var(--radius-md);
  transition: var(--transition-fast);
  margin-bottom: 6px;
}

.stats-tx-item:last-child {
  margin-bottom: 0;
}

.stats-tx-item:hover {
  background: rgba(var(--surface-elevated-rgb), 0.5);
}

.stats-tx-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.stats-tx-info {
  flex: 1;
  min-width: 0;
}

.stats-tx-top {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.stats-tx-cat {
  font-size: 0.875rem;
  font-weight: 600;
}

.stats-tx-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-expense {
  background: rgba(var(--danger-rgb), 0.15);
  color: var(--expense-color);
}

.badge-income {
  background: rgba(var(--success-rgb), 0.15);
  color: var(--income-color);
}

.stats-tx-note {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-tx-amount {
  font-size: 0.9375rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin-top: 2px;
}

.stats-tx-amount.expense { color: var(--expense-color); }
.stats-tx-amount.income  { color: var(--income-color); }

/* ══════════════════════════════════════
   14. SETTINGS
   ══════════════════════════════════════ */

.settings-group {
  margin-bottom: var(--space-lg);
}

.settings-group-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: var(--space-sm);
  padding-left: var(--space-xs);
}

.settings-list {
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.settings-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 14px var(--space-md);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition-fast);
}

.settings-item:last-child {
  border-bottom: none;
}

.settings-item:active {
  background: var(--surface-elevated);
}

.settings-item-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  flex-shrink: 0;
}

.settings-item-info {
  flex: 1;
  min-width: 0;
}

.settings-item-label {
  font-size: 0.9375rem;
  font-weight: 500;
}

.settings-item-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 1px;
}

.settings-item-action {
  color: var(--text-tertiary);
  font-size: 0.875rem;
}

.settings-item .toggle {
  margin-left: auto;
}

.app-version {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: var(--space-xl);
  padding: var(--space-md);
}

/* ══════════════════════════════════════
   15. GUIDE & ONBOARDING
   ══════════════════════════════════════ */

/* ── Onboarding Overlay ── */
.onboarding-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 500;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.onboarding-overlay.show {
  display: flex;
}

.onboarding-slides {
  width: 100%;
  max-width: var(--max-width);
  padding: var(--space-xl);
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.onboarding-slide {
  display: none;
  text-align: center;
  animation: fadeSlideUp 0.4s ease;
}

.onboarding-slide.active {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.onboarding-emoji {
  font-size: 4rem;
  margin-bottom: var(--space-lg);
}

.onboarding-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--space-sm);
}

.onboarding-desc {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 320px;
}

.onboarding-footer {
  width: 100%;
  max-width: var(--max-width);
  padding: var(--space-lg) var(--space-xl);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
}

.onboarding-dots {
  display: flex;
  gap: var(--space-sm);
}

.onboarding-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
  transition: var(--transition);
}

.onboarding-dot.active {
  width: 24px;
  border-radius: var(--radius-full);
  background: var(--primary);
}

.onboarding-actions {
  display: flex;
  width: 100%;
  gap: var(--space-sm);
}

.onboarding-actions .btn {
  flex: 1;
}

/* ── Guide / Help Page ── */
.guide-section {
  margin-bottom: var(--space-md);
}

.accordion-item {
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: var(--space-sm);
  background: var(--surface);
  border: 1px solid var(--border);
}

.accordion-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 14px var(--space-md);
  width: 100%;
  text-align: left;
  font-weight: 600;
  font-size: 0.9375rem;
  transition: var(--transition-fast);
}

.accordion-header:active {
  background: var(--surface-elevated);
}

.accordion-icon {
  margin-left: auto;
  transition: transform var(--transition);
  color: var(--text-secondary);
}

.accordion-item.open .accordion-icon {
  transform: rotate(180deg);
}

.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.accordion-item.open .accordion-body {
  max-height: 500px;
}

.accordion-content {
  padding: 0 var(--space-md) var(--space-md);
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.accordion-content ol, .accordion-content ul {
  padding-left: var(--space-lg);
  margin-top: var(--space-sm);
}

.accordion-content li {
  margin-bottom: var(--space-xs);
}

/* ══════════════════════════════════════
   16. TOAST NOTIFICATIONS
   ══════════════════════════════════════ */

#toast-container {
  position: fixed;
  top: var(--space-md);
  left: 50%;
  transform: translateX(-50%);
  z-index: 600;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  width: 100%;
  max-width: calc(var(--max-width) - 32px);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 12px var(--space-md);
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: translateY(-20px);
  opacity: 0;
  transition: var(--transition);
  pointer-events: auto;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.toast-msg {
  font-size: 0.875rem;
  font-weight: 500;
}

.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-info { border-left: 3px solid var(--primary); }

/* ══════════════════════════════════════
   17. VERSION & CHANGELOG
   ══════════════════════════════════════ */

/* ── Changelog List ── */
.cl-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  max-height: 350px;
  overflow-y: auto;
  padding-right: 4px;
}

.cl-entry {
  border-bottom: 1px solid var(--border);
  background: transparent;
  transition: var(--transition-fast);
}

.cl-entry:last-child {
  border-bottom: none;
}

.cl-entry-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-xs);
  text-align: left;
  gap: var(--space-sm);
  cursor: pointer;
  transition: var(--transition-fast);
}

.cl-entry-header:active {
  background: rgba(var(--surface-elevated-rgb), 0.3);
}

.cl-entry-left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex: 1;
  min-width: 0;
}

.cl-entry-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.cl-entry-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cl-entry-date {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.cl-chevron {
  font-size: 1.25rem;
  color: var(--text-secondary);
  transition: transform var(--transition-fast);
  flex-shrink: 0;
  line-height: 1;
}

/* ── Changelog Items ── */
.cl-item-list {
  list-style: none;
  padding: 0 var(--space-xs) var(--space-md);
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: fadeSlideUp 0.2s ease;
}

.cl-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
}

.cl-item-icon {
  font-size: 0.875rem;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
  margin-top: 1px;
}

.cl-item-text {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Change type color accents */
.cl-new    .cl-item-text { color: var(--text); }
.cl-fix    .cl-item-text { color: var(--danger); }
.cl-improve .cl-item-text { color: var(--warning); }

/* ══════════════════════════════════════
   18. UTILITY CLASSES
   ══════════════════════════════════════ */

.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.gap-sm { gap: var(--space-sm); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

/* ══════════════════════════════════════
   18. RESPONSIVE
   ══════════════════════════════════════ */

@media (min-width: 480px) {
  body {
    background: var(--bg);
  }

  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    min-height: 100vh;
  }
}

/* Small screens */
@media (max-width: 360px) {
  .category-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .summary-card .amount {
    font-size: 1rem;
  }
}
