/* ============================================
   TRACKIFY - Personal Finance Tracker
   Modern, Animated, Responsive CSS
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
  /* Colors - Light Theme */
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border-color: #e5e7eb;
  --accent: #6C63FF;
  --accent-light: #8b83ff;
  --accent-dark: #5a52d5;
  --income-color: #10b981;
  --income-bg: rgba(16, 185, 129, 0.1);
  --expense-color: #ef4444;
  --expense-bg: rgba(239, 68, 68, 0.1);
  --balance-color: #6C63FF;
  --balance-bg: rgba(108, 99, 255, 0.08);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.1);
  --shadow-xl: 0 20px 50px rgba(0,0,0,0.12);
  --gradient-primary: linear-gradient(135deg, #6C63FF 0%, #48C6EF 100%);
  --gradient-income: linear-gradient(135deg, #10b981 0%, #34d399 100%);
  --gradient-expense: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #1e1e35;
  --text-primary: #e8e8f0;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --border-color: #2d2d4a;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.35);
  --shadow-xl: 0 20px 50px rgba(0,0,0,0.4);
  --income-bg: rgba(16, 185, 129, 0.15);
  --expense-bg: rgba(239, 68, 68, 0.15);
  --balance-bg: rgba(108, 99, 255, 0.15);
}

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

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-color var(--transition-smooth), color var(--transition-smooth);
}

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
}

/* --- Animated Background --- */
.bg-gradient {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.bg-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.25;
  animation: blobFloat 20s ease-in-out infinite;
}

[data-theme="dark"] .bg-blob {
  opacity: 0.12;
}

.bg-blob-1 {
  width: 400px;
  height: 400px;
  background: #6C63FF;
  top: -100px;
  right: -100px;
  animation-delay: 0s;
}

.bg-blob-2 {
  width: 350px;
  height: 350px;
  background: #48C6EF;
  bottom: -80px;
  left: -80px;
  animation-delay: -7s;
}

.bg-blob-3 {
  width: 300px;
  height: 300px;
  background: #10b981;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -14s;
}

@keyframes blobFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(30px, -40px) scale(1.05); }
  50% { transform: translate(-20px, 20px) scale(0.95); }
  75% { transform: translate(15px, 30px) scale(1.02); }
}

/* --- Header --- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
  transition: background var(--transition-smooth), border-color var(--transition-smooth);
  animation: slideDown 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

[data-theme="dark"] .header {
  background: rgba(15, 15, 26, 0.8);
}

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  display: flex;
  animation: logoRotate 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s both;
}

@keyframes logoRotate {
  from { transform: rotate(-180deg) scale(0); opacity: 0; }
  to { transform: rotate(0) scale(1); opacity: 1; }
}

.logo-text {
  font-size: 1.4rem;
  font-weight: 800;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: fadeInRight 0.6s 0.4s both;
}

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

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* --- Theme Toggle --- */
.theme-toggle {
  position: relative;
  width: 44px;
  height: 44px;
  border: none;
  background: var(--bg-card);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
  overflow: hidden;
}

.theme-toggle:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-md);
}

.theme-toggle:active {
  transform: scale(0.95);
}

.icon-sun, .icon-moon {
  position: absolute;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-theme="light"] .icon-moon {
  transform: rotate(90deg) scale(0);
  opacity: 0;
}

[data-theme="light"] .icon-sun {
  transform: rotate(0) scale(1);
  opacity: 1;
}

[data-theme="dark"] .icon-sun {
  transform: rotate(-90deg) scale(0);
  opacity: 0;
}

[data-theme="dark"] .icon-moon {
  transform: rotate(0) scale(1);
  opacity: 1;
}

/* --- Main --- */
.main {
  padding: 32px 20px 60px;
}

/* --- Section Title --- */
.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text-primary);
}

/* --- Summary Cards --- */
.summary-section {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 36px;
}

.summary-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  transition: all var(--transition-normal);
  position: relative;
  overflow: hidden;
  cursor: default;
}

.summary-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  transition: height var(--transition-normal);
}

.summary-card--balance::before { background: var(--gradient-primary); }
.summary-card--income::before { background: var(--gradient-income); }
.summary-card--expense::before { background: var(--gradient-expense); }

.summary-card:hover {
  transform: translateY(-6px) scale(1.02);
  box-shadow: var(--shadow-xl);
}

.summary-card:hover::before {
  height: 6px;
}

.summary-card__icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  transition: transform var(--transition-normal);
}

.summary-card:hover .summary-card__icon {
  transform: scale(1.1) rotate(-5deg);
}

.summary-card--balance .summary-card__icon { background: var(--balance-bg); color: var(--balance-color); }
.summary-card--income .summary-card__icon { background: var(--income-bg); color: var(--income-color); }
.summary-card--expense .summary-card__icon { background: var(--expense-bg); color: var(--expense-color); }

.summary-card__label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.summary-card__value {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.2;
}

.summary-card--balance .summary-card__value { color: var(--balance-color); }
.summary-card--income .summary-card__value { color: var(--income-color); }
.summary-card--expense .summary-card__value { color: var(--expense-color); }

/* --- Form Section --- */
.form-section {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 28px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  margin-bottom: 36px;
  transition: all var(--transition-normal);
}

.form-section:hover {
  box-shadow: var(--shadow-lg);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.form-row:last-child {
  margin-bottom: 0;
}

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

.form-group--btn {
  justify-content: flex-end;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  transition: color var(--transition-fast);
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.95rem;
  transition: all var(--transition-fast);
  outline: none;
}

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

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(108, 99, 255, 0.15);
  background: var(--bg-secondary);
}

