/* ============================================================
   Budget Buddy — Redesigned style.css
   DM Sans · Navy/Emerald palette · Modern fintech aesthetic
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap');

/* ============================================================
   Design tokens
   ============================================================ */
:root {
  /* Brand */
  --primary:          #059669;
  --primary-dark:     #047857;
  --primary-hover:    #10B981;
  --primary-soft:     #D1FAE5;
  --primary-softer:   #ECFDF5;
  --accent:           #D97706;
  --accent-soft:      #FEF3C7;
  --accent-softer:    #FFFBEB;

  /* Status */
  --income-color:     #059669;
  --expense-color:    #DC2626;
  --danger:           #DC2626;
  --danger-soft:      #FEE2E2;
  --danger-softer:    #FEF2F2;
  --warning:          #D97706;
  --warning-soft:     #FEF3C7;

  /* Surfaces */
  --bg:               #F0F2F5;
  --surface:          #FFFFFF;
  --surface-2:        #F8FAFC;
  --surface-3:        #F1F5F9;
  --border:           #E2E8F0;
  --border-2:         #CBD5E1;

  /* Text */
  --text-primary:     #0D1B2A;
  --text-secondary:   #475569;
  --text-muted:       #94A3B8;

  /* Sidebar */
  --sidebar-bg:        #0D1B2A;
  --sidebar-bg-2:      #162032;
  --sidebar-active:    rgba(5, 150, 105, 0.16);
  --sidebar-active-text: #34D399;
  --sidebar-text:      rgba(255,255,255, 0.45);
  --sidebar-text-hi:   rgba(255,255,255, 0.85);
  --sidebar-border:    rgba(255,255,255, 0.07);
  --sidebar-width:     240px;

  /* Elevation */
  --shadow-xs: 0 1px 2px rgba(13,27,42,.05);
  --shadow-sm: 0 1px 3px rgba(13,27,42,.08), 0 1px 2px rgba(13,27,42,.05);
  --shadow-md: 0 4px 16px rgba(13,27,42,.08), 0 2px 4px rgba(13,27,42,.04);
  --shadow-lg: 0 16px 48px rgba(13,27,42,.14), 0 4px 12px rgba(13,27,42,.06);

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

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 150ms var(--ease);
}

[data-theme="dark"] {
  --primary:          #10B981;
  --primary-dark:     #059669;
  --primary-hover:    #34D399;
  --primary-soft:     rgba(16,185,129, 0.16);
  --primary-softer:   rgba(16,185,129, 0.08);
  --accent:           #FBBF24;
  --accent-soft:      rgba(251,191,36, 0.15);
  --accent-softer:    rgba(251,191,36, 0.08);

  --income-color:     #34D399;
  --expense-color:    #F87171;
  --danger:           #F87171;
  --danger-soft:      rgba(248,113,113, 0.18);
  --danger-softer:    rgba(248,113,113, 0.08);
  --warning:          #FBBF24;
  --warning-soft:     rgba(251,191,36, 0.15);

  --bg:               #0A0F1C;
  --surface:          #111827;
  --surface-2:        #1A2438;
  --surface-3:        #1E2D40;
  --border:           #1F2D42;
  --border-2:         #2D3D55;

  --text-primary:     #E8EFF8;
  --text-secondary:   #8FA0BD;
  --text-muted:       #4B607A;

  --sidebar-bg:       #080D18;
  --sidebar-bg-2:     #0E1624;
  --sidebar-active:   rgba(16,185,129, 0.14);
  --sidebar-active-text: #34D399;
  --sidebar-text:     rgba(255,255,255, 0.35);
  --sidebar-text-hi:  rgba(255,255,255, 0.8);
  --sidebar-border:   rgba(255,255,255, 0.05);

  --shadow-xs: 0 1px 2px rgba(0,0,0, 0.3);
  --shadow-sm: 0 1px 4px rgba(0,0,0, 0.4);
  --shadow-md: 0 4px 20px rgba(0,0,0, 0.4);
  --shadow-lg: 0 20px 60px rgba(0,0,0, 0.55);
}

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

html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition), color var(--transition);
}

h1, h2, h3 { font-family: 'DM Sans', sans-serif; letter-spacing: -0.25px; }

button, input, select, textarea { font-family: inherit; }

