/* ============================================
   Layouts — App Shell, Sidebar, POS, Pages
   Fully responsive: Phone, Tablet, Desktop
   ============================================ */

/* App Shell */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width); background: var(--bg-dark); color: var(--text-inverse);
  display: flex; flex-direction: column; flex-shrink: 0;
  border-right: 1px solid rgba(255,255,255,0.06); z-index: 500;
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  will-change: transform;
}
.sidebar__header { padding: var(--space-4); border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar__logo { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3); }
.logo-icon { font-size: 1.5rem; } .logo-text { font-size: 1.125rem; font-weight: 700; letter-spacing: -0.02em; }

.shop-switcher { position: relative; }
.shop-switcher__btn { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 0.5rem 0.75rem; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1); border-radius: var(--radius-sm); color: rgba(255,255,255,0.8); font-size: 0.8125rem; cursor: pointer; min-height: 38px; }
.shop-switcher__btn:hover { background: rgba(255,255,255,0.12); }
.shop-switcher__list { position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); list-style: none; z-index: 10; overflow: hidden; }
.shop-switcher__list li { padding: 0.625rem 0.75rem; cursor: pointer; color: var(--text-primary); font-size: 0.875rem; }
.shop-switcher__list li:hover { background: var(--bg-tertiary); }

.sidebar__nav { flex: 1; overflow-y: auto; padding: var(--space-2) 0; -webkit-overflow-scrolling: touch; }
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 0.625rem var(--space-4); color: rgba(255,255,255,0.55);
  font-size: 0.875rem; font-weight: 500; text-decoration: none;
  border-left: 3px solid transparent; min-height: var(--touch-min);
  transition: all var(--transition); touch-action: manipulation;
}
.nav-item:hover { color: rgba(255,255,255,0.85); background: rgba(255,255,255,0.04); text-decoration: none; }
.nav-item.active { color: white; background: rgba(255,255,255,0.08); border-left-color: var(--primary-light); }
.nav-item__icon { font-size: 1.125rem; width: 24px; text-align: center; flex-shrink: 0; }
.nav-item__label { flex: 1; }
.nav-item__badge { background: var(--danger); color: white; font-size: 0.625rem; font-weight: 700; padding: 1px 6px; border-radius: var(--radius-full); min-width: 18px; text-align: center; }
.nav-divider { border-top: 1px solid rgba(255,255,255,0.08); margin: var(--space-2) 0; }

.sidebar__footer { padding: var(--space-3) var(--space-4); border-top: 1px solid rgba(255,255,255,0.08); }
.sidebar__user { display: flex; align-items: center; gap: var(--space-3); }
.sidebar__avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.875rem; flex-shrink: 0; }
.sidebar__user-name { font-size: 0.8125rem; font-weight: 600; color: rgba(255,255,255,0.9); }
.sidebar__user-role { font-size: 0.6875rem; color: rgba(255,255,255,0.4); text-transform: capitalize; }

/* Mobile Sidebar Overlay */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 499; }

/* Main Content */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.page-container { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding: var(--space-5); }
.page-header { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--border-color); background: var(--bg-primary); min-height: 56px; flex-shrink: 0; z-index: 5; }
.page-header h2 { flex: 1; font-size: 1.125rem; }

/* Mobile Header */
.mobile-header { display: none; padding: var(--space-3) var(--space-4); background: var(--bg-primary); border-bottom: 1px solid var(--border-color); min-height: 56px; align-items: center; gap: var(--space-3); z-index: 5; }
.mobile-header__title { flex: 1; font-weight: 700; font-size: 1rem; }

/* ============================
   POS Layout — Split View
   ============================ */
