/* ========================================
   DESIGN SYSTEM - CSS Variables
   ======================================== */
:root {
  /* Colors */
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #60a5fa;
  --secondary: #64748b;
  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  
  /* Neutrals */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  
  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  
  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 200ms ease;
  --transition-slow: 300ms ease;
  
  /* Layout */
  --nav-height: 64px;
  --mobile-nav-height: 72px;
  --container-max: 1200px;
  --sidebar-width: 280px;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--primary-dark);
}

img {
  max-width: 100%;
  height: auto;
}

/* ========================================
   TYPOGRAPHY
   ======================================== */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--gray-900);
}

h1 { font-size: 1.875rem; margin-bottom: var(--space-lg); }
h2 { font-size: 1.5rem; margin-bottom: var(--space-md); }
h3 { font-size: 1.25rem; margin-bottom: var(--space-sm); }

p { margin-bottom: var(--space-md); }

small { font-size: 0.875rem; color: var(--gray-500); }

/* ========================================
   LAYOUT
   ======================================== */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-lg);
}

@media (max-width: 768px) {
  .container {
    padding: var(--space-md);
    padding-bottom: calc(var(--mobile-nav-height) + var(--space-lg));
  }
}

/* ========================================
   NAVBAR - Desktop
   ======================================== */
.navbar {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  height: var(--nav-height);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.navbar-inner {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--space-lg);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-brand a {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.nav-brand svg {
  width: 28px;
  height: 28px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.nav-links a {
  padding: var(--space-sm) var(--space-md);
  color: var(--gray-600);
  font-weight: 500;
  font-size: 0.9375rem;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.nav-links a:hover {
  color: var(--gray-900);
  background: var(--gray-100);
}

.nav-links a.active {
  color: var(--primary);
  background: rgba(59, 130, 246, 0.1);
}

.nav-links .admin-link {
  color: var(--warning);
}

.nav-links .admin-link:hover {
  background: var(--warning-light);
}

.nav-user {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.nav-user:hover {
  background: var(--gray-100);
}

.nav-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  object-fit: cover;
}

.nav-user-name {
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--gray-700);
}

/* Hide desktop nav on mobile */
@media (max-width: 768px) {
  .nav-links, .nav-user {
    display: none;
  }
}

/* ========================================
   MOBILE BOTTOM NAVIGATION
   ======================================== */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid var(--gray-200);
  height: var(--mobile-nav-height);
  z-index: 100;
  box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1);
  padding-bottom: env(safe-area-inset-bottom);
}

.mobile-nav-inner {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 100%;
  max-width: 500px;
  margin: 0 auto;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-sm);
  color: var(--gray-500);
  font-size: 0.75rem;
  font-weight: 500;
  text-decoration: none;
  transition: color var(--transition-fast);
  min-width: 64px;
}

.mobile-nav-item svg {
  width: 24px;
  height: 24px;
  margin-bottom: 2px;
}

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

.mobile-nav-item.admin-link {
  color: var(--warning);
}

@media (max-width: 768px) {
  .mobile-nav {
    display: block;
  }
}

/* ========================================
   BUTTONS
   ======================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  color: white;
}

.btn-secondary {
  background: white;
  color: var(--gray-700);
  border-color: var(--gray-300);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--gray-50);
  border-color: var(--gray-400);
  color: var(--gray-700);
}

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

.btn-success:hover:not(:disabled) {
  background: #059669;
  color: white;
}

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

.btn-warning:hover:not(:disabled) {
  background: #d97706;
  color: white;
}

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

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
  color: white;
}

.btn-sm {
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.8125rem;
}

.btn-lg {
  padding: var(--space-md) var(--space-xl);
  font-size: 1rem;
}

.btn-google {
  background: white;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
  width: 100%;
  padding: var(--space-md);
}

.btn-google:hover {
  background: var(--gray-50);
  box-shadow: var(--shadow-md);
  color: var(--gray-700);
}

/* ========================================
   FORMS
   ======================================== */
.form-group {
  margin-bottom: var(--space-md);
}

