/* ============================================ */
/* M-Pesa Payment Gateway — Global Styles       */
/* ============================================ */

*, *::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: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

a { text-decoration: none; color: inherit; }
img { max-width: 100%; height: auto; }

/* Mobile Topbar Header */
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 0;
  z-index: 99;
  width: 100%;
  max-width: 100vw;
  box-sizing: border-box;
}

.mobile-toggle-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
  font-size: 1.35rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  transition: background 0.2s;
}

.mobile-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.95rem;
  color: #22c55e;
}

.user-menu-wrapper {
  position: relative;
}

.mobile-user-avatar {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #22c55e;
  font-size: 1.25rem;
  width: 38px;
  height: 38px;
  min-width: 38px;
  min-height: 38px;
  flex-shrink: 0;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
}

.mobile-user-avatar:hover, .mobile-user-avatar.active {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.4);
  color: #4ade80;
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.25);
}

/* User Profile Dropdown Card */
.user-dropdown-card {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 270px;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  animation: dropdownIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.user-dropdown-card.active {
  display: block;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.dropdown-user-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.dropdown-avatar-circle {
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  flex-shrink: 0;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

.modal-avatar-circle {
  width: 52px;
  height: 52px;
  min-width: 52px;
  min-height: 52px;
  flex-shrink: 0;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  box-shadow: 0 4px 14px rgba(34, 197, 94, 0.3);
}

.dropdown-user-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.dropdown-user-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-user-email {
  font-size: 0.73rem;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-role-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.25);
  margin-top: 4px;
}

.dropdown-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 10px 0;
}

.dropdown-item-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: transparent;
  border: none;
  color: #cbd5e1;
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  font-family: inherit;
}

.dropdown-item-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.dropdown-item-btn i {
  font-size: 1.05rem;
  color: #22c55e;
}

.dropdown-item-logout {
  color: #ef4444;
}

.dropdown-item-logout i {
  color: #ef4444;
}

.dropdown-item-logout:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
}

/* Sidebar Backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 101;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-backdrop.active {
  display: block;
  opacity: 1;
}

/* Admin Overall Layout */
.admin-layout {
  display: flex;
  min-height: 100vh;
  background: #0f172a;
  position: relative;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  box-sizing: border-box;
}

.admin-sidebar {
  width: 260px;
  background: rgba(15, 23, 42, 0.98);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 102;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  padding: 22px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.25rem;
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.7rem;
  color: #64748b;
}

.sidebar-close-btn {
  display: none;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #94a3b8;
  font-size: 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
}

.sidebar-menu {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.menu-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: #475569;
  font-weight: 700;
  padding: 12px 12px 6px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 500;
  color: #94a3b8;
  transition: all 0.2s ease;
  margin-bottom: 2px;
}

.sidebar-link i {
  font-size: 1.1rem;
  transition: transform 0.2s ease;
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.04);
  color: #e2e8f0;
}

.sidebar-link:hover i {
  transform: translateX(2px);
}

.sidebar-link.active {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.15), rgba(34, 197, 94, 0.05));
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.2);
  font-weight: 600;
}

.sidebar-link.active i {
  color: #22c55e;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.2);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #22c55e;
  font-size: 1rem;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.65rem;
  color: #64748b;
  text-transform: capitalize;
}

.btn-logout {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.btn-logout:hover {
  background: #ef4444;
  color: #fff;
}

/* Main Content Area */
.admin-main {
  flex: 1;
  margin-left: 260px;
  padding: 32px 36px;
  max-width: 1400px;
  width: calc(100% - 260px);
  min-width: 0; /* Critical fix for flex child overflow */
  box-sizing: border-box;
}

/* Screen Breakpoints */
@media (max-width: 1024px) {
  .admin-layout {
    flex-direction: column !important;
    max-width: 100vw !important;
    width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }
  .mobile-topbar {
    display: flex !important;
    width: 100% !important;
    max-width: 100vw !important;
    position: sticky;
    top: 0;
    z-index: 99;
    flex-shrink: 0;
    box-sizing: border-box !important;
  }
  .admin-sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px !important;
    max-width: 85vw;
    transform: translateX(-100%);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
    z-index: 1000 !important;
  }
  .admin-sidebar.mobile-open {
    transform: translateX(0) !important;
  }
  .sidebar-close-btn { display: flex !important; }
  .admin-main {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    flex: 1;
    min-width: 0 !important;
    padding: 20px 14px;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }
}

