/* ==========================================================================
   Smart Grocery Budget Tracker - Lush Ledger Design System
   Modern Emerald Glassmorphism & High-Precision Financial Tracking
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CSS Custom Properties / Design Tokens
   -------------------------------------------------------------------------- */
:root {
  /* Color Palette - Emerald & Slate Theme (Light Mode Default) */
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-dark: #006c49;
  --primary-light: #d1fae5;
  --primary-rgb: 16, 185, 129;

  --secondary: #3b82f6;
  --secondary-hover: #2563eb;
  --secondary-light: #dbeafe;

  --accent-amber: #f59e0b;
  --accent-amber-light: #fef3c7;
  --accent-amber-border: #fcd34d;

  --accent-danger: #ef4444;
  --accent-danger-hover: #dc2626;
  --accent-danger-light: #fee2e2;
  --accent-danger-border: #fca5a5;

  --accent-purple: #8b5cf6;
  --accent-purple-light: #ede9fe;

  /* Surfaces & Backgrounds */
  --bg-app: #f8fafc;
  --bg-glow-1: rgba(16, 185, 129, 0.12);
  --bg-glow-2: rgba(59, 130, 246, 0.08);

  --surface-card: rgba(255, 255, 255, 0.85);
  --surface-card-hover: rgba(255, 255, 255, 0.95);
  --surface-input: #ffffff;
  --surface-subtle: #f1f5f9;
  --surface-hover: #e2e8f0;
  --surface-modal: rgba(255, 255, 255, 0.96);

  /* Borders & Dividers */
  --border-glass: rgba(226, 232, 240, 0.8);
  --border-glass-highlight: rgba(255, 255, 255, 0.9);
  --border-focus: #10b981;

  /* Text Colors */
  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  /* Typography */
  --font-display: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Elevations & Shadows */
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 8px 10px -6px rgba(15, 23, 42, 0.04);
  --shadow-xl: 0 20px 35px -5px rgba(15, 23, 42, 0.12), 0 10px 15px -5px rgba(15, 23, 42, 0.08);
  --shadow-emerald: 0 4px 14px 0 rgba(16, 185, 129, 0.35);

  /* Border Radii */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-pill: 9999px;

  /* Transitions */
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --------------------------------------------------------------------------
   2. Dark Mode Theme Overrides
   -------------------------------------------------------------------------- */
[data-theme="dark"] {
  --bg-app: #090d16;
  --bg-glow-1: rgba(16, 185, 129, 0.08);
  --bg-glow-2: rgba(59, 130, 246, 0.06);

  --surface-card: rgba(15, 23, 42, 0.78);
  --surface-card-hover: rgba(30, 41, 59, 0.88);
  --surface-input: #1e293b;
  --surface-subtle: #1e293b;
  --surface-hover: #334155;
  --surface-modal: rgba(15, 23, 42, 0.96);

  --border-glass: rgba(51, 65, 85, 0.6);
  --border-glass-highlight: rgba(255, 255, 255, 0.08);
  --border-focus: #34d399;

  --text-main: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-inverse: #0f172a;

  --primary-light: rgba(16, 185, 129, 0.18);
  --secondary-light: rgba(59, 130, 246, 0.18);
  --accent-amber-light: rgba(245, 158, 11, 0.18);
  --accent-danger-light: rgba(239, 68, 68, 0.18);
  --accent-purple-light: rgba(139, 92, 246, 0.18);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 10px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.6);
}

/* --------------------------------------------------------------------------
   3. Reset & Base Styles
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-main);
  background-color: var(--bg-app);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* Ambient Background Glows */
.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  z-index: 0;
}

.bg-glow-1 {
  width: 500px;
  height: 500px;
  background: var(--bg-glow-1);
  top: -100px;
  right: -50px;
}

.bg-glow-2 {
  width: 600px;
  height: 600px;
  background: var(--bg-glow-2);
  bottom: 0;
  left: -100px;
}

/* Accessibility helper */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   4. Glassmorphism Card Container
   -------------------------------------------------------------------------- */