[data-icon] svg, .icon-svg {
  width: 1.15em;
  height: 1.15em;
  display: block;
}

/* ============================================================
   App shell
   ============================================================ */
.app-shell {
  display: none; /* shown via .app-shell--visible once auth confirms a user */
  min-height: 100vh;
}
.app-shell--visible {
  display: flex;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(8, 15, 30, 0.6);
  z-index: 190;
  opacity: 0;
  transition: opacity 0.25s var(--ease);
  backdrop-filter: blur(2px);
}

/* ============================================================
   Boot loading overlay
   ============================================================ */
.boot-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 450; /* below the auth screen (500), above the app shell */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
}
.boot-loading-overlay[hidden] { display: none; }
.boot-loading-overlay p {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}
.boot-loading-spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  animation: bootSpin 0.7s linear infinite;
}
@keyframes bootSpin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .boot-loading-spinner { animation: none; }
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 200;
  border-right: 1px solid var(--sidebar-border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(5,150,105, 0.4);
}
.brand-mark svg { width: 18px; height: 18px; }

.brand-name {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.3px;
  line-height: 1.2;
}

/* Hide tagline class if present */
.brand-tagline { display: none; }

.sidebar-close { display: none; margin-left: auto; color: var(--sidebar-text); }

.sidebar-nav {
  flex: 1;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--sidebar-text);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px 8px 4px;
  opacity: 0.6;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  position: relative;
}

.nav-icon {
  display: flex;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}
.nav-icon svg { width: 16px; height: 16px; }

.nav-item:hover {
  background: rgba(255,255,255, 0.06);
  color: var(--sidebar-text-hi);
}

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

/* ============================================================
   Sidebar footer: switchers + user
   ============================================================ */
.sidebar-switchers {
  padding: 0 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--sidebar-border);
  padding-top: 12px;
}

.sidebar-switcher-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--sidebar-text);
  opacity: 0.6;
  margin-top: 6px;
}
.sidebar-switcher-label:first-child { margin-top: 0; }

.sidebar-select {
  padding: 7px 10px;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255, 0.06);
  color: var(--sidebar-text-hi);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.4)' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
.sidebar-select option { color: #0D1B2A; }

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

/* Theme toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255, 0.04);
  color: var(--sidebar-text);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 10px;
}
.theme-toggle:hover { background: rgba(255,255,255, 0.08); color: var(--sidebar-text-hi); }
.theme-toggle-label { flex: 1; text-align: left; }

.theme-icon-moon { display: none; }
[data-theme="dark"] .theme-icon-sun { display: none; }
[data-theme="dark"] .theme-icon-moon { display: flex; }

.theme-toggle-switch {
  position: relative;
  width: 32px;
  height: 18px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255, 0.12);
  flex-shrink: 0;
  transition: background var(--transition);
}
.theme-toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--transition);
}
[data-theme="dark"] .theme-toggle-switch { background: var(--primary); }
[data-theme="dark"] .theme-toggle-switch::after { transform: translateX(14px); }

/* Settings page theme toggle */
.theme-toggle-settings {
  width: auto;
  border-color: var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  margin-bottom: 0;
}
.theme-toggle-settings .theme-toggle-switch { background: var(--border-2); }
[data-theme="dark"] .theme-toggle-settings .theme-toggle-switch { background: var(--primary); }
.theme-toggle-settings .theme-toggle-switch::after { background: #fff; }

/* Sidebar user row */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255, 0.04);
  border: 1px solid var(--sidebar-border);
}

