:root {
  --bg-main: #f1f5f9;
  --bg-card: #ffffff;
  --bg-glass: #ffffffd9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #e0e7ff;
  --success: #10b981;
  --success-hover: #059669;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-light: #fee2e2;
  --border-light: #e2e8f0;
  --border-card: #cbd5e1;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 28px rgba(15, 23, 42, 0.12);
  --shadow-glow: 0 0 20px rgba(79, 70, 229, 0.25);
  --font-sans: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

html, body {
  width: 100%;
  min-height: 100vh;
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-main);
  overflow-x: hidden;
  overflow-y: auto;
  touch-action: pan-x pan-y;
}

body {
  min-height: 100vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   DESKTOP DEFAULT LAYOUT (> 1024px)
   ========================================================================== */
.app-container {
  background: #e2e8f0;
  gap: 0.75rem;
  width: 100vw;
  height: 100vh;
  padding: 0.75rem;
  display: flex;
  box-sizing: border-box;
}

.glass-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.sidebar {
  color: #f8fafc;
  border-radius: var(--radius-lg);
  width: 200px;
  box-shadow: var(--shadow-md);
  z-index: 20;
  flex-direction: column;
  padding: 1rem 0.75rem;
  display: flex;
  background: #0f172a !important;
  flex-shrink: 0;
}

.sidebar .logo {
  color: #ffffff;
  border-radius: var(--radius-md);
  letter-spacing: -0.02em;
  background: rgba(255, 255, 255, 0.08);
  align-items: center;
  gap: 10px;
  margin-bottom: 1.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 1.15rem;
  font-weight: 800;
  display: flex;
}

.nav-menu {
  flex-direction: column;
  flex: 1;
  gap: 0.35rem;
  display: flex;
}

.nav-item {
  color: #94a3b8;
  border-radius: var(--radius-md);
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 0.75rem 0.85rem;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.18s;
  display: flex;
  cursor: pointer;
}

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

.nav-item.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
}

.main-content {
  flex-direction: column;
  flex: 1;
  gap: 0.75rem;
  display: flex;
  overflow: hidden;
  min-width: 0;
}

.topbar {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 1.25rem;
  display: flex;
}

.search-bar {
  align-items: center;
  gap: 0.75rem;
  display: flex;
}

.search-bar input {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: #f8fafc;
  outline: none;
  width: 280px;
  padding: 0.65rem 1.25rem;
  font-family: inherit;
  font-size: 0.95rem;
  transition: all 0.2s;
}

.search-bar input:focus {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.user-profile {
  color: var(--text-main);
  background: #f1f5f9;
  border-radius: 30px;
  align-items: center;
  gap: 6px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
}

.pos-layout {
  flex: 1;
  gap: 0.75rem;
  display: flex;
  overflow: hidden;
}

.catalog-panel {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  flex-direction: column;
  flex: 1;
  padding: 1rem;
  display: flex;
  overflow: hidden;
  min-width: 0;
}

.category-tabs {
  scrollbar-width: thin;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
}

.category-tabs::-webkit-scrollbar {
  height: 4px;
}

.category-tabs::-webkit-scrollbar-thumb {
  background: var(--border-card);
  border-radius: 4px;
}

.tab {
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  background: #f8fafc;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  padding: 0.65rem 1.25rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  transition: all 0.15s;
  display: inline-flex;
}

.tab:hover {
  color: var(--text-main);
  background: #e2e8f0;
}

.tab.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.products-grid {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.85rem;
  padding: 0.5rem 0.25rem 1.5rem;
  display: grid;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.product-card {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  cursor: pointer;
  height: 175px;
  box-shadow: var(--shadow-sm);
  background: #ffffff;
  flex-direction: column;
  justify-content: flex-end;
  transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
  display: flex;
  position: relative;
  overflow: hidden;
}

.product-card:hover, .product-card:active {
  box-shadow: var(--shadow-md);
  border-color: var(--primary-light);
  transform: translateY(-3px);
}

.product-card-info {
  z-index: 2;
  color: #ffffff;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(15,23,42,0.6) 25%, rgba(15,23,42,0.92) 100%);
  padding: 0.75rem 0.85rem;
  position: relative;
}

.product-name {
  color: #ffffff;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 0.25rem;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
  display: -webkit-box;
  overflow: hidden;
}

.product-price {
  color: #fbbf24;
  font-size: 1.05rem;
  font-weight: 800;
}

.current-order-panel {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  width: 420px;
  box-shadow: var(--shadow-md);
  background: #ffffff;
  flex-direction: column;
  padding: 1.15rem;
  display: flex;
  overflow: hidden;
  flex-shrink: 0;
}

.cart-items {
  flex-direction: column;
  flex: 1;
  gap: 0.65rem;
  margin: 0.75rem 0;
  padding-right: 0.25rem;
  display: flex;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.cart-item {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: #f8fafc;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 0.95rem;
  transition: all 0.15s;
  display: flex;
}

.cart-item:hover {
  border-color: var(--border-card);
  background: #f1f5f9;
}

.cart-summary {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: #f8fafc;
  margin-bottom: 0.85rem;
  padding: 0.95rem 1.15rem;
}

.summary-line {
  color: var(--text-muted);
  justify-content: space-between;
  margin-bottom: 0.4rem;
  font-size: 0.95rem;
  display: flex;
}

.summary-line.total {
  color: var(--text-main);
  border-top: 2px dashed var(--border-card);
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  font-size: 1.35rem;
  font-weight: 800;
}

.btn-touch {
  border-radius: var(--radius-md);
  cursor: pointer;
  border: none;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0.75rem 1.25rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  transition: all 0.15s;
  display: inline-flex;
}

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

.btn-checkout {
  background: linear-gradient(135deg, var(--success), var(--success-hover));
  color: #ffffff;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: none;
  width: 100%;
  min-height: 56px;
  font-size: 1.2rem;
  font-weight: 800;
  transition: all 0.2s;
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.35);
}

.btn-checkout:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.45);
}