.glass-card {
  background: var(--surface-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  transition: box-shadow var(--transition-normal), border-color var(--transition-normal), background var(--transition-normal);
  position: relative;
}

.glass-card:hover {
  box-shadow: var(--shadow-lg);
}

/* --------------------------------------------------------------------------
   5. Header Navigation
   -------------------------------------------------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-glass);
  box-shadow: var(--shadow-sm);
  padding: 0.85rem 1.5rem;
  transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.header-container {
  max-width: 1360px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-icon-wrapper {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary) 0%, #059669 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: var(--shadow-emerald);
  flex-shrink: 0;
}

.brand-icon {
  width: 24px;
  height: 24px;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-highlight {
  color: var(--primary);
  background: linear-gradient(135deg, var(--primary) 0%, #059669 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 400;
  display: block;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

/* --------------------------------------------------------------------------
   6. Buttons & Interactive Controls
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  cursor: pointer;
  outline: none;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(var(--primary-rgb), 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-hover) 0%, var(--primary-dark) 100%);
  box-shadow: 0 4px 16px rgba(var(--primary-rgb), 0.45);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--surface-subtle);
  color: var(--text-main);
  border-color: var(--border-glass);
}

.btn-secondary:hover {
  background: var(--surface-hover);
  color: var(--text-main);
  border-color: var(--text-muted);
}

.btn-danger {
  background: var(--accent-danger);
  color: #ffffff;
}

.btn-danger:hover {
  background: var(--accent-danger-hover);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-outline {
  background: transparent;
  border-color: currentColor;
  color: inherit;
}

.btn-outline:hover {
  background: rgba(0, 0, 0, 0.05);
}

.btn-sm {
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
}

.btn-xs {
  font-size: 0.75rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-sm);
}

.btn-lg {
  font-size: 1rem;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
}

.btn-block {
  width: 100%;
}

.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-glass);
  background: var(--surface-subtle);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  transition: all var(--transition-fast);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

.btn-icon:hover {
  background: var(--surface-hover);
  border-color: var(--text-muted);
  transform: scale(1.05);
}

/* Theme Toggle Icon Switching */
[data-theme="light"] .moon-icon { display: block; }
[data-theme="light"] .sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: block; }

/* Currency & Form Select Wrappers */
.select-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.select-wrapper .control-icon,
.select-wrapper .sort-icon {
  position: absolute;
  left: 0.75rem;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 2;
}

.form-select {
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--surface-input);
  color: var(--text-main);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  padding: 0.5rem 2rem 0.5rem 0.85rem;
  font-family: var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  background-image: url("data:image/svg2+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  background-size: 14px;
}

.currency-select {
  padding-left: 2rem;
  border-radius: var(--radius-pill);
  font-weight: 600;
}

.sort-select {
  padding-left: 2.1rem;
  border-radius: var(--radius-pill);
}

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

/* --------------------------------------------------------------------------
   7. Main Layout Container
   -------------------------------------------------------------------------- */
.app-main {
  max-width: 1360px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: relative;
  z-index: 10;
}

/* --------------------------------------------------------------------------
   8. Dynamic Budget Alert Banner
   -------------------------------------------------------------------------- */
.budget-alert-banner {
  border-radius: var(--radius-md);
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-normal);
  animation: fadeIn 0.3s ease-out;
}

.alert-icon-wrap {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.alert-icon-wrap svg {
  width: 18px;
  height: 18px;
}

.alert-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.alert-title {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 700;
}

.alert-msg {
  font-size: 0.85rem;
}

.alert-action-btn {
  margin-left: auto;
  flex-shrink: 0;
}

/* Alert States */
.alert-safe {
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1px solid rgba(var(--primary-rgb), 0.3);
}
.alert-safe .alert-icon-wrap {
  background: var(--primary);
  color: #ffffff;
}

.alert-warning {
  background: var(--accent-amber-light);
  color: #92400e;
  border: 1px solid var(--accent-amber-border);
}
.alert-warning .alert-icon-wrap {
  background: var(--accent-amber);
  color: #ffffff;
}

.alert-danger {
  background: var(--accent-danger-light);
  color: #991b1b;
  border: 1px solid var(--accent-danger-border);
  animation: pulseAlert 2s infinite ease-in-out;
}
.alert-danger .alert-icon-wrap {
  background: var(--accent-danger);
  color: #ffffff;
}

@keyframes pulseAlert {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.2); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0.1); }
}