.form-input:focus ~ .form-label,
.form-input:focus + .form-label {
  color: var(--accent);
}

.form-input.input-error {
  border-color: var(--expense-color);
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.1);
  animation: inputShake 0.4s ease-in-out;
}

@keyframes inputShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.form-error {
  font-size: 0.78rem;
  color: var(--expense-color);
  margin-top: 4px;
  min-height: 18px;
  opacity: 0;
  transform: translateY(-4px);
  transition: all var(--transition-fast);
}

.form-error.visible {
  opacity: 1;
  transform: translateY(0);
}

.form-select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

/* --- Button --- */
.btn {
  position: relative;
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  transition: all var(--transition-normal);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background: var(--gradient-primary);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(108, 99, 255, 0.35);
  min-height: 48px;
  width: 100%;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(108, 99, 255, 0.45);
}

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

/* Button Ripple Effect */
.btn-ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  transform: scale(0);
  pointer-events: none;
  animation: none;
}

.btn-ripple.active {
  animation: rippleEffect 0.6s ease-out forwards;
}

@keyframes rippleEffect {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

/* --- Charts Section --- */
.charts-section {
  margin-bottom: 36px;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.chart-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  transition: all var(--transition-normal);
  position: relative;
}

.chart-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.chart-card__title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-secondary);
}

.chart-wrapper {
  position: relative;
  width: 100%;
  max-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-wrapper canvas {
  max-height: 260px;
}

.chart-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 20px 0;
}

/* --- Transaction History --- */
.history-section {
  margin-bottom: 36px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.history-header .section-title {
  margin-bottom: 0;
}

.filter-group {
  display: flex;
  gap: 10px;
  align-items: center;
}

.filter-select {
  padding: 8px 14px;
  font-size: 0.85rem;
  min-width: 140px;
}

.transaction-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Transaction Item */
.transaction-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  transition: all var(--transition-normal);
  animation: txnSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
  position: relative;
  overflow: hidden;
}

.transaction-item::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: 4px 0 0 4px;
}

.transaction-item.income::after { background: var(--income-color); }
.transaction-item.expense::after { background: var(--expense-color); }

.transaction-item:hover {
  transform: translateX(4px);
  box-shadow: var(--shadow-md);
}

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

.transaction-item.removing {
  animation: txnSlideOut 0.4s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes txnSlideOut {
  to {
    opacity: 0;
    transform: translateX(60px) scale(0.9);
    max-height: 0;
    padding: 0 20px;
    margin: 0;
    border: none;
  }
}

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

.transaction-item:hover .txn-icon {
  transform: scale(1.15) rotate(-8deg);
}

.txn-icon.income { background: var(--income-bg); }
.txn-icon.expense { background: var(--expense-bg); }

.txn-details {
  flex: 1;
  min-width: 0;
}

.txn-note {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.txn-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.txn-category-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.txn-category-badge.income {
  background: var(--income-bg);
  color: var(--income-color);
}

.txn-category-badge.expense {
  background: var(--expense-bg);
  color: var(--expense-color);
}

.txn-amount {
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
}

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

.txn-delete {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.txn-delete:hover {
  background: var(--expense-bg);
  color: var(--expense-color);
  transform: scale(1.15);
}

.txn-delete:active {
  transform: scale(0.9);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.empty-icon {
  opacity: 0.4;
  animation: emptyBounce 2s ease-in-out infinite;
}

@keyframes emptyBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* --- Footer --- */
.footer {
  text-align: center;
  padding: 24px 20px;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border-color);
  transition: border-color var(--transition-smooth);
}

/* --- Toast Notifications --- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  pointer-events: auto;
  animation: toastIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
  max-width: 340px;
}

.toast.removing {
  animation: toastOut 0.3s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

.toast.toast-success { border-left: 4px solid var(--income-color); }
.toast.toast-error { border-left: 4px solid var(--expense-color); }
.toast.toast-info { border-left: 4px solid var(--accent); }

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(100px) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateX(100px) scale(0.8);
  }
}

/* --- Scroll Reveal --- */
.reveal-on-scroll {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.reveal-on-scroll.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
  .summary-section {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .summary-card {
    padding: 18px;
  }

  .summary-card__value {
    font-size: 1.4rem;
  }

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

  .charts-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .form-section {
    padding: 20px;
  }

  .history-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .filter-group {
    width: 100%;
    flex-direction: column;
  }

  .filter-select {
    width: 100%;
    min-width: unset;
  }

  .main {
    padding: 20px 16px 48px;
  }

  .transaction-item {
    padding: 14px 16px;
    gap: 10px;
  }

  .txn-icon {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }

  .txn-note {
    font-size: 0.88rem;
  }

  .txn-amount {
    font-size: 0.95rem;
  }

  .toast-container {
    bottom: 16px;
    right: 16px;
    left: 16px;
  }

  .toast {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .header-inner {
    height: 56px;
  }

  .logo-text {
    font-size: 1.2rem;
  }

  .summary-card__label {
    font-size: 0.78rem;
  }

  .summary-card__value {
    font-size: 1.25rem;
  }

  .section-title {
    font-size: 1.1rem;
  }
}

/* --- Utility Classes --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* --- Loading / Page Transition --- */
.page-loading {
  opacity: 0;
  animation: pageLoad 0.8s 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

/* --- Focus visible for accessibility --- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Scrollbar styling --- */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}
