* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #667eea;
  --primary-dark: #5a67d8;
  --success: #48bb78;
  --danger: #f56565;
  --warning: #ed8936;
  --gray-100: #f7fafc;
  --gray-200: #edf2f7;
  --gray-300: #e2e8f0;
  --gray-600: #718096;
  --gray-800: #2d3748;
  --bg: var(--gray-100);
  --card-bg: white;
  --text: var(--gray-800);
  --text-secondary: var(--gray-600);
}

/* Dark Mode */
body.dark-mode {
  --bg: #1a202c;
  --card-bg: #2d3748;
  --text: #f7fafc;
  --text-secondary: #a0aec0;
  --gray-100: #2d3748;
  --gray-200: #4a5568;
  --gray-300: #4a5568;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  min-height: 100vh;
  color: var(--text);
  transition: background 0.3s, color 0.3s;
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 100px;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  margin-bottom: 16px;
}

header h1 {
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), #764ba2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: var(--card-bg);
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: var(--gray-200);
}

.nav-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 8px;
  transition: background 0.2s;
}

.nav-link:hover {
  background: var(--gray-200);
}

/* Budget Bar */
.budget-bar {
  background: var(--card-bg);
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 16px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.budget-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-weight: 600;
}

.budget-info span:first-child {
  font-size: 20px;
}

.budget-track {
  height: 8px;
  background: var(--gray-200);
  border-radius: 4px;
  overflow: hidden;
}

.budget-progress {
  height: 100%;
  background: var(--success);
  border-radius: 4px;
  transition: width 0.3s, background 0.3s;
}

.budget-progress.warning {
  background: var(--warning);
}

.budget-progress.danger {
  background: var(--danger);
}

/* Camera Section */
.camera-section {
  background: #000;
  overflow: hidden;
  margin: 0 -16px 12px -16px;
  position: relative;
}

#video, #preview {
  width: 100%;
  height: 70vh;
  object-fit: cover;
  display: block;
}

.camera-controls {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 10;
}

.camera-controls .btn {
  padding: 14px 24px;
  font-size: 16px;
  border-radius: 50px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.camera-controls .btn .icon {
  font-size: 16px;
}

/* Manual Entry */
.manual-btn {
  width: 100%;
  margin-bottom: 16px;
}

.manual-entry {
  background: var(--card-bg);
  padding: 24px;
  border-radius: 16px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  margin-bottom: 16px;
}

.manual-entry h3 {
  margin-bottom: 20px;
  font-size: 18px;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.form-actions .btn {
  flex: 1;
}

/* Buttons */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  flex: 1;
}

.btn .icon {
  font-size: 20px;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--gray-300);
  color: var(--gray-800);
}

body.dark-mode .btn-secondary {
  background: var(--gray-200);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--gray-200);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: #38a169;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Form */
.expense-form {
  background: var(--card-bg);
  padding: 24px;
  border-radius: 16px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

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

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--gray-200);
  border-radius: 12px;
  font-size: 16px;
  transition: border-color 0.2s;
  background: var(--card-bg);
  color: var(--text);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
}

/* Messages */
.success-message,
.error-message {
  text-align: center;
  padding: 40px 24px;
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.success-message .icon,
.error-message .icon {
  font-size: 48px;
  display: block;
  margin-bottom: 16px;
}

.success-message p,
.error-message p {
  font-size: 18px;
  margin-bottom: 24px;
}

/* History Page */
.filters {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filters input,
.filters select {
  flex: 1;
  min-width: 120px;
  padding: 12px 16px;
  border: 2px solid var(--gray-200);
  border-radius: 12px;
  font-size: 14px;
  background: var(--card-bg);
  color: var(--text);
}

.expense-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.expense-card {
  background: var(--card-bg);
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.expense-info {
  flex: 1;
}

.expense-description {
  font-weight: 600;
  margin-bottom: 4px;
}

.expense-meta {
  font-size: 14px;
  color: var(--text-secondary);
}

.expense-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.expense-amount {
  font-size: 20px;
  font-weight: 700;
  color: var(--danger);
}

.delete-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--gray-200);
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
}

.delete-btn:hover {
  background: #fecaca;
  transform: scale(1.05);
}

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

.category-badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  margin-right: 8px;
}