/* --------------------------------------------------------------------------
   9. Bento Grid Overview Cards
   -------------------------------------------------------------------------- */
.overview-bento {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
}

.bento-card {
  background: var(--surface-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.75rem;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.bento-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.bento-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.bento-icon-box {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.bento-icon-box svg {
  width: 18px;
  height: 18px;
}

.icon-emerald { background: var(--primary-light); color: var(--primary); }
.icon-blue { background: var(--secondary-light); color: var(--secondary); }
.icon-amber { background: var(--accent-amber-light); color: var(--accent-amber); }
.icon-red { background: var(--accent-danger-light); color: var(--accent-danger); }
.icon-purple { background: var(--accent-purple-light); color: var(--accent-purple); }

.bento-label {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.bento-action-badge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.bento-action-badge svg {
  width: 12px;
  height: 12px;
}

.bento-action-badge:hover {
  background: var(--primary);
  color: #ffffff;
}

.bento-value {
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-main);
  line-height: 1.1;
}

.bento-subtext {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.text-emphasis {
  color: var(--text-main);
  font-weight: 600;
}

.remaining-overbudget {
  color: var(--accent-danger) !important;
}

/* --------------------------------------------------------------------------
   10. Visual Dynamic Progress Bar
   -------------------------------------------------------------------------- */
.progress-section {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.25rem 1.5rem;
}

.progress-info-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.progress-meta {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.progress-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

.progress-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.progress-badge-wrap {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.progress-percent-badge {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.status-pill {
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status-safe {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.status-warning {
  background: var(--accent-amber-light);
  color: #92400e;
}

.status-danger {
  background: var(--accent-danger-light);
  color: #991b1b;
}

.progress-track-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.progress-track {
  width: 100%;
  height: 14px;
  background: var(--surface-subtle);
  border-radius: var(--radius-pill);
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border-glass);
}

.progress-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, #10b981 0%, #059669 100%);
  transition: width var(--transition-slow), background var(--transition-normal);
  position: relative;
  overflow: hidden;
  max-width: 100%;
}

.progress-fill.fill-warning {
  background: linear-gradient(90deg, #f59e0b 0%, #d97706 100%);
}

.progress-fill.fill-danger {
  background: linear-gradient(90deg, #ef4444 0%, #b91c1c 100%);
}

.progress-stripes {
  position: absolute;
  inset: 0;
  background-image: linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.2) 25%,
    transparent 25%,
    transparent 50%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(255, 255, 255, 0.2) 75%,
    transparent 75%,
    transparent
  );
  background-size: 20px 20px;
  animation: stripeMove 1.5s linear infinite;
  opacity: 0.6;
}

@keyframes stripeMove {
  0% { background-position: 0 0; }
  100% { background-position: 20px 0; }
}

.progress-markers {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-weight: 500;
  padding: 0 0.25rem;
}

/* --------------------------------------------------------------------------
   11. Main Workspace Grid (Form + List)
   -------------------------------------------------------------------------- */
.workspace-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.sticky-card {
  position: sticky;
  top: 80px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border-glass);
}

.card-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.card-header-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-header-icon svg {
  width: 18px;
  height: 18px;
}

.card-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-main);
}

.card-caption {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Form Styles */
.grocery-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  position: relative;
}

.form-label {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.required-star {
  color: var(--accent-danger);
}

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

.input-icon {
  position: absolute;
  left: 0.75rem;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.input-currency-prefix {
  position: absolute;
  left: 0.85rem;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text-muted);
  pointer-events: none;
  font-size: 0.9rem;
}

.form-input {
  width: 100%;
  background: var(--surface-input);
  color: var(--text-main);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem 0.6rem 2.2rem;
  font-family: var(--font-body);
  font-size: 0.88rem;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:not(.has-prefix):not([type="text"]) {
  padding-left: 0.85rem;
}

.form-input.has-prefix {
  padding-left: 2rem;
}

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

.form-input.input-error {
  border-color: var(--accent-danger) !important;
  background-color: var(--accent-danger-light);
}

.form-error {
  font-size: 0.72rem;
  color: var(--accent-danger);
  font-weight: 500;
  display: none;
  animation: fadeIn 0.2s ease-out;
}

.form-error.show {
  display: block;
}

.form-row-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* Stepper Input */
.stepper-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  background: var(--surface-input);
  overflow: hidden;
}

.stepper-btn {
  background: var(--surface-subtle);
  border: none;
  width: 34px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.stepper-btn svg {
  width: 14px;
  height: 14px;
}

.stepper-btn:hover {
  background: var(--surface-hover);
  color: var(--primary);
}

.stepper-input {
  border: none !important;
  box-shadow: none !important;
  text-align: center;
  padding: 0.5rem 0.25rem !important;
  font-weight: 600;
  border-radius: 0 !important;
  width: 100%;
}

/* Hide native number spinners */
input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
  -webkit-appearance: none; 
  margin: 0; 
}
input[type=number] {
  -moz-appearance: textfield;
}

/* Live Calculation Preview Card */
.live-calc-card {
  background: linear-gradient(135deg, rgba(var(--primary-rgb), 0.08) 0%, rgba(59, 130, 246, 0.05) 100%);
  border: 1px dashed rgba(var(--primary-rgb), 0.3);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0.25rem 0;
}

.calc-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.calc-label svg {
  width: 16px;
  height: 16px;
  color: var(--primary);
}

.calc-result {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary-dark);
}
[data-theme="dark"] .calc-result {
  color: #34d399;
}

/* Category Spending Breakdown Widget */
.category-breakdown-card {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-glass);
}

.breakdown-title {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.breakdown-title svg {
  width: 14px;
  height: 14px;
  color: var(--primary);
}

.category-breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.empty-breakdown-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}

.cat-breakdown-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.cat-breakdown-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.76rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.cat-breakdown-bar-track {
  height: 6px;
  background: var(--surface-subtle);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.cat-breakdown-bar-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--primary);
  transition: width var(--transition-normal);
}

/* --------------------------------------------------------------------------
   12. Shopping List Column & Table
   -------------------------------------------------------------------------- */
.list-column .glass-card {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.list-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.toolbar-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.toolbar-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.badge-count {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-pill);
}

.search-wrap {
  position: relative;
  flex-grow: 1;
  max-width: 320px;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: var(--surface-input);
  color: var(--text-main);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-pill);
  padding: 0.5rem 2rem 0.5rem 2.2rem;
  font-size: 0.85rem;
  outline: none;
  transition: all var(--transition-fast);
}

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

.clear-search-btn {
  position: absolute;
  right: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.clear-search-btn svg {
  width: 14px;
  height: 14px;
}

.toolbar-secondary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Status Filter Segmented Tabs */
.filter-segmented {
  display: inline-flex;
  background: var(--surface-subtle);
  padding: 3px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-glass);
}

.filter-tab {
  background: transparent;
  border: none;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.filter-tab:hover {
  color: var(--text-main);
}

.filter-tab.active {
  background: var(--surface-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Horizontal Scrolling Category Pills */
.category-pills-bar {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.4rem;
  margin: 0 -0.25rem;
  scrollbar-width: thin;
}

.category-pills-bar::-webkit-scrollbar {
  height: 4px;
}
.category-pills-bar::-webkit-scrollbar-thumb {
  background: var(--border-glass);
  border-radius: 4px;
}

.cat-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--surface-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-glass);
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.cat-pill:hover {
  background: var(--surface-hover);
  color: var(--text-main);
}

.cat-pill.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.35);
}

.cat-pill-count {
  font-size: 0.7rem;
  background: rgba(0, 0, 0, 0.1);
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-pill);
}
.cat-pill.active .cat-pill-count {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

/* Bulk Action Bar */
.bulk-actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  padding: 0.4rem 0.5rem;
  background: var(--surface-subtle);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-glass);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.bulk-actions-left, .bulk-actions-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.bulk-info {
  font-weight: 600;
  color: var(--text-muted);
}

