/* Expense Tracker - Mobile-first PWA Styles */

:root {
  --primary: #3B82F6;
  --primary-dark: #2563EB;
  --success: #10B981;
  --danger: #EF4444;
  --warning: #F59E0B;
  --bg: #F3F4F6;
  --card: #FFFFFF;
  --text: #1F2937;
  --text-secondary: #6B7280;
  --border: #E5E7EB;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 80px;
}

/* Header */
.header {
  background: var(--primary);
  color: white;
  padding: 16px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(59,130,246,0.3);
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.header .subtitle {
  font-size: 0.8rem;
  opacity: 0.85;
}

/* Summary Card */
.summary-card {
  background: var(--card);
  margin: 16px;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.summary-card .balance {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  margin: 8px 0;
}

.summary-card .balance.positive { color: var(--success); }
.summary-card .balance.negative { color: var(--danger); }

.summary-row {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.summary-item {
  text-align: center;
  flex: 1;
}

.summary-item .label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.summary-item .value {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 4px;
}

.summary-item.income .value { color: var(--success); }
.summary-item.expense .value { color: var(--danger); }

/* Quick Actions */
.quick-actions {
  display: flex;
  gap: 12px;
  padding: 0 16px;
  margin-bottom: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
}

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

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

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

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

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.85rem;
}

.btn-block {
  width: 100%;
}

/* Section */
.section {
  padding: 0 16px;
  margin-bottom: 24px;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Transaction List */
.transaction-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.transaction-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.transaction-item:active {
  background: #F9FAFB;
}

.transaction-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.transaction-info {
  flex: 1;
  min-width: 0;
}

.transaction-info .desc {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.transaction-info .meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.transaction-amount {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
}

.transaction-amount.income { color: var(--success); }
.transaction-amount.expense { color: var(--danger); }

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

/* Modal / Overlay */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

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

.modal-header h2 {
  font-size: 1.2rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
}

/* Form */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.form-control {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: var(--card);
  color: var(--text);
  transition: border-color 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236B7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

/* Type Toggle */
.type-toggle {
  display: flex;
  gap: 8px;
}

.type-toggle button {
  flex: 1;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.type-toggle button.active.expense {
  border-color: var(--danger);
  background: #FEF2F2;
  color: var(--danger);
}

.type-toggle button.active.income {
  border-color: var(--success);
  background: #F0FDF4;
  color: var(--success);
}

/* Camera / Upload */
.camera-section {
  text-align: center;
  margin-bottom: 20px;
}

.camera-preview {
  width: 100%;
  max-height: 300px;
  border-radius: var(--radius);
  object-fit: contain;
  background: #000;
  display: none;
}

.camera-preview.active {
  display: block;
}

.camera-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 12px;
}

/* OCR Results */
.ocr-result {
  background: #F9FAFB;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.ocr-result .confidence {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.ocr-result .raw-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  max-height: 100px;
  overflow-y: auto;
  white-space: pre-wrap;
  font-family: monospace;
  background: #F3F4F6;
  padding: 8px;
  border-radius: 6px;
  margin-top: 8px;
}

/* Category Grid */
.category-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.category-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px;
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--card);
}

.category-item.selected {
  border-color: var(--primary);
  background: #EFF6FF;
}

.category-item .icon {
  font-size: 1.5rem;
  margin-bottom: 4px;
}

.category-item .name {
  font-size: 0.7rem;
  text-align: center;
  color: var(--text-secondary);
}

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  display: flex;
  border-top: 1px solid var(--border);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.7rem;
  gap: 2px;
}

.nav-item.active {
  color: var(--primary);
}

.nav-item .nav-icon {
  font-size: 1.4rem;
}

/* Page */
.page {
  display: none;
}

.page.active {
  display: block;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.filter-chip {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 0.85rem;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Settings */
.settings-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.settings-item .label {
  font-weight: 500;
}

.settings-item .value {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1F2937;
  color: white;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 0.9rem;
  z-index: 300;
  transition: transform 0.3s ease;
  white-space: nowrap;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* Loading */
.loading {
  display: flex;
  justify-content: center;
  padding: 20px;
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Auth Pages */
.auth-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg);
}

.auth-logo {
  font-size: 3rem;
  margin-bottom: 8px;
}

.auth-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}

.auth-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.auth-form {
  width: 100%;
  max-width: 360px;
}

.auth-form .form-group {
  margin-bottom: 14px;
}

.auth-link {
  text-align: center;
  margin-top: 16px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.auth-link a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
}

.auth-error {
  background: #FEF2F2;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 14px;
  display: none;
}

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

.qr-container {
  text-align: center;
  margin: 20px 0;
}

.qr-container img {
  max-width: 200px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
}

.backup-codes {
  background: #FFFBEB;
  border: 2px solid var(--warning);
  border-radius: var(--radius);
  padding: 16px;
  margin: 16px 0;
}

.backup-codes h4 {
  color: var(--warning);
  margin-bottom: 8px;
}

.backup-codes code {
  display: block;
  font-family: monospace;
  font-size: 0.9rem;
  padding: 4px 0;
}

.user-menu {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.user-menu .username {
  font-weight: 500;
  font-size: 0.9rem;
}

/* Responsive */
@media (min-width: 768px) {
  body {
    max-width: 600px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    min-height: 100vh;
  }

  .bottom-nav {
    max-width: 600px;
    left: 50%;
    transform: translateX(-50%);
  }

  .header {
    max-width: 600px;
    margin: 0 auto;
  }
}
