/* ==========================================================================
   HELTARA GREASE TRAP SOLUTIONS - DESIGN SYSTEM
   Brand Colors: HELTARA Red (#D7192D), Dark Navy (#0F3D5E), Orange (#F57C00)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@500;600;700;800;900&display=swap');

:root {
  /* Brand Palette */
  --primary: #D7192D;
  --primary-hover: #BA1222;
  --primary-light: #FEE2E2;
  --primary-soft: rgba(215, 25, 45, 0.08);

  --secondary: #0F3D5E;
  --secondary-hover: #0A2B42;
  --secondary-light: #E0F2FE;

  --accent: #F57C00;
  --accent-light: #FFEDD5;

  /* Surfaces & Backgrounds */
  --bg-app: #F8FAFC;
  --surface: #FFFFFF;
  --surface-alt: #F1F5F9;
  --surface-card: #FFFFFF;

  /* Industrial Slates & Text */
  --dark-slate: #1E293B;
  --darker-slate: #0F172A;
  --text-main: #1E293B;
  --text-muted: #64748B;
  --text-light: #94A3B8;
  --text-inverse: #FFFFFF;

  /* Borders & Dividers */
  --border-color: #E2E8F0;
  --border-strong: #CBD5E1;
  --border-focus: #D7192D;

  /* Semantic Feedback */
  --color-success: #10B981;
  --color-success-bg: #ECFDF5;
  --color-warning: #F59E0B;
  --color-warning-bg: #FFFBEB;
  --color-danger: #EF4444;
  --color-danger-bg: #FEF2F2;
  --color-info: #3B82F6;
  --color-info-bg: #EFF6FF;

  /* Priority Tokens */
  --priority-hot: #DC2626;
  --priority-hot-bg: #FEE2E2;
  --priority-warm: #D97706;
  --priority-warm-bg: #FEF3C7;
  --priority-cold: #2563EB;
  --priority-cold-bg: #DBEAFE;

  /* Elevation & Shadows */
  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.08), 0 1px 2px 0 rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  /* Geometry */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  /* Dimensions */
  --sidebar-width: 256px;
  --sidebar-collapsed-width: 72px;
  --header-height: 64px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-main);
  background-color: var(--bg-app);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  color: var(--dark-slate);
  letter-spacing: -0.02em;
}

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

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

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

/* ==========================================================================
   APP SHELL LAYOUT
   ========================================================================== */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--darker-slate);
  color: var(--text-inverse);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition-normal);
  z-index: 40;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  text-decoration: none;
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--primary), #B91323);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFF;
  font-family: 'Outfit', sans-serif;
  font-weight: 900;
  font-size: 20px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(215, 25, 45, 0.4);
}

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

.brand-name {
  font-family: 'Outfit', sans-serif;
  font-weight: 900;
  font-size: 19px;
  color: #FFF;
  letter-spacing: 0.5px;
}

.brand-subtitle {
  font-size: 8.5px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.sidebar.collapsed .brand-text {
  display: none;
}

.btn-toggle-sidebar {
  background: transparent;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-toggle-sidebar:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #FFF;
}

/* Nav Menu */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: #94A3B8;
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  margin-bottom: 2px;
  transition: all var(--transition-fast);
  cursor: pointer;
  position: relative;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #FFFFFF;
}

.nav-item.active {
  background: var(--primary);
  color: #FFFFFF;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(215, 25, 45, 0.35);
}

.nav-item .nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-item .nav-label {
  flex: 1;
  white-space: nowrap;
}

.sidebar.collapsed .nav-label {
  display: none;
}

.nav-badge {
  background: rgba(255, 255, 255, 0.18);
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

.nav-badge.danger {
  background: #EF4444;
}

.nav-badge.warning {
  background: #F59E0B;
}

.sidebar.collapsed .nav-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  padding: 2px 5px;
  font-size: 9px;
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-light);
}

/* Main Content Area */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Top App Header */
.topbar {
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  z-index: 30;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  max-width: 540px;
}

.global-search-container {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 38px;
  padding: 0 40px 0 36px;
  background: var(--surface-alt);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  outline: none;
  font-size: 13.5px;
  transition: all var(--transition-fast);
}

