:root {
  --primary: #0A84FF;
  --primary-light: #32D74B;
  --accent-blue: #0A84FF;
  --accent-teal: #36B7CC;
  --accent-gray: #E5E7EB;
  /* Light theme defaults */
  --bg-start: #f8fafc;
  --bg-end: #eef2f7;
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(15, 23, 42, 0.08);
  --glass-shadow: rgba(2, 6, 23, 0.08);
  --container-grad-0: rgba(255, 255, 255, 0.65);
  --container-grad-1: rgba(255, 255, 255, 0.45);
  --glass-hover-bg: rgba(255, 255, 255, 0.25);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --blur-intensity: 16px;
}

/* Dark mode support */
.theme-dark {
  --bg-start: #0b1020;
  --bg-end: #121a2e;
  --glass-bg: rgba(17, 24, 39, 0.6); /* slate-900 w/ alpha */
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-shadow: rgba(0, 0, 0, 0.3);
  --container-grad-0: rgba(17, 24, 39, 0.6);
  --container-grad-1: rgba(30, 41, 59, 0.5);
  --glass-hover-bg: rgba(255, 255, 255, 0.16);
  --text-primary: #FFFFFF;
  --text-secondary: #CBD5E1;
  --blur-intensity: 20px;
}

/* Base styling */
body {
  background: linear-gradient(180deg, var(--bg-start, #f8fafc) 0%, var(--bg-end, #eef2f7) 100%);
  min-height: 100dvh; /* dynamic viewport height for mobile */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text-primary, #0f172a);
  padding-bottom: env(safe-area-inset-bottom);
  padding-top: env(safe-area-inset-top);
}

/* Ensure page can scroll fully with sticky header + fixed tabbar */
main { min-height: calc(100dvh - 64px); }

/* Desktop constraints */
@media (min-width: 768px) {
  .container-glass {
    max-width: 800px;
    margin: 0 auto;
  }
  
  .glass-card {
    max-width: none;
  }
  
  /* Prevent over-scaling on desktop */
  .floating {
    animation: none;
  }
  
  .card:hover {
    transform: translateY(-1px);
  }
  
  .glass-card:hover {
    transform: translateY(-1px);
  }
}

/* Glassmorphism card styles */
.card {
  background: var(--glass-bg, rgba(255, 255, 255, 0.7));
  backdrop-filter: blur(var(--blur-intensity));
  -webkit-backdrop-filter: blur(var(--blur-intensity));
  border: 1px solid var(--glass-border, rgba(15, 23, 42, 0.08));
  border-radius: 20px;
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.1),
    0 1px 0 rgba(255, 255, 255, 0.1) inset;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 
    0 20px 40px rgba(0, 0, 0, 0.15),
    0 1px 0 rgba(255, 255, 255, 0.1) inset;
}

/* Enhanced glass card variant */
.glass-card {
  background: var(--glass-bg, rgba(255, 255, 255, 0.7));
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border: 1px solid var(--glass-border, rgba(15, 23, 42, 0.08));
  border-radius: 24px;
  box-shadow: 
    0 12px 40px rgba(0, 0, 0, 0.12),
    0 2px 8px rgba(0, 0, 0, 0.08),
    0 1px 0 rgba(255, 255, 255, 0.15) inset;
}

/* Modern buttons */
.brand-bg {
  background: linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-teal) 100%);
  color: white;
  border: none;
  border-radius: 16px;
  padding: 14px 28px;
  font-weight: 600;
  font-size: 16px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 
    0 4px 20px rgba(10, 132, 255, 0.3),
    0 1px 0 rgba(255, 255, 255, 0.2) inset;
}

.brand-bg:hover {
  transform: translateY(-1px);
  box-shadow: 
    0 8px 30px rgba(10, 132, 255, 0.4),
    0 1px 0 rgba(255, 255, 255, 0.2) inset;
}

.brand-bg:active {
  transform: translateY(0);
  transition-duration: 0.1s;
}

