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

/* ═══════════════════════════════════════════════════════════════
   DESIGN TOKENS
   ═══════════════════════════════════════════════════════════════ */
:root {
  --kitkat-red: #C8102E;
  --kitkat-red-hover: #A50A24;
  --kitkat-red-soft: #FFE4E6;
  --kitkat-cocoa: #2D1500;
  --kitkat-chocolate: #4A2810;
  --kitkat-wafer-gold: #D4A373;
  --nescafe-ice-blue: #00A3E0;
  --nescafe-cyan: #06B6D4;
  --nescafe-frost-bg: #F0F9FF;

  --bg-gradient: linear-gradient(165deg, #2D1500 0%, #4A2810 30%, #0B192C 70%, #003049 100%);
  --panel-bg: rgba(255, 255, 255, 0.96);
  --panel-glass: rgba(255, 255, 255, 0.88);
  --panel-dark: #0B192C;
  --surface: #ffffff;

  --primary: #C8102E;
  --primary-hover: #A50A24;
  --primary-soft: #FFE4E6;

  --ice-accent: #00A3E0;
  --ice-soft: #E0F2FE;

  --success: #10B981;
  --success-soft: #D1FAE5;
  --warning: #F59E0B;
  --warning-soft: #FEF3C7;
  --danger: #EF4444;
  --danger-soft: #FEE2E2;
  --info: #0284C7;
  --info-soft: #E0F2FE;

  --text: #1E1B18;
  --text-muted: #64748B;
  --text-secondary: #475569;
  --border: #E2E8F0;
  --shadow-sm: 0 3px 6px rgba(0,0,0,0.06);
  --shadow-md: 0 10px 30px -5px rgba(45,21,0,0.12), 0 4px 12px -2px rgba(0,163,224,0.08);
  --shadow-lg: 0 20px 40px -10px rgba(11,25,44,0.22);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;
  --transition: all 0.22s cubic-bezier(0.4,0,0.2,1);

  /* Fluid spacing scale */
  --space-xs: clamp(4px, 1vw, 8px);
  --space-sm: clamp(8px, 1.5vw, 14px);
  --space-md: clamp(12px, 2vw, 20px);
  --space-lg: clamp(16px, 2.5vw, 28px);
  --space-xl: clamp(20px, 3vw, 36px);

  /* Fluid font scale */
  --fs-xs: clamp(0.7rem, 1.5vw, 0.8rem);
  --fs-sm: clamp(0.78rem, 1.8vw, 0.88rem);
  --fs-base: clamp(0.875rem, 2vw, 1rem);
  --fs-md: clamp(0.95rem, 2.2vw, 1.1rem);
  --fs-lg: clamp(1.1rem, 2.5vw, 1.35rem);
  --fs-xl: clamp(1.3rem, 3vw, 1.7rem);
  --fs-2xl: clamp(1.6rem, 4vw, 2.2rem);
}

/* ═══════════════════════════════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════════════════════════════ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  /* DO NOT set overflow:hidden here — it breaks mobile scrolling */
  height: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: 'Cairo', 'Inter', system-ui, -apple-system, sans-serif;
  background: #f8fafc;
  color: var(--text);
  min-height: 100%;
  direction: rtl;
  text-align: right;
  line-height: 1.6;
  font-size: var(--fs-base);
  /* DO NOT set overflow:hidden here — it breaks iOS Safari scrolling */
}

body[dir="ltr"] {
  direction: ltr;
  text-align: left;
}

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

img, svg, video, canvas {
  max-width: 100%;
  height: auto;
}

/* ═══════════════════════════════════════════════════════════════
   APP SHELL — THE CORE LAYOUT
   Desktop: sidebar fixed left/right + main scrolls
   Mobile:  sidebar is a drawer overlay, main panel scrolls
   ═══════════════════════════════════════════════════════════════ */
.app-shell {
  display: flex;
  width: 100%;
  height: 100dvh;
  height: 100vh; /* fallback */
  position: relative;
  /* Desktop: do NOT set overflow:hidden on app-shell itself;
     instead let sidebar scroll internally & main-panel handle its own scroll */
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════════ */
.sidebar {
  width: clamp(240px, 22vw, 290px);
  background: var(--bg-gradient);
  color: #f8fafc;
  padding: var(--space-lg) var(--space-md);
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 25px rgba(0,0,0,0.15);
  z-index: 50;
  height: 100%;
  flex: 0 0 clamp(240px, 22vw, 290px);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-track { background: rgba(0,0,0,0.15); border-radius: 10px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.25); border-radius: 10px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.45); }

