/* ========================================
   WASTE MANAGEMENT - SHARED DASHBOARD CSS
   ======================================== */

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

:root {
  --green-50: #f0fdf4;
  --green-100: #dcfce7;
  --green-200: #bbf7d0;
  --green-400: #4ade80;
  --green-500: #22c55e;
  --green-600: #16a34a;
  --green-700: #15803d;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --blue-500: #3b82f6;
  --blue-100: #dbeafe;
  --yellow-500: #eab308;
  --yellow-100: #fef9c3;
  --red-500: #ef4444;
  --red-100: #fee2e2;
  --orange-500: #f97316;
  --orange-100: #ffedd5;
  --white: #ffffff;
  --sidebar-width: 260px;
  --header-height: 64px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.22);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition: 0.2s ease;
}

/* Dark mode */
[data-theme="dark"] {
  --white: #1e293b;
  --gray-50: #0f172a;
  --gray-100: #1e293b;
  --gray-200: #334155;
  --gray-300: #475569;
  --gray-400: #64748b;
  --gray-500: #94a3b8;
  --gray-600: #cbd5e1;
  --gray-700: #e2e8f0;
  --gray-800: #f1f5f9;
  --gray-900: #f8fafc;
}

html, body {
  max-width: 100%;
  overflow-x: hidden;
}
body {
  font-family: var(--font);
  color: var(--gray-800);
  background: var(--gray-50);
  line-height: 1.5;
}
img, svg, video, canvas { max-width: 100%; height: auto; }
.main-content { min-width: 0; }
.page-content { min-width: 0; max-width: 100%; }

/* ---- LAYOUT ---- */
.dashboard-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 200;
  transition: transform var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: var(--header-height);
}
.sidebar-logo {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--gray-900);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.sidebar-logo .logo-icon { font-size: 1.3rem; }
.sidebar-logo-img {
  height: 46px;
  width: auto;
  max-width: 180px;
  object-fit: contain;
  display: block;
}
.sidebar-nav { flex: 1; padding: 1rem 0; }
.nav-section { margin-bottom: 0.5rem; }
.nav-section-title {
  padding: 0.4rem 1.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1.5rem;
  text-decoration: none;
  color: var(--gray-600);
  font-size: 0.9rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  position: relative;
}
.nav-item:hover {
  background: var(--gray-50);
  color: var(--green-600);
  border-left-color: var(--green-200);
}
.nav-item.active {
  background: var(--green-50);
  color: var(--green-700);
  border-left-color: var(--green-600);
  font-weight: 600;
}
.nav-item i { width: 18px; text-align: center; font-size: 0.95rem; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--red-500);
  color: var(--white);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
}
.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-100);
}
.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--green-600);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.user-details { flex: 1; min-width: 0; }
.user-name { font-size: 0.85rem; font-weight: 600; color: var(--gray-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.72rem; color: var(--gray-400); text-transform: capitalize; }
.logout-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--gray-100);
  color: var(--gray-500);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.logout-btn:hover { background: var(--red-100); color: var(--red-500); }

/* ---- MAIN CONTENT ---- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- TOP BAR ---- */
.topbar {
  height: var(--header-height);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gray-900);
  flex: 1;
}
.topbar-actions { display: flex; align-items: center; gap: 0.75rem; }
.topbar-btn {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--gray-100);
  color: var(--gray-600);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.topbar-btn:hover { background: var(--green-50); color: var(--green-600); }
.badge-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red-500);
  border: 2px solid var(--white);
}
.sidebar-toggle { display: none; }

/* ---- PAGE CONTENT ---- */
.page-content { padding: 1.5rem; flex: 1; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.page-header h1 {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--gray-900);
}
.page-header p { color: var(--gray-500); font-size: 0.9rem; margin-top: 0.25rem; }

