/* Himoga Food Processing ERP - Core Stylesheet & iOS Mobile Engine */
:root {
  color-scheme: light;
  --primary: #059669; /* Emerald Green */
  --primary-hover: #047857;
  --primary-light: #ecfdf5;
  --primary-dark: #064e3b;
  --secondary: #d97706; /* Amber / Turmeric tone */
  --secondary-light: #fef3c7;
  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-400: #94a3b8;
  --slate-300: #cbd5e1;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --slate-50: #f8fafc;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --success: #10b981;
  --warning: #f59e0b;
  --info: #3b82f6;
  --info-light: #eff6ff;
  --white: #ffffff;
  --border: #e2e8f0;
  --ios-bg: #f2f2f7; /* iOS System Grouped Background */
  --ios-card: #ffffff;
  --sidebar-bg: #0f172a;
  --sidebar-border: #1e293b;
  --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.08), 0 2px 6px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 28px -4px rgba(0, 0, 0, 0.12), 0 4px 10px -2px rgba(0, 0, 0, 0.06);
  --sidebar-width: 260px;
}

/* Dark Mode System Variables */
[data-theme="dark"] {
  color-scheme: dark;
  --primary: #10b981; /* High contrast Emerald */
  --primary-hover: #34d399;
  --primary-light: rgba(16, 185, 129, 0.15);
  --primary-dark: #064e3b;
  --secondary: #f59e0b;
  --secondary-light: rgba(245, 158, 11, 0.15);
  --slate-900: #f8fafc; /* Inverted for primary text */
  --slate-800: #f1f5f9;
  --slate-700: #e2e8f0;
  --slate-600: #cbd5e1;
  --slate-500: #94a3b8;
  --slate-400: #64748b;
  --slate-300: #3f3f46;
  --slate-200: #27272a;
  --slate-100: #18181b;
  --slate-50: #121214;
  --white: #141416; /* Surfaces that were pure white */
  --border: #27272a;
  --ios-bg: #000000; /* Pure Apple OLED dark background */
  --ios-card: #1c1c1e; /* Apple iOS dark mode grouped secondary background */
  --sidebar-bg: #0b0d13;
  --sidebar-border: #1a1e2b;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 12px 28px -4px rgba(0, 0, 0, 0.7);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background-color: var(--ios-bg);
  font-family: var(--font-family);
  color: var(--slate-900);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* App Layout */
.app-container {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  position: relative;
}

/* Desktop Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--sidebar-border);
  z-index: 25;
}

.brand-section {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #10b981, #047857);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 1.2rem;
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: #ffffff;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.72rem;
  color: #10b981;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.nav-menu {
  flex: 1;
  padding: 1rem 0.75rem;
  overflow-y: auto;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  color: var(--slate-400);
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 0.75rem 0.75rem 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  color: #94a3b8;
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s ease-in-out;
  cursor: pointer;
}

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

.nav-item.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.4);
  font-weight: 600;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  padding: 0.15rem 0.45rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.78rem;
  color: var(--slate-400);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Main Area */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--ios-bg);
  position: relative;
}

/* Desktop Header */
.top-header {
  height: 64px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.75rem;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--slate-900);
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  background: #ecfdf5;
  color: #059669;
  border: 1px solid #a7f3d0;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #10b981;
  animation: pulse 1.8s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.9; }
  50% { transform: scale(1.3); opacity: 0.4; }
  100% { transform: scale(0.95); opacity: 0.9; }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.current-time {
  font-size: 0.82rem;
  color: var(--slate-500);
  font-weight: 500;
  padding: 0.4rem 0.75rem;
  background: var(--slate-100);
  border-radius: var(--radius-sm);
}

/* iOS Mobile Header (Default hidden on desktop) */
.ios-mobile-header {
  display: none;
}

/* Content Area */
.content-body {
  flex: 1;
  padding: 1.5rem 1.75rem;
  overflow-y: auto;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

/* Common Components */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.96);
}

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

