:root {
  --color-primary: #2563eb;
  --color-primary-light: #2563eb22;
  --color-background: #f8fafc;
  --color-surface: #ffffff;
  --color-text: #1e293b;
  --color-text-secondary: #64748b;
  --color-border: #e2e8f0;
  --color-success: #10b981;
  --color-error: #ef4444;
  --color-warning: #f59e0b;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--color-background);
  color: var(--color-text);
  line-height: 1.5;
}

/* --- Typography --- */
h1, h2, h3, h4 { color: var(--color-text); font-weight: 600; }
p { margin-bottom: 0.5rem; }
a { color: var(--color-primary); text-decoration: none; }

/* --- Forms & Buttons --- */
.form-group { margin-bottom: 1rem; }
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }
label { display: block; font-weight: 500; margin-bottom: 0.5rem; font-size: 0.875rem; color: var(--color-text); }
input, select, textarea {
  width: 100%; padding: 0.75rem;
  border: 1px solid var(--color-border); border-radius: 0.5rem;
  font-family: inherit; font-size: 1rem;
  transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.75rem 1.5rem; border-radius: 0.5rem; font-weight: 500;
  cursor: pointer; transition: all 0.2s; border: none; font-size: 1rem;
}
.btn-primary { background: var(--color-primary); color: white; }
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-outline { background: transparent; border: 1px solid var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: var(--color-surface); }
.btn-danger { background: #fee2e2; color: var(--color-error); }
.btn-sm { padding: 0.5rem 1rem; font-size: 0.875rem; }
.btn-full { width: 100%; }

/* --- Layout --- */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 260px;
  background: var(--color-surface); border-right: 1px solid var(--color-border);
  display: flex; flex-direction: column; z-index: 40;
  transition: transform 0.3s ease;
}
.sidebar-header {
  padding: 1.5rem; border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; gap: 1rem;
}
.user-avatar {
  width: 40px; height: 40px; border-radius: 0.5rem;
  background: var(--color-primary); color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: bold; font-size: 1.25rem;
}
.user-name { font-weight: 600; font-size: 0.875rem; margin-bottom: 0; }
.user-email { font-size: 0.75rem; color: var(--color-text-secondary); margin-bottom: 0; }

.sidebar-nav { padding: 1rem 0; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1.5rem; color: var(--color-text-secondary);
  transition: all 0.2s; font-weight: 500; font-size: 0.875rem;
}
.nav-item:hover { background: var(--color-background); color: var(--color-text); }
.nav-active {
  background: var(--color-primary-light); color: var(--color-primary);
  border-right: 3px solid var(--color-primary);
}
.sidebar-footer { padding: 1rem; border-top: 1px solid var(--color-border); }
.nav-logout { color: var(--color-error); width: 100%; border-radius: 0.5rem; }
.nav-logout:hover { background: #fee2e2; }

.main-content { margin-left: 260px; padding: 2rem; min-height: 100vh; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; }
.page-title { font-size: 1.5rem; }

/* --- Mobile --- */
.mobile-header { display: none; }
.sidebar-overlay { display: none; }
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 1rem; padding-top: 5rem; }
  .mobile-header {
    display: flex; align-items: center; justify-content: space-between;
    position: fixed; top: 0; left: 0; right: 0; height: 60px;
    background: var(--color-surface); border-bottom: 1px solid var(--color-border);
    padding: 0 1rem; z-index: 30;
  }
  .btn-icon { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--color-text); }
  .mobile-title { font-weight: 600; }
  .sidebar.open ~ .sidebar-overlay {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 35;
  }
}

/* --- Cards & UI Components --- */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 1rem; padding: 1.5rem; }
.badge {
  display: inline-flex; align-items: center; padding: 0.25rem 0.5rem;
  border-radius: 999px; font-size: 0.75rem; font-weight: 500;
}
.badge-primary { background: var(--color-primary-light); color: var(--color-primary); }
.badge-success { background: #dcfce7; color: var(--color-success); }
.badge-warning { background: #fef3c7; color: var(--color-warning); }

.alert { padding: 1rem; border-radius: 0.5rem; margin-bottom: 1rem; font-size: 0.875rem; }
.alert-error { background: #fee2e2; color: var(--color-error); border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: var(--color-success); border: 1px solid #bbf7d0; }

.empty-state {
  text-align: center; padding: 3rem 1rem;
  background: var(--color-surface); border: 1px dashed var(--color-border); border-radius: 1rem;
}

/* --- HTMX Loaders --- */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }
.spinner {
  width: 1.25rem; height: 1.25rem;
  border: 2px solid rgba(255,255,255,0.3); border-radius: 50%;
  border-top-color: currentColor; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Offline Banner --- */
.offline-banner {
  position: fixed; top: 0; left: 0; right: 0;
  background: var(--color-warning); color: #fff;
  text-align: center; padding: 0.5rem; font-size: 0.875rem;
  z-index: 100; font-weight: 500;
}
.offline-banner.hidden { display: none; }

/* --- Toast --- */
.toast-container { position: fixed; bottom: 1rem; right: 1rem; z-index: 50; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  padding: 1rem 1.5rem; border-radius: 0.5rem; background: var(--color-surface);
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); font-size: 0.875rem; font-weight: 500;
  animation: slideIn 0.3s ease forwards, fadeOut 0.3s ease 3s forwards;
}
.toast-success { border-left: 4px solid var(--color-success); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; visibility: hidden; } }

/* --- Specific Modules --- */
/* Auth */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--color-surface); padding: 1rem; }
.auth-card { width: 100%; max-width: 400px; }
.auth-logo { text-align: center; margin-bottom: 2rem; }
.auth-title { font-size: 1.5rem; text-align: center; margin-bottom: 0.5rem; }
.auth-subtitle { text-align: center; color: var(--color-text-secondary); margin-bottom: 2rem; }
.auth-links { text-align: center; margin-top: 1.5rem; font-size: 0.875rem; }
.otp-input { text-align: center; font-size: 2rem; letter-spacing: 0.5rem; font-weight: bold; }

/* Dashboard & Loyalty */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 1rem; padding: 1.5rem; display: flex; align-items: center; gap: 1rem; }
.stat-icon { font-size: 2rem; }
.stat-label { font-size: 0.875rem; color: var(--color-text-secondary); margin: 0; }
.stat-value { font-size: 1.5rem; font-weight: 700; margin: 0; }
.loyalty-hero { background: linear-gradient(135deg, var(--color-primary), #1e40af); border-radius: 1rem; padding: 2rem; color: white; }

/* Orders */
.order-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 1rem; margin-bottom: 1rem; overflow: hidden; }
.order-card-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--color-border); background: var(--color-background); display: flex; justify-content: space-between; }
.order-item-summary { padding: 1.5rem; display: flex; gap: 1rem; align-items: center; }
.order-item-img { width: 60px; height: 60px; object-fit: cover; border-radius: 0.5rem; background: var(--color-border); }
.order-card-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--color-border); display: flex; justify-content: space-between; align-items: center; }

/* Addresses */
.address-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.address-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 1rem; padding: 1.5rem; }
.address-card-header { display: flex; justify-content: space-between; margin-bottom: 1rem; }
.address-actions { display: flex; gap: 0.5rem; margin-top: 1.5rem; border-top: 1px solid var(--color-border); padding-top: 1rem; }

/* Modals */
.modal-container:empty { display: none; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 100; }
.modal-box { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: var(--color-surface); width: 100%; max-width: 500px; border-radius: 1rem; z-index: 101; max-height: 90vh; overflow-y: auto; padding: 1.5rem; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