/* ---- STATS GRID ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  transition: all var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.stat-icon.green { background: var(--green-100); color: var(--green-600); }
.stat-icon.blue { background: var(--blue-100); color: var(--blue-500); }
.stat-icon.yellow { background: var(--yellow-100); color: var(--yellow-500); }
.stat-icon.red { background: var(--red-100); color: var(--red-500); }
.stat-icon.orange { background: var(--orange-100); color: var(--orange-500); }
.stat-info { flex: 1; min-width: 0; }
.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--gray-900);
  line-height: 1;
  margin-bottom: 0.25rem;
}
.stat-label { font-size: 0.8rem; color: var(--gray-500); font-weight: 500; }
.stat-change {
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 0.25rem;
}
.stat-change.up { color: var(--green-600); }
.stat-change.down { color: var(--red-500); }

/* ---- CARD ---- */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--gray-100);
  gap: 1rem;
}
.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--gray-800);
}
.card-body { padding: 1.25rem; }
.card-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--gray-100);
  background: var(--gray-50);
}

/* ---- TABLES ---- */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
table { width: 100%; border-collapse: collapse; min-width: 600px; }

/* Responsive visibility helpers used on table headers/cells.
   Apply hide-md to less-essential columns; they vanish on tablets.
   Apply hide-sm to lowest-priority columns; they vanish on phones. */
@media (max-width: 768px) { .hide-md { display: none !important; } }
@media (max-width: 480px) { .hide-sm { display: none !important; } table { min-width: 0; } }
thead th {
  padding: 0.75rem 1rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gray-500);
  text-align: left;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
tbody td {
  padding: 0.85rem 1rem;
  font-size: 0.875rem;
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
tbody tr:hover { background: var(--gray-50); }
tbody tr:last-child td { border-bottom: none; }

/* ---- BADGES ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: var(--green-100); color: var(--green-700); }
.badge-warning { background: var(--yellow-100); color: #854d0e; }
.badge-danger { background: var(--red-100); color: #991b1b; }
.badge-info { background: var(--blue-100); color: #1d4ed8; }
.badge-secondary { background: var(--gray-100); color: var(--gray-600); }
.badge-orange { background: var(--orange-100); color: #9a3412; }

/* ---- FORMS ---- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-700);
}
.form-control {
  padding: 0.7rem 1rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--gray-800);
  background: var(--white);
  transition: border-color var(--transition);
  width: 100%;
}
.form-control:focus {
  outline: none;
  border-color: var(--green-500);
  box-shadow: 0 0 0 3px rgba(34,197,94,0.12);
}
.form-control.error { border-color: var(--red-500); }
.form-error { font-size: 0.8rem; color: var(--red-500); margin-top: 0.25rem; }
.form-hint { font-size: 0.8rem; color: var(--gray-400); margin-top: 0.25rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--green-600); color: var(--white); border-color: var(--green-600); }
.btn-primary:hover { background: var(--green-700); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border-color: var(--gray-200); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-danger { background: var(--red-500); color: var(--white); border-color: var(--red-500); }
.btn-danger:hover { background: #dc2626; }
.btn-outline { background: transparent; color: var(--green-600); border-color: var(--green-500); }
.btn-outline:hover { background: var(--green-50); }
.btn-sm { padding: 0.4rem 0.85rem; font-size: 0.8rem; }
.btn-icon { padding: 0.5rem; width: 34px; height: 34px; }
.btn-full { width: 100%; }

/* ---- MODALS ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform var(--transition);
  box-shadow: var(--shadow-lg);
}
.modal-overlay.open .modal { transform: scale(1); }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-100);
}
.modal-title { font-size: 1rem; font-weight: 700; color: var(--gray-900); }
.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--gray-100);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
  transition: all var(--transition);
}
.modal-close:hover { background: var(--red-100); color: var(--red-500); }
.modal-body { padding: 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-100);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* ---- TOAST NOTIFICATIONS ---- */
.toast-container {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow-lg);
  min-width: 280px;
  max-width: 380px;
  pointer-events: all;
  transform: translateX(120%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  border-left: 4px solid transparent;
}
.toast.show { transform: translateX(0); }
.toast.success { border-left-color: var(--green-500); }
.toast.error { border-left-color: var(--red-500); }
.toast.warning { border-left-color: var(--yellow-500); }
.toast.info { border-left-color: var(--blue-500); }
.toast-icon { font-size: 1rem; flex-shrink: 0; }
.toast.success .toast-icon { color: var(--green-500); }
.toast.error .toast-icon { color: var(--red-500); }
.toast.warning .toast-icon { color: var(--yellow-500); }
.toast.info .toast-icon { color: var(--blue-500); }
.toast-content { flex: 1; }
.toast-title { font-size: 0.85rem; font-weight: 700; color: var(--gray-800); }
.toast-message { font-size: 0.8rem; color: var(--gray-500); margin-top: 0.15rem; }
.toast-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray-400);
  padding: 0.1rem;
  font-size: 0.8rem;
  flex-shrink: 0;
}