/* Glass button variant */
.glass-button {
  background: var(--glass-bg, rgba(255, 255, 255, 0.7));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border, rgba(15, 23, 42, 0.08));
  color: var(--text-primary, #0f172a);
  border-radius: 14px;
  padding: 12px 24px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.glass-button:hover {
  background: var(--glass-hover-bg);
  transform: translateY(-1px);
}

/* Destructive action button */
.btn-danger {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: #fff;
  border: none;
  border-radius: 12px;
  transition: all 0.2s ease;
}
.btn-danger:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn-danger:active { transform: translateY(0); }

/* Soft row styling for grids */
.row-soft {
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 12px;
}

/* Pills */
.pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.1);
}
.pill.success { background: rgba(34,197,94,0.15); color: #86efac; border-color: rgba(34,197,94,0.25); }
.pill.warn { background: rgba(234,179,8,0.15); color: #fde68a; border-color: rgba(234,179,8,0.25); }
.pill.info { background: rgba(59,130,246,0.15); color: #93c5fd; border-color: rgba(59,130,246,0.25); }

/* Glass input utility to ensure visible text and borders */
.glass-input {
  background: var(--glass-bg, rgba(255, 255, 255, 0.7));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border, rgba(15, 23, 42, 0.08));
  color: var(--text-primary, #0f172a);
}

/* Modern form inputs */
input, textarea, select {
  background: var(--glass-bg, rgba(255, 255, 255, 0.7));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border, rgba(15, 23, 42, 0.08));
  border-radius: 12px;
  padding: 14px 16px;
  color: var(--text-primary, #0f172a);
  font-size: 16px;
  transition: all 0.3s ease;
}

/* Default: use native dropdown arrows to avoid duplication */
select { appearance: auto; -webkit-appearance: auto; -moz-appearance: auto; }

/* Optional custom chevron: apply only when explicitly using .custom-select or .role-select */
.custom-select, .role-select { appearance: none; -webkit-appearance: none; -moz-appearance: none; }
.custom-select:not([multiple]), .role-select:not([multiple]) {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' fill='none'><path d='M6 8l4 4 4-4' stroke='%2399A3B0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem; /* space for chevron */
}

/* Dark mode chevron color for custom selects */
.theme-dark .custom-select:not([multiple]), .theme-dark .role-select:not([multiple]) {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' fill='none'><path d='M6 8l4 4 4-4' stroke='%23CBD5E1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}

/* Native dropdown panel best-effort styling */
select option, select optgroup {
  background-color: #f8fafc; /* light dropdown bg */
  color: #0f172a;
}
.theme-dark select option, .theme-dark select optgroup {
  background-color: #0f172a; /* dark dropdown bg */
  color: #E5E7EB;
}
.theme-dark select option:checked {
  background-color: #1f2937; /* slate-800 */
  color: #ffffff;
}

/* Role dropdown enhancements */
.role-select {
  min-width: 160px;
  font-weight: 500;
  border-radius: 14px;
  padding-right: 2.25rem; /* ensure space for chevron */
}
.role-select:hover {
  background: var(--glass-hover-bg);
}
.role-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.2);
}

/* Dedicated wrapper-based chevron to avoid background duplication */
.select-wrap {
  position: relative;
  display: inline-block;
}
.select-wrap .role-select { background-image: none !important; /* prevent built-in chevron */ }
.select-wrap::after {
  content: '';
  position: absolute;
  pointer-events: none;
  right: 12px;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' fill='none'><path d='M6 8l4 4 4-4' stroke='%2399A3B0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  opacity: 0.9;
}
.theme-dark .select-wrap::after {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' fill='none'><path d='M6 8l4 4 4-4' stroke='%23CBD5E1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}

/* Disabled button visual for small action buttons */
.btn-disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Ensure readable text inside glass containers */
.container-glass, .glass-card, .card {
  color: var(--text-primary, #0f172a);
}

input::placeholder, textarea::placeholder {
  color: rgba(148, 163, 184, 0.9); /* slate-400 */
}

input:focus, textarea:focus, select:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.2);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
  transform: translateY(-1px);
}

/* Brand styling */
.brand {
  color: var(--primary);
  text-shadow: 0 1px 2px rgba(0, 122, 255, 0.2);
}