.btn-checkout:disabled {
  box-shadow: none;
  cursor: not-allowed;
  background: #cbd5e1;
  transform: none;
}

.modal-overlay {
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: 1000;
  background: rgba(15, 23, 42, 0.65);
  justify-content: center;
  align-items: center;
  animation: 0.2s fadeIn;
  display: flex;
  position: fixed;
  inset: 0;
  padding: 1rem;
}

.modal-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  padding: 2rem;
  animation: 0.25s cubic-bezier(0.2, 0, 0, 1) slideUp;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  box-sizing: border-box;
  touch-action: pan-y;
}

@keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes slideUp {
  0% { opacity: 0; transform: translateY(20px); }
  100% { opacity: 1; transform: translateY(0); }
}

.badge {
  border-radius: 20px;
  align-items: center;
  gap: 4px;
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 700;
  display: inline-flex;
}

.badge.ok {
  background: var(--success-light);
  color: var(--success-hover);
}

.badge.warning {
  background: var(--warning-light);
  color: #b45309;
}

.badge.danger {
  background: var(--danger-light);
  color: var(--danger-hover);
}

.inventory-table {
  border-collapse: collapse;
  border-radius: var(--radius-md);
  width: 100%;
  box-shadow: var(--shadow-sm);
  background: #ffffff;
  margin-top: 1rem;
  overflow: hidden;
}

.inventory-table th, .inventory-table td {
  text-align: left;
  border-bottom: 1px solid var(--border-light);
  padding: 1rem 1.15rem;
}

.inventory-table th {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #f8fafc;
  font-size: 0.85rem;
  font-weight: 700;
}

.inventory-table tr:hover td {
  background: #f8fafc;
}

#print-container {
  display: none;
}

@media print {
  body * {
    visibility: hidden;
  }
  #print-container, #print-container * {
    visibility: visible;
  }
  #print-container {
    color: #000000;
    background: #ffffff;
    width: 80mm;
    padding: 6mm 5mm;
    font-family: "Courier New", monospace;
    font-size: 12px;
    display: block;
    position: absolute;
    top: 0;
    left: 0;
  }
  canvas {
    visibility: visible !important;
  }
  .print-line {
    justify-content: space-between;
    margin-bottom: 4px;
    display: flex;
  }
  .print-divider {
    border: none;
    border-bottom: 1px dashed #555;
    margin: 8px 0;
  }
}

/* ==========================================================================
   MOBILE & TABLET RESPONSIVE OVERRIDES (<= 1024px)
   ========================================================================== */