/* ---- LOADING STATES ---- */
.skeleton {
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--green-600);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: inherit;
}

/* ---- SEARCH & FILTER BAR ---- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}
.search-input-wrapper {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}
.search-input-wrapper i {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  font-size: 0.9rem;
  pointer-events: none;
}
.search-input-wrapper input {
  padding-left: 2.5rem;
  width: 100%;
}

/* ---- PAGINATION ---- */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.pagination-btn {
  min-width: 34px;
  height: 34px;
  border: 1px solid var(--gray-200);
  background: var(--white);
  color: var(--gray-600);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all var(--transition);
  font-family: var(--font);
  padding: 0 0.5rem;
}
.pagination-btn:hover { border-color: var(--green-500); color: var(--green-600); }
.pagination-btn.active { background: var(--green-600); color: var(--white); border-color: var(--green-600); }
.pagination-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- EMPTY STATE ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  text-align: center;
}
.empty-icon { font-size: 3rem; color: var(--gray-200); margin-bottom: 1rem; }
.empty-title { font-size: 1rem; font-weight: 600; color: var(--gray-600); margin-bottom: 0.4rem; }
.empty-subtitle { font-size: 0.875rem; color: var(--gray-400); }

/* ---- AVATAR ---- */
.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: var(--green-600);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.avatar-sm { width: 30px; height: 30px; font-size: 0.7rem; }
.avatar-md { width: 40px; height: 40px; font-size: 0.85rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1rem; }
.avatar-xl { width: 80px; height: 80px; font-size: 1.3rem; }

/* ---- UTILS ---- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-2 { margin-bottom: 1rem; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--gray-400); }
.text-success { color: var(--green-600); }
.text-danger { color: var(--red-500); }
.font-bold { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

/* ---- CHART CONTAINER ---- */
.chart-container { position: relative; }

/* ---- MAP ---- */
#map { min-height: 400px; border-radius: var(--radius); border: 1px solid var(--gray-200); }

/* ---- FILE UPLOAD ---- */
.file-upload-area {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--gray-50);
}
.file-upload-area:hover, .file-upload-area.drag-over {
  border-color: var(--green-500);
  background: var(--green-50);
}
.file-preview { margin-top: 1rem; display: flex; align-items: center; gap: 0.75rem; }
.file-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: var(--radius-sm); }

/* ---- SIDEBAR OVERLAY (injected by initSidebar) ---- */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 199;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.sidebar-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ---- PERFORMANCE HINTS ---- */
.sidebar          { will-change: transform; }
.modal-overlay    { will-change: opacity, visibility; }
.toast            { will-change: transform; }
.skeleton         { contain: strict; }

/* ---- TOUCH-FRIENDLY MINIMUM TARGETS ---- */
.nav-item,
.btn,
.logout-btn,
.topbar-btn,
.pagination-btn { min-height: 44px; }
.logout-btn { width: 36px; height: 36px; min-height: 36px; }