.pos-layout { display: flex; height: 100%; overflow: hidden; }
.pos-products { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.pos-search { display: flex; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-color); background: var(--bg-primary); flex-wrap: wrap; }
.pos-categories { display: flex; gap: var(--space-2); padding: var(--space-3) var(--space-4); overflow-x: auto; border-bottom: 1px solid var(--border-light); flex-shrink: 0; -webkit-overflow-scrolling: touch; scroll-snap-type: x mandatory; }
.pos-categories::-webkit-scrollbar { display: none; }
.pos-category-chip { scroll-snap-align: start; }
/* Alias for chip styling */
.pos-category-chip { display: inline-flex; align-items: center; padding: 6px 14px; border-radius: var(--radius-full); font-size: 0.8125rem; font-weight: 500; background: var(--bg-tertiary); color: var(--text-secondary); border: 1px solid var(--border-color); cursor: pointer; white-space: nowrap; min-height: 36px; transition: all var(--transition); touch-action: manipulation; }
.pos-category-chip:hover { background: var(--primary-50); border-color: var(--primary); color: var(--primary); }
.pos-category-chip.active { background: var(--primary); color: white; border-color: var(--primary); }

.pos-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: var(--space-2); padding: var(--space-3) var(--space-4); overflow-y: auto;
  flex: 1; -webkit-overflow-scrolling: touch; align-content: start;
}
.pos-item {
  background: var(--bg-primary); border: 2px solid var(--border-color); border-radius: var(--radius-lg);
  padding: var(--space-3); text-align: center; cursor: pointer; min-height: 110px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  transition: all 0.12s ease; touch-action: manipulation; user-select: none; position: relative;
}
.pos-item:hover { border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.pos-item:active { transform: scale(0.94); background: var(--primary-50); border-color: var(--primary); }
.pos-item--expired { border-color: var(--expired); background: #fef2f2; opacity: 0.5; pointer-events: none; }
.pos-item--low { border-color: var(--warning); background: #fffbeb; }
.pos-item[data-dis] { opacity: 0.4; pointer-events: none; }
.pos-item__name { font-size: 0.8125rem; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.2; }
.pos-item__price { font-size: 1rem; font-weight: 800; color: var(--primary); font-family: var(--font-mono); letter-spacing: -0.02em; }
.pos-item__stock { font-size: 0.6875rem; color: var(--text-muted); font-weight: 500; }
.pos-item__tag { position: absolute; top: 4px; right: 4px; padding: 1px 6px; border-radius: var(--radius-full); font-size: 0.5625rem; font-weight: 800; letter-spacing: 0.03em; text-transform: uppercase; }
.pos-item__tag--danger { background: var(--danger-light); color: var(--danger); }
.pos-item__tag--warn { background: var(--warning-light); color: var(--warning); }
.pos-item__tag--controlled { background: #fef2f2; color: var(--controlled); }
.pos-item__tag--rx { background: #f5f3ff; color: var(--prescription); }
.pos-item__tag--otc { background: #ecfdf5; color: var(--otc); }

/* Cart */
.pos-cart {
  width: 380px; border-left: 1px solid var(--border-color); display: flex; flex-direction: column;
  background: var(--bg-primary); flex-shrink: 0; overflow: hidden;
}
.pos-cart__header { display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-color); min-height: 52px; }
.pos-cart__items { flex: 1; overflow-y: auto; padding: var(--space-2) var(--space-4); -webkit-overflow-scrolling: touch; }
.pos-cart__empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; opacity: 0.5; text-align: center; }
.pos-cart__summary { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border-color); }
.pos-cart__actions { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border-color); display: flex; gap: var(--space-2); }

/* Cart Items */
.cart-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--border-light); }
.cart-item__info { flex: 1; min-width: 0; }
.cart-item__name { font-size: 0.8125rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-item__meta { font-size: 0.6875rem; color: var(--text-muted); }
.cart-item__qty { display: flex; align-items: center; gap: 0; }
.cart-item__qty button { width: 32px; height: 32px; border: 1px solid var(--border-color); background: var(--bg-tertiary); border-radius: var(--radius-sm); cursor: pointer; font-weight: 700; display: flex; align-items: center; justify-content: center; touch-action: manipulation; }
.cart-item__qty span { padding: 0 8px; font-size: 0.875rem; font-weight: 600; min-width: 28px; text-align: center; }
.cart-item__total { font-size: 0.875rem; font-weight: 600; min-width: 64px; text-align: right; font-family: var(--font-mono); }
.cart-item__remove { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; font-size: 1rem; }

/* Grids for dashboard, inventory etc */
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-3); }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--space-4); }
.grid-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--space-3); }
.dashboard-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--space-4); }

