/* ==========================================================================
   Expense & Budget Visualizer — styles.css  (Premium Dashboard Redesign)
   Font: Inter 400/500/600/700/800 via Google Fonts
   ========================================================================== */

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

/* ─── CSS VARIABLES — LIGHT THEME ────────────────────────────────────────── */
:root {
  /* Brand / accent */
  --accent:          #6c63ff;
  --accent-light:    #a78bfa;
  --accent-grad:     linear-gradient(135deg, #6c63ff 0%, #a78bfa 100%);

  /* Page background */
  --bg-page-from:    #e0e7ff;
  --bg-page-via:     #f0fdf4;
  --bg-page-to:      #fdf4ff;

  /* Glassmorphism surfaces */
  --glass-bg:        rgba(255, 255, 255, 0.72);
  --glass-border:    rgba(255, 255, 255, 0.60);
  --glass-shadow:    0 8px 32px rgba(108, 99, 255, 0.10),
                     0 2px 8px rgba(0, 0, 0, 0.06);
  --glass-shadow-lg: 0 20px 60px rgba(108, 99, 255, 0.15),
                     0 4px 20px rgba(0, 0, 0, 0.08);

  /* Text */
  --text-primary:    #1a1a2e;
  --text-secondary:  #4a4a6a;
  --text-muted:      #7c7ca0;
  --text-heading:    #1a1a2e;

  /* Borders & inputs */
  --border:          rgba(108, 99, 255, 0.18);
  --input-bg:        rgba(255, 255, 255, 0.90);
  --input-border:    rgba(108, 99, 255, 0.28);

  /* Status */
  --color-positive:  #059669;
  --color-negative:  #dc2626;
  --color-warning-bg:#fffbeb;
  --color-warning-bd:#f59e0b;

  /* Shared */
  --radius-card:  16px;
  --radius-input: 12px;
  --radius-btn:   12px;
  --radius-badge: 20px;
  --transition:   0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── CSS VARIABLES — DARK THEME ─────────────────────────────────────────── */
[data-theme="dark"] {
  --bg-page-from:    #0f0e1a;
  --bg-page-via:     #13111f;
  --bg-page-to:      #16132a;

  --glass-bg:        rgba(30, 27, 50, 0.82);
  --glass-border:    rgba(108, 99, 255, 0.22);
  --glass-shadow:    0 8px 32px rgba(0, 0, 0, 0.40),
                     0 2px 8px rgba(0, 0, 0, 0.30);
  --glass-shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.55),
                     0 4px 20px rgba(108, 99, 255, 0.20);

  --text-primary:    #e8e6ff;
  --text-secondary:  #b0acd8;
  --text-muted:      #7b78a8;
  --text-heading:    #f0eeff;

  --border:          rgba(108, 99, 255, 0.28);
  --input-bg:        rgba(20, 18, 40, 0.90);
  --input-border:    rgba(108, 99, 255, 0.40);

  --color-warning-bg:#2d1f00;
  --color-warning-bd:#f59e0b;
}

/* ─── BASE ───────────────────────────────────────────────────────────────── */
html {
  font-size: 16px;
  scroll-behavior: smooth;
}
html { color-scheme: light; }
[data-theme="dark"] html { color-scheme: dark; }

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-primary);
  min-height: 100vh;
  transition: background 0.3s ease;

  /* Gradient background — light theme (hardcoded so dark-mode override works) */
  background:
    radial-gradient(circle at 20% 20%, rgba(108,99,255,0.18) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(167,139,250,0.18) 0%, transparent 50%),
    radial-gradient(circle at 50% 10%, rgba(52,211,153,0.12) 0%, transparent 40%),
    linear-gradient(135deg, #e0e7ff 0%, #f0fdf4 50%, #fdf4ff 100%);
  background-attachment: fixed;
}

[data-theme="dark"] body {
  background:
    radial-gradient(circle at 20% 20%, rgba(108,99,255,0.22) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(167,139,250,0.15) 0%, transparent 50%),
    radial-gradient(circle at 50% 10%, rgba(52,211,153,0.08) 0%, transparent 40%),
    linear-gradient(135deg, #0f0e1a 0%, #13111f 50%, #16132a 100%);
  background-attachment: fixed;
}

/* ─── UTILITY ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

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

/* ─── HEADER ─────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: var(--glass-bg);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 2px 16px rgba(108, 99, 255, 0.08);
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 {
  flex: 1;
  text-align: center;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  padding: 0;
}

/* ─── THEME TOGGLE ───────────────────────────────────────────────────────── */
#theme-toggle {
  flex: 0 0 auto;
  min-height: 44px;
  min-width: 44px;
  padding: 0 0.625rem;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-btn);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: background var(--transition), transform var(--transition),
              box-shadow var(--transition);
  box-shadow: var(--glass-shadow);
}

#theme-toggle:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: var(--glass-shadow-lg);
}

#theme-toggle:active { transform: scale(0.97); }

#theme-toggle:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.45);
}