.category-badge.Food { background: #fef3c7; color: #92400e; }
.category-badge.Transportation { background: #dbeafe; color: #1e40af; }
.category-badge.Personal { background: #fce7f3; color: #9d174d; }
.category-badge.Health-medical { background: #d1fae5; color: #065f46; }
.category-badge.Travel { background: #ede9fe; color: #5b21b6; }
.category-badge.Home-Rent { background: #fed7aa; color: #9a3412; }
.category-badge.Utilities { background: #cffafe; color: #0e7490; }
.category-badge.Gifts { background: #fecaca; color: #991b1b; }
.category-badge.Pets { background: #d9f99d; color: #3f6212; }
.category-badge.Productivity { background: #e0e7ff; color: #3730a3; }
.category-badge.Other { background: var(--gray-200); color: var(--gray-600); }

.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-secondary);
}

.empty-state .icon {
  font-size: 64px;
  margin-bottom: 16px;
}

/* Total */
.total-bar {
  background: linear-gradient(135deg, var(--primary), #764ba2);
  color: white;
  padding: 16px 24px;
  border-radius: 12px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.total-bar .label {
  font-size: 14px;
  opacity: 0.9;
}

.total-bar .amount {
  font-size: 24px;
  font-weight: 700;
}

/* Items List */
.items-list {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.items-header {
  display: flex;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-200);
  margin-bottom: 12px;
  font-weight: 600;
}

#itemsTotal {
  color: var(--success);
}

#itemsContainer {
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: 16px;
}

.item-card {
  display: flex;
  align-items: center;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  background: var(--gray-100);
  gap: 8px;
  transition: opacity 0.2s;
}

.item-card.unselected {
  opacity: 0.5;
}

.item-card input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

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

.item-name-edit {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  background: transparent;
  color: var(--text);
  margin-bottom: 4px;
}

.item-name-edit:focus {
  border-color: var(--primary);
  background: var(--card-bg);
  outline: none;
}

.item-category-edit {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 12px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.item-category-edit:focus {
  border-color: var(--primary);
  background: var(--card-bg);
  outline: none;
}

.item-name {
  font-weight: 500;
  margin-bottom: 4px;
}

.item-category {
  font-size: 12px;
  color: var(--text-secondary);
}

.item-price {
  font-weight: 700;
  color: var(--danger);
}

.item-price-edit {
  display: flex;
  align-items: center;
  font-weight: 700;
  color: var(--danger);
  flex-shrink: 0;
}

.item-price-edit span {
  font-size: 14px;
}

.item-price-edit input {
  width: 60px;
  padding: 6px 4px;
  border: 2px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--danger);
  text-align: right;
  background: var(--card-bg);
}

.item-price-edit input:focus {
  outline: none;
  border-color: var(--primary);
}

.item-delete {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--danger);
  color: white;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.item-delete:hover {
  opacity: 1;
}

/* Stats */
.stats-section {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.stats-section h3 {
  margin-bottom: 16px;
  font-size: 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.stat-card {
  background: var(--gray-100);
  padding: 16px;
  border-radius: 12px;
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Chart */
.chart-container {
  margin-top: 16px;
}

.chart-bar {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.chart-label {
  width: 100px;
  font-size: 12px;
  color: var(--text-secondary);
}

.chart-track {
  flex: 1;
  height: 24px;
  background: var(--gray-200);
  border-radius: 4px;
  overflow: hidden;
  margin: 0 8px;
}

.chart-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}

.chart-value {
  width: 60px;
  font-size: 12px;
  font-weight: 600;
  text-align: right;
}

/* Date filter */
.date-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.date-btn {
  padding: 8px 16px;
  border: 2px solid var(--gray-200);
  background: var(--card-bg);
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text);
}

.date-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

/* Responsive */
@media (max-width: 400px) {
  .container {
    padding: 12px;
  }

  header h1 {
    font-size: 20px;
  }

  .btn {
    padding: 12px 16px;
    font-size: 14px;
  }

  .header-actions {
    gap: 4px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
}

/* Autocomplete */
.autocomplete-wrapper {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}

.autocomplete-list.show {
  display: block;
}

.autocomplete-item {
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--gray-100);
  transition: background 0.2s;
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background: var(--gray-100);
}

.autocomplete-item-name {
  font-weight: 500;
  color: var(--text);
}

.autocomplete-item-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.autocomplete-item-price {
  font-weight: 600;
  color: var(--primary);
}

.autocomplete-item-category {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--gray-100);
  border-radius: 4px;
  color: var(--text-secondary);
}

/* Voice Input */
.voice-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.voice-btn:hover {
  background: var(--primary-dark);
}

.voice-btn.listening {
  background: #ef4444;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { transform: translateY(-50%) scale(1); }
  50% { transform: translateY(-50%) scale(1.1); }
}

.autocomplete-wrapper {
  position: relative;
}

.autocomplete-wrapper input {
  padding-right: 50px;
}

/* Savings Goals */
.savings-card {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
}

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

.savings-title {
  font-size: 14px;
  opacity: 0.9;
}

.savings-amount {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

.savings-target {
  font-size: 14px;
  opacity: 0.8;
}

.savings-progress {
  height: 8px;
  background: rgba(255,255,255,0.3);
  border-radius: 4px;
  margin-top: 12px;
  overflow: hidden;
}

.savings-progress-fill {
  height: 100%;
  background: white;
  border-radius: 4px;
  transition: width 0.3s;
}

/* Recurring Expenses */
.recurring-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--card-bg);
  border-radius: 12px;
  margin-bottom: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.recurring-info {
  flex: 1;
}

.recurring-name {
  font-weight: 600;
  margin-bottom: 2px;
}

.recurring-schedule {
  font-size: 12px;
  color: var(--text-secondary);
}

.recurring-amount {
  font-weight: 700;
  color: var(--danger);
}

.recurring-toggle {
  margin-left: 12px;
}

/* Period Comparison */
.comparison-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

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

.comparison-periods {
  display: flex;
  gap: 20px;
}

.comparison-period {
  text-align: center;
}

.period-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.period-amount {
  font-size: 20px;
  font-weight: 700;
}

.period-amount.current {
  color: var(--primary);
}

.comparison-change {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 600;
}

.comparison-change.up {
  color: #ef4444;
}

.comparison-change.down {
  color: #10b981;
}

/* Category Budget */
.category-budget-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-200);
}

.category-budget-item:last-child {
  border-bottom: none;
}

.category-budget-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  margin-right: 12px;
}

.category-budget-info {
  flex: 1;
}

.category-budget-name {
  font-weight: 600;
  margin-bottom: 4px;
}

.category-budget-progress {
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  overflow: hidden;
}

.category-budget-progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.category-budget-amounts {
  text-align: right;
  font-size: 13px;
}

.category-budget-spent {
  font-weight: 600;
}

.category-budget-limit {
  color: var(--text-secondary);
}