.brand-box {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.brand-mark {
  width: clamp(40px, 6vw, 50px);
  height: clamp(40px, 6vw, 50px);
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #38bdf8 0%, #0284c7 100%);
  border-radius: 14px;
  font-size: clamp(1.3rem, 3vw, 1.6rem);
  box-shadow: 0 0 20px rgba(56,189,248,0.4);
  flex-shrink: 0;
}

.brand-name {
  font-weight: 800;
  font-size: var(--fs-md);
  color: #ffffff;
  letter-spacing: -0.5px;
}

.brand-sub {
  font-size: var(--fs-xs);
  color: #94a3b8;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: var(--space-xl);
}

.nav-item {
  border: none;
  background: transparent;
  color: #cbd5e1;
  border-radius: var(--radius-md);
  padding: clamp(10px, 1.5vw, 14px) clamp(12px, 2vw, 16px);
  font-weight: 600;
  font-size: var(--fs-sm);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: var(--transition);
  min-height: 44px;
  width: 100%;
  text-align: start;
}

.nav-item:hover, .nav-item:focus-visible {
  background: rgba(255,255,255,0.08);
  color: #ffffff;
  outline: none;
}

.nav-item.active {
  background: linear-gradient(135deg, #0284c7 0%, #0d9488 100%);
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(2,132,199,0.35);
}

.nav-badge {
  margin-inline-start: auto;
  background: #ef4444;
  color: white;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
}

/* Vault nav special golden glow */
.nav-vault {
  background: linear-gradient(135deg, rgba(245,158,11,0.15) 0%, rgba(217,119,6,0.12) 100%);
  color: #fcd34d !important;
  border: 1px solid rgba(245,158,11,0.25);
}
.nav-vault:hover {
  background: linear-gradient(135deg, rgba(245,158,11,0.28) 0%, rgba(217,119,6,0.22) 100%) !important;
  color: #fde68a !important;
  box-shadow: 0 0 12px rgba(245,158,11,0.3);
}
.nav-vault.active {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%) !important;
  color: #ffffff !important;
  box-shadow: 0 4px 16px rgba(245,158,11,0.45);
}

/* Mobile Sidebar Backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.55);
  z-index: 40;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-backdrop.open {
  display: block !important;
  pointer-events: auto !important;
  opacity: 1 !important;
}

/* ═══════════════════════════════════════════════════════════════
   MAIN PANEL — THE SCROLLABLE CONTENT AREA
   KEY: On desktop, main-panel uses overflow-y:auto for its own
   scroll. On mobile, it's the only scrollable container.
   ═══════════════════════════════════════════════════════════════ */
.main-panel {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-lg);
  padding-bottom: calc(var(--space-lg) + env(safe-area-inset-bottom, 0px));
}

.main-panel::-webkit-scrollbar { width: 7px; }
.main-panel::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 8px; }
.main-panel::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; border: 2px solid #f1f5f9; }
.main-panel::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Content view — not the scroller, just a natural-height flex child */
#contentView {
  flex: 1 0 auto;
  min-height: 0;
  width: 100%;
}

/* ═══════════════════════════════════════════════════════════════
   TOPBAR
   ═══════════════════════════════════════════════════════════════ */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  margin-bottom: var(--space-md);
  gap: var(--space-sm);
  flex-wrap: wrap;
  position: sticky;
  top: calc(-1 * var(--space-lg));
  background: #f8fafc;
  z-index: 10;
  padding-top: var(--space-xs);
  padding-bottom: var(--space-xs);
}

.mobile-toggle {
  display: none;
  background: #ffffff;
  border: 1px solid var(--border);
  font-size: 1.3rem;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  min-height: 40px;
  align-items: center;
  justify-content: center;
}

.topbar-brand, .topbar-title, .section-title {
  min-width: 0;
}

.topbar-title h1 {
  font-size: var(--fs-xl);
  font-weight: 800;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-title p {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.lang-button {
  border: 1px solid var(--border);
  background: #ffffff;
  color: #0f172a;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  min-height: 40px;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #ffffff;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.role-pill {
  font-size: var(--fs-xs);
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}

.logout-btn {
  background: #fee2e2;
  color: #dc2626;
  border: none;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s ease;
}
.logout-btn:hover { background: #fca5a5; }

/* ═══════════════════════════════════════════════════════════════
   SUMMARY / STATS SECTION
   ═══════════════════════════════════════════════════════════════ */
#summaryWrap {
  display: block;
  flex-shrink: 0;
  margin-bottom: var(--space-md);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(clamp(140px, 20vw, 190px), 1fr));
  gap: var(--space-sm);
}

.stat-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: clamp(10px, 2vw, 18px) clamp(12px, 2.5vw, 20px);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.5vw, 14px);
  cursor: pointer;
  user-select: none;
  touch-action: pan-y;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--kitkat-red), var(--nescafe-ice-blue));
  opacity: 0;
  transition: opacity 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 28px -5px rgba(200,16,46,0.15), 0 8px 16px -4px rgba(0,163,224,0.12);
  border-color: rgba(0,163,224,0.3);
}
.stat-card:hover::after { opacity: 1; }
.stat-card:active { transform: scale(0.97); box-shadow: var(--shadow-sm); }

.stat-icon {
  width: clamp(36px, 6vw, 52px);
  height: clamp(36px, 6vw, 52px);
  border-radius: clamp(10px, 2vw, 14px);
  display: grid;
  place-items: center;
  font-size: clamp(1.1rem, 3vw, 1.55rem);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}
.stat-card:hover .stat-icon { transform: scale(1.08); }

