/* Base Layout & CSS Variables */
:root {
  --bg-color: #f8f9fc;
  --card-bg: #ffffff;
  --text-main: #111827;
  --text-muted: #9ca3af;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --disabled: #e5e7eb;
  --danger: #ef4444;
  --toast-bg: #111827;
  --toast-text: #ffffff;
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Nunito', sans-serif;
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

button, a, input, select, .category-btn {
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

#app {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  padding-bottom: 120px; /* space for toast */
}

/* Header */
.header {
  padding: 24px 20px 16px;
  text-align: center;
  position: relative;
}

.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 8px;
}

.nav-btn {
  background: white;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  transition: transform 0.1s;
}
.nav-btn:active {
  transform: scale(0.95);
}

#current-month {
  font-size: 12px;
  font-weight: 800;
  color: #818cf8; /* slightly purplish blue */
  letter-spacing: 1px;
}

.total-spent {
  margin-top: 12px;
}

#total-amount {
  text-align: center;
  font-size: 48px;
  font-weight: 900;
  color: #1e1b4b; /* deep dark blue */
  letter-spacing: -1px;
}

#total-amount .currency-symbol {
  font-size: 36px;
  margin-right: 2px;
  position: relative;
  top: -4px;
}

#total-amount .cents {
  font-size: 32px;
  color: var(--primary);
}

.subtitle {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 1px;
  margin-top: 4px;
}

/* Top Notification */
.notification {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translate(-50%, -20px);
  opacity: 0;
  background: white;
  padding: 8px 16px;
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  white-space: nowrap;
  z-index: 9999;
  transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}
.notification.active {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.notification i {
  color: var(--primary);
  font-size: 20px;
}

.notification-text {
  font-size: 13px;
  color: var(--text-main);
}

/* Quick Entry Card */
.quick-entry-card {
  background: var(--card-bg);
  border-radius: var(--radius-xl);
  margin: 0 16px;
  padding: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.04);
  position: relative;
  overflow: hidden;
}

.section-title {
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.amount-display {
  text-align: center;
  margin-bottom: 16px;
  position: relative;
}

.amount-display .currency-symbol {
  font-size: 42px;
  font-weight: 700;
  color: #a5b4fc;
  margin-right: 4px;
  position: relative;
  top: -5px;
}

#draft-amount {
  font-size: 56px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

#reset-amount {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: var(--disabled);
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
}

/* Quick Add Grid */
.quick-add-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}

.add-btn {
  background: #f1f5f9;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}

.add-btn:active {
  transform: scale(0.96);
  background: #e2e8f0;
}

.add-btn .val {
  font-size: 24px;
  font-weight: 800;
  color: #0f172a;
}

.add-btn .lbl {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-top: 4px;
}

/* Categories Section */
.section-subtitle {
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.category-btn {
  background: white;
  border: 1px dashed var(--disabled);
  border-radius: var(--radius-lg);
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--disabled);
  cursor: pointer;
  transition: all 0.2s;
}

.category-btn i {
  font-size: 20px;
}

.category-btn:not([disabled]) {
  border: 1px solid var(--disabled);
  color: var(--text-main);
  background: white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.category-btn:not([disabled]):active {
  transform: scale(0.95);
  background: #f8fafc;
}

.new-category-btn {
  width: 100%;
  background: #f8fafc;
  border: none;
  border-radius: var(--radius-lg);
  padding: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}

/* Save Overlay */
.save-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  opacity: 0;
  transform: scale(0.95);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.save-overlay.active {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.save-overlay .check-circle {
  width: 80px;
  height: 80px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 40px;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.3);
}

.save-overlay h2 {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 4px;
}

.save-overlay p {
  font-size: 14px;
  color: var(--text-muted);
}

/* Recent Section */
.recent-section {
  margin-top: 32px;
  padding: 0 16px 24px;
}

.recent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 8px;
  margin-bottom: 16px;
}

.recent-header h3 {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 1px;
}

.recent-item {
  background: white;
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.02);
}

.item-icon {
  width: 40px;
  height: 40px;
  background: #f1f5f9;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 20px;
}

.item-details {
  flex: 1;
}

.item-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 2px;
}

.item-time {
  font-size: 13px;
  color: var(--text-muted);
}

.item-amount {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-main);
}

/* Bottom Toast */
.bottom-toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  width: calc(100% - 32px);
  max-width: 448px;
  background: var(--toast-bg);
  border-radius: var(--radius-xl);
  padding: 16px 20px;
  color: var(--toast-text);
  box-shadow: 0 12px 32px rgba(0,0,0,0.15);
  z-index: 100;
  transform: translate(-50%, 150%);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.bottom-toast.active {
  transform: translate(-50%, 0);
}

.toast-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.toast-icon-circle {
  width: 28px;
  height: 28px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.toast-title {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
}

.toast-body {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255,255,255,0.05);
  padding: 12px 16px;
  border-radius: var(--radius-md);
}

.toast-info {
  font-size: 14px;
  font-weight: 600;
}

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

.toast-actions button {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
}

.toast-actions .divider {
  color: rgba(255,255,255,0.2);
}

.toast-progress {
  height: 3px;
  background: var(--primary);
  border-radius: 2px;
  margin-top: 12px;
  width: 100%;
  opacity: 0.8;
}

@keyframes shrinkProgress {
  from { width: 100%; }
  to { width: 0%; }
}

/* Edit Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.modal-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 90%;
  max-width: 320px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
  transform: translateY(20px);
  transition: transform 0.2s ease;
}
.modal-overlay.active .modal-card {
  transform: translateY(0);
}
.modal-title {
  font-size: 16px; font-weight: 800; margin-bottom: 16px; text-align: center;
}
.input-group { margin-bottom: 16px; }
.input-group label { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 4px; }
.amount-input-wrapper { display: flex; align-items: center; background: var(--bg-color); border-radius: var(--radius-sm); padding: 0 12px; }
.amount-input-wrapper span { font-weight: 800; color: var(--text-main); }
.input-group input, .input-group select { width: 100%; border: none; background: transparent; padding: 12px; font-size: 16px; font-family: 'Nunito', sans-serif; font-weight: 700; color: var(--text-main); outline: none; }
.input-group select#edit-category { 
  background: var(--bg-color) url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2220%22%20height%3D%2220%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20256%20256%22%3E%3Cpath%20fill%3D%22%239ca3af%22%20d%3D%22M213.66%2C101.66l-80%2C80a8%2C8%2C0%2C0%2C1-11.32%2C0l-80-80A8%2C8%2C0%2C0%2C1%2C53.66%2C90.34L128%2C164.69l74.34-74.35a8%2C8%2C0%2C0%2C1%2C11.32%2C11.32Z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E") no-repeat right 12px center;
  background-size: 16px;
  border-radius: var(--radius-sm); 
  appearance: none; 
  -webkit-appearance: none; 
  cursor: pointer; 
  padding-right: 36px;
}
.modal-actions { display: flex; gap: 12px; margin-bottom: 16px; }
.modal-actions button { flex: 1; padding: 12px; border-radius: var(--radius-sm); border: none; font-size: 14px; font-weight: 800; cursor: pointer; transition: transform 0.1s;}
.modal-actions button:active { transform: scale(0.96); }
.btn-cancel { background: var(--disabled); color: var(--text-main); }
.btn-save { background: var(--primary); color: white; }
.btn-delete { width: 100%; padding: 12px; background: transparent; border: 1px dashed var(--danger); color: var(--danger); border-radius: var(--radius-sm); font-size: 14px; font-weight: 700; cursor: pointer; transition: transform 0.1s;}
.btn-delete:active { transform: scale(0.96); }