.btn-secondary {
  background: var(--white);
  color: var(--slate-700);
  border-color: var(--slate-200);
}
.btn-secondary:hover {
  background: var(--slate-100);
}

.btn-amber {
  background: var(--secondary);
  color: white;
}
.btn-amber:hover {
  background: #b45309;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
}

/* Cards */
.card {
  background: var(--ios-card);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(0, 0, 0, 0.05);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--white);
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--slate-900);
  letter-spacing: -0.01em;
}

.card-body {
  padding: 1.25rem;
}

/* Metric Cards Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.metric-card {
  background: var(--ios-card);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.metric-card:active {
  transform: scale(0.98);
}

.metric-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.metric-icon-wrap.green { background: #d1fae5; color: #059669; }
.metric-icon-wrap.blue { background: #dbeafe; color: #2563eb; }
.metric-icon-wrap.amber { background: #fef3c7; color: #d97706; }
.metric-icon-wrap.purple { background: #ede9fe; color: #7c3aed; }
.metric-icon-wrap.red { background: #fee2e2; color: #dc2626; }

.metric-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--slate-500);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.metric-value {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--slate-900);
  line-height: 1.2;
  margin-top: 0.2rem;
  letter-spacing: -0.02em;
}

.metric-sub {
  font-size: 0.75rem;
  color: var(--slate-500);
  margin-top: 0.2rem;
}

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

.data-table th {
  background: var(--slate-50);
  color: var(--slate-600);
  font-weight: 600;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--slate-700);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #e0f2fe; color: #0369a1; }
.badge-neutral { background: #e2e8f0; color: #334155; }

/* Modals & iOS Sheets */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-dialog {
  background: white;
  width: 95%;
  max-width: 600px;
  max-height: 90vh;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.94);
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-overlay.active .modal-dialog {
  transform: scale(1);
}

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

.ios-sheet-handle {
  display: none;
}

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

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--slate-900);
}

.modal-close {
  background: #f1f5f9;
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--slate-500);
  line-height: 1;
  transition: all 0.15s ease;
}
.modal-close:hover {
  background: #e2e8f0;
  color: var(--slate-800);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  background: var(--slate-50);
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--slate-700);
  margin-bottom: 0.35rem;
}

.form-control, .form-select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-size: 0.88rem;
  border: 1px solid var(--slate-300);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--slate-800);
  outline: none;
  transition: border-color 0.15s ease;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 280px;
  max-width: 380px;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: white;
  padding: 0.85rem 1.15rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: slideDown 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  border-left: 4px solid var(--primary);
}

.toast.toast-error {
  border-left-color: var(--danger);
}

@keyframes slideDown {
  from { transform: translateY(-30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* POS Desktop Layout */
.pos-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.25rem;
  height: calc(100vh - 120px);
}

.pos-products-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pos-filter-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  overflow-x: auto;
  padding-bottom: 0.35rem;
  -webkit-overflow-scrolling: touch;
}

.category-pill {
  padding: 0.45rem 1rem;
  border-radius: 9999px;
  background: white;
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--slate-600);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.category-pill:active {
  transform: scale(0.96);
}

.category-pill.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(5, 150, 105, 0.3);
}

.pos-products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  overflow-y: auto;
  padding-right: 0.25rem;
  -webkit-overflow-scrolling: touch;
}

.product-pos-card {
  background: white;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: var(--radius-lg);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.product-pos-card:active {
  transform: scale(0.97);
}

.pos-cart-panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.pos-cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  -webkit-overflow-scrolling: touch;
}

.pos-cart-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--slate-100);
}

.pos-totals-box {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--slate-50);
}

/* Tabs */
.tabs-nav {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
  gap: 1.5rem;
}

.tab-btn {
  background: none;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--slate-500);
  padding: 0.75rem 0.25rem;
  cursor: pointer;
  position: relative;
  transition: color 0.15s;
}

.tab-btn.active {
  color: var(--primary);
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--primary);
}