.form-group label {
  display: block;
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--gray-700);
  margin-bottom: var(--space-xs);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  font-size: 1rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  background: white;
  transition: all var(--transition-fast);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group small {
  display: block;
  margin-top: var(--space-xs);
  color: var(--gray-500);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-md);
}

.form-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

.checkbox-group {
  display: flex;
  align-items: center;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  font-weight: normal;
  margin-bottom: 0;
}

.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* ========================================
   CARDS
   ======================================== */
.card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-lg);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--gray-100);
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
}

/* ========================================
   STATS GRID
   ======================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.stat-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-md);
  border-left: 4px solid var(--primary);
}

.stat-card h3 {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-sm);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--gray-900);
  margin: 0;
}

.stat-card:nth-child(2) {
  border-left-color: var(--success);
}

.stat-card:nth-child(3) {
  border-left-color: var(--warning);
}

/* ========================================
   TABLES
   ======================================== */
.table-container {
  overflow-x: auto;
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: var(--gray-50);
}

th {
  padding: var(--space-md);
  text-align: left;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--gray-200);
}

td {
  padding: var(--space-md);
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.9375rem;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover {
  background: var(--gray-50);
}

tr.pending {
  background: var(--warning-light);
}

.actions {
  display: flex;
  gap: var(--space-xs);
  flex-wrap: wrap;
}

/* Responsive table */
@media (max-width: 768px) {
  th, td {
    padding: var(--space-sm);
    font-size: 0.875rem;
  }
  
  .actions {
    flex-direction: column;
  }
}

/* ========================================
   BADGES
   ======================================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  background: var(--gray-100);
  color: var(--gray-600);
}

.badge-success {
  background: var(--success-light);
  color: #065f46;
}

.badge-warning {
  background: var(--warning-light);
  color: #92400e;
}

.badge-danger {
  background: var(--danger-light);
  color: #991b1b;
}

.badge-admin {
  background: #dbeafe;
  color: #1d4ed8;
}

/* ========================================
   ALERTS
   ======================================== */
.alert {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  font-size: 0.9375rem;
}

.alert-success {
  background: var(--success-light);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert-error {
  background: var(--danger-light);
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-warning {
  background: var(--warning-light);
  color: #92400e;
  border: 1px solid #fde68a;
}

/* ========================================
   AUTH CONTAINER
   ======================================== */
.auth-container {
  max-width: 400px;
  margin: 80px auto;
  padding: var(--space-xl);
  background: white;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  text-align: center;
}

.auth-container h1 {
  font-size: 1.75rem;
  color: var(--primary);
  margin-bottom: var(--space-xs);
}

.auth-container h2 {
  font-size: 1.125rem;
  color: var(--gray-500);
  font-weight: 400;
  margin-bottom: var(--space-xl);
}

.auth-note {
  margin-top: var(--space-lg);
  font-size: 0.875rem;
  color: var(--gray-500);
}

/* ========================================
   DASHBOARD
   ======================================== */
.section {
  margin-bottom: var(--space-xl);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}

.section-header h2 {
  margin: 0;
}

.empty-state {
  text-align: center;
  padding: var(--space-2xl);
  color: var(--gray-500);
  background: white;
  border-radius: var(--radius-lg);
  border: 2px dashed var(--gray-200);
}

/* ========================================
   BILLS LIST
   ======================================== */
.bills-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.bill-card {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast);
}

.bill-card:hover {
  box-shadow: var(--shadow-md);
}

.bill-date {
  font-weight: 600;
  color: var(--gray-800);
  min-width: 100px;
}

.bill-amount {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 80px;
}

.bill-provider {
  color: var(--gray-500);
  flex: 1;
}

@media (max-width: 640px) {
  .bill-card {
    flex-wrap: wrap;
  }
  
  .bill-provider {
    width: 100%;
    order: 3;
  }
}

/* ========================================
   UPLOAD / CAPTURE
   ======================================== */
.capture-container {
  max-width: 600px;
  margin: 0 auto;
}

.upload-zone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl);
  text-align: center;
  background: white;
  cursor: pointer;
  transition: all var(--transition-normal);
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.05);
}

.upload-icon {
  font-size: 3rem;
  margin-bottom: var(--space-md);
}