.search-input:focus {
  background: #FFFFFF;
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(15, 61, 94, 0.1);
}

.search-shortcut {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  background: #E2E8F0;
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.role-switcher-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-alt);
  padding: 4px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  font-size: 12.5px;
}

.role-switcher-box label {
  color: var(--text-muted);
  font-weight: 500;
}

.role-select {
  background: transparent;
  border: none;
  color: var(--secondary);
  font-weight: 700;
  outline: none;
  cursor: pointer;
}

.btn-quick-lead {
  background: var(--primary);
  color: #FFF;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(215, 25, 45, 0.25);
  transition: all var(--transition-fast);
}

.btn-quick-lead:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(215, 25, 45, 0.35);
}

.btn-apk-download:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

/* Windows App Download Button */
.btn-windows-download {
  background: linear-gradient(135deg, #0284C7, #0369A1);
  color: #FFFFFF !important;
  font-weight: 700;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(2, 132, 199, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn-windows-download:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.4);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 8px;
  border-left: 1px solid var(--border-color);
}

.user-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--secondary), #1A547E);
  color: #FFF;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.user-details {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-weight: 600;
  font-size: 13px;
  line-height: 1.2;
}

.user-role-badge {
  font-size: 11px;
  color: var(--text-muted);
}

/* Page Scroll Container */
.page-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  -webkit-overflow-scrolling: touch;
}

/* --------------------------------------------------------------------------
 * MOBILE COMPONENTS & PWA UI SYSTEM
 * -------------------------------------------------------------------------- */
.btn-mobile-menu {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-dark);
  cursor: pointer;
  padding: 8px;
  margin-right: 8px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
}
.btn-mobile-menu:active {
  background: #F1F5F9;
}

.mobile-brand-title {
  display: none;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  margin-right: 12px;
}
.m-brand-red {
  font-family: var(--font-heading);
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 1px;
  color: var(--primary);
}
.m-brand-sub {
  font-size: 10px;
  font-weight: 800;
  background: var(--dark-slate);
  color: #FFF;
  padding: 2px 6px;
  border-radius: 4px;
}

.btn-pwa-install {
  background: linear-gradient(135deg, #1E293B, #0F172A);
  color: #F8FAFC;
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  animation: pulsePwa 2.5s infinite;
}
@keyframes pulsePwa {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); box-shadow: 0 4px 12px rgba(215, 25, 45, 0.25); }
}

/* Mobile Floating Action Button (FAB) */
.mobile-fab {
  display: none;
  position: fixed;
  bottom: 84px;
  right: 18px;
  width: 54px;
  height: 54px;
  border-radius: 27px;
  background: linear-gradient(135deg, #EF4444 0%, #D7192D 100%);
  color: #FFFFFF;
  border: none;
  box-shadow: 0 8px 24px rgba(215, 25, 45, 0.45), 0 2px 8px rgba(0,0,0,0.2);
  align-items: center;
  justify-content: center;
  z-index: 90;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
  touch-action: manipulation;
}
.mobile-fab:active {
  transform: scale(0.92);
}

/* Mobile Bottom Navigation Bar */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: rgba(15, 23, 42, 0.98);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0 10px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.25);
  justify-content: space-around;
  align-items: center;
}

.mobile-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #94A3B8;
  text-decoration: none;
  height: 100%;
  position: relative;
  transition: color 0.15s ease, transform 0.15s ease;
  touch-action: manipulation;
}
.mobile-nav-item:active {
  transform: scale(0.92);
}
.mobile-nav-item.active {
  color: #EF4444;
}
.mobile-nav-item.active .mobile-nav-icon {
  filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.5));
}
.mobile-nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 3px;
}
.mobile-nav-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.mobile-nav-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  background: var(--primary);
  color: #FFF;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 10px;
  min-width: 16px;
  text-align: center;
}
.mobile-nav-badge.overdue-dot {
  width: 8px;
  height: 8px;
  min-width: 8px;
  padding: 0;
  border-radius: 50%;
  top: 8px;
  right: calc(50% - 12px);
  background: #EF4444;
  box-shadow: 0 0 6px #EF4444;
  animation: pulseDot 1.5s infinite;
}
@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.4); }
}