.sidebar-user-email {
  flex: 1;
  font-size: 11px;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user .icon-btn {
  background: transparent;
  border-color: transparent;
  color: var(--sidebar-text);
  padding: 3px;
}
.sidebar-user .icon-btn:hover { background: rgba(255,255,255, 0.1); color: var(--sidebar-text-hi); border-color: transparent; }
.sidebar-user .icon-btn svg { width: 14px; height: 14px; }

.sidebar-meta {
  text-align: center;
  font-size: 10px;
  color: var(--sidebar-text);
  opacity: 0.4;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

/* ============================================================
   Main content area
   ============================================================ */
.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.topbar h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.4px;
  flex: 1;
  color: var(--text-primary);
}

.menu-toggle { display: none; }

.topbar-actions { display: flex; gap: 8px; }

/* Buttons base */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover {
  background: var(--primary-softer);
  color: var(--primary);
  border-color: var(--primary-soft);
}

main {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
  flex: 1;
}

/* Views */
.view {
  display: none;
  flex-direction: column;
  gap: 20px;
  animation: viewIn 0.2s var(--ease);
}
.view.active { display: flex; }

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

/* ============================================================
   Dashboard: balance hero strip
   ============================================================ */
.summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* Balance card gets full-width hero treatment.
   Uses .card.balance-card (two classes) so its background reliably
   beats the generic .card rule regardless of CSS source order. */
.card.balance-card {
  grid-column: 1 / -1;
  background: var(--sidebar-bg);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  display: flex;
  align-items: center;
  gap: 0;
  position: relative;
  overflow: hidden;
  border: none;
  box-shadow: var(--shadow-md);
}
.balance-card::before {
  content: '';
  position: absolute;
  right: -60px; top: -60px;
  width: 220px; height: 220px;
  border-radius: 50%;
  background: rgba(5,150,105, 0.12);
  pointer-events: none;
}
.balance-card::after {
  content: '';
  position: absolute;
  right: 80px; bottom: -80px;
  width: 160px; height: 160px;
  border-radius: 50%;
  background: rgba(8,145,178, 0.07);
  pointer-events: none;
}

.balance-card .card-icon {
  display: none; /* hide the icon; the hero is typographic */
}

.balance-card .card-body {
  position: relative;
  z-index: 1;
}

.balance-card .card-body h2 {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255, 0.45);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.balance-card .card-body #balance {
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 700;
  letter-spacing: -1.5px;
  color: #fff;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* Income & expense summary cards */
.income-card,
.expenses-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--transition), transform var(--transition);
}
.income-card:hover,
.expenses-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

/* Generic card (used in dashboard) */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--transition), transform var(--transition);
}
.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}
.card-icon svg { width: 20px; height: 20px; }

.balance-card .card-icon { background: rgba(255,255,255, 0.1); color: rgba(255,255,255, 0.7); }
.income-card .card-icon  { background: var(--primary-soft); color: var(--primary-dark); }
.expenses-card .card-icon{ background: var(--danger-soft);  color: var(--danger); }

.card-body h2 {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 4px;
}
.card-body p {
  font-size: clamp(18px, 2.2vw, 24px);
  font-weight: 700;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
}

.card.animate { animation: pulse 0.3s ease-in-out; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.02); }
}

.balance   { color: #fff; }
.income    { color: var(--income-color); }
.expenses  { color: var(--expense-color); }

/* ============================================================
   Dashboard grid
   ============================================================ */
.dashboard-grid {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 20px;
  align-items: stretch;
}

.chart-section,
.recent-section {
  display: flex;
  flex-direction: column;
}

/* ============================================================
   Shared card sections
   ============================================================ */
.chart-section,
.add-transaction,
.filter-section,
.transactions,
.recent-section {
  background: var(--surface);
  padding: 22px 24px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  border: 1px solid var(--border);
}

.filter-section { padding: 14px 20px; }

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 10px;
}

.chart-header h2,
.add-transaction h2,
.transactions-header h2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.add-transaction h2 { margin-bottom: 20px; }

#chartPeriod, #reportYear {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition);
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
#chartPeriod:hover, #reportYear:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Chart & legend */
.chart-container {
  display: flex;
  flex: 1;
  gap: 20px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}
#categoryChart {
  max-width: 200px;
  height: auto;
  flex-shrink: 0;
}

.chart-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 160px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  cursor: default;
}
.legend-item:hover { background: var(--surface-2); }

.legend-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  flex-shrink: 0;
}
.legend-icon svg { width: 12px; height: 12px; }

.legend-color {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend-label {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.legend-value {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Category badge
   ============================================================ */
.category-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  flex-shrink: 0;
}
.category-badge svg { width: 17px; height: 17px; }

/* ============================================================
   Recent activity
   ============================================================ */
.recent-list {
  list-style: none;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
}

.recent-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  cursor: default;
}
.recent-list li:hover { background: var(--surface-2); }

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

.recent-desc {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.recent-amount {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.recent-amount.income  { color: var(--income-color); }
.recent-amount.expense { color: var(--expense-color); }

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  transition: opacity var(--transition);
}
.link-btn:hover { opacity: 0.75; }
.link-btn svg { width: 14px; height: 14px; }

/* ============================================================
   Forms
   ============================================================ */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  transition: var(--transition);
  background: var(--surface-2);
  color: var(--text-primary);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-softer);
}