/* Item Card (inventory) */
.item-card { display: flex; gap: var(--space-3); padding: var(--space-4); }
.item-card__photo { width: 48px; height: 48px; border-radius: var(--radius-sm); background: var(--bg-tertiary); display: flex; align-items: center; justify-content: center; font-size: 1.25rem; flex-shrink: 0; }
.item-card__details { flex: 1; min-width: 0; }
.item-card__name { font-weight: 600; font-size: 0.875rem; margin-bottom: 2px; }
.item-card__meta { font-size: 0.75rem; color: var(--text-muted); }

/* Inventory Header */
.inventory-header { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--border-color); background: var(--bg-primary); min-height: 56px; flex-shrink: 0; flex-wrap: wrap; }
.inventory-filters { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }

/* Summary row for cart / checkout */
.summary-row { display: flex; justify-content: space-between; padding: var(--space-1) 0; font-size: 0.875rem; }
.summary-row--total { font-weight: 700; font-size: 1.125rem; padding: var(--space-2) 0; border-top: 2px solid var(--border-color); margin-top: var(--space-2); }

/* ============================
   RESPONSIVE — Phone & Tablet
   ============================ */

/* Tablet (768-1024px) */
@media (max-width: 1024px) {
  .pos-cart { width: 320px; }
  .pos-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .grid-stats { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
}

/* Phone (< 768px) */
@media (max-width: 768px) {
  :root { --sidebar-width: 280px; }

  /* Sidebar: slide-over with overlay */
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100vh; height: 100dvh;
    transform: translateX(-100%); z-index: 500;
  }
  .sidebar.open, .sidebar.sidebar--open { transform: translateX(0); }
  .sidebar-overlay.visible, .sidebar-overlay:not(.hidden) { display: block; }

  /* Mobile header visible */
  .mobile-header { display: flex !important; }

  /* POS: stack vertically */
  .pos-layout { flex-direction: column; }
  .pos-cart { width: 100%; max-height: 45vh; border-left: none; border-top: 2px solid var(--border-color); }
  .pos-grid { grid-template-columns: repeat(auto-fill, minmax(95px, 1fr)); gap: 6px; padding: 8px; }
  .pos-item { padding: 8px 4px; min-height: 90px; border-radius: 12px; border-width: 2px; }
  .pos-item__name { font-size: 0.6875rem; }
  .pos-item__price { font-size: 0.8125rem; }
  .pos-search { padding: var(--space-2) var(--space-3); }
  .pos-categories { padding: var(--space-2) var(--space-3); }

  /* Page content */
  .page-container { padding: var(--space-3); }
  .page-header { padding: var(--space-3); min-height: 48px; flex-wrap: wrap; }
  .page-header h2 { font-size: 1rem; }

  /* Grids */
  .grid-stats { grid-template-columns: repeat(2, 1fr); gap: var(--space-2); }
  .grid-cards { grid-template-columns: 1fr; }
  .grid-items { grid-template-columns: 1fr; }
  .dashboard-charts { grid-template-columns: 1fr; }
  .inventory-header { flex-direction: column; align-items: stretch; }
  .inventory-filters { flex-wrap: wrap; }

  /* Tables: horizontal scroll */
  .data-table { display: block; overflow-x: auto; }

  /* Modal: full width bottom sheet */
  .modal { max-width: 100%; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .modal--lg { max-width: 100%; }

  /* Stat cards smaller */
  .stat-card__value { font-size: 1.25rem; }
}

/* Small phone (< 400px) */
@media (max-width: 400px) {
  .pos-grid { grid-template-columns: repeat(3, 1fr); }
  .grid-stats { grid-template-columns: repeat(2, 1fr); }
  .btn { padding: 0.5rem 0.75rem; font-size: 0.8125rem; }
  h1 { font-size: 1.375rem; }
  h2 { font-size: 1.125rem; }
}

/* Landscape phone */
@media (max-width: 768px) and (orientation: landscape) {
  .pos-layout { flex-direction: row; }
  .pos-cart { width: 300px; max-height: none; border-left: 1px solid var(--border-color); border-top: none; }
}

/* Large desktop (1400+) */
@media (min-width: 1400px) {
  .pos-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .pos-cart { width: 420px; }
}

/* Print */
@media print { .sidebar, .mobile-header, .offline-banner, .sync-bar, .toast-container, .mobile-bottom-nav { display: none !important; } .main-content { width: 100%; } .app { display: block; } }

/* ============================
   MOBILE BOTTOM NAV BAR
   Like a native app footer
   ============================ */
.mobile-bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 400;
  background: var(--bg-primary); border-top: 1px solid var(--border-color);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
  padding: 4px 0; padding-bottom: env(safe-area-inset-bottom, 4px);
}
.mobile-bottom-nav__items {
  display: flex; justify-content: space-around; align-items: center; max-width: 500px; margin: 0 auto;
}
.mobile-bottom-nav__item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 12px; text-decoration: none; color: var(--text-muted);
  font-size: 0.6rem; font-weight: 600; border-radius: 12px;
  transition: all 0.2s ease; touch-action: manipulation; min-width: 56px;
}
.mobile-bottom-nav__item:hover { text-decoration: none; }
.mobile-bottom-nav__item .bnav-icon { font-size: 1.3rem; line-height: 1; }
.mobile-bottom-nav__item.active { color: var(--primary); }
.mobile-bottom-nav__item.active .bnav-icon { transform: scale(1.15); }
/* Special sell button in center */
.mobile-bottom-nav__sell {
  display: flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--success, #10b981); color: white; font-size: 1.5rem;
  box-shadow: 0 4px 16px rgba(16,185,129,0.4);
  margin-top: -20px; border: 3px solid var(--bg-primary);
  text-decoration: none; transition: all 0.2s;
}
.mobile-bottom-nav__sell:hover { transform: scale(1.08); box-shadow: 0 6px 24px rgba(16,185,129,0.5); text-decoration: none; }