.bulk-divider {
  color: var(--border-glass);
}

.btn-text-action {
  background: none;
  border: none;
  color: var(--primary);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.78rem;
  cursor: pointer;
  transition: color var(--transition-fast);
  padding: 0.15rem 0.3rem;
  border-radius: 4px;
}

.btn-text-action:hover {
  text-decoration: underline;
}

.btn-text-action.danger-action {
  color: var(--accent-danger);
}

/* Items Table */
.items-table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
  background: var(--surface-input);
  min-height: 200px;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.items-table thead {
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border-glass);
}

.items-table th {
  padding: 0.75rem 1rem;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.th-check { width: 44px; text-align: center; }
.th-price, .th-total { text-align: right; }
.th-qty { text-align: center; width: 110px; }
.th-actions { text-align: right; width: 90px; }

.items-table tbody tr {
  border-bottom: 1px solid var(--border-glass);
  transition: background var(--transition-fast), opacity var(--transition-fast);
}

.items-table tbody tr:hover {
  background: var(--surface-subtle);
}

.items-table tbody tr.item-purchased {
  background: rgba(0, 0, 0, 0.015);
  opacity: 0.65;
}
.items-table tbody tr.item-purchased .item-name-text {
  text-decoration: line-through;
  color: var(--text-muted);
}

.items-table td {
  padding: 0.75rem 1rem;
  vertical-align: middle;
  font-size: 0.88rem;
}

/* Custom Checkbox */
.item-checkbox {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  cursor: pointer;
  accent-color: var(--primary);
}

/* Item Name & Category cell */
.item-cell {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.item-name-text {
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.2;
}

.item-unit-tag {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 0.35rem;
}

.item-cat-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-pill);
  width: fit-content;
}