/* Mobile Slide-Over Drawer */
.mobile-drawer-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.mobile-drawer-overlay.open {
  display: block;
  opacity: 1;
}

.mobile-drawer {
  position: fixed;
  top: 0;
  right: -320px;
  width: 300px;
  max-width: 85vw;
  height: 100vh;
  background: #FFFFFF;
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.2);
  z-index: 210;
  display: flex;
  flex-direction: column;
  transition: right 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}
.mobile-drawer.open {
  right: 0;
}

.mobile-drawer-header {
  padding: 20px;
  background: var(--dark-slate);
  color: #FFF;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.btn-close-drawer {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #FFF;
  font-size: 16px;
  width: 32px;
  height: 32px;
  border-radius: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-drawer-user {
  padding: 14px 20px;
  background: #F8FAFC;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 12px;
}

.mobile-drawer-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}
.mobile-drawer-section {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--text-muted);
  padding: 12px 20px 6px 20px;
}
.drawer-nav-item {
  display: flex;
  align-items: center;
  padding: 11px 20px;
  color: var(--text-dark);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s;
}
.drawer-nav-item:active {
  background: #F1F5F9;
}

.mobile-drawer-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  background: #F8FAFC;
}

/* --------------------------------------------------------------------------
 * RESPONSIVE BREAKPOINTS (Mobile & Tablet)
 * -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .sidebar {
    display: none;
  }
  
  .btn-mobile-menu {
    display: flex;
  }
  
  .mobile-brand-title {
    display: flex;
  }

  .global-search-container {
    display: none; /* Collapsed on mobile for clean header */
  }

  .user-profile {
    display: none; /* Accessible in mobile drawer */
  }

  .topbar {
    padding: 0 12px;
    height: 54px;
  }

  .topbar-right {
    gap: 8px;
  }

  .topbar-right .btn-windows-download,
  .topbar-right .btn-apk-download {
    display: none !important; /* Retained cleanly inside Mobile Drawer */
  }

  .page-container {
    padding: 12px;
    padding-bottom: calc(85px + env(safe-area-inset-bottom, 0px)); /* Safe space for bottom nav & FAB */
  }

  .mobile-bottom-nav {
    display: flex;
    height: 60px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .mobile-fab {
    display: flex;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    width: 52px;
    height: 52px;
  }

  .btn-quick-lead {
    display: none; /* Use FAB instead */
  }

  .role-switcher-box select {
    font-size: 12px;
    padding: 4px 6px;
    max-width: 120px;
  }

  /* Responsive Cards & Grids */
  .metrics-grid, .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
  .metric-card, .stat-card {
    padding: 12px 14px !important;
    border-radius: 12px !important;
  }
  .metric-value, .stat-value {
    font-size: 22px !important;
  }

  /* Modals on Mobile: Native Bottom Sheet appearance */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
    z-index: 2500 !important;
  }
  .modal-dialog, .modal-card {
    border-radius: 20px 20px 0 0 !important;
    max-height: 92vh !important;
    max-height: 92dvh !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    animation: sheetSlideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4) !important;
  }

  .modal-header {
    flex-shrink: 0;
    padding: 14px 18px !important;
  }

  .modal-body {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 16px 18px !important;
    max-height: none !important;
  }

  .modal-footer {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    background: #FFFFFF !important;
    border-top: 1px solid var(--border-color);
    padding: 12px 18px !important;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
    z-index: 20;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
  }

  #edit-lead-form, #quick-add-form, #lost-reason-form, #reassign-lead-form {
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 auto !important;
    overflow: hidden !important;
  }

  @keyframes sheetSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  .form-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .form-grid .col-span-2 {
    grid-column: span 1 !important;
  }

  .form-input, .form-select, .form-textarea {
    font-size: 16px !important; /* Prevents auto-zoom on mobile Android/iOS */
    min-height: 44px;
    touch-action: manipulation;
  }
}

@media (max-width: 480px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 14px;
  }
  .page-title-group h1 {
    font-size: 20px !important;
  }
  .page-subtitle {
    font-size: 12px !important;
  }
  .page-actions {
    width: 100%;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }
  .page-actions .btn {
    flex: 1;
    min-width: 120px;
    font-size: 12px;
  }
}