/* Recipe & Van Cards */
.recipe-card, .van-card {
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: var(--radius-lg);
  background: white;
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease;
}

.recipe-card:active, .van-card:active {
  transform: scale(0.99);
}

.van-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.van-plate {
  font-weight: 800;
  font-size: 1rem;
  color: var(--slate-900);
  background: #f1f5f9;
  padding: 0.25rem 0.6rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  letter-spacing: 0.02em;
}

/* Responsive View Helpers */
.desktop-only {
  display: block;
}
.mobile-only {
  display: none !important;
}

/* iOS Native Record Cards (For Mobile) */
.ios-card-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  width: 100%;
}

.ios-record-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(0, 0, 0, 0.06);
  padding: 1.1rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  transition: transform 0.12s ease;
}

.ios-record-card:active {
  transform: scale(0.985);
}

.ios-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ios-card-product-name {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--slate-900);
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.ios-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  background: var(--slate-50);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  border: 1px solid rgba(0, 0, 0, 0.04);
}

.ios-detail-grid.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.ios-detail-item {
  display: flex;
  flex-direction: column;
}

.ios-detail-lbl {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--slate-500);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.ios-detail-val {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--slate-800);
  margin-top: 1px;
}

.ios-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border);
  gap: 0.5rem;
}

/* Van Inventory Feed on Mobile */
.van-inventory-feed {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.van-inventory-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--slate-50);
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  border: 1px solid rgba(0,0,0,0.03);
}

.van-inventory-name {
  font-weight: 700;
  color: var(--slate-900);
}

.van-inventory-stats {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.78rem;
}

/* iOS Bottom Tab Bar (Hidden on desktop) */
.ios-bottom-bar {
  display: none;
}

.ios-floating-cart-bar {
  display: none;
}

/* ==========================================================================
   ======================= MOBILE / IPHONE APP EXPERIENCE ===================
   ========================================================================== */