/* ---- SCROLLABLE SIDEBAR NAV (long menus on small heights) ---- */
.sidebar-nav { overflow-y: auto; overflow-x: hidden; }

/* ---- TOPBAR RESPONSIVE TITLE TRUNCATE ---- */
.topbar-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- MOBILE: tablets and phones ---- */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }
  .main-content   { margin-left: 0; }
  .sidebar-toggle { display: flex; }

  /* Stats: 2 columns on tablet */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  .page-content { padding: 1rem; }

  /* Collapse multi-col grids */
  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  .page-header h1 { font-size: 1.15rem; }

  /* Modal fits viewport */
  .modal { max-width: calc(100vw - 2rem); margin: 1rem; }
  .modal-footer { flex-wrap: wrap; }
  .modal-footer .btn { flex: 1; min-width: 120px; }

  .sidebar-logo-img { height: 38px; max-width: 150px; }

  /* Cards: allow header to wrap */
  .card-header { flex-wrap: wrap; row-gap: 0.5rem; }

  /* Charts take full width */
  .chart-container canvas { max-width: 100%; }

  /* Filter bar wraps */
  .filter-bar { flex-wrap: wrap; }
  .search-input-wrapper { min-width: 0; flex: 1 1 200px; max-width: 100%; }
}

/* ---- MOBILE: phones ---- */
@media (max-width: 480px) {
  /* Stats: 1 column on phone */
  .stats-grid { grid-template-columns: 1fr; }
  .stat-value  { font-size: 1.35rem; }

  /* Full-width filter bar — !important defeats the inline width:140px etc.
     that legacy pages still set on filter selects/inputs/date pickers. */
  .filter-bar  { flex-direction: column; align-items: stretch; }
  .filter-bar select,
  .filter-bar input,
  .filter-bar button { width: 100% !important; }

  /* Page header stacks */
  .page-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .page-header > div:last-child { width: 100%; }
  .page-header > div:last-child .btn,
  .page-header > div:last-child a { width: 100%; justify-content: center; }

  /* Card body padding reduction */
  .card-body { padding: 1rem; }
  .card-header { padding: 0.85rem 1rem; }

  /* Topbar compact */
  .topbar { padding: 0 0.85rem; gap: 0.5rem; }
  .topbar-title { font-size: 0.9rem; }
  .topbar-actions { gap: 0.4rem; }
  .topbar-btn { width: 34px; height: 34px; }

  /* Toast full-width on phone */
  .toast-container { left: 1rem; right: 1rem; top: 1rem; }
  .toast { min-width: 0; max-width: 100%; }

  /* Modals: full-screen on tiny screens */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    margin: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 92vh;
  }

  /* Pagination wraps more compactly */
  .pagination-btn { min-width: 36px; height: 36px; font-size: 0.8rem; }

  /* Sidebar footer: narrower */
  .sidebar-footer { padding: 0.85rem 1rem; }
  .user-name  { font-size: 0.8rem; }

  /* Tables: ensure horizontal scroll works */
  .table-wrapper { -webkit-overflow-scrolling: touch; }
}

/* ---- VERY SMALL PHONES (360px) ---- */
@media (max-width: 390px) {
  .page-content { padding: 0.75rem; }
  .stats-grid   { gap: 0.6rem; }
  .stat-card    { padding: 0.9rem; }
}

/* ---- LANDSCAPE PHONES ---- */
@media (max-width: 768px) and (orientation: landscape) {
  .sidebar { max-height: 100dvh; }
  .modal   { max-height: 90dvh; }
}

/* ---- iOS SAFE AREAS ---- */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .sidebar-footer {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }
  .topbar {
    padding-top: env(safe-area-inset-top, 0);
  }
}

/* ---- DARK MODE MOBILE OVERLAY ---- */
[data-theme="dark"] .sidebar-overlay { background: rgba(0,0,0,0.65); }