/* Specific Category Badge Palettes */
.cat-produce { background: #dcfce7; color: #15803d; }
.cat-dairy { background: #e0f2fe; color: #0369a1; }
.cat-bakery { background: #fef3c7; color: #b45309; }
.cat-meat { background: #ffe4e6; color: #be123c; }
.cat-pantry { background: #fef9c3; color: #a16207; }
.cat-beverages { background: #e0e7ff; color: #4338ca; }
.cat-snacks { background: #fae8ff; color: #86198f; }
.cat-frozen { background: #cffafe; color: #0e7490; }
.cat-household { background: #f1f5f9; color: #475569; }
.cat-personal { background: #fce7f3; color: #9d174d; }
.cat-other { background: #f3f4f6; color: #4b5563; }

/* Inline Qty Adjuster */
.table-qty-control {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--surface-subtle);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-pill);
  padding: 0.15rem 0.4rem;
}

.table-qty-btn {
  background: none;
  border: none;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  border-radius: 50%;
  transition: all var(--transition-fast);
}

.table-qty-btn:hover {
  background: var(--surface-hover);
  color: var(--primary);
}

.table-qty-btn svg {
  width: 12px;
  height: 12px;
}

.table-qty-val {
  font-weight: 700;
  font-size: 0.82rem;
  min-width: 18px;
  text-align: center;
}

.table-price-val {
  font-family: var(--font-display);
  color: var(--text-secondary);
  text-align: right;
}

.table-total-val {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--text-main);
  text-align: right;
}

/* Row Action Buttons */
.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
}

.btn-action-icon {
  background: none;
  border: 1px solid transparent;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-action-icon svg {
  width: 15px;
  height: 15px;
}

.btn-action-icon:hover {
  background: var(--surface-hover);
  color: var(--primary);
  border-color: var(--border-glass);
}

.btn-action-icon.btn-delete:hover {
  background: var(--accent-danger-light);
  color: var(--accent-danger);
  border-color: var(--accent-danger-border);
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3.5rem 1.5rem;
  text-align: center;
}

.empty-icon-wrap {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--surface-subtle);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}

.empty-icon-wrap svg {
  width: 32px;
  height: 32px;
}

.empty-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.35rem;
}

.empty-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 360px;
  margin-bottom: 1.25rem;
}

/* Table Footer Summary */
.table-footer-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-glass);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.footer-total-box {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.footer-total-label {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text-secondary);
}

.footer-total-val {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--primary-dark);
}
[data-theme="dark"] .footer-total-val {
  color: #34d399;
}

/* --------------------------------------------------------------------------
   13. Modals & Dialogs
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--surface-modal);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
  transform: scale(0.95) translateY(10px);
  transition: transform var(--transition-normal);
}

.modal-card-sm {
  max-width: 380px;
}

.modal-overlay.open .modal-card {
  transform: scale(1) translateY(0);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-glass);
}

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.modal-icon-box {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-icon-box svg {
  width: 20px;
  height: 20px;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.modal-close-btn svg {
  width: 18px;
  height: 18px;
}

.modal-close-btn:hover {
  background: var(--surface-hover);
  color: var(--text-main);
}

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.modal-large-input {
  font-size: 1.4rem;
  font-weight: 700;
  font-family: var(--font-display);
  padding: 0.65rem 0.85rem 0.65rem 2.2rem;
}

.budget-presets-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.preset-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.presets-row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.btn-preset {
  background: var(--surface-subtle);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-preset:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}

.modal-footer {
  padding: 1rem 1.5rem;
  background: var(--surface-subtle);
  border-top: 1px solid var(--border-glass);
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
}

/* --------------------------------------------------------------------------
   14. Toast Notification Stack
   -------------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  pointer-events: none;
  max-width: 380px;
  width: 100%;
}

.toast-item {
  pointer-events: auto;
  background: var(--surface-modal);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.toast-item.toast-out {
  animation: toastOut 0.25s forwards;
}

.toast-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.toast-icon svg {
  width: 14px;
  height: 14px;
}

.toast-success .toast-icon { background: var(--primary-light); color: var(--primary); }
.toast-error .toast-icon { background: var(--accent-danger-light); color: var(--accent-danger); }
.toast-warning .toast-icon { background: var(--accent-amber-light); color: var(--accent-amber); }
.toast-info .toast-icon { background: var(--secondary-light); color: var(--secondary); }

.toast-content {
  flex-grow: 1;
  font-size: 0.85rem;
  color: var(--text-main);
  line-height: 1.3;
}

.toast-undo-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0.2rem;
}

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

@keyframes toastOut {
  from {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
  to {
    transform: translateY(10px) scale(0.95);
    opacity: 0;
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --------------------------------------------------------------------------
   15. Responsive Media Queries
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .overview-bento {
    grid-template-columns: repeat(2, 1fr);
  }

  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .sticky-card {
    position: static;
  }
}

@media (max-width: 640px) {
  .app-header {
    padding: 0.75rem 1rem;
  }

  .header-container {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .btn-text {
    display: none;
  }

  .overview-bento {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .bento-value {
    font-size: 1.5rem;
  }

  .app-main {
    padding: 1rem 1rem 3rem;
    gap: 1rem;
  }

  .glass-card {
    padding: 1.15rem;
  }

  .toolbar-main {
    flex-direction: column;
    align-items: stretch;
  }

  .search-wrap {
    max-width: 100%;
  }

  .toolbar-secondary {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-segmented {
    width: 100%;
    justify-content: space-around;
  }

  .toast-container {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    max-width: none;
  }
}

/* --------------------------------------------------------------------------
   16. Print Stylesheet for Physical Receipt / Shopping List
   -------------------------------------------------------------------------- */
.print-only {
  display: none;
}

@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .app-header,
  .overview-bento,
  .progress-section,
  .form-column,
  .list-toolbar,
  .category-pills-bar,
  .bulk-actions-bar,
  .row-actions,
  .th-actions,
  .toast-container,
  .modal-overlay,
  .bg-glow {
    display: none !important;
  }

  .print-only {
    display: block !important;
    padding: 20px;
    font-family: monospace;
  }

  .receipt-card {
    max-width: 480px;
    margin: 0 auto;
    border: 1px dashed #000000;
    padding: 20px;
  }

  .receipt-header {
    text-align: center;
    margin-bottom: 15px;
  }

  .receipt-header h2 {
    font-size: 1.25rem;
    margin-bottom: 4px;
  }

  .receipt-divider {
    border-top: 1px dashed #000000;
    margin: 12px 0;
  }

  .receipt-budget-summary {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
  }

  .receipt-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
  }

  .receipt-table th, .receipt-table td {
    padding: 4px 6px;
    text-align: left;
  }

  .receipt-table th:last-child, .receipt-table td:last-child {
    text-align: right;
  }

  .receipt-footer {
    text-align: center;
    margin-top: 15px;
    font-size: 0.8rem;
  }
}
