/* ===== Design System ===== */
:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-elevated: #e2e8f0;
  --bg-input: #f8fafc;

  --accent-blue: #2563eb;
  --accent-blue-glow: rgba(37, 99, 235, 0.15);
  --accent-cyan: #0891b2;
  --accent-green: #059669;
  --accent-green-glow: rgba(5, 150, 105, 0.15);
  --accent-purple: #7c3aed;
  --accent-purple-glow: rgba(124, 58, 237, 0.15);
  --accent-amber: #d97706;
  --accent-red: #dc2626;
  --accent-red-glow: rgba(220, 38, 38, 0.15);
  --accent-teal: #0d9488;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  --border-color: rgba(15, 23, 42, 0.1);
  --border-glow: rgba(37, 99, 235, 0.2);

  --gradient-blue: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  --gradient-green: linear-gradient(135deg, #10b981 0%, #047857 100%);
  --gradient-purple: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
  --gradient-amber: linear-gradient(135deg, #f59e0b 0%, #b45309 100%);
  --gradient-red: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
  --gradient-dark: linear-gradient(180deg, #f1f5f9 0%, #ffffff 100%);
  --gradient-card: linear-gradient(145deg, #ffffff 0%, #f8fafc 100%);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow-blue: 0 0 20px rgba(59, 130, 246, 0.15);
  --shadow-glow-green: 0 0 20px rgba(16, 185, 129, 0.15);

  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --bg-elevated: #334155;
  --bg-input: #1e293b;

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-inverse: #0f172a;

  --border-color: rgba(255, 255, 255, 0.1);
  --border-glow: rgba(37, 99, 235, 0.4);

  --gradient-dark: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  --gradient-card: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; height: 100%; }
body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }

/* ===== Loading Spinner ===== */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
.spinner--dark {
  border-color: rgba(15,23,42,0.15);
  border-top-color: var(--accent-blue);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Fade In Animation ===== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: fadeInUp 0.35s ease-out both; }
.animate-in-d1 { animation-delay: 0.05s; }
.animate-in-d2 { animation-delay: 0.1s; }
.animate-in-d3 { animation-delay: 0.15s; }
.animate-in-d4 { animation-delay: 0.2s; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.pulse { animation: pulse 2s ease-in-out infinite; }

@keyframes ripple {
  0% { transform: scale(0.8); opacity: 1; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* ===== Screen Container ===== */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(70px + var(--safe-bottom));
}

.screen-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  border-bottom: 1px solid var(--border-color);
}
.screen-header h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.3px;
}
.screen-header .subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.screen-body {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
}

/* ===== Login Screen ===== */
.login-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--gradient-dark);
  position: relative;
  overflow: hidden;
}

.login-screen::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 30%, rgba(59,130,246,0.08) 0%, transparent 50%),
              radial-gradient(circle at 70% 80%, rgba(139,92,246,0.06) 0%, transparent 50%);
  pointer-events: none;
}

.login-card {
  width: 100%;
  max-width: 380px;
  position: relative;
  z-index: 1;
}

.login-logo {
  text-align: center;
  margin-bottom: 40px;
}
.login-logo .icon {
  width: 72px;
  height: 72px;
  background: var(--gradient-blue);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin: 0 auto 16px;
  box-shadow: var(--shadow-glow-blue);
}
.login-logo h1 {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #f1f5f9 0%, #94a3b8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.login-logo p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.3px;
}
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-blue-glow);
}
.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-muted);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--gradient-blue);
  color: #fff;
  box-shadow: var(--shadow-glow-blue);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 0 30px rgba(59,130,246,0.3); }

.btn-green {
  background: var(--gradient-green);
  color: #fff;
  box-shadow: var(--shadow-glow-green);
}

.btn-purple {
  background: var(--gradient-purple);
  color: #fff;
}

.btn-red {
  background: var(--gradient-red);
  color: #fff;
}

.btn-amber {
  background: var(--gradient-amber);
  color: var(--text-inverse);
}

.btn-ghost {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-card-hover);
}

.btn-sm {
  padding: 10px 14px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.btn-icon {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: var(--radius-md);
  font-size: 18px;
}

/* ===== Cards ===== */
.card {
  background: var(--gradient-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
  transition: border-color 0.2s, transform 0.2s;
}
.card:active { transform: scale(0.985); }
.card-glow {
  box-shadow: var(--shadow-glow-blue);
  border-color: rgba(59,130,246,0.2);
}
.card-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}
.card-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ===== Stat Cards ===== */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--gradient-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}
.stat-card--blue::before { background: var(--gradient-blue); }
.stat-card--green::before { background: var(--gradient-green); }
.stat-card--purple::before { background: var(--gradient-purple); }
.stat-card--amber::before { background: var(--gradient-amber); }

.stat-card .label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.stat-card .value {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
}
.stat-card--blue .value { color: var(--accent-blue); }
.stat-card--green .value { color: var(--accent-green); }
.stat-card--purple .value { color: var(--accent-purple); }
.stat-card--amber .value { color: var(--accent-amber); }

