/* ==========================================================================
   NICSY FASHION ERP - CORE DESIGN SYSTEM & STYLESHEET
   Manufacturing Intelligence for Intimate Apparel & Panty Production
   ========================================================================== */

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

:root {
  /* Color Palette - Industrial Tailored Precision */
  --bg-app: #0f172a;          /* Slate 900 */
  --bg-sidebar: #090e1a;      /* Deep Slate */
  --bg-header: rgba(15, 23, 42, 0.92);
  --bg-surface: #1e293b;      /* Slate 800 */
  --bg-surface-elevated: #283548;
  --bg-surface-subtle: #162032;
  --bg-input: #0b1120;
  
  --border-subtle: #334155;    /* Slate 700 */
  --border-focus: #10b981;     /* Emerald 500 */
  --border-muted: #1e293b;
  
  --text-primary: #f8fafc;     /* Slate 50 */
  --text-secondary: #94a3b8;   /* Slate 400 */
  --text-muted: #64748b;       /* Slate 500 */
  --text-inverse: #0f172a;
  
  /* Brand & Status Accents */
  --brand-primary: #10b981;    /* Emerald for precision/quality */
  --brand-primary-hover: #059669;
  --brand-glow: rgba(16, 185, 129, 0.15);
  
  --accent-blue: #38bdf8;      /* Sky 400 */
  --accent-indigo: #818cf8;    /* Indigo 400 */
  --accent-amber: #f59e0b;     /* Amber 500 for WIP / Rework */
  --accent-rose: #f43f5e;      /* Rose 500 for Rejections / Defect */
  --accent-emerald: #10b981;   /* Emerald for Finished / Pass */
  
  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Outfit', var(--font-sans);
  --font-mono: 'JetBrains Mono', Consolas, monospace;
  
  /* Radii & Shadows */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.45);
  --shadow-popup: 0 20px 40px rgba(0, 0, 0, 0.6);
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* Light Theme Variables & Component Styles */
[data-theme="light"] {
  --bg-app: #f8fafc;          /* Slate 50 */
  --bg-sidebar: #0f172a;      /* Deep Slate for high contrast navigation */
  --bg-header: rgba(255, 255, 255, 0.95);
  --bg-surface: #ffffff;      /* Pure white cards */
  --bg-surface-elevated: #f1f5f9; /* Slate 100 */
  --bg-surface-subtle: #f8fafc;
  --bg-input: #ffffff;
  
  --border-subtle: #e2e8f0;    /* Slate 200 */
  --border-focus: #10b981;
  --border-muted: #cbd5e1;
  
  --text-primary: #0f172a;     /* Slate 900 */
  --text-secondary: #475569;   /* Slate 600 */
  --text-muted: #64748b;       /* Slate 500 */
  --text-inverse: #ffffff;
  
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.1);
  --shadow-popup: 0 20px 40px rgba(15, 23, 42, 0.15);
}

[data-theme="light"] .card {
  background: #ffffff;
  border-color: #e2e8f0;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
}

[data-theme="light"] .data-table th {
  background: #f1f5f9;
  color: #334155;
  border-bottom-color: #cbd5e1;
}

[data-theme="light"] .data-table td {
  border-bottom-color: #f1f5f9;
  color: #1e293b;
}

[data-theme="light"] .data-table tbody tr:hover {
  background-color: #f8fafc;
}

[data-theme="light"] .form-control {
  background-color: #ffffff;
  color: #0f172a;
  border-color: #cbd5e1;
}