@media (max-width: 480px) {
  .admin-main {
    padding: 14px 10px !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
  }
  .mobile-topbar {
    padding: 10px 12px !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
  }
  .mobile-brand span {
    font-size: 0.88rem;
  }
}

@media (max-width: 360px) {
  .admin-main {
    padding: 12px 8px;
  }
  .mobile-brand span {
    font-size: 0.8rem;
  }
}

/* ============================================ */
/* PWA Custom Install Banner                    */
/* ============================================ */
.pwa-install-banner {
  position: fixed;
  bottom: 20px;
  left: 20px;
  right: 20px;
  max-width: 460px;
  margin: 0 auto;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(34, 197, 94, 0.3);
  backdrop-filter: blur(16px);
  border-radius: 16px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  z-index: 9999;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.5);
  animation: pwaSlideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pwaSlideUp {
  from { transform: translateY(100px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.pwa-banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.pwa-banner-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.pwa-banner-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.pwa-banner-text strong {
  font-size: 0.85rem;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pwa-banner-text span {
  font-size: 0.72rem;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pwa-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-pwa-install {
  padding: 8px 14px;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.2s;
}

.btn-pwa-install:hover {
  transform: translateY(-1px);
}

.btn-pwa-dismiss {
  background: transparent;
  border: none;
  color: #64748b;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.btn-pwa-dismiss:hover {
  color: #e2e8f0;
}

@media (max-width: 480px) {
  .pwa-install-banner {
    bottom: 12px;
    left: 12px;
    right: 12px;
    padding: 12px 14px;
  }
}

/* Custom Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.25); }

/* ============================================ */
/* Map & Scanner Styles                         */
/* ============================================ */

/* Leaflet map tile fix for global img max-width */
.leaflet-container img {
  max-width: none !important;
}

#map-container {
  height: 100vh;
  width: 100vw;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}

/* Scan Floating Action Button (FAB) */
.scan-fab {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  border: none;
  border-radius: 100px;
  padding: 16px 32px;
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 10px 25px rgba(0, 80, 170, 0.4);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.scan-fab:active {
  transform: translateX(-50%) scale(0.95);
}

.scan-fab i {
  font-size: 1.5rem;
}

/* ========================================================== */
/* Scanner Overlay Styles (Consistent Dark Glassmorphism)     */
/* ========================================================== */

#scanner-overlay,
.scanner-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(15, 23, 42, 0.98) !important;
    backdrop-filter: blur(24px) !important;
    -webkit-backdrop-filter: blur(24px) !important;
    z-index: 9999 !important;
    display: none !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    color: #f8fafc !important;
    overflow-y: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
}

#scanner-overlay.active,
.scanner-overlay.active {
    display: flex !important;
}

.scanner-header-new {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 16px 24px !important;
    width: 100% !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
    background: rgba(15, 23, 42, 0.9) !important;
    box-sizing: border-box !important;
}

.scanner-header-new .brand {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    height: auto !important;
    min-height: 40px !important;
}

.scanner-header-new .brand img,
.scanner-header-new .brand .brand-logo-img {
    height: 40px !important;
    max-height: 42px !important;
    max-width: 170px !important;
    width: auto !important;
    object-fit: contain !important;
    display: block !important;
}

.scanner-header-new .brand .bi {
    font-size: 1.4rem !important;
    color: #3b82f6 !important;
}

.scanner-header-new .brand-text {
    font-size: 1.15rem !important;
    font-weight: 700 !important;
    color: #f8fafc !important;
}

.scanner-header-new .close-btn {
    background: rgba(255, 255, 255, 0.08) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    color: #f8fafc !important;
    font-size: 1.2rem !important;
    cursor: pointer !important;
    width: 38px !important;
    height: 38px !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s ease !important;
    line-height: 1 !important;
    padding: 0 !important;
    flex-shrink: 0 !important;
}

.scanner-header-new .close-btn:hover {
    background: rgba(239, 68, 68, 0.25) !important;
    border-color: rgba(239, 68, 68, 0.5) !important;
    color: #ef4444 !important;
    transform: scale(1.05) !important;
}

.scanner-content-new {
    flex: 1 1 auto !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    padding: 24px 20px 32px !important;
    text-align: center !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

.scanner-title {
    font-size: 1.5rem !important;
    font-weight: 700 !important;
    color: #f8fafc !important;
    margin: 4px 0 8px 0 !important;
    letter-spacing: -0.3px !important;
}

.scanner-subtitle {
    font-size: 0.92rem !important;
    color: #94a3b8 !important;
    margin-bottom: 24px !important;
    max-width: 360px !important;
    line-height: 1.45 !important;
}

.scanner-camera-wrapper {
    position: relative !important;
    width: 280px !important;
    height: 280px !important;
    max-width: 80vw !important;
    max-height: 80vw !important;
    border-radius: 24px !important;
    overflow: hidden !important;
    margin: 0 auto 24px auto !important;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.12) !important;
    background: #020617 !important;
}

.scanner-camera-wrapper #reader {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    background: transparent !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

.scanner-camera-wrapper #reader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

.viewfinder-bracket {
    position: absolute !important;
    width: 36px !important;
    height: 36px !important;
    border: 3.5px solid #3b82f6 !important;
    z-index: 10 !important;
    pointer-events: none !important;
}

.bracket-tl { top: 14px; left: 14px; border-right: none !important; border-bottom: none !important; border-top-left-radius: 12px; }
.bracket-tr { top: 14px; right: 14px; border-left: none !important; border-bottom: none !important; border-top-right-radius: 12px; }
.bracket-bl { bottom: 14px; left: 14px; border-right: none !important; border-top: none !important; border-bottom-left-radius: 12px; }
.bracket-br { bottom: 14px; right: 14px; border-left: none !important; border-top: none !important; border-bottom-right-radius: 12px; }

.scanner-cancel-btn {
    margin-top: auto !important;
    margin-bottom: 16px !important;
    background: rgba(255, 255, 255, 0.08) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    color: #f8fafc !important;
    padding: 12px 28px !important;
    border-radius: 100px !important;
    font-weight: 600 !important;
    font-size: 0.95rem !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    transition: all 0.2s ease !important;
    backdrop-filter: blur(8px) !important;
    text-decoration: none !important;
}

.scanner-cancel-btn:hover {
    background: rgba(239, 68, 68, 0.2) !important;
    border-color: rgba(239, 68, 68, 0.4) !important;
    color: #fca5a5 !important;
    transform: translateY(-1px) !important;
}

.scanner-footer-text {
    font-size: 0.78rem !important;
    color: #64748b !important;
    text-align: center !important;
    margin-bottom: 8px !important;
    padding: 0 10px !important;
}

.scanner-developer-credit {
    font-size: 0.72rem !important;
    color: #64748b !important;
    text-align: center !important;
    position: relative !important;
    z-index: 10 !important;
}

.scanner-developer-credit a,
.scanner-dev-link {
    color: #94a3b8 !important;
    text-decoration: underline !important;
    transition: color 0.2s ease !important;
}

.scanner-developer-credit a:hover,
.scanner-dev-link:hover {
    color: #cbd5e1 !important;
}

/* Loading State */
.map-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(8px);
  padding: 16px 24px;
  border-radius: 30px;
  font-weight: 600;
  color: #f8fafc;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255,255,255,0.1);
}

.hidden {
  display: none !important;
}