@media (max-width: 1024px) {
  html, body {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    height: auto !important;
    min-height: 100vh !important;
  }

  .app-container {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    min-height: 100vh !important;
    width: 100% !important;
    padding: 0 !important;
    gap: 0.5rem !important;
    overflow: visible !important;
    box-sizing: border-box !important;
  }

  /* Compact Horizontal Top Navigation Bar */
  .sidebar {
    position: sticky !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: 54px !important;
    min-height: 54px !important;
    padding: 0.35rem 0.65rem !important;
    border-radius: 0 0 var(--radius-md) var(--radius-md) !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    z-index: 9999 !important;
    background: #0f172a !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25) !important;
    box-sizing: border-box !important;
    flex-shrink: 0 !important;
  }

  .sidebar .logo {
    margin-bottom: 0 !important;
    font-size: 0.85rem !important;
    padding: 0.25rem 0.5rem !important;
    border-radius: 8px !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    gap: 6px !important;
  }

  .nav-menu {
    display: flex !important;
    flex-direction: row !important;
    flex: 1 !important;
    gap: 0.35rem !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-x !important;
    scrollbar-width: none !important;
    padding-left: 0.5rem !important;
  }

  .nav-menu::-webkit-scrollbar {
    display: none !important;
  }

  .nav-item {
    min-height: 38px !important;
    padding: 0.4rem 0.75rem !important;
    font-size: 0.82rem !important;
    white-space: nowrap !important;
    border-radius: 8px !important;
    flex-shrink: 0 !important;
  }

  .main-content {
    display: flex !important;
    flex-direction: column !important;
    overflow: visible !important;
    gap: 0.5rem !important;
    width: 100% !important;
    padding: 0.5rem !important;
    box-sizing: border-box !important;
    height: auto !important;
  }

  .topbar {
    padding: 0.65rem 0.85rem !important;
    gap: 0.5rem !important;
    flex-direction: column !important;
    align-items: stretch !important;
    border-radius: var(--radius-md) !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .search-bar {
    width: 100% !important;
    display: flex !important;
    flex-direction: row !important;
    gap: 0.5rem !important;
  }

  .search-bar input {
    flex: 1 !important;
    width: 100% !important;
    padding: 0.55rem 0.85rem !important;
    font-size: 0.88rem !important;
    border-radius: 10px !important;
  }

  .user-profile {
    padding: 0.35rem 0.75rem !important;
    font-size: 0.82rem !important;
  }

  /* POS Layout Stacked */
  .pos-layout {
    display: flex !important;
    flex-direction: column !important;
    overflow: visible !important;
    gap: 0.75rem !important;
    width: 100% !important;
    height: auto !important;
  }

  /* Root wrapper inside pos-layout override */
  .pos-layout > div {
    height: auto !important;
  }

  .catalog-panel {
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    padding: 0.75rem !important;
    border-radius: var(--radius-md) !important;
    box-sizing: border-box !important;
  }

  .category-tabs {
    padding-bottom: 0.4rem !important;
    margin-bottom: 0.25rem !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-x !important;
  }

  .tab {
    min-height: 40px !important;
    padding: 0.45rem 0.85rem !important;
    font-size: 0.85rem !important;
    flex-shrink: 0 !important;
  }

  /* Mobile Catalog Grid - Fully Scrollable */
  .products-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.65rem !important;
    padding: 0.35rem 0 1rem 0 !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    touch-action: pan-y !important;
  }

  .product-card {
    height: 155px !important;
    border-radius: var(--radius-md) !important;
  }

  .product-card-info {
    padding: 0.5rem 0.65rem !important;
    border-radius: 0 0 var(--radius-md) var(--radius-md) !important;
  }

  .product-name {
    font-size: 0.85rem !important;
  }

  .product-price {
    font-size: 0.95rem !important;
  }

  /* Current Order Panel Mobile Full Width Stacked Below Catalog */
  .current-order-panel {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    padding: 0.85rem !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-md) !important;
    margin-top: 0.5rem !important;
    box-sizing: border-box !important;
    overflow: visible !important;
  }

  .cart-items {
    max-height: 280px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
  }

  .cart-item {
    padding: 0.65rem 0.75rem !important;
    font-size: 0.88rem !important;
    border-radius: 10px !important;
  }

  .cart-summary {
    padding: 0.75rem 0.95rem !important;
    border-radius: 10px !important;
  }

  .summary-line.total {
    font-size: 1.2rem !important;
  }

  .btn-checkout {
    min-height: 52px !important;
    font-size: 1.1rem !important;
    border-radius: 12px !important;
  }

  /* Modals Responsive */
  .modal-overlay {
    padding: 0.5rem !important;
  }

  .modal-card {
    width: 100% !important;
    max-width: 580px !important;
    padding: 1.25rem !important;
    border-radius: var(--radius-lg) !important;
    max-height: 88vh !important;
    box-sizing: border-box !important;
  }

  .inventory-table {
    display: block !important;
    width: 100% !important;
    overflow-x: auto !important;
    white-space: nowrap !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .inventory-table th, .inventory-table td {
    padding: 0.75rem 0.85rem !important;
    font-size: 0.85rem !important;
  }
}

/* ==========================================================================
   SMARTPHONES & SMALL TOUCH DEVICES (<= 576px)
   ========================================================================== */
@media (max-width: 576px) {
  .products-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem !important;
  }

  .product-card {
    height: 145px !important;
  }

  .product-name {
    font-size: 0.82rem !important;
  }

  .product-price {
    font-size: 0.9rem !important;
  }

  .nav-item {
    min-height: 36px !important;
    padding: 0.35rem 0.65rem !important;
    font-size: 0.8rem !important;
  }
}

/* ==========================================================================
   EXTRA SMALL MOBILE SCREENS (<= 380px)
   ========================================================================== */
@media (max-width: 380px) {
  .products-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.4rem !important;
  }

  .product-card {
    height: 135px !important;
  }

  .nav-item {
    padding: 0.3rem 0.5rem !important;
    font-size: 0.78rem !important;
  }
}