/* ─── APP LAYOUT ─────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.5rem 1rem;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

@media (min-width: 768px) {
  .app-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "balance  balance"
      "form     limit"
      "list     list"
      "chart    chart";
    gap: 1.5rem;
    padding: 2rem 1.5rem;
    align-items: start;
  }

  #balance-section        { grid-area: balance; }
  #form-section           { grid-area: form;    }
  #spending-limit-section { grid-area: limit;   }
  #list-section           { grid-area: list;    }
  #chart-section          { grid-area: chart;   }
}

@media (min-width: 1024px) {
  .app-layout {
    padding: 2rem 2.5rem;
    gap: 1.75rem;
  }
}

/* ─── CARD (GLASSMORPHISM) ───────────────────────────────────────────────── */
section {
  background: var(--glass-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-card);
  padding: 1.5rem;
  box-shadow: var(--glass-shadow);
  transition: box-shadow var(--transition), transform var(--transition);
  animation: card-in 0.35s ease-out both;
}

section:hover {
  box-shadow: var(--glass-shadow-lg);
  transform: translateY(-2px);
}

section h2 {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

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

/* ─── BALANCE SECTION ────────────────────────────────────────────────────── */
#balance-section {
  text-align: center;
  background: var(--accent-grad);
  border: none;
  position: relative;
  overflow: hidden;
}

#balance-section::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 30% 50%, rgba(255,255,255,0.18) 0%, transparent 60%),
              radial-gradient(ellipse at 80% 20%, rgba(255,255,255,0.10) 0%, transparent 50%);
  pointer-events: none;
}

#balance-section h2 {
  color: rgba(255,255,255,0.75);
  font-size: 0.6875rem;
}

#balance-display {
  font-size: clamp(2.25rem, 5vw, 3.25rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  color: #ffffff;
  line-height: 1.1;
  padding: 0.5rem 0 0.25rem;
  text-shadow: 0 2px 12px rgba(0,0,0,0.15);
  position: relative;
  z-index: 1;
}

.balance--negative {
  color: #fca5a5 !important;
}

/* ─── FORM SECTION ───────────────────────────────────────────────────────── */
#form-section form {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.form-group label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

input[type="text"],
input[type="number"],
select {
  min-height: 48px;
  width: 100%;
  padding: 0.625rem 1rem;
  font-size: 0.9375rem;
  font-family: inherit;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--input-bg);
  border: 1.5px solid var(--input-border);
  border-radius: var(--radius-input);
  transition: border-color var(--transition), box-shadow var(--transition),
              background var(--transition);
  appearance: auto;
  outline: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  border-color: var(--accent);
  background: var(--input-bg);
  box-shadow: 0 0 0 4px rgba(108, 99, 255, 0.18);
}

input::placeholder { color: var(--text-muted); opacity: 0.75; }

.error-msg,
[id^="error-"] {
  font-size: 0.78125rem;
  font-weight: 500;
  color: #ef4444;
  line-height: 1.3;
  padding-left: 0.25rem;
}

.error-msg:empty,
[id^="error-"]:empty { display: none; }

/* Submit button */
#add-btn {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 1.5rem;
  font-size: 0.9375rem;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-btn);
  background: var(--accent-grad);
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(108, 99, 255, 0.38);
  transition: transform var(--transition), box-shadow var(--transition),
              filter var(--transition);
  margin-top: 0.25rem;
  position: relative;
  overflow: hidden;
}

#add-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0);
  transition: background var(--transition);
}

#add-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(108, 99, 255, 0.50);
  filter: brightness(1.06);
}

#add-btn:hover::after { background: rgba(255,255,255,0.08); }

#add-btn:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 10px rgba(108, 99, 255, 0.30);
}

#add-btn:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 4px rgba(108, 99, 255, 0.45);
}

/* General button base (covers delete-btn, theme-toggle base sizes) */
button {
  min-height: 44px;
  min-width: 44px;
  cursor: pointer;
}

/* ─── SPENDING LIMIT ─────────────────────────────────────────────────────── */
.field-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ─── TRANSACTION LIST ───────────────────────────────────────────────────── */
.list-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

#sort-order {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-family: inherit;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--input-bg);
  border: 1.5px solid var(--input-border);
  border-radius: var(--radius-input);
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  appearance: auto;
}

#sort-order:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(108, 99, 255, 0.18);
}

/* Scrollable list container */
#transaction-list {
  overflow-y: auto;
  max-height: 44vh;
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  /* Custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: rgba(108,99,255,0.3) transparent;
}

#transaction-list::-webkit-scrollbar { width: 5px; }
#transaction-list::-webkit-scrollbar-track { background: transparent; }
#transaction-list::-webkit-scrollbar-thumb {
  background: rgba(108,99,255,0.30);
  border-radius: 99px;
}

/* Individual transaction card */
#transaction-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.9375rem;
  min-height: 56px;
  transition: background var(--transition), box-shadow var(--transition),
              transform var(--transition);
  animation: row-in 0.2s ease-out both;
}

#transaction-list li:hover {
  background: rgba(108, 99, 255, 0.06);
  box-shadow: 0 4px 16px rgba(108, 99, 255, 0.10);
  transform: translateX(3px);
}