.upload-zone h3 {
  color: var(--gray-700);
  margin-bottom: var(--space-sm);
}

.upload-zone p {
  color: var(--gray-500);
  margin: 0;
}

.upload-progress {
  text-align: center;
  padding: var(--space-xl);
  background: white;
  border-radius: var(--radius-lg);
}

.progress-bar {
  height: 8px;
  background: var(--gray-200);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin: var(--space-md) 0;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
}

.results-container {
  background: white;
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
}

.result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--gray-100);
}

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

.result-item.success .status {
  color: var(--success);
}

.result-item.error .status {
  color: var(--danger);
}

.results-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
  justify-content: center;
}

/* ========================================
   PROFILE
   ======================================== */
.profile-header {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--gray-200);
}

.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-full);
  object-fit: cover;
}

.profile-header h2 {
  margin-bottom: var(--space-xs);
}

.profile-header p {
  color: var(--gray-500);
  margin: 0;
}

.profile-form,
.user-form {
  max-width: 500px;
  background: white;
  padding: var(--space-lg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.status-linked {
  color: var(--success);
  font-weight: 500;
}

/* ========================================
   ADMIN
   ======================================== */
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-xl);
}

.admin-header h1 {
  margin-bottom: var(--space-xs);
}

.admin-header p {
  color: var(--gray-500);
  margin: 0;
}

.users-table-container {
  overflow-x: auto;
}

.users-table {
  width: 100%;
  background: white;
  border-collapse: collapse;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.users-table th,
.users-table td {
  padding: var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--gray-100);
}

.users-table th {
  background: var(--gray-50);
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.users-table tr:last-child td {
  border-bottom: none;
}

.users-table tr.pending {
  background: var(--warning-light);
}

/* ========================================
   BILL DETAIL
   ======================================== */
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-xl);
}

.detail-actions {
  display: flex;
  gap: var(--space-sm);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.detail-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-md);
}

.detail-card h3 {
  font-size: 1rem;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--gray-100);
}

.detail-card dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
}

.detail-card dt {
  color: var(--gray-500);
  font-size: 0.875rem;
}

.detail-card dd {
  font-weight: 500;
  text-align: right;
}

.detail-card dd.amount {
  font-size: 1.25rem;
  color: var(--primary);
}

/* ========================================
   REVIEW FORM
   ======================================== */
.review-container {
  max-width: 800px;
}

.review-info {
  margin-bottom: var(--space-lg);
}

.review-form {
  background: white;
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-md);
}

.review-form h3 {
  margin-top: var(--space-lg);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--gray-100);
}

.review-form h3:first-of-type {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.ocr-text {
  margin-top: var(--space-xl);
  background: white;
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
}

.ocr-text pre {
  background: var(--gray-50);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-size: 0.875rem;
  max-height: 300px;
}

/* ========================================
   EXPORT
   ======================================== */
.export-container {
  max-width: 500px;
  margin: 0 auto;
}

.export-form {
  background: white;
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  box-shadow: var(--shadow-md);
}

.export-buttons {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-lg);
}

.export-buttons .btn {
  flex: 1;
}

/* ========================================
   FILTERS
   ======================================== */
.filters {
  margin-bottom: var(--space-lg);
}

.filter-form {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
  align-items: center;
}

.filter-form input,
.filter-form select {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
}

@media (max-width: 640px) {
  .filter-form {
    flex-direction: column;
  }
  
  .filter-form input,
  .filter-form select,
  .filter-form .btn {
    width: 100%;
  }
}

/* ========================================
   ERROR PAGE
   ======================================== */
.error-container {
  text-align: center;
  padding: var(--space-2xl);
}

.error-container h1 {
  font-size: 3rem;
  color: var(--danger);
}

/* ========================================
   PAGE HEADER
   ======================================== */
.page-header {
  margin-bottom: var(--space-xl);
}

.page-header h1 {
  margin-bottom: var(--space-xs);
}

.page-header p {
  color: var(--gray-500);
  margin: 0;
}

/* ========================================
   UTILITIES
   ======================================== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-md { margin-top: var(--space-md); }
.mb-md { margin-bottom: var(--space-md); }
.hidden { display: none; }