.form-group input.error,
.form-group select.error {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-softer);
}

.error-message {
  display: block;
  color: var(--danger);
  font-size: 11px;
  font-weight: 500;
  margin-top: 4px;
  min-height: 1rem;
}

/* Transaction type toggle */
.transaction-type {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 6px;
}

.transaction-type input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.transaction-type label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
}

.transaction-type input:checked + .income-label {
  background: var(--primary-soft);
  color: var(--primary-dark);
  border-color: var(--primary);
}

.transaction-type input:checked + .expense-label {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger);
}

.income-label:hover  { border-color: var(--primary); color: var(--primary-dark); }
.expense-label:hover { border-color: var(--danger);  color: var(--danger); }

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn-primary,
.btn-secondary,
.btn-danger-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: -0.1px;
}
.btn-primary svg, .btn-secondary svg, .btn-danger-outline svg {
  width: 15px; height: 15px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(5,150,105, 0.3);
}
.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 14px rgba(5,150,105, 0.35);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-softer);
}

.btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border: 1.5px solid var(--danger);
  padding: 7px 14px;
  font-size: 13px;
}
.btn-danger-outline:hover {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 2px 8px rgba(220,38,38, 0.25);
}

.settings-btn { flex-shrink: 0; }

/* ============================================================
   Filter section
   ============================================================ */
.filter-controls {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 10px;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
  display: flex;
}
.search-icon svg { width: 15px; height: 15px; }

#searchBox {
  width: 100%;
  padding: 9px 12px 9px 36px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface-2);
  color: var(--text-primary);
  transition: var(--transition);
}
#searchBox:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-softer);
}

#filterCategory, #filterType {
  padding: 9px 28px 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
#filterCategory:hover, #filterType:hover { border-color: var(--primary); }
#filterCategory:focus, #filterType:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-softer);
}

/* ============================================================
   Transaction list
   ============================================================ */
.transactions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

#transaction-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#transaction-list li {
  background: var(--surface-2);
  padding: 11px 14px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: var(--transition);
  border: 1px solid transparent;
  border-left: 3px solid transparent;
  opacity: 0;
  animation: slideIn 0.25s var(--ease) forwards;
}

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

#transaction-list li:hover {
  background: var(--surface);
  border-color: var(--border);
  border-left-color: transparent;
  box-shadow: var(--shadow-sm);
}

#transaction-list li.income  { border-left-color: var(--income-color); }
#transaction-list li.expense { border-left-color: var(--expense-color); }