.stat-icon.kitkat-red   { background: linear-gradient(135deg, #FFE4E6 0%, #FECDD3 100%); color: #C8102E; }
.stat-icon.kitkat-cocoa { background: linear-gradient(135deg, #F5EBE6 0%, #E8D5C8 100%); color: #4A2810; }
.stat-icon.nescafe-ice  { background: linear-gradient(135deg, #E0F2FE 0%, #BAE6FD 100%); color: #00A3E0; }
.stat-icon.nescafe-cyan { background: linear-gradient(135deg, #CFFAFE 0%, #A5F3FC 100%); color: #0891B2; }
.stat-icon.primary  { background: #e0f2fe; color: #0284c7; }
.stat-icon.success  { background: #d1fae5; color: #10b981; }
.stat-icon.warning  { background: #fef3c7; color: #f59e0b; }
.stat-icon.danger   { background: #fee2e2; color: #ef4444; }

.stat-info { display: flex; flex-direction: column; min-width: 0; }
.stat-label { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 600; }
.stat-value { font-size: clamp(1.15rem, 3vw, 1.55rem); font-weight: 800; color: #0f172a; line-height: 1.2; }

/* ═══════════════════════════════════════════════════════════════
   CONTENT BOX (main section wrapper)
   ═══════════════════════════════════════════════════════════════ */
.content-box {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  box-shadow: var(--shadow-md);
  width: 100%;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.section-title h2 {
  font-size: var(--fs-lg);
  font-weight: 800;
  color: #0f172a;
}

.section-actions {
  display: flex;
  gap: var(--space-xs);
  flex-wrap: wrap;
  align-items: center;
}

/* ═══════════════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════════════ */
.btn {
  padding: clamp(7px, 1.5vw, 10px) clamp(12px, 2.5vw, 20px);
  border-radius: var(--radius-sm);
  font-weight: 700;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: var(--transition);
  min-height: 40px;
  font-size: var(--fs-sm);
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-outline { background: white; border: 1px solid var(--border); color: #0f172a; }
.btn-outline:hover { background: #f8fafc; }

/* ═══════════════════════════════════════════════════════════════
   FILTER BARS
   ═══════════════════════════════════════════════════════════════ */
.filter-bar {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
  margin-bottom: var(--space-md);
  background: #f8fafc;
  padding: var(--space-sm);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.filter-input, .filter-select {
  padding: clamp(7px, 1.5vw, 10px) clamp(10px, 2vw, 14px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: white;
  outline: none;
  flex: 1;
  min-width: clamp(120px, 20vw, 180px);
  min-height: 40px;
  font-size: var(--fs-sm);
}
.filter-input:focus, .filter-select:focus { border-color: var(--primary); }

/* ═══════════════════════════════════════════════════════════════
   TABLE & TABLE WRAPPER
   KEY: .table-responsive wraps tables and allows horizontal scroll
   ═══════════════════════════════════════════════════════════════ */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  touch-action: pan-x pan-y;
  margin-top: var(--space-xs);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

th {
  background: #f1f5f9;
  color: #475569;
  font-weight: 700;
  font-size: var(--fs-sm);
  padding: clamp(9px, 1.5vw, 13px) clamp(10px, 2vw, 15px);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

td {
  padding: clamp(9px, 1.5vw, 13px) clamp(10px, 2vw, 15px);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm);
  color: #334155;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

/* ═══════════════════════════════════════════════════════════════
   STATUS BADGES
   ═══════════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: var(--fs-xs);
  font-weight: 700;
  white-space: nowrap;
}

.badge-active     { background: #D1FAE5; color: #065F46; border: 1px solid #6EE7B7; }
.badge-rih        { background: #D1FAE5; color: #065F46; border: 1px solid #6EE7B7; }
.badge-maintenance{ background: #FEF3C7; color: #92400E; border: 1px solid #FDE68A; }
.badge-writeoff   { background: #FFEDD5; color: #9A3412; border: 1px solid #FED7AA; }
.badge-scrap      { background: #FEE2E2; color: #991B1B; border: 1px solid #FCA5A5; }
.badge-rejected   { background: #FEE2E2; color: #991B1B; }
.badge-lost       { background: #f3e8ff; color: #6b21a8; border: 1px solid #e9d5ff; }
.badge-pending    { background: #FEF3C7; color: #b45309; }
.badge-approved   { background: #D1FAE5; color: #047857; }
.badge-complete   { background: #D1FAE5; color: #047857; border: 1px solid #6EE7B7; }
.badge-incomplete { background: #FFEDD5; color: #c2410c; border: 1px solid #FDBA74; }

/* ═══════════════════════════════════════════════════════════════
   MODALS & OVERLAY
   KEY: overlay is position:fixed + overflow-y:auto (scrolls).
   Card uses max-height + internal scroll in body.
   On mobile: card is full-width, overlay scrolls vertically.
   ═══════════════════════════════════════════════════════════════ */
#modalContainer:empty {
  display: none !important;
  pointer-events: none !important;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.65);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: clamp(8px, 3vw, 24px);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* Ensure overlay can be scrolled by touch on iOS */
  touch-action: pan-y;
}

.modal-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  max-width: min(1100px, calc(100vw - clamp(16px, 4vw, 48px)));
  width: 100%;
  padding: 0;
  box-shadow: 0 25px 50px -12px rgba(15,23,42,0.25);
  /* Let content grow; overlay does the scrolling */
  max-height: min(92dvh, calc(100vh - clamp(32px, 6vh, 80px)));
  overflow: hidden;
  display: flex;
  flex-direction: column;
  margin: auto;
  border: 1px solid rgba(226,232,240,0.8);
  flex-shrink: 0;
}

/* Modal Header — sticky inside card */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: clamp(12px, 2vw, 20px) clamp(14px, 2.5vw, 24px);
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.98);
  position: sticky;
  top: 0;
  z-index: 2;
  flex-shrink: 0;
  gap: var(--space-sm);
}

/* Modal Body — SCROLLS internally */
.modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: clamp(14px, 2.5vw, 24px);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #94a3b8 #f1f5f9;
}

.modal-body::-webkit-scrollbar { width: 6px; }
.modal-body::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 8px; }
.modal-body::-webkit-scrollbar-track { background: #f1f5f9; }

/* Modal forms inside card also scroll */
.modal-card > form {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: clamp(14px, 2.5vw, 24px);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #94a3b8 #f1f5f9;
  -webkit-overflow-scrolling: touch;
}

.modal-card > form::-webkit-scrollbar { width: 6px; }
.modal-card > form::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 8px; }
.modal-card > form::-webkit-scrollbar-track { background: #f1f5f9; }

/* Modal Footer — sticky at bottom */
.modal-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: var(--space-sm);
  padding: clamp(10px, 1.5vw, 14px) clamp(14px, 2.5vw, 24px);
  border-top: 1px solid var(--border);
  background: #f8fafc;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  line-height: 1;
  flex-shrink: 0;
}
.modal-close:hover { background: #f1f5f9; color: #0f172a; }

/* If div inside modal-card is not a known role */
.modal-card > div:not(.modal-header):not(.modal-footer):not(.modal-body) {
  flex: 0 0 auto;
  padding: var(--space-sm) clamp(14px, 2.5vw, 24px) 0;
}

/* User permissions modal */
.user-permissions-modal {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-permissions-modal > form {
  display: block;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: var(--space-sm) clamp(14px, 2.5vw, 20px) var(--space-md);
  scrollbar-width: thin;
  scrollbar-color: #94a3b8 #f1f5f9;
  -webkit-overflow-scrolling: touch;
}

.user-permissions-modal > form::-webkit-scrollbar { width: 6px; }
.user-permissions-modal > form::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 8px; }
.user-permissions-modal > form::-webkit-scrollbar-track { background: #f1f5f9; }

.permissions-scroll {
  max-width: 100%;
  max-height: min(40vh, 380px);
  overflow-x: auto !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  border: 1px solid #dfe7f1;
  border-radius: 12px;
  padding: 8px;
  box-shadow: inset 0 1px 2px rgba(15,23,42,0.04);
}

.modal-card .table-responsive {
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: auto;
  max-width: 100%;
  overflow-x: auto;
}

.permissions-matrix-table { min-width: 680px; }
.permissions-matrix-table th, .permissions-matrix-table td { white-space: nowrap; }
.permissions-matrix-table td:first-child { width: 150px; white-space: normal; }
.permissions-matrix-table label {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  font-size: var(--fs-xs);
}

/* ═══════════════════════════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════════════════════════ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: var(--space-xs);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(clamp(180px, 30vw, 260px), 1fr));
  gap: var(--space-sm);
}

.form-grid .full-width { grid-column: 1 / -1; }

.form-group label {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: #1e293b;
}

.form-control {
  padding: clamp(8px, 1.5vw, 11px) clamp(10px, 2vw, 14px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  width: 100%;
  min-height: 42px;
  font-size: var(--fs-sm);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(2,132,199,0.15);
}

/* ═══════════════════════════════════════════════════════════════
   DOCUMENT UPLOAD ROW (7-document system)
   ═══════════════════════════════════════════════════════════════ */
.doc-check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(clamp(160px, 25vw, 220px), 1fr));
  gap: var(--space-xs);
  margin: var(--space-sm) 0;
}

.doc-check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: clamp(8px, 1.5vw, 11px) clamp(10px, 2vw, 14px);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  border: 1px solid var(--border);
  font-size: var(--fs-sm);
  font-weight: 600;
}
.doc-check-item.uploaded { background: #f0fdf4; border-color: #86efac; color: #166534; }
.doc-check-item.missing  { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }

.doc-upload-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: clamp(7px, 1.5vw, 10px) clamp(10px, 2vw, 14px);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  border: 1px solid var(--border);
  transition: background 0.2s;
  flex-wrap: wrap;
}
.doc-upload-row:hover { background: #f1f5f9; }

.doc-upload-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}
.doc-upload-label input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

.doc-upload-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.btn-upload-photo {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  border-radius: 20px;
  font-size: var(--fs-xs);
  font-weight: 700;
  cursor: pointer;
  border: none;
  white-space: nowrap;
  transition: opacity 0.18s, transform 0.15s;
}
.btn-upload-photo:hover { opacity: 0.88; transform: scale(1.04); }

.doc-preview-thumb {
  border-radius: 6px;
  border: 2px solid #059669;
  object-fit: cover;
  width: 40px;
  height: 40px;
  transition: transform 0.18s;
}
.doc-preview-thumb:hover { transform: scale(1.12); }

/* ═══════════════════════════════════════════════════════════════
   ANOMALY CARDS
   ═══════════════════════════════════════════════════════════════ */
.anomaly-card {
  border-inline-start: 5px solid #ef4444;
  background: #fef2f2;
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
}
.anomaly-icon { font-size: 1.5rem; flex-shrink: 0; }
.anomaly-title { font-weight: 800; color: #991b1b; margin-bottom: 4px; }
.anomaly-desc { font-size: var(--fs-sm); color: #7f1d1d; }

/* ═══════════════════════════════════════════════════════════════
   EXCEL HUB CARDS
   ═══════════════════════════════════════════════════════════════ */
.excel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(clamp(200px, 30vw, 280px), 1fr));
  gap: var(--space-md);
}

.excel-card {
  border: 1px dashed var(--primary);
  background: #f0f9ff;
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
}

/* ═══════════════════════════════════════════════════════════════
   DASHBOARD DUAL WRAP
   ═══════════════════════════════════════════════════════════════ */
.dashboard-dual-wrap {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(clamp(280px, 40vw, 550px), 1fr));
  gap: var(--space-md);
  width: 100%;
  padding: var(--space-md) 0 var(--space-xs) 0;
}

.dashboard-half-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-width: 0;
}

.inventory-half { border-top: 3px solid var(--nescafe-ice-blue); }
.sales-half     { border-top: 3px solid #10b981; }

.dashboard-half-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-xs);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--border);
}

.dashboard-half-title {
  font-size: var(--fs-sm);
  font-weight: 800;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.quarter-pills { display: flex; gap: 4px; align-items: center; }
.quarter-btn {
  padding: 3px 10px;
  font-size: var(--fs-xs);
  font-weight: 700;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}
.quarter-btn:hover { border-color: #10b981; color: #059669; background: #f0fdf4; }
.quarter-btn.active { background: #10b981; border-color: #10b981; color: #ffffff; box-shadow: 0 2px 6px rgba(16,185,129,0.35); }

.dashboard-half-box .stats-grid {
  grid-template-columns: repeat(auto-fill, minmax(clamp(110px, 18vw, 150px), 1fr));
  gap: var(--space-xs);
}

/* ═══════════════════════════════════════════════════════════════
   VAULT / BANK
   ═══════════════════════════════════════════════════════════════ */
.vault-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(clamp(180px, 28vw, 250px), 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.vault-kpi-card {
  border-radius: var(--radius-md);
  padding: var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  box-shadow: var(--shadow-md);
  border: 1px solid transparent;
  transition: var(--transition);
}
.vault-kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.vault-kpi-balance { background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%); border-color: #bae6fd; }
.vault-kpi-in      { background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%); border-color: #bbf7d0; }
.vault-kpi-out     { background: linear-gradient(135deg, #fff5f5 0%, #fee2e2 100%); border-color: #fecaca; }
.vault-kpi-count   { background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%); border-color: #bfdbfe; }

.vault-kpi-icon {
  width: clamp(40px, 6vw, 56px);
  height: clamp(40px, 6vw, 56px);
  border-radius: clamp(12px, 2vw, 16px);
  display: grid;
  place-items: center;
  font-size: clamp(1.4rem, 3vw, 1.9rem);
  background: rgba(255,255,255,0.7);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.vault-kpi-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.vault-kpi-label { font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted); white-space: nowrap; }
.vault-kpi-value { font-size: clamp(1.05rem, 2.5vw, 1.35rem); font-weight: 800; line-height: 1.2; word-break: break-word; }

#vaultLedgerTable tbody tr:hover { filter: brightness(0.97); }

/* ═══════════════════════════════════════════════════════════════
   INTERACTIVE MAP
   ═══════════════════════════════════════════════════════════════ */
.map-panel {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  box-shadow: var(--shadow-md);
  margin-bottom: var(--space-lg);
}
.map-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
  flex-wrap: wrap;
  gap: var(--space-xs);
}
.map-title { display: flex; align-items: center; gap: var(--space-xs); font-size: var(--fs-md); font-weight: 800; color: #0f172a; }
.map-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.map-filter-btn {
  border: 1px solid var(--border);
  background: #f8fafc;
  color: #475569;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: var(--fs-xs);
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}
.map-filter-btn:hover, .map-filter-btn.active { background: var(--kitkat-red); color: #ffffff; border-color: var(--kitkat-red); }

.map-container {
  width: 100%;
  height: clamp(260px, 40vw, 440px);
  border-radius: var(--radius-md);
  border: 2px solid rgba(0,163,224,0.25);
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* Map Marker */
.user-location-marker { position: relative; width: 24px; height: 24px; }
.user-location-dot { width: 16px; height: 16px; background: #00A3E0; border: 3px solid #ffffff; border-radius: 50%; position: absolute; top: 4px; left: 4px; box-shadow: 0 0 12px rgba(0,163,224,0.9); }
.user-location-pulse { position: absolute; width: 36px; height: 36px; top: -6px; left: -6px; border-radius: 50%; background: rgba(0,163,224,0.4); animation: userPulse 2s infinite ease-out; }
@keyframes userPulse { 0% { transform: scale(0.4); opacity: 1; } 100% { transform: scale(2.2); opacity: 0; } }

.kitkat-map-marker { background: transparent !important; border: none !important; display: flex !important; align-items: center !important; justify-content: center !important; transition: transform 0.22s cubic-bezier(0.34,1.56,0.64,1); }
.kitkat-map-marker:hover { transform: scale(1.35) translateY(-3px); z-index: 9999 !important; }

.leaflet-popup-content-wrapper { border-radius: var(--radius-md) !important; box-shadow: var(--shadow-lg) !important; border: 1px solid var(--border) !important; font-family: inherit !important; padding: 4px !important; }
.map-popup-card { padding: 6px; min-width: 180px; }
.map-popup-title { font-weight: 800; font-size: var(--fs-sm); color: #0f172a; margin-bottom: 4px; }
.map-popup-sub { font-size: var(--fs-xs); color: var(--text-muted); margin-bottom: 8px; }

/* ═══════════════════════════════════════════════════════════════
   SCHEDULE / TIMELINE
   ═══════════════════════════════════════════════════════════════ */
.schedule-container { display: flex; flex-direction: column; gap: var(--space-md); }
.area-cluster-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-md);
  position: relative;
  transition: var(--transition);
}
.area-cluster-card:hover { border-color: var(--nescafe-ice-blue); box-shadow: var(--shadow-md); }
.area-cluster-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #f1f5f9; padding-bottom: var(--space-sm); margin-bottom: var(--space-md); flex-wrap: wrap; gap: var(--space-xs); }
.area-cluster-title { display: flex; align-items: center; gap: var(--space-xs); font-size: var(--fs-md); font-weight: 800; color: var(--kitkat-cocoa); }
.area-cluster-badge { background: var(--kitkat-red); color: #ffffff; font-size: var(--fs-xs); padding: 4px 10px; border-radius: var(--radius-full); font-weight: 700; }
.schedule-timeline { display: flex; flex-direction: column; gap: var(--space-sm); }
.timeline-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: clamp(10px, 2vw, 15px) clamp(12px, 2.5vw, 20px);
  transition: var(--transition);
  flex-wrap: wrap;
}
.timeline-item:hover { background: #ffffff; border-color: var(--nescafe-ice-blue); }
.timeline-order { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--kitkat-red), var(--kitkat-cocoa)); color: #ffffff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1rem; box-shadow: 0 4px 10px rgba(200,16,46,0.25); flex-shrink: 0; }
.timeline-time { min-width: 120px; font-size: var(--fs-sm); font-weight: 700; color: var(--nescafe-ice-blue); background: #e0f2fe; padding: 5px 12px; border-radius: var(--radius-sm); text-align: center; flex-shrink: 0; }
.timeline-content { flex-grow: 1; min-width: 0; }
.timeline-title { font-weight: 700; font-size: var(--fs-sm); color: #0f172a; margin-bottom: 4px; }
.timeline-meta { font-size: var(--fs-xs); color: var(--text-muted); display: flex; gap: var(--space-sm); flex-wrap: wrap; }
.timeline-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ═══════════════════════════════════════════════════════════════
   NOTIFICATION BELL & DROPDOWN
   ═══════════════════════════════════════════════════════════════ */
.notif-btn {
  position: relative;
  background: #ffffff;
  border: 1px solid var(--border);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  flex-shrink: 0;
}
.notif-btn:hover { background: #f1f5f9; transform: scale(1.05); }

.notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--danger);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 800;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 2px solid #ffffff;
}

.notif-dropdown {
  display: none;
  position: fixed;
  inset-inline-end: 16px;
  top: 68px;
  width: min(340px, calc(100vw - 32px));
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  overflow: hidden;
  animation: fadeIn 0.2s ease-out;
}

.notif-header { padding: 14px 16px; background: #f8fafc; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: var(--fs-sm); color: #0f172a; }
.notif-body { max-height: 360px; overflow-y: auto; }
.notif-item { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.2s ease; }
.notif-item:hover { background: #f1f5f9; }
.notif-item.unread { background: #eff6ff; }
.notif-title { font-weight: 700; font-size: var(--fs-sm); color: var(--primary); margin-bottom: 4px; }
.notif-text { font-size: var(--fs-xs); color: var(--text); line-height: 1.4; }
.notif-time { font-size: 0.72rem; color: var(--text-muted); margin-top: 6px; }
.notif-read-all-btn { background: none; border: 1px solid var(--border); color: var(--primary); font-size: var(--fs-xs); font-weight: 700; padding: 4px 10px; border-radius: 8px; cursor: pointer; margin-inline-start: 4px; }
.notif-empty-text { padding: 14px; text-align: center; color: var(--text-muted); font-size: var(--fs-sm); }

@keyframes bellRing {
  0%, 100% { transform: rotate(0); }
  15% { transform: rotate(16deg); }
  30% { transform: rotate(-16deg); }
  45% { transform: rotate(12deg); }
  60% { transform: rotate(-12deg); }
  75% { transform: rotate(6deg); }
}
.notif-btn.bell-shake { animation: bellRing 0.8s ease-in-out infinite !important; border-color: #ef4444 !important; box-shadow: 0 0 15px rgba(239,68,68,0.5) !important; }

/* ═══════════════════════════════════════════════════════════════
   FOOTER
   ═══════════════════════════════════════════════════════════════ */
footer {
  margin-top: auto;
  padding: var(--space-md);
  text-align: center;
  font-size: var(--fs-xs);
  color: #64748b;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ═══════════════════════════════════════════════════════════════
   SPLASH SCREEN
   ═══════════════════════════════════════════════════════════════ */
.splash-screen {
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.5s cubic-bezier(0.4,0,0.2,1), visibility 0.5s ease;
  user-select: none;
}
.splash-screen.splash-hidden { opacity: 0; visibility: hidden; pointer-events: none; display: none !important; z-index: -1 !important; }
.splash-content { display: flex; flex-direction: column; align-items: center; gap: 20px; animation: splashPulse 2s ease-in-out infinite alternate; }
.splash-logo-ring {
  position: relative;
  width: clamp(80px, 15vw, 120px);
  height: clamp(80px, 15vw, 120px);
  border-radius: 50%;
  background-image: linear-gradient(#0f172a, #0f172a), linear-gradient(135deg, #00A3E0, #FFD700, #C8102E);
  background-origin: border-box;
  background-clip: content-box, border-box;
  border: 3px solid transparent;
  display: grid;
  place-items: center;
  box-shadow: 0 0 40px rgba(0,163,224,0.4), 0 0 20px rgba(255,215,0,0.3);
  animation: ringRotate 4s linear infinite;
}
.splash-logo-icon { font-size: clamp(2.5rem, 7vw, 4rem); filter: drop-shadow(0 0 16px rgba(0,163,224,0.8)); animation: shimmerGlow 2.5s ease-in-out infinite alternate; }
.splash-title { font-size: clamp(1.6rem, 5vw, 2.4rem); font-weight: 900; letter-spacing: 0.05em; background: linear-gradient(135deg, #ffffff 0%, #38bdf8 50%, #fef08a 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.splash-loader { width: 48px; height: 4px; border-radius: 4px; background: rgba(255,255,255,0.15); position: relative; overflow: hidden; margin-top: 8px; }
.splash-loader::after { content: ''; position: absolute; top: 0; left: -100%; width: 100%; height: 100%; background: linear-gradient(90deg, #00A3E0, #FFD700, #C8102E); animation: splashLoading 1.4s ease-in-out infinite; }
.splash-footer { position: absolute; bottom: 24px; font-size: var(--fs-xs); font-weight: 600; color: #94a3b8; letter-spacing: 0.03em; text-align: center; }

@keyframes splashPulse { 0% { transform: scale(0.98); } 100% { transform: scale(1.02); } }
@keyframes ringRotate { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes shimmerGlow { 0% { filter: drop-shadow(0 0 12px rgba(0,163,224,0.6)); } 100% { filter: drop-shadow(0 0 24px rgba(255,215,0,0.9)); } }
@keyframes splashLoading { 0% { left: -100%; } 100% { left: 100%; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* ═══════════════════════════════════════════════════════════════
   GUEST MODE
   ═══════════════════════════════════════════════════════════════ */
.guest-disabled .stat-card { cursor: pointer; transition: var(--transition); }
.guest-disabled .stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.guest-mode-badge { display: inline-flex; align-items: center; gap: 6px; background: #fef3c7; color: #92400e; border: 1px solid #fde68a; padding: 4px 10px; border-radius: 20px; font-size: var(--fs-xs); font-weight: 700; }

/* ═══════════════════════════════════════════════════════════════
   MOBILE LOCK: When sidebar drawer is open, prevent background scroll
   Only lock on MOBILE screens — on desktop this class should never apply
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 820px) {
  body.sidebar-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    /* Prevent iOS bounce scroll going to background */
    touch-action: none !important;
  }
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
   ───────────────────────────────────────────────────────────────
   CORE STRATEGY:
   • On DESKTOP: app-shell is height:100vh + overflow:hidden, and
     main-panel is the internal scroller (overflow-y:auto).
   • On MOBILE: We BREAK OUT of that pattern completely.
     - app-shell becomes height:auto (no overflow clip)
     - main-panel becomes height:auto (no overflow scroll)
     - BODY becomes the scroller (overflow-y: auto)
     - The sidebar becomes a fixed drawer overlay
   This is the ONLY reliable way to get natural mobile scrolling.
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 820px) {

  /* ── 1. BODY & HTML: enable natural vertical scrolling ─────── */
  html {
    height: 100%;
    overflow-x: hidden;
  }
  body {
    height: auto;
    min-height: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── 2. APP SHELL: release height lock, stack vertically ───── */
  .app-shell {
    flex-direction: column;
    height: auto !important;
    min-height: 100svh;
    min-height: 100dvh;
    overflow: visible !important;
    max-width: 100vw;
    position: relative;
  }

  /* ── 3. SHOW HAMBURGER TOGGLE ──────────────────────────────── */
  .mobile-toggle {
    display: inline-flex;
  }

  /* ── 4. SIDEBAR: fixed RTL drawer, hidden off-screen right ─── */
  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    left: auto;
    bottom: 0;
    width: min(285px, calc(100vw - 24px));
    height: 100%;
    height: 100dvh;
    flex: none !important;
    z-index: 10000;
    transform: translateX(110%);   /* fully off screen to the right */
    visibility: hidden;
    pointer-events: none;
    box-shadow: -6px 0 30px rgba(0,0,0,0.35);
    padding: var(--space-md);
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    transition:
      transform 0.3s cubic-bezier(0.4,0,0.2,1),
      visibility 0s linear 0.3s;
  }

  /* LTR sites: drawer slides in from left */
  html[dir="ltr"] .sidebar,
  body[dir="ltr"] .sidebar {
    right: auto;
    left: 0;
    transform: translateX(-110%);
  }

  /* Open state */
  .sidebar.open {
    transform: translateX(0) !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transition:
      transform 0.3s cubic-bezier(0.4,0,0.2,1),
      visibility 0s linear 0s;
  }

  /* ── 5. MAIN PANEL: full width, natural height, NO overflow ─── */
  .main-panel {
    width: 100% !important;
    max-width: 100vw !important;
    height: auto !important;
    min-height: 0 !important;
    flex: none !important;
    overflow: visible !important;     /* body scrolls — not main-panel */
    padding: clamp(10px, 3vw, 16px);
    padding-top: calc(clamp(10px, 3vw, 16px) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(clamp(48px, 8vw, 80px) + env(safe-area-inset-bottom, 32px));
  }

  /* ── 6. CONTENT VIEW: natural height, no scroll clipping ───── */
  #contentView {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* ── 7. TOPBAR: static, wraps nicely ───────────────────────── */
  .topbar {
    position: static;
    margin-bottom: var(--space-sm);
    background: transparent;
    padding: 0;
    gap: 8px;
    flex-wrap: wrap;
  }

  .topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1 1 auto;
  }

  .topbar-title h1 {
    font-size: clamp(1rem, 4vw, 1.2rem);
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.3;
  }

  .topbar-title p {
    font-size: var(--fs-xs);
    white-space: normal;
  }

  /* ── 8. STATS GRID: 2 cols ──────────────────────────────────── */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-xs);
  }

  /* ── 9. CONTENT BOX ─────────────────────────────────────────── */
  .content-box {
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    overflow: visible;
    width: 100% !important;
    max-width: 100% !important;
  }

  .section-header { margin-bottom: var(--space-sm); padding-bottom: var(--space-xs); }
  .filter-bar { padding: var(--space-xs) var(--space-sm); margin-bottom: var(--space-sm); }

  /* ── 10. MODAL: fullscreen card, scrolls inside ─────────────── */
  .modal-overlay {
    padding: clamp(8px, 2vw, 12px);
    padding-top: calc(clamp(8px, 2vw, 12px) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(clamp(16px, 4vw, 24px) + env(safe-area-inset-bottom, 16px));
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .modal-card {
    width: 100%;
    max-width: min(620px, calc(100vw - 16px));
    max-height: calc(100dvh - 32px);
    max-height: calc(100vh - 32px);
    height: auto;
    margin: auto;
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    border: 1px solid rgba(226,232,240,0.8);
    flex-shrink: 0;
  }

  .modal-card > form,
  .modal-body {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    max-height: none !important;
    padding: 14px 16px !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .modal-header {
    padding: 12px 16px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,0.98);
    z-index: 2;
  }
  .modal-footer {
    padding: 10px 16px;
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    background: #f8fafc;
  }
  .modal-card > form { padding: 14px 16px; }
  .modal-card > div:not(.modal-header):not(.modal-footer):not(.modal-body) {
    padding: var(--space-xs) var(--space-sm) 0;
  }
  .user-permissions-modal > form { padding: var(--space-xs) var(--space-sm); }

  /* ── 11. FILTER INPUTS ──────────────────────────────────────── */
  .filter-input, .filter-select { min-width: 0; flex: 1 1 100%; }

  /* ── 12. DASHBOARD LAYOUT ───────────────────────────────────── */
  .dashboard-dual-wrap { grid-template-columns: 1fr; gap: var(--space-sm); }

  .vault-kpi-grid { grid-template-columns: repeat(2, 1fr); gap: var(--space-xs); }
  .vault-kpi-value { font-size: 1.05rem; }
  .vault-kpi-icon { width: 42px; height: 42px; font-size: 1.4rem; }

  .doc-check-grid { grid-template-columns: repeat(2, 1fr); }
  .doc-upload-row { flex-wrap: wrap; }

  .timeline-item { flex-wrap: wrap; }
  .timeline-time { min-width: 100px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }

  .topbar-title h1 { font-size: clamp(0.95rem, 4.5vw, 1.2rem); overflow-wrap: anywhere; }

  .section-actions { flex-direction: column; align-items: stretch; }
  .section-actions .btn { width: 100%; justify-content: center; }

  .vault-kpi-grid { grid-template-columns: 1fr 1fr; }

  .doc-check-grid { grid-template-columns: 1fr; }

  .form-grid { grid-template-columns: 1fr !important; gap: 10px; }

  .form-control { min-height: 44px; font-size: 0.92rem; width: 100%; }

  th, td { padding: 7px 9px; font-size: var(--fs-xs); }
}

@media (max-width: 360px) {
  .stats-grid { grid-template-columns: 1fr; }
  .vault-kpi-grid { grid-template-columns: 1fr; }
}

/* PWA Standalone Mode */
@media all and (display-mode: standalone) {
  .main-panel {
    padding-top: calc(var(--space-md) + env(safe-area-inset-top, 12px));
    padding-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom, 28px));
  }
  .modal-overlay {
    padding-top: calc(var(--space-sm) + env(safe-area-inset-top, 10px));
    padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 20px));
  }
}