/* Utility classes */
.fade-in {
  animation: fadeIn 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeIn {
  from { 
    opacity: 0; 
    transform: translateY(20px);
  }
  to { 
    opacity: 1; 
    transform: translateY(0);
  }
}

.slide-up {
  animation: slideUp 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Modern navigation */
.nav-glass {
  background: var(--glass-bg, rgba(255, 255, 255, 0.7));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--glass-border, rgba(15, 23, 42, 0.08));
  padding-bottom: env(safe-area-inset-bottom);
}

/* Bottom tabbar safe area helper */
.safe-area-inset-bottom { padding-bottom: max(env(safe-area-inset-bottom), 8px); }

/* Improve mobile tap targets */
@media (max-width: 640px) {
  button, .glass-button, .brand-bg, .btn-danger {
    min-height: 44px; /* Apple HIG minimum tap target height */
  }
  input, select, textarea { font-size: 16px; } /* prevent iOS zoom */
}

/* Bottom tabbar buttons: remove iOS tap highlight and keep layout stable */
.tabbar-btn {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  border-width: 0; /* keep layout stable without visible border */
  align-items: center;
  justify-content: center;
}
.tabbar-btn:focus { outline: none; box-shadow: none; }
.tabbar-btn:active { background-color: rgba(255,255,255,0.06); }

/* Compact square highlight behind tab icon */
.tab-highlight {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px; /* square-ish */
  transition: background-color 150ms ease;
}
.tab-highlight.active {
  background-color: rgba(255,255,255,0.12);
}

/* Container improvements */
.container-glass {
  background: linear-gradient(135deg, var(--container-grad-0, rgba(255, 255, 255, 0.65)) 0%, var(--container-grad-1, rgba(255, 255, 255, 0.45)) 100%);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border-radius: 28px;
  padding: 24px;
  margin: 16px;
  border: 1px solid var(--glass-border, rgba(15, 23, 42, 0.08));
  max-width: 100%;
}

@media (min-width: 768px) {
  .container-glass {
    padding: 32px;
    margin: 24px auto;
    max-width: 1200px;
  }
}

/* Enhanced shadows */
.shadow-glass {
  box-shadow: 
    0 20px 60px rgba(0, 0, 0, 0.12),
    0 8px 25px rgba(0, 0, 0, 0.08),
    0 1px 0 rgba(255, 255, 255, 0.1) inset;
}

/* Floating elements */
.floating {
  animation: floating 3s ease-in-out infinite;
}

@keyframes floating {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

/* Improved text styling */
.text-glass { color: var(--text-primary, #0f172a); }
.text-glass-secondary { color: var(--text-secondary, #475569); }

/* Legacy support */
.hairline {
  border-bottom: 0.5px solid rgba(255, 255, 255, 0.2);
}

/* Wallet carousel (Saved Vendors) */
.wallet-wrapper { position: relative; }
.wallet-carousel {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 80%;
  gap: 16px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding-left: 50%;
  scroll-padding-right: 50%;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: none; /* Firefox */
  padding-bottom: 6px;
}
@media (min-width: 768px) {
  .wallet-carousel { grid-auto-columns: 55%; }
}
.wallet-carousel::-webkit-scrollbar { display: none; }
.wallet-card {
  scroll-snap-align: center;
  scroll-snap-stop: always;
  border-radius: 18px;
  overflow: hidden;
  position: relative;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 24px var(--glass-shadow);
  cursor: pointer;
  transition: transform 220ms ease, box-shadow 220ms ease, border-color 220ms ease;
}
.wallet-card.is-active { transform: scale(1.02); box-shadow: 0 14px 36px rgba(0,0,0,0.25); border-color: rgba(10,132,255,0.35); }
.wallet-img {
  width: 100%;
  height: 240px;
  object-fit: cover;
  display: block;
}
.wallet-fallback { position: relative; height: 240px; }
.wallet-fallback-bg {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  filter: blur(6px) brightness(0.8);
}
.wallet-fallback-inner {
  position: absolute; inset: 0; display: flex; align-items: center; gap: 14px; padding: 16px;
}
.wallet-logo { width: 56px; height: 56px; border-radius: 12px; overflow: hidden; background: rgba(255,255,255,0.6); border: 1px solid var(--glass-border); }
.wallet-logo img { width: 100%; height: 100%; object-fit: cover; }
.wallet-meta { color: var(--text-primary); text-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.wallet-title { font-weight: 700; font-size: 18px; }
.wallet-sub { font-size: 12px; opacity: 0.9; }
.wallet-chip {
  position: absolute; bottom: 10px; right: 10px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 999px; padding: 6px 10px; font-size: 12px;
}
.wallet-nav { position: absolute; z-index: 2; top: -10px; right: 0; display: flex; gap: 6px; }
.wallet-btn { background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: 10px; padding: 6px 8px; }

.dark-bg {
  background: linear-gradient(135deg, var(--dark) 0%, #2C2C2E 100%);
  color: #fff;
}

.separator {
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.focus-ring {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.rfid-pulse {
  animation: rfidPulse 1.2s infinite;
}

@keyframes rfidPulse {
  0% { box-shadow: 0 0 0 0 var(--primary); }
  70% { box-shadow: 0 0 0 12px rgba(0, 122, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 122, 255, 0); }
}