/* ===== Status Badge ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.badge--active {
  background: rgba(16,185,129,0.15);
  color: var(--accent-green);
}
.badge--inactive {
  background: rgba(100,116,139,0.15);
  color: var(--text-muted);
}
.badge--warning {
  background: rgba(245,158,11,0.15);
  color: var(--accent-amber);
}
.badge--danger {
  background: rgba(239,68,68,0.15);
  color: var(--accent-red);
}

/* ===== Tracking Status Dot ===== */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  position: relative;
}
.status-dot--active {
  background: var(--accent-green);
}
.status-dot--active::after {
  content: '';
  position: absolute;
  top: -3px; left: -3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent-green);
  animation: ripple 1.5s ease-out infinite;
}
.status-dot--inactive { background: var(--text-muted); }

/* ===== Live Status Bar ===== */
.live-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(16,185,129,0.08);
  border: 1px solid rgba(16,185,129,0.15);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}
.live-bar--error {
  background: rgba(239,68,68,0.08);
  border-color: rgba(239,68,68,0.15);
}
.live-bar .text {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent-green);
}
.live-bar--error .text {
  color: var(--accent-red);
}

/* ===== Product Card ===== */
.product-card {
  display: flex;
  align-items: center;
  gap: 12px;
}
.product-card .info { flex: 1; }
.product-card .name {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 2px;
}
.product-card .meta {
  font-size: 12px;
  color: var(--text-secondary);
}
.product-card .price {
  font-size: 16px;
  font-weight: 800;
  color: var(--accent-cyan);
}

/* ===== Stop Card ===== */
.stop-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.stop-card .number {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--gradient-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.stop-card .details { flex: 1; }
.stop-card .time { font-weight: 600; font-size: 13px; }
.stop-card .duration { font-size: 12px; color: var(--text-secondary); }
.stop-card .coords { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ===== Bottom Navigation ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-color);
  padding: 8px 0 calc(8px + var(--safe-bottom));
  display: flex;
  justify-content: space-around;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-family);
}
.nav-item .icon { font-size: 22px; }
.nav-item .label { font-size: 10px; font-weight: 600; letter-spacing: 0.3px; }
.nav-item--active {
  color: var(--accent-blue);
}
.nav-item--active .icon {
  filter: drop-shadow(0 0 6px rgba(59,130,246,0.4));
}

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-sheet {
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  background: var(--bg-secondary);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-sheet .handle {
  width: 36px;
  height: 4px;
  background: var(--text-muted);
  border-radius: 2px;
  margin: 0 auto 16px;
}
.modal-sheet h2 {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 4px;
}
.modal-sheet .modal-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

/* ===== Onboarding ===== */
.onboarding {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--gradient-dark);
}
.onboarding-progress {
  display: flex;
  gap: 8px;
  padding: 24px 20px 0;
}
.onboarding-progress .dot {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-elevated);
  transition: background 0.3s;
}
.onboarding-progress .dot--active {
  background: var(--gradient-blue);
}

.onboarding-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
}
.onboarding-content .step-icon {
  font-size: 64px;
  margin-bottom: 24px;
}
.onboarding-content h2 {
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 12px;
  letter-spacing: -0.3px;
}
.onboarding-content p {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 320px;
}

.onboarding-actions {
  padding: 20px 24px calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.onboarding-actions .skip {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  font-family: var(--font-family);
}

/* ===== Capture Photo Preview ===== */
.photo-preview {
  width: 100%;
  height: 140px;
  border-radius: var(--radius-md);
  object-fit: cover;
  border: 1px solid var(--border-color);
  margin-bottom: 12px;
}

/* ===== Tips section ===== */
.tips-card {
  border-left: 3px solid var(--accent-amber);
  padding-left: 14px !important;
}
.tips-card .tip-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-amber);
  margin-bottom: 8px;
}
.tips-card .tip {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 5px;
  line-height: 1.5;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state .title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.empty-state .desc {
  font-size: 13px;
  line-height: 1.5;
}

/* ===== Toast Notification ===== */
.toast {
  position: fixed;
  top: calc(var(--safe-top) + 16px);
  left: 16px;
  right: 16px;
  z-index: 5000;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideDown 0.3s ease, fadeOut 0.3s ease 2.7s;
  pointer-events: none;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}
.toast--success { background: var(--accent-green); }
.toast--error { background: var(--accent-red); }
.toast--info { background: var(--accent-blue); }

/* ===== Utility ===== */
.flex-row { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.hidden { display: none !important; }

/* ===== Checklist ===== */
.checklist { list-style: none; }
.checklist li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.checklist li:last-child { border-bottom: none; }

/* ===== Searchable Dropdown ===== */
.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
  margin-top: 4px;
  display: none;
}
.search-results.active { display: block; }
.search-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  font-size: 14px;
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--bg-card-hover); }
.search-item .name { font-weight: 600; color: var(--text-primary); }
.search-item .addr { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