@media screen and (max-width: 820px) {

  /* 1. Hide Desktop Sidebar & Desktop Header */
  .sidebar, .desktop-only-header {
    display: none !important;
  }

  .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: flex !important;
  }

  .table-responsive {
    overflow-x: hidden !important;
  }

  body {
    background-color: var(--ios-bg);
  }

  /* 2. Main wrapper adjusts for iOS headers & bottom bar */
  .main-wrapper {
    height: 100vh;
    height: 100dvh;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 16px));
  }

  /* 3. iOS Native Header */
  .ios-mobile-header {
    display: block;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.12);
    padding: max(10px, env(safe-area-inset-top, 10px)) 1.25rem 0.85rem;
    position: sticky;
    top: 0;
    z-index: 40;
    flex-shrink: 0;
  }

  .ios-header-status-area {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
  }

  .ios-brand-badge {
    display: flex;
    align-items: center;
    gap: 0.6rem;
  }

  .ios-brand-logo {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #10b981, #047857);
    color: white;
    font-weight: 800;
    font-size: 1rem;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.4);
  }

  .ios-brand-name {
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--slate-900);
    line-height: 1.1;
  }

  .ios-brand-sub {
    font-size: 0.68rem;
    color: #059669;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .ios-header-right {
    display: flex;
    align-items: center;
    gap: 0.6rem;
  }

  .ios-live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.55rem;
    background: #ecfdf5;
    color: #059669;
    border-radius: 9999px;
    font-size: 0.72rem;
    font-weight: 700;
  }

  .ios-icon-btn {
    width: 36px;
    height: 36px;
    background: #f1f5f9;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--slate-800);
    cursor: pointer;
    transition: background 0.15s ease;
  }

  .ios-icon-btn:active {
    background: #e2e8f0;
    transform: scale(0.94);
  }

  .ios-large-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .ios-large-title {
    font-size: 1.55rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--slate-900);
    line-height: 1.15;
  }

  /* 4. Content Body Mobile Spacing */
  .content-body {
    padding: 0.85rem 0.85rem 4.5rem;
    overflow-x: hidden !important;
  }

  .card {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    margin-bottom: 1.25rem;
    overflow: visible !important;
  }

  .card-header {
    background: transparent !important;
    border-bottom: none !important;
    padding: 0.4rem 0.25rem 0.65rem !important;
  }

  .card-body {
    padding: 0 !important;
  }

  .ios-card-list {
    padding: 0 !important;
    gap: 0.75rem;
  }

  /* 5. Metrics Mobile Grid (2x2 iPhone Widget Style) */
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.25rem;
  }

  .metric-card {
    padding: 1rem;
    border-radius: var(--radius-lg);
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
  }

  .metric-icon-wrap {
    width: 38px;
    height: 38px;
    border-radius: 10px;
  }

  .metric-label {
    font-size: 0.68rem;
  }

  .metric-value {
    font-size: 1.25rem;
  }

  .metric-sub {
    font-size: 0.7rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  /* 6. Dual Table Grid -> Single Column on Mobile */
  div[style*="grid-template-columns:repeat(auto-fit, minmax(450px, 1fr))"] {
    grid-template-columns: 1fr !important;
  }

  /* 7. POS Mobile Architecture: catalog top, floating cart bottom */
  .pos-layout {
    display: flex;
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .pos-cart-panel {
    display: none; /* Hidden on mobile; accessible via floating cart bar / bottom sheet */
  }

  .pos-products-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    overflow: visible;
    padding-bottom: 5rem;
  }

  .product-pos-card {
    padding: 0.85rem;
    border-radius: var(--radius-lg);
  }

  .product-pos-card h4 {
    font-size: 0.85rem !important;
  }

  /* 8. Mobile Floating Cart Bar */
  .ios-floating-cart-bar {
    display: flex;
    position: fixed;
    bottom: calc(72px + env(safe-area-inset-bottom, 14px));
    left: 1rem;
    right: 1rem;
    background: #0f172a;
    color: white;
    border-radius: var(--radius-lg);
    padding: 0.75rem 1.15rem;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
    z-index: 55;
    animation: popUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    cursor: pointer;
  }

  .ios-floating-cart-bar:active {
    transform: scale(0.98);
  }

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

  .ios-cart-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  .ios-cart-badge {
    background: var(--primary);
    color: white;
    font-weight: 800;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
  }

  .ios-cart-checkout-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius);
    font-weight: 700;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
  }

  /* 9. iOS Frosted Glass Bottom Tab Bar */
  .ios-bottom-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(64px + env(safe-area-inset-bottom, 12px));
    padding-bottom: env(safe-area-inset-bottom, 12px);
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    border-top: 0.5px solid rgba(0, 0, 0, 0.15);
    z-index: 60;
    align-items: center;
    justify-content: space-around;
  }

  .ios-tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 0.35rem 0;
    color: #64748b;
    cursor: pointer;
    transition: color 0.15s ease;
  }

  .ios-tab-item span {
    font-size: 0.68rem;
    font-weight: 600;
    margin-top: 2px;
    letter-spacing: -0.01em;
  }

  .ios-tab-item svg {
    transition: transform 0.15s ease;
  }

  .ios-tab-item:active svg {
    transform: scale(0.88);
  }

  .ios-tab-item.active {
    color: var(--primary);
  }

  .ios-tab-item.active span {
    font-weight: 700;
  }

  /* Prominent Center POS Tab */
  .pos-special-tab .ios-tab-center-btn {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #059669, #047857);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(5, 150, 105, 0.4);
    margin-top: -10px;
    transition: transform 0.15s ease;
  }

  .pos-special-tab:active .ios-tab-center-btn {
    transform: scale(0.92);
  }

  /* 10. Modals Transform into Native iOS Bottom Sheets on Mobile */
  .modal-overlay {
    align-items: flex-end;
  }

  .modal-dialog {
    width: 100%;
    max-width: 100%;
    max-height: 88vh;
    border-radius: 26px 26px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  }

  .modal-overlay.active .modal-dialog {
    transform: translateY(0);
  }

  .ios-sheet-handle {
    display: block;
    width: 36px;
    height: 5px;
    background: #cbd5e1;
    border-radius: 999px;
    margin: 10px auto 4px auto;
  }

  .modal-header {
    padding: 0.75rem 1.25rem;
  }

  .modal-body {
    padding: 1.15rem;
  }

  /* 11. iOS More Menu Sheet Grid */
  .ios-menu-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.85rem;
    margin-bottom: 1.25rem;
  }

  .ios-menu-tile {
    background: #f8fafc;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-lg);
    padding: 1.1rem;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
  }

  .ios-menu-tile:active {
    background: #f1f5f9;
    transform: scale(0.96);
  }

  .ios-tile-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.6rem;
  }

  .ios-tile-icon.green { background: #d1fae5; color: #059669; }
  .ios-tile-icon.blue { background: #dbeafe; color: #2563eb; }
  .ios-tile-icon.purple { background: #ede9fe; color: #7c3aed; }
  .ios-tile-icon.amber { background: #fef3c7; color: #d97706; }

  .ios-tile-title {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--slate-900);
  }

  .ios-tile-sub {
    font-size: 0.72rem;
    color: var(--slate-500);
    margin-top: 2px;
  }

  .ios-company-card {
    background: #f1f5f9;
    padding: 1rem;
    border-radius: var(--radius);
    text-align: center;
  }
}

/* ==========================================================================
   ======================= THEME ENGINE (DARK / LIGHT MODE) ===================
   ========================================================================== */

/* Toggle Buttons */
.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.75rem;
  background: var(--slate-100);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--slate-700);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.theme-toggle-btn:hover {
  background: var(--slate-200);
  color: var(--slate-900);
}

.theme-toggle-btn:active {
  transform: scale(0.96);
}

/* Theme Icon Swapping System */
.theme-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

html:not([data-theme="dark"]) .light-icon {
  display: none !important;
}
html:not([data-theme="dark"]) .dark-icon {
  display: inline-flex !important;
}

[data-theme="dark"] .light-icon {
  display: inline-flex !important;
}
[data-theme="dark"] .dark-icon {
  display: none !important;
}

/* Sidebar Theme Switch Button */
.sidebar-theme-switch-wrap {
  width: 100%;
}

.sidebar-theme-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.48rem 0.75rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  color: #e2e8f0;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sidebar-theme-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

.sidebar-theme-btn:active {
  transform: scale(0.97);
}

/* Comprehensive Dark Mode Component Overrides */
[data-theme="dark"] .top-header {
  background: #141417;
  border-bottom-color: #27272a;
}

[data-theme="dark"] .card {
  background: var(--ios-card);
  border-color: #27272a;
}

[data-theme="dark"] .card-header {
  background: #18181b;
  border-bottom-color: #27272a;
}

[data-theme="dark"] .metric-card {
  background: var(--ios-card);
  border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .metric-icon-wrap.green { background: rgba(16, 185, 129, 0.16); color: #34d399; }
[data-theme="dark"] .metric-icon-wrap.blue { background: rgba(59, 130, 246, 0.16); color: #60a5fa; }
[data-theme="dark"] .metric-icon-wrap.amber { background: rgba(245, 158, 11, 0.16); color: #fbbf24; }
[data-theme="dark"] .metric-icon-wrap.purple { background: rgba(139, 92, 246, 0.16); color: #c084fc; }
[data-theme="dark"] .metric-icon-wrap.red { background: rgba(239, 68, 68, 0.16); color: #f87171; }

[data-theme="dark"] .badge-success { background: rgba(16, 185, 129, 0.16); color: #34d399; }
[data-theme="dark"] .badge-warning { background: rgba(245, 158, 11, 0.16); color: #fbbf24; }
[data-theme="dark"] .badge-danger { background: rgba(239, 68, 68, 0.16); color: #f87171; }
[data-theme="dark"] .badge-info { background: rgba(59, 130, 246, 0.16); color: #60a5fa; }
[data-theme="dark"] .badge-neutral { background: rgba(148, 163, 184, 0.16); color: #cbd5e1; }

[data-theme="dark"] .live-badge {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.3);
}

[data-theme="dark"] .data-table th {
  background: #18181b;
  border-bottom-color: #27272a;
  color: #94a3b8;
}

[data-theme="dark"] .data-table td {
  border-bottom-color: #232326;
  color: #e2e8f0;
}

[data-theme="dark"] .data-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] input[type="date"],
[data-theme="dark"] input[type="search"],
[data-theme="dark"] select,
[data-theme="dark"] textarea {
  background: #242426;
  border-color: #38383a;
  color: #f1f5f9;
}

[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus {
  border-color: #10b981;
  background: #28282b;
}

[data-theme="dark"] .form-control::placeholder {
  color: #71717a;
}

[data-theme="dark"] .btn-secondary {
  background: #242428;
  color: #f1f5f9;
  border-color: #38383e;
}

[data-theme="dark"] .btn-secondary:hover {
  background: #2e2e34;
  border-color: #484852;
}

[data-theme="dark"] .modal-dialog {
  background: #1c1c1e;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #f1f5f9;
}

[data-theme="dark"] .modal-header {
  border-bottom-color: #2c2c2e;
}

[data-theme="dark"] .modal-footer {
  background: #141416;
  border-top-color: #2c2c2e;
}

[data-theme="dark"] .modal-close {
  background: #2c2c2e;
  color: #cbd5e1;
}

[data-theme="dark"] .modal-close:hover {
  background: #3a3a3c;
  color: #ffffff;
}

[data-theme="dark"] .ios-sheet-handle {
  background: #3f3f46;
}

[data-theme="dark"] .product-pos-card {
  background: var(--ios-card);
  border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .pos-cart-panel {
  background: var(--ios-card);
  border-color: #27272a;
}

[data-theme="dark"] .category-pill {
  background: #1c1c1e;
  border-color: #2c2c30;
  color: #94a3b8;
}

[data-theme="dark"] .category-pill.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

[data-theme="dark"] .pos-totals-box {
  background: #161618;
  border-top-color: #27272a;
}

[data-theme="dark"] .pos-cart-item {
  border-bottom-color: #27272a;
}

[data-theme="dark"] .ios-mobile-header {
  background: rgba(18, 18, 20, 0.88);
  border-bottom-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .ios-live-indicator {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
}

[data-theme="dark"] .ios-icon-btn {
  background: #27272a;
  color: #f4f4f5;
}

[data-theme="dark"] .ios-icon-btn:active {
  background: #343438;
}

[data-theme="dark"] .ios-bottom-bar {
  background: rgba(18, 18, 20, 0.88);
  border-top-color: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .ios-tab-item {
  color: #71717a;
}

[data-theme="dark"] .ios-tab-item.active {
  color: var(--primary);
}

[data-theme="dark"] .ios-record-card {
  background: var(--ios-card);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .ios-detail-grid {
  background: #232326;
  border-color: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .ios-card-footer {
  border-top-color: #27272a;
}

[data-theme="dark"] .van-inventory-row {
  background: #232326;
  border-color: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .ios-menu-tile {
  background: #1c1c1e;
  border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .ios-menu-tile:active {
  background: #27272a;
}

[data-theme="dark"] .ios-tile-icon.gray {
  background: #2c2c2e;
  color: #fbbf24;
}

[data-theme="dark"] .ios-company-card {
  background: #1c1c1e;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .ios-floating-cart-bar {
  background: #1c1c1e;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: #333338;
}

[data-theme="dark"] ::-webkit-scrollbar-track {
  background: #121214;
}

/* Print Styles */
@media print {
  body * {
    visibility: hidden;
  }
  #printable-invoice, #printable-invoice * {
    visibility: visible;
  }
  #printable-invoice {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    margin: 0;
    padding: 20px;
    background: white;
  }
  .no-print {
    display: none !important;
  }
}