.transaction-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.transaction-description {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.transaction-category {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.transaction-amount {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.transaction-amount.income  { color: var(--income-color); }
.transaction-amount.expense { color: var(--expense-color); }

.transaction-actions { display: flex; gap: 4px; }

.transaction-actions button {
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  border-radius: 6px;
  transition: var(--transition);
  display: flex;
  color: var(--text-muted);
}
.transaction-actions button svg { width: 15px; height: 15px; }

.edit-btn:hover   { background: var(--primary-softer); color: var(--primary); }
.delete-btn:hover { background: var(--danger-softer);  color: var(--danger); }

/* Recurring tag */
.recurring-tag {
  font-size: 10px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-softer);
  border: 1px solid var(--primary-soft);
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 4px;
}

/* ============================================================
   Reports view
   ============================================================ */
.report-table-wrap { overflow-x: auto; }

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.report-table th, .report-table td {
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.report-table th:first-child, .report-table td:first-child { text-align: left; }

.report-table thead th {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
  padding-bottom: 12px;
}

.report-table tfoot th {
  font-weight: 700;
  border-top: 2px solid var(--border-2);
  border-bottom: none;
  padding-top: 14px;
}

.report-table td.income-cell  { color: var(--income-color);  font-weight: 600; }
.report-table td.expense-cell { color: var(--expense-color); font-weight: 600; }
.report-table td.net-cell.positive, .report-table th.positive { color: var(--income-color); }
.report-table td.net-cell.negative, .report-table th.negative { color: var(--expense-color); }

/* ============================================================
   Settings view
   ============================================================ */
.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.settings-row:last-child { border-bottom: none; }

.settings-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
  line-height: 1.5;
}

/* ============================================================
   No-data state
   ============================================================ */
.no-data {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
}

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text-primary);
  color: var(--surface);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s var(--ease);
  z-index: 1000;
  max-width: 320px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.toast.success  { background: var(--primary); color: #fff; }
.toast.warning  { background: var(--warning); color: #fff; }
.toast.error    { background: var(--danger);  color: #fff; }

/* .toast sets display:flex unconditionally, which otherwise beats the
   browser's default [hidden]{display:none} rule and stops the toast from
   ever disappearing. This rule restores hidden's effect. */
.toast[hidden] { display: none; }

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

/* ============================================================
   Auth screen
   ============================================================ */
.auth-screen {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  z-index: 500;
  background: var(--surface);
}
.auth-screen[hidden] { display: none; }

/* ---------------------------------------------------------
   Left: brand / value panel
   --------------------------------------------------------- */
.auth-panel {
  position: relative;
  background:
    radial-gradient(820px 520px at 12% -10%, rgba(16,185,129,0.16), transparent 60%),
    radial-gradient(680px 480px at 100% 110%, rgba(8,145,178,0.12), transparent 55%),
    linear-gradient(165deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  color: rgba(255,255,255,0.92);
  display: flex;
  align-items: center;
  padding: 64px;
  overflow: hidden;
}
.auth-panel::before {
  /* faint ledger-rule texture, like graph paper for money */
  content: '';
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.035) 0px,
    rgba(255,255,255,0.035) 1px,
    transparent 1px,
    transparent 48px
  );
  pointer-events: none;
}

.auth-panel-inner {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
}

.auth-panel .auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 56px;
}
.auth-panel .brand-name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #fff;
}

.auth-panel-headline {
  font-size: clamp(32px, 3vw, 42px);
  font-weight: 700;
  letter-spacing: -1.2px;
  line-height: 1.12;
  color: #fff;
  margin-bottom: 16px;
}

.auth-panel-sub {
  font-size: 15px;
  line-height: 1.6;
  color: rgba(255,255,255,0.55);
  max-width: 380px;
  margin-bottom: 40px;
}

/* Signature element: ambient ledger strip — animated bars settling into place,
   echoing the category-spend bars used throughout the real app. */
.ledger-strip {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 24px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-lg);
  margin-bottom: 36px;
  backdrop-filter: blur(6px);
}

.ledger-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 14px;
}