[data-theme="light"] .form-control:focus {
  border-color: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

[data-theme="light"] .modal-content {
  background-color: #ffffff;
  color: #0f172a;
  border-color: #cbd5e1;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

[data-theme="light"] .kpi-card {
  background-color: #ffffff;
  border-color: #e2e8f0;
}

[data-theme="light"] .header-metric-badge {
  background-color: #f1f5f9;
  border-color: #e2e8f0;
}

[data-theme="light"] .user-profile-header {
  background-color: #f1f5f9 !important;
  border-color: #e2e8f0 !important;
}

[data-theme="light"] #header-factory-box {
  background-color: #f1f5f9 !important;
  border-color: #e2e8f0 !important;
}

[data-theme="light"] .login-card {
  background: rgba(255, 255, 255, 0.95) !important;
  color: #0f172a !important;
  border-color: #e2e8f0 !important;
}

[data-theme="light"] .login-card h1 {
  color: #0f172a !important;
}

[data-theme="light"] .login-card label {
  color: #334155 !important;
}

[data-theme="light"] .login-card input {
  background: #ffffff !important;
  color: #0f172a !important;
  border-color: #cbd5e1 !important;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Layout Scaffold */
#app {
  display: flex;
  min-height: 100vh;
  width: 100vw;
}

/* Sidebar */
.app-sidebar {
  width: 270px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  transition: transform var(--transition-normal);
  overflow-y: auto;
}

.brand-section {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo-badge {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #10b981 0%, #047857 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.35);
  flex-shrink: 0;
}

.brand-meta h1 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #ffffff;
  line-height: 1.2;
}

.brand-meta p {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

.sidebar-nav {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.nav-group-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  padding: 0 8px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: #cbd5e1;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

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

.nav-item.active {
  background-color: rgba(16, 185, 129, 0.14);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.3);
  font-weight: 600;
}

.nav-item svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.nav-item .badge-count {
  margin-left: auto;
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--bg-surface-subtle);
  padding: 2px 6px;
  border-radius: 12px;
  color: var(--text-secondary);
}

.nav-item.active .badge-count {
  background: rgba(16, 185, 129, 0.25);
  color: #a7f3d0;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 14px;
  border-top: 1px solid var(--border-subtle);
  background-color: rgba(0, 0, 0, 0.2);
}

.buyer-pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.buyer-badge {
  font-size: 10.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent-blue);
  border: 1px solid rgba(56, 189, 248, 0.25);
}

/* Main Layout Content */
.main-wrapper {
  margin-left: 270px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 64px;
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-title-wrap h2 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.page-title-wrap p {
  font-size: 12px;
  color: var(--text-secondary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-metric-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
}

.header-metric-badge .val {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--brand-primary);
}

/* Content Container */
.page-container {
  padding: 24px;
  flex: 1;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background-color: var(--brand-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--brand-primary-hover);
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.3);
}

.btn-secondary {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.btn-secondary:hover {
  background-color: var(--bg-surface-elevated);
  border-color: var(--text-muted);
}

.btn-outline-danger {
  background-color: transparent;
  color: var(--accent-rose);
  border-color: rgba(244, 63, 94, 0.4);
}

.btn-outline-danger:hover {
  background-color: rgba(244, 63, 94, 0.12);
  border-color: var(--accent-rose);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 4px;
}

.btn-sm svg {
  width: 14px;
  height: 14px;
}

/* Cards & Containers */
.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  position: relative;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body {
  padding: 20px;
}

/* Stat KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.kpi-card:hover {
  border-color: var(--text-muted);
  transform: translateY(-2px);
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.kpi-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.kpi-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface-subtle);
  color: var(--brand-primary);
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
  margin-bottom: 4px;
}

.kpi-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.data-table th {
  background-color: var(--bg-surface-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tr:hover td {
  background-color: rgba(255, 255, 255, 0.02);
}

.mono {
  font-family: var(--font-mono);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
}

.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-danger {
  background: rgba(244, 63, 94, 0.15);
  color: #fb7185;
  border: 1px solid rgba(244, 63, 94, 0.3);
}

.badge-info {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.badge-neutral {
  background: rgba(148, 163, 184, 0.15);
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.form-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13.5px;
  transition: border-color var(--transition-fast);
}

.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px var(--brand-glow);
}

.form-control[readonly], .form-control:disabled {
  background-color: var(--bg-surface-subtle);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-popup);
  width: 100%;
  max-width: 780px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(10px) scale(0.98);
  transition: transform var(--transition-normal);
}

.modal-backdrop.open .modal-dialog {
  transform: translateY(0) scale(1);
}

.modal-dialog.lg {
  max-width: 1000px;
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  background-color: var(--bg-surface-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast-success {
  border-left: 4px solid var(--brand-primary);
}

.toast-error {
  border-left: 4px solid var(--accent-rose);
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ==========================================================================
   MOBILE-FIRST RESPONSIVE DESIGN SYSTEM & DRAWER NAVIGATION
   ========================================================================== */

/* Mobile Backdrop for Drawer */
.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 998;
  opacity: 0;
  transition: opacity var(--transition-normal);
}

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