@media (max-width: 768px) {
  .mobile-bottom-nav { display: block; }
  /* Give space for bottom nav */
  .page-container { padding-bottom: 80px !important; }
  .pos-cart__actions { padding-bottom: 72px !important; }
  /* Hide mobile header menu button text */
  .mobile-header { position: sticky; top: 0; z-index: 10; }
}

/* Share receipt button */
.share-btn-row { display: flex; gap: var(--space-2); flex-wrap: wrap; justify-content: center; margin-top: var(--space-3); }
.share-btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 18px; border-radius: var(--radius-lg, 14px); font-size: 0.85rem; font-weight: 600; cursor: pointer; border: 1px solid var(--border-color); background: var(--bg-primary); color: var(--text-primary); transition: all 0.2s; touch-action: manipulation; }
.share-btn:hover { background: var(--bg-tertiary); }
.share-btn--whatsapp { background: #25D366; color: white; border-color: #25D366; }
.share-btn--whatsapp:hover { background: #1da851; }
.share-btn--bluetooth { background: #0082FC; color: white; border-color: #0082FC; }
.share-btn--bluetooth:hover { background: #006ad4; }

/* POS-only fullwidth mode for cashier/bar_staff */
.app.pos-fullwidth .sidebar { display: none !important; }
.app.pos-fullwidth .main-content { margin-left: 0 !important; width: 100% !important; max-width: 100% !important; }
.app.pos-fullwidth .mobile-header { display: none !important; }
.app.pos-fullwidth .page-container { padding-top: 0; }
/* Body-level kiosk mode — catches elements outside .app (bottom nav, overlay) */
body.pos-kiosk-mode .mobile-bottom-nav { display: none !important; }
body.pos-kiosk-mode .sidebar-overlay { display: none !important; }