@keyframes row-in {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0);    }
}

/* Over-limit row */
.over-limit {
  background: var(--color-warning-bg) !important;
  border-color: var(--color-warning-bd) !important;
  border-left: 3px solid var(--color-warning-bd) !important;
}

.over-limit:hover {
  background: var(--color-warning-bg) !important;
  box-shadow: 0 4px 16px rgba(245, 158, 11, 0.20) !important;
}

.over-limit-icon {
  color: #d97706;
  font-size: 0.875rem;
  flex: 0 0 auto;
  animation: pulse-warn 1.8s ease-in-out infinite;
}

[data-theme="dark"] .over-limit-icon { color: #fbbf24; }

@keyframes pulse-warn {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.55; }
}

/* Transaction name */
.transaction-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-primary);
}

/* Transaction amount */
.transaction-amount {
  flex: 0 0 auto;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.9375rem;
  color: var(--text-secondary);
}

/* Category badges */
.transaction-category {
  flex: 0 0 auto;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 3px 10px;
  border-radius: var(--radius-badge);
  white-space: nowrap;
  text-transform: uppercase;
}

/* Food = Green */
.transaction-category[data-category="Food"] {
  background: #dcfce7;
  color: #15803d;
}

[data-theme="dark"] .transaction-category[data-category="Food"] {
  background: rgba(21, 128, 61, 0.25);
  color: #4ade80;
}

/* Transport = Blue */
.transaction-category[data-category="Transport"] {
  background: #dbeafe;
  color: #1d4ed8;
}

[data-theme="dark"] .transaction-category[data-category="Transport"] {
  background: rgba(29, 78, 216, 0.25);
  color: #60a5fa;
}

/* Fun = Orange */
.transaction-category[data-category="Fun"] {
  background: #fff7ed;
  color: #c2410c;
}

[data-theme="dark"] .transaction-category[data-category="Fun"] {
  background: rgba(194, 65, 12, 0.22);
  color: #fb923c;
}

/* Delete button */
.delete-btn {
  flex: 0 0 auto;
  min-height: 36px;
  min-width: 36px;
  padding: 0 0.625rem;
  background: transparent;
  border: 1.5px solid #f87171;
  border-radius: 10px;
  color: #ef4444;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: 0.02em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition),
              transform var(--transition), box-shadow var(--transition);
}

.delete-btn:hover {
  background: #ef4444;
  border-color: #ef4444;
  color: #ffffff;
  transform: scale(1.08);
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.40);
}

.delete-btn:active { transform: scale(0.95); }

.delete-btn:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.40);
}

/* Empty state */
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.9375rem;
  font-weight: 500;
  text-align: center;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: transparent;
  min-height: unset !important;
}

/* ─── CHART SECTION ──────────────────────────────────────────────────────── */
#chart-container {
  position: relative;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

#chart-canvas {
  width: 100% !important;
  max-height: 340px;
  display: block;
  filter: drop-shadow(0 4px 12px rgba(108, 99, 255, 0.12));
}

#chart-placeholder {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9375rem;
  font-weight: 500;
  padding: 3rem 1rem;
  border: 2px dashed var(--border);
  border-radius: 12px;
}

#chart-error {
  text-align: center;
  color: #ef4444;
  font-size: 0.9375rem;
  font-weight: 500;
  padding: 1.5rem;
}

/* ─── TOAST NOTIFICATIONS ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  min-width: 280px;
  max-width: min(90vw, 420px);
  padding: 1rem 1.25rem;
  border-radius: 14px;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.4;
  color: #ffffff;
  box-shadow: 0 8px 32px rgba(0,0,0,0.22);
  animation: toast-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  word-break: break-word;
  backdrop-filter: blur(8px);
}

.toast--warning {
  background: linear-gradient(135deg, #f97316 0%, #fb923c 100%);
}

.toast--error {
  background: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
}

.toast--info {
  background: linear-gradient(135deg, #6c63ff 0%, #a78bfa 100%);
  color: #ffffff;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(1.5rem) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ─── RESPONSIVE ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .toast {
    right: 0.75rem;
    left: 0.75rem;
    min-width: unset;
    max-width: unset;
    bottom: 1rem;
  }

  header { padding: 0.875rem 1rem; }
  header h1 { font-size: 1.125rem; }

  .app-layout { padding: 1rem 0.75rem; gap: 1rem; }

  section { padding: 1.25rem 1rem; }

  #balance-display { font-size: 2.25rem; }
}

@media (max-width: 320px) {
  .app-layout { padding: 0.75rem 0.5rem; }
  header h1   { font-size: 1rem; }
  #balance-display { font-size: 1.875rem; }
}

/* Tablet breakpoint card animation delays */
@media (min-width: 768px) {
  #balance-section        { animation-delay: 0.00s; }
  #form-section           { animation-delay: 0.07s; }
  #spending-limit-section { animation-delay: 0.12s; }
  #list-section           { animation-delay: 0.17s; }
  #chart-section          { animation-delay: 0.22s; }
}