/* Mobile Hamburger Menu Button */
.mobile-menu-btn {
  display: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
}

.mobile-menu-btn:hover {
  background: var(--bg-surface-elevated);
  color: var(--brand-primary);
}

/* Mobile Bottom Quick Navigation Bar */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-subtle);
  z-index: 990;
  padding: 0 4px;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
}

.mobile-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  min-width: 54px;
  text-decoration: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.mobile-nav-btn svg {
  width: 19px;
  height: 19px;
  stroke-width: 2;
}

/* ==========================================================================
   MOBILE APP MODEL DESIGN SYSTEM (SMARTPHONE & TABLET LAYOUTS)
   ========================================================================== */

.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(62px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 990;
  padding-left: 6px;
  padding-right: 6px;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -6px 25px rgba(0, 0, 0, 0.5);
}

.mobile-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 58px;
  text-decoration: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.mobile-nav-btn svg {
  width: 21px;
  height: 21px;
  stroke-width: 2;
  transition: transform 0.18s ease, stroke 0.18s ease;
}

.mobile-nav-btn.active {
  color: #10b981;
  background: rgba(16, 185, 129, 0.14);
}

.mobile-nav-btn.active svg {
  stroke: #10b981;
  transform: translateY(-1px);
}

.mobile-nav-btn:active {
  transform: scale(0.88);
}