.ledger-label {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.4);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ledger-bar {
  position: relative;
  height: 7px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.07);
  overflow: hidden;
}
.ledger-bar i {
  position: absolute;
  inset: 0;
  width: var(--w, 40%);
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--primary-dark), var(--primary-hover));
  transform-origin: left center;
  animation: ledgerGrow 1.6s var(--ease) both;
  animation-delay: var(--delay, 0s);
}
.ledger-bar--income i {
  background: linear-gradient(90deg, #0E9F6E, #34D399);
}

@keyframes ledgerGrow {
  from { transform: scaleX(0); opacity: 0; }
  to   { transform: scaleX(1); opacity: 1; }
}

.auth-panel-points {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-panel-points li {
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 13.5px;
  font-weight: 500;
  color: rgba(255,255,255,0.75);
}
.auth-panel-points li span[data-icon] {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(16,185,129,0.14);
  color: var(--primary-hover);
  flex-shrink: 0;
}
.auth-panel-points li span[data-icon] svg { width: 14px; height: 14px; }

/* ---------------------------------------------------------
   Right: auth form panel
   --------------------------------------------------------- */
.auth-form-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: var(--surface);
}

.auth-card {
  width: 100%;
  max-width: 380px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.auth-brand--mobile { display: none; }

.brand-name-dark {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.auth-card h2 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.6px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.auth-card-sub {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-bottom: 28px;
  line-height: 1.5;
}

.auth-card .form-group input {
  padding: 12px 14px;
  font-size: 14.5px;
}

/* Password show/hide toggle */
.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.password-wrap input {
  width: 100%;
  padding-right: 42px;
}
.password-toggle-btn {
  position: absolute;
  right: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.password-toggle-btn svg { width: 17px; height: 17px; display: block; }
.password-toggle-btn:hover {
  color: var(--primary);
  background: var(--primary-softer);
}
.password-toggle-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.btn-auth-submit {
  width: 100%;
  padding: 12px 18px;
  font-size: 14.5px;
  margin-top: 4px;
}

.auth-mode-toggle {
  display: block;
  margin: 18px auto 0;
  text-align: center;
  width: 100%;
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.auth-mode-toggle:hover { opacity: 0.8; }

.auth-card-footer {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

#authError:empty { display: none; }

/* ---------------------------------------------------------
   Responsive: collapse to single column, hide value panel
   --------------------------------------------------------- */
@media (max-width: 880px) {
  .auth-screen {
    grid-template-columns: 1fr;
    background: var(--sidebar-bg);
  }
  .auth-panel { display: none; }
  .auth-form-panel { padding: 24px; background: transparent; }
  .auth-card {
    background: var(--surface);
    padding: 32px 26px;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
  }
  .auth-brand--mobile {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
  }
  .auth-brand--mobile .brand-name-dark { font-size: 16px; }
  .auth-card h2, .auth-card-sub { text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  .ledger-bar i { animation: none; transform: scaleX(1); opacity: 1; }
}

/* ============================================================
   Reminder banner
   ============================================================ */
.reminder-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 24px;
  background: var(--accent-softer);
  border-bottom: 1px solid var(--accent-soft);
}

.reminder-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--accent-soft);
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}
.reminder-pill svg { width: 13px; height: 13px; color: var(--accent); }

/* ============================================================
   Recurring checkbox group
   ============================================================ */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-secondary);
}
.checkbox-label input { width: auto; accent-color: var(--primary); }

.recurring-group { display: flex; flex-direction: column; gap: 8px; }
#recurrenceRuleWrap select { max-width: 200px; }

/* ============================================================
   Manager lists (Settings)
   ============================================================ */
.manager-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.manager-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  transition: background var(--transition);
}
.manager-row:hover { background: var(--surface-3); }

.manager-row span {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}

.manager-row .icon-btn { padding: 5px; }
.manager-row .icon-btn svg { width: 14px; height: 14px; }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.inline-form input[type="text"],
.inline-form input[type="number"] {
  flex: 1;
  min-width: 130px;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  transition: var(--transition);
}
.inline-form input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-softer);
}

.inline-form select {
  padding: 8px 28px 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.inline-form input[type="color"] {
  width: 40px;
  height: 38px;
  padding: 2px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
}

.inline-form .btn-secondary { flex-shrink: 0; }

/* ============================================================
   Budget vs actual bars
   ============================================================ */
.budget-vs-actual-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.budget-row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}
.budget-row-header span:first-child {
  display: flex;
  align-items: center;
  gap: 8px;
}

.budget-bar-track {
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  overflow: hidden;
}

.budget-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--primary);
  transition: width 0.5s var(--ease);
}
.budget-bar-fill.over { background: var(--danger); }

/* ============================================================
   Responsive
   ============================================================ */

/* Sidebar close button — never shown (overlay + swipe handles dismiss) */
.sidebar-close { display: none !important; }

/* Menu toggle — only on mobile */
.menu-toggle { display: none; }

@media (max-width: 992px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; opacity: 1; }
  .app-main { margin-left: 0; }
  .menu-toggle { display: flex; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .summary { grid-template-columns: 1fr 1fr; }
  .balance-card { grid-column: 1 / -1; }
}

@media (max-width: 768px) {
  .summary { grid-template-columns: 1fr; }
  .form-row, .filter-controls { grid-template-columns: 1fr; }
  .chart-container { flex-direction: column; }
  .transaction-type { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  main { padding: 16px; }
  .add-transaction,
  .transactions,
  .chart-section,
  .recent-section,
  .filter-section { padding: 16px; }
  .topbar { padding: 0 16px; }
  .balance-card { padding: 18px 20px; }
  .balance-card .card-body #balance { font-size: 26px; }
}

/* ============================================================
   Print
   ============================================================ */
@media print {
  .sidebar, .topbar, .add-transaction, .filter-section,
  .transaction-actions, .icon-btn { display: none; }
  .app-main { margin-left: 0; }
  body { background: white; }
  .card, .transactions, .chart-section { box-shadow: none; border: 1px solid #ddd; }
}

/* ============================================================
   Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