/* Tablet & Mobile Breakpoint (<= 1024px) */
@media (max-width: 1024px) {
  .sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .sidebar-backdrop.active {
    opacity: 1;
    pointer-events: auto;
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(320px, 86vw);
    max-width: 86vw;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 8px 0 35px rgba(0, 0, 0, 0.65);
    background: var(--bg-sidebar, #090e1a);
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .app-sidebar.mobile-open {
    transform: translateX(0);
  }

  .main-wrapper {
    margin-left: 0 !important;
    width: 100vw;
    min-width: 100vw;
    padding-bottom: calc(75px + env(safe-area-inset-bottom, 0px)) !important;
  }

  .mobile-menu-btn {
    display: flex !important;
  }

  .mobile-bottom-nav {
    display: flex !important;
  }

  #btn-close-mobile-drawer {
    display: flex !important;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
  }
}

/* Smartphone Native Mobile App Layout (<= 768px) */
@media (max-width: 768px) {
  html, body {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
  }

  /* Sticky App Bar Header */
  .app-header {
    padding: 0 12px;
    height: calc(56px + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    gap: 8px;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .header-left {
    gap: 10px;
    align-items: center;
    flex: 1;
    min-width: 0;
  }

  .mobile-menu-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    display: flex !important;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    flex-shrink: 0;
    transition: transform 0.15s ease, background 0.15s ease;
  }

  .mobile-menu-btn:active {
    transform: scale(0.92);
    background: var(--bg-surface-elevated);
  }

  .page-title-wrap {
    min-width: 0;
    flex: 1;
  }

  .page-title-wrap h2 {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-right {
    gap: 6px;
    flex-shrink: 0;
  }

  /* Clean up desktop buttons from mobile header */
  .btn-text-desktop,
  .header-metric-badge,
  .app-header > .header-right > .btn-secondary,
  .app-header > .header-right > label.btn-secondary,
  .app-header > .header-right > .btn-outline-danger {
    display: none !important;
  }

  #btn-mobile-app-hdr {
    padding: 5px 8px !important;
    border-radius: 8px !important;
    font-size: 12px;
  }

  #btn-mobile-app-hdr span:last-child {
    display: none;
  }

  #btn-cloud-sync {
    padding: 5px 8px !important;
    border-radius: 8px !important;
  }

  #btn-cloud-sync #cloud-sync-text {
    display: none;
  }

  #header-user-profile {
    padding: 3px 6px !important;
    border-radius: 20px !important;
    gap: 6px !important;
  }

  #header-user-profile #hdr-user-name,
  #header-user-profile #hdr-user-role,
  #header-user-profile svg {
    display: none;
  }

  #hdr-user-avatar {
    width: 28px !important;
    height: 28px !important;
    font-size: 11px !important;
  }

  /* Page Content Container */
  .page-container {
    padding: 12px;
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Mobile KPI Grid */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px;
    margin-bottom: 16px;
  }

  .kpi-card {
    padding: 12px 14px;
    border-radius: 12px;
    background: linear-gradient(145deg, var(--bg-surface) 0%, rgba(30, 41, 59, 0.7) 100%);
    box-shadow: var(--shadow-sm);
  }

  .kpi-label {
    font-size: 10.5px;
    margin-bottom: 4px;
    letter-spacing: 0.2px;
  }

  .kpi-value {
    font-size: 20px;
    font-weight: 800;
  }

  .kpi-meta {
    font-size: 10px;
    margin-top: 4px;
  }

  /* Form & Grid Layouts */
  .form-grid,
  .form-group-grid,
  .grid-2-col,
  .grid-3-col,
  .grid-4-col {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Touch-friendly inputs (16px base font prevents iOS safari auto-zoom) */
  input,
  select,
  textarea,
  .form-control {
    font-size: 16px !important;
    min-height: 44px;
    border-radius: 10px;
  }

  .btn {
    min-height: 42px;
    font-size: 13.5px;
    font-weight: 600;
    border-radius: 10px;
  }

  .btn-lg {
    min-height: 48px;
    font-size: 15px;
  }

  /* Cards on Mobile */
  .card {
    border-radius: 14px;
    margin-bottom: 16px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  }

  .card-header {
    padding: 12px 14px;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .card-header > div:last-child {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .card-header .btn {
    flex: 1;
  }

  .card-body {
    padding: 12px 14px;
  }

  /* Native Bottom-Sheet Style Modals */
  .modal-backdrop {
    align-items: flex-end !important;
    padding: 0 !important;
    backdrop-filter: blur(6px) !important;
    -webkit-backdrop-filter: blur(6px) !important;
  }

  .modal-box {
    width: 100% !important;
    max-width: 100vw !important;
    max-height: 92vh !important;
    border-radius: 24px 24px 0 0 !important;
    border-bottom: none !important;
    border-left: none !important;
    border-right: none !important;
    margin: 0 !important;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6) !important;
    animation: slideUpSheet 0.32s cubic-bezier(0.16, 1, 0.3, 1) !important;
    display: flex;
    flex-direction: column;
    position: relative;
  }

  .modal-box::before {
    content: '';
    display: block;
    width: 40px;
    height: 5px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.25);
    margin: 10px auto 4px;
    flex-shrink: 0;
  }

  .modal-header {
    padding: 12px 18px 14px;
    position: sticky;
    top: 0;
    background: var(--bg-surface);
    z-index: 10;
    border-bottom: 1px solid var(--border-subtle);
  }

  .modal-header h3 {
    font-size: 16px;
    font-weight: 800;
  }

  .modal-body {
    padding: 16px 18px;
    max-height: calc(92vh - 140px) !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
  }

  .modal-footer {
    padding: 12px 18px max(14px, env(safe-area-inset-bottom, 0px));
    position: sticky;
    bottom: 0;
    background: var(--bg-surface-elevated);
    z-index: 10;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    gap: 10px;
  }

  .modal-footer button,
  .modal-footer .btn {
    flex: 1;
    min-height: 46px;
    font-size: 14.5px;
    font-weight: 700;
    border-radius: 10px;
  }

  /* Data Tables Mobile Optimization */
  .table-responsive {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
    margin: 0 -2px;
  }

  .data-table th,
  .data-table td {
    padding: 9px 10px;
    font-size: 12px;
    white-space: nowrap;
  }

  /* Process Funnel Mobile Grid */
  .pipeline-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .pipeline-arrow {
    display: none;
  }

  .pipeline-step {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
  }

  /* Stepper Cards on Mobile */
  #container-operation-stepper {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  /* Master Sub-Tabs Scrollable Chip Bar */
  .master-subtabs-wrap {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding-bottom: 6px;
    margin-bottom: 12px;
  }

  .master-subtabs-wrap::-webkit-scrollbar {
    display: none;
  }
}

/* Extra Small Phones (<= 480px) */
@media (max-width: 480px) {
  .kpi-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px;
  }

  .kpi-card {
    padding: 10px 12px;
  }

  .kpi-value {
    font-size: 18px;
  }

  .page-title-wrap h2 {
    font-size: 15px;
  }

  #container-operation-stepper {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

@keyframes slideUpSheet {
  from {
    transform: translateY(100%);
    opacity: 0.6;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}


