@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Kantumruy+Pro:wght@300;400;500;600;700&family=Battambang:wght@300;400;700;900&family=Moul&display=swap');

:root {
  --primary-color: #f40101;
  /* red */
  --primary-hover: #a50202;
  --secondary-color: #2596be;
  /* Soft Blue-Cyan */
  --secondary-hover: #1c799a;

  /* Light Theme Defaults */
  --bg-gradient: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  --bg-color: #f8fafc;
  --text-color: #0f172a;
  --text-secondary: #475569;
  --card-bg: rgba(255, 255, 255, 0.45);
  --card-bg-solid: #ffffff;
  --card-border: rgba(255, 255, 255, 0.45);
  --card-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.06);
  --header-bg: rgba(254, 243, 199, 0.5);
  --header-text: #78350f;

  /* Yellow Category Styles */
  --yellow-bg: rgba(255, 251, 235, 0.4);
  --yellow-accent: rgba(254, 243, 199, 0.5);
  --yellow-border: rgba(253, 230, 138, 0.5);
  --yellow-cell: rgba(255, 253, 236, 0.35);

  /* Blue Category Styles */
  --blue-bg: rgba(37, 150, 190, 0.04);
  --blue-accent: rgba(37, 150, 190, 0.1);
  --blue-border: rgba(37, 150, 190, 0.45);
  --blue-cell: rgba(37, 150, 190, 0.02);

  --font-sans: 'Outfit', 'Battambang', 'Kantumruy Pro', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-title: 'Moul', cursive, 'Outfit', 'Battambang', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --glass-blur: 24px;
}

/* Dark theme overrides when preferred or requested by Telegram */
/* Dark theme overrides applied manually via body.dark-theme class */
body.dark-theme {
  --bg-gradient: linear-gradient(135deg, #090d16 0%, #020408 100%);
  --bg-color: #090d16;
  --text-color: #f8fafc;
  --text-secondary: #94a3b8;
  --card-bg: rgba(15, 23, 42, 0.45);
  --card-bg-solid: #0f172a;
  --card-border: rgba(255, 255, 255, 0.1);
  --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
  --header-bg: rgba(245, 158, 11, 0.12);
  --header-text: #fef3c7;

  --yellow-bg: rgba(251, 191, 36, 0.04);
  --yellow-accent: rgba(251, 191, 36, 0.08);
  --yellow-border: rgba(251, 191, 36, 0.15);
  --yellow-cell: rgba(251, 191, 36, 0.02);

  --blue-bg: rgba(37, 150, 190, 0.04);
  --blue-accent: rgba(37, 150, 190, 0.08);
  --blue-border: rgba(37, 150, 190, 0.2);
  --blue-cell: rgba(37, 150, 190, 0.02);
}

/* Telegram Native Theme variables override via Class */
body.telegram-theme {
  background: var(--tg-bg-color, #181818);
  --bg-gradient: linear-gradient(135deg, var(--tg-bg-color, #181818) 0%, var(--tg-secondary-bg-color, #202020) 100%);
  --bg-color: var(--tg-bg-color, #181818);
  --text-color: var(--tg-text-color, #ffffff);
  --text-secondary: var(--tg-hint-color, #aaaaaa);
  --card-bg: rgba(30, 30, 30, 0.45);
  --card-bg-solid: #1e1e1e;
  --card-border: rgba(255, 255, 255, 0.08);
  --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.35);

  --primary-color: var(--tg-button-color, #2481cc);
  --primary-hover: var(--tg-button-color, #2481cc);
  --header-bg: rgba(251, 191, 36, 0.15);
  --header-text: #fcd34d;
}

/* Liquid Background Blob Animations */
.liquid-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: -2;
  overflow: hidden;
  background: var(--bg-gradient);
  transition: var(--transition);
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.45;
  mix-blend-mode: multiply;
  animation: float 22s infinite alternate ease-in-out;
  transition: var(--transition);
}

@media (prefers-color-scheme: dark) {
  .blob {
    opacity: 0.28;
    mix-blend-mode: screen;
  }
}

body.telegram-theme .blob {
  opacity: 0.28;
  mix-blend-mode: screen;
}

.blob-1 {
  width: 450px;
  height: 450px;
  background: radial-gradient(circle, rgba(251, 191, 36, 0.8) 0%, rgba(245, 158, 11, 0.8) 100%);
  /* Yellow */
  top: -10%;
  left: -10%;
  animation-duration: 25s;
}

.blob-2 {
  width: 550px;
  height: 550px;
  background: radial-gradient(circle, rgba(147, 197, 253, 0.8) 0%, rgba(59, 130, 246, 0.8) 100%);
  /* Blue */
  bottom: -10%;
  right: -10%;
  animation-duration: 32s;
  animation-delay: -6s;
}

.blob-3 {
  width: 380px;
  height: 380px;
  background: radial-gradient(circle, rgba(244, 114, 182, 0.6) 0%, rgba(236, 72, 153, 0.6) 100%);
  /* Pink */
  top: 35%;
  left: 45%;
  animation-duration: 20s;
  animation-delay: -10s;
}

@keyframes float {
  0% {
    transform: translate(0, 0) scale(1) rotate(0deg);
    border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
  }

  33% {
    transform: translate(60px, -50px) scale(1.15) rotate(120deg);
    border-radius: 50% 50% 30% 70% / 50% 60% 40% 60%;
  }

  66% {
    transform: translate(-40px, 70px) scale(0.9) rotate(240deg);
    border-radius: 60% 40% 60% 40% / 40% 50% 50% 60%;
  }

  100% {
    transform: translate(0, 0) scale(1) rotate(360deg);
    border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
}

body {
  font-family: var(--font-sans);
  background: transparent;
  /* Transparent body to allow liquid backdrop */
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  padding-bottom: 90px;
  /* space for cart bottom bar */
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-title);
  font-weight: normal;
}

.app-container {
  width: 100%;
  max-width: 600px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header & Banner styling */
.header-card {
  background: var(--card-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  position: relative;
  transition: var(--transition);
}

.banner-img-container {
  width: 100%;
  height: 160px;
  position: relative;
  background-color: var(--bg-color);
  overflow: hidden;
}

.banner-img-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.8s ease;
}

.header-card:hover .banner-img-container img {
  transform: scale(1.05);
}

.header-info {
  padding: 20px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.app-title {
  font-family: var(--font-title);
  font-size: 24px;
  font-weight: normal;
  letter-spacing: normal;
  background: linear-gradient(45deg, #f59e0b, #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-title-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  height: 32px;
  max-width: 130px;
  width: auto;
  object-fit: contain;
  background-color: #ffffff;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: transform var(--transition);
}

.header-card:hover .header-logo {
  transform: scale(1.05);
}

.admin-link-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid var(--card-border);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-color);
  transition: var(--transition);
  text-decoration: none;
}

.admin-link-btn:hover {
  background: var(--primary-color);
  color: white;
  transform: rotate(15deg);
}

.theme-toggle-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid var(--card-border);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-color);
  transition: var(--transition);
  outline: none;
}

.theme-toggle-btn:hover {
  background: var(--primary-color);
  color: white;
  transform: rotate(30deg);
}

/* In light theme, show moon, hide sun */
body:not(.dark-theme) .sun-icon {
  display: none;
}

body:not(.dark-theme) .moon-icon {
  display: block;
}

/* In dark theme, show sun, hide moon */
body.dark-theme .sun-icon {
  display: block;
}

body.dark-theme .moon-icon {
  display: none;
}

.app-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Search Bar Styling */
.search-container {
  display: flex;
  gap: 10px;
  width: 100%;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 42px;
  background: var(--card-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  color: var(--text-color);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
}

.search-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  pointer-events: none;
}

/* Category Filter Tabs */
.filter-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.filter-tab {
  padding: 8px 16px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  color: var(--text-color);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.filter-tab.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* Table Card Layout */
.table-card {
  background: var(--card-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  transition: var(--transition);
}

.table-wrapper {
  overflow-x: auto;
  width: 100%;
}

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

th {
  background: var(--header-bg);
  color: var(--header-text);
  font-weight: 600;
  padding: 10px 8px;
  border-bottom: 2px solid var(--card-border);
  white-space: nowrap;
  font-size: 12px;
}

td {
  padding: 8px;
  border-bottom: 1px solid var(--card-border);
  vertical-align: middle;
}

/* Replicate image colors */
tr.row-yellow td.highlight-col {
  background-color: var(--yellow-cell);
}

tr.row-yellow {
  border-bottom: 1px solid var(--yellow-border);
}

tr.row-blue td.highlight-col {
  background-color: var(--blue-cell);
}

tr.row-blue {
  border-bottom: 1px solid var(--blue-border);
}

.col-no {
  width: 30px;
  text-align: center;
  font-weight: 600;
  color: var(--text-secondary);
}

.col-img {
  width: 44px;
  text-align: center;
}

.col-code {
  width: 75px;
  font-family: monospace;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

.col-name {
  min-width: 130px;
}

.col-product {
  min-width: 130px;
}

.col-qty {
  width: 40px;
  text-align: center;
  font-weight: 600;
}

.col-price {
  width: 60px;
  text-align: right;
  font-weight: 600;
  color: #10b981;
  /* green price */
}

.col-action {
  width: 80px;
  text-align: center;
}

/* Name details */
.product-name-en {
  font-weight: 600;
  font-size: 12px;
}

.product-name-kh {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.product-tag {
  color: #ef4444;
  /* red tag in image */
  font-weight: 600;
  font-size: 10px;
  margin-left: 4px;
  background: rgba(239, 68, 68, 0.1);
  padding: 1px 4px;
  border-radius: 4px;
}

/* Image styling & fallback gradient */
.product-image-container {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  overflow: hidden;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
}

.product-image-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.product-image-container:hover img {
  transform: scale(1.15);
}

.product-image-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 12px;
  color: white;
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
}

/* Order Quantity Selectors */
.qty-selector {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.qty-btn {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--text-color);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: bold;
  font-size: 18px;
  transition: var(--transition);
  user-select: none;
}

.qty-btn:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.qty-input {
  width: 32px;
  text-align: center;
  border: none;
  background: transparent;
  color: var(--text-color);
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 17px;
  outline: none;
}


.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Floating Bottom Cart Bar */
.cart-bar {
  position: fixed;
  border-radius: 25px;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--card-border);
  box-shadow: 0 -10px 25px rgba(0, 0, 0, 0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
  transition: var(--transition);
}

body.telegram-theme .cart-bar {
  background: rgba(30, 30, 30, 0.85);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 -10px 25px rgba(0, 0, 0, 0.3);
}

.cart-summary {
  display: flex;
  flex-direction: column;
}

.cart-total-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cart-total-val {
  font-size: 20px;
  font-weight: 700;
  color: #10b981;
}

.cart-submit-btn {
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 24px;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition);
}

.cart-submit-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.45);
}

.cart-submit-btn:active {
  transform: translateY(1px);
}

/* Back link */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  transition: var(--transition);
}

.back-btn:hover {
  color: var(--primary-color);
}

/* Dialog Modal Style */
dialog {
  margin: auto;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  background: var(--bg-color);
  color: var(--text-color);
  box-shadow: var(--card-shadow);
  width: 90%;
  max-width: 450px;
  outline: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

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

.dialog-title {
  font-size: 18px;
  font-weight: 700;
}

.dialog-close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 20px;
}

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

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

.form-control {
  padding: 10px 14px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text-color);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
}

.form-control:focus {
  border-color: var(--primary-color);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.btn {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
}

.btn-secondary {
  background: transparent;
  border-color: var(--card-border);
  color: var(--text-color);
}

.btn-secondary:hover {
  background: rgba(0, 0, 0, 0.05);
}

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

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

.btn-danger {
  background: #ef4444;
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

/* Admin Specific */
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.token-input-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
}

.token-input {
  padding: 8px 12px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  font-family: monospace;
  font-size: 12px;
  background: var(--card-bg);
  color: var(--text-color);
  outline: none;
  width: 160px;
}

.action-row-buttons {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.action-icon-btn {
  background: transparent;
  border: 1px solid var(--card-border);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-color);
  transition: var(--transition);
}

.action-icon-btn:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.action-icon-btn.btn-delete-item:hover {
  background: #ef4444;
  border-color: #ef4444;
}

/* Loader styling */
.loader-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  gap: 12px;
  color: var(--text-secondary);
}

.loader {
  border: 3px solid var(--card-border);
  border-top: 3px solid var(--primary-color);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* Custom Alert/Toasts */
.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(15, 23, 42, 0.9);
  color: white;
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.toast-error {
  background: #ef4444;
}

.toast.toast-success {
  background: #10b981;
}

/* --- Bulk Import Mode Tabs --- */
.import-tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm, 10px);
}

.dark-theme .import-tabs {
  background: rgba(255, 255, 255, 0.04);
}

.import-tab {
  flex: 1;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: calc(var(--radius-sm, 10px) - 4px);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.import-tab:hover {
  color: var(--text-primary, inherit);
}

.import-tab.active {
  background: var(--primary-color);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* --- Image Upload Control (Add/Edit form) --- */
.image-upload-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.image-upload-preview {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: var(--radius-sm, 10px);
  border: 1px solid var(--card-border);
  background: rgba(0, 0, 0, 0.04);
}

.image-upload-controls {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.image-upload-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* --- Responsive & Mobile Layout Optimization for Storefront --- */

.stock-badge-inline {
  display: none;
}

/* Hide scrollbar for filter tabs */
.filter-tabs::-webkit-scrollbar {
  display: none;
}

.filter-tabs {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.view-toggle-btn {
  background: var(--card-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-color);
  transition: var(--transition);
  outline: none;
  flex-shrink: 0;
}

.view-toggle-btn:hover {
  background: var(--primary-color);
  color: white;
  transform: translateY(-1px);
}

.table-card.grid-mode {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  overflow: visible !important;
}

/* Grid View Layout (Desktop/General) */
#productsTable.grid-view {
  display: block !important;
  width: 100% !important;
  background: transparent !important;
  border: none !important;
}

#productsTable.grid-view thead {
  display: none !important;
}

#productsTable.grid-view #productsBody {
  display: grid !important;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  padding: 8px 4px;
}

#productsTable.grid-view #productsBody tr {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  justify-content: space-between !important;
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, rgba(255, 255, 255, 0.96) 100%), var(--product-img) !important;
  background-size: cover !important;
  background-position: center !important;
  background-repeat: no-repeat !important;
  border: 1px solid var(--card-border) !important;
  border-radius: var(--radius-lg) !important;
  padding: 16px !important;
  gap: 10px !important;
  box-shadow: var(--card-shadow) !important;
  transition: var(--transition) !important;
  border-left: none !important;
  border-top: 4px solid var(--primary-color) !important;
  will-change: transform;
}

body.dark-theme #productsTable.grid-view #productsBody tr,
body.telegram-theme #productsTable.grid-view #productsBody tr {
  background-image: linear-gradient(180deg, rgb(15 23 42 / 32%) 0%, rgba(15, 23, 42, 0.96) 100%), var(--product-img) !important;
}

#productsTable.grid-view #productsBody tr:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08) !important;
}

#productsTable.grid-view #productsBody tr.row-yellow {
  border-top: 4px solid var(--primary-color) !important;
}

#productsTable.grid-view #productsBody tr.row-blue {
  border-top: 4px solid var(--secondary-color) !important;
}

#productsTable.grid-view #productsBody td {
  display: block !important;
  padding: 0 !important;
  border: none !important;
  background: transparent !important;
  width: 100% !important;
  text-align: left !important;
}

#productsTable.grid-view #productsBody .col-img {
  display: none !important;
}

#productsTable.grid-view #productsBody .col-product {
  text-align: center !important;
  align-items: center !important;
  flex-grow: 1 !important;
  display: flex;
  flex-direction: column;
}

#productsTable.grid-view #productsBody .product-name-en {
  text-align: center !important;
  font-size: 13px !important;
  margin-top: 4px !important;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  height: 36px;
}

#productsTable.grid-view #productsBody .stock-badge-inline {
  display: flex !important;
  justify-content: center !important;
  margin-top: 4px !important;
}

#productsTable.grid-view #productsBody .col-price {
  align-self: center !important;
  align-items: center !important;
  text-align: center !important;
  margin: 6px 0 !important;
}

#productsTable.grid-view #productsBody .col-price div {
  text-align: center !important;
}

#productsTable.grid-view #productsBody .col-stock {
  display: none !important;
}

#productsTable.grid-view #productsBody .col-action {
  align-self: center !important;
  width: 100% !important;
  display: flex !important;
  justify-content: center !important;
}

#productsTable.grid-view #productsBody .qty-selector {
  width: 100% !important;
  max-width: 110px !important;
  margin: 0 auto !important;
}

@media (max-width: 680px) {

  /* Disable animated background blobs on mobile to prevent continuous paint/repaint cycles */
  .blob {
    animation: none !important;
    transform: none !important;
    will-change: auto !important;
  }

  .stock-badge-inline {
    display: inline-block;
    margin-left: 2px;
  }

  /* Reset table structure to flex/grid on mobile */
  .table-card {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
  }

  .table-wrapper {
    overflow-x: visible !important;
    padding: 0 !important;
  }

  #productsTable {
    display: block;
    width: 100% !important;
    border: none !important;
    background: transparent !important;
  }

  #productsTable thead {
    display: none !important;
  }

  #productsBody {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 2px;
  }

  #productsBody tr {
    display: grid !important;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "info price"
      "info action";
    align-items: center;
    gap: 8px 12px;
    background-image: linear-gradient(90deg, rgba(255, 255, 255, 0.92) 0%, rgba(255, 255, 255, 0.96) 100%), var(--product-img) !important;
    background-size: cover !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    border: 1px solid var(--card-border) !important;
    border-radius: var(--radius-lg) !important;
    padding: 12px 16px !important;
    box-shadow: var(--card-shadow) !important;
    backdrop-filter: none !important;
    /* Remove performance-heavy backdrop blur */
    -webkit-backdrop-filter: none !important;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s ease;
    will-change: transform;
    /* Hardware acceleration */
  }

  body.dark-theme #productsBody tr,
  body.telegram-theme #productsBody tr {
    background-image: linear-gradient(90deg, rgba(15, 23, 42, 0.92) 0%, rgba(15, 23, 42, 0.96) 100%), var(--product-img) !important;
  }

  #productsBody tr:active {
    transform: translateY(1px) scale(0.99);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
  }

  #productsBody tr.row-yellow {
    border-left: 5px solid var(--primary-color) !important;
  }

  #productsBody tr.row-blue {
    border-left: 5px solid var(--secondary-color) !important;
  }

  #productsBody td {
    display: block !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
  }

  #productsBody .col-img {
    display: none !important;
  }

  #productsBody .col-product {
    grid-area: info;
    text-align: left !important;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  #productsBody .col-price {
    grid-area: price;
    text-align: right !important;
    align-self: start;
    padding-top: 2px !important;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
  }

  #productsBody .col-stock {
    display: none !important;
  }

  #productsBody .col-action {
    grid-area: action;
    align-self: end;
    display: flex;
    justify-content: flex-end;
  }

  /* Interactive Styled Quantity Selector */
  #productsBody .qty-selector {
    width: 108px !important;
    height: 36px !important;
    background: rgba(120, 120, 120, 0.08) !important;
    border: 1px solid var(--card-border) !important;
    border-radius: 18px !important;
    padding: 0 4px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
  }

  #productsBody .qty-selector .qty-btn {
    width: 28px !important;
    height: 28px !important;
    font-size: 16px !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    color: var(--text-color) !important;
    transition: background 0.15s ease, transform 0.1s ease, color 0.15s ease !important;
    cursor: pointer !important;
    user-select: none !important;
  }

  /* Micro-animation touch feedback */
  #productsBody .qty-selector .qty-btn:active {
    background: var(--primary-color) !important;
    color: white !important;
    transform: scale(0.88) !important;
  }

  #productsBody .qty-selector .qty-input {
    font-size: 15px !important;
    width: 32px !important;
    font-weight: 700 !important;
    color: var(--text-color) !important;
  }

  /* Optimize bottom floating panel for phone screens */
  .cart-bar {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.08);
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 12px)) !important;
  }

  /* Grid View Mobile Override */
  #productsTable.grid-view #productsBody {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
    padding: 4px 2px !important;
  }

  #productsTable.grid-view #productsBody tr {
    padding: 10px !important;
    gap: 8px !important;
    min-height: 200px !important;
    border-radius: var(--radius-md) !important;
    background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, rgba(255, 255, 255, 0.96) 100%), var(--product-img) !important;
    background-size: cover !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    backdrop-filter: none !important;
    /* Remove backdrop blur */
    -webkit-backdrop-filter: none !important;
    will-change: transform;
  }

  body.dark-theme #productsTable.grid-view #productsBody tr,
  body.telegram-theme #productsTable.grid-view #productsBody tr {
    background-image: linear-gradient(180deg, rgb(15 23 42 / 32%) 0%, rgba(15, 23, 42, 0.96) 100%), var(--product-img) !important;
  }

  #productsTable.grid-view #productsBody tr:active {
    transform: translateY(1px) scale(0.98) !important;
  }

  #productsTable.grid-view #productsBody .product-name-en {
    font-size: 11.5px !important;
    height: 32px !important;
  }
}

/* Free Item Selection UI Styling */
.add-free-btn {
  padding: 4px 10px;
  font-size: 10px;
  background: rgba(16, 185, 129, 0.08);
  color: #10b981;
  border: 1px dashed rgba(16, 185, 129, 0.4);
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
}

.add-free-btn:hover {
  background: rgba(16, 185, 129, 0.15);
  border-color: #10b981;
}

.add-free-btn:active {
  transform: scale(0.95);
}

.free-qty-selector {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: 18px;
  padding: 0 4px;
  height: 30px;
  width: 108px;
}

.free-qty-selector .qty-btn {
  width: 24px !important;
  height: 24px !important;
  font-size: 14px !important;
  border: none !important;
  background: transparent !important;
  color: #10b981 !important;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease !important;
}

.free-qty-selector .qty-btn:active {
  background: #10b981 !important;
  color: white !important;
  transform: scale(0.88) !important;
}

/* --- Image Lightbox Overlay Zoom --- */
.lightbox-modal {
  position: fixed;
  z-index: 1100;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: lightboxFadeIn 0.25s ease-out;
}

@keyframes lightboxFadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.lightbox-content {
  margin: auto;
  display: block;
  width: 85%;
  max-width: 480px;
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  transform: scale(1);
  animation: lightboxZoomIn 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  object-fit: contain;
  max-height: 70vh;
}

@keyframes lightboxZoomIn {
  from {
    transform: scale(0.75);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

.lightbox-close {
  position: absolute;
  top: 30px;
  right: 30px;
  color: #ffffff;
  font-size: 38px;
  font-weight: bold;
  transition: var(--transition);
  cursor: pointer;
  user-select: none;
  z-index: 1120;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.lightbox-close:hover {
  color: var(--primary-color);
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.05);
}

.lightbox-caption {
  margin-top: 15px;
  text-align: center;
  color: #f1f1f1;
  font-family: var(--font-title);
  font-size: 15px;
  letter-spacing: 0.5px;
  max-width: 85%;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* --- Invoice Modal Styles --- */
.invoice-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 1050;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
  padding: 20px 10px;
}

.invoice-container {
  background: #ffffff;
  width: 100%;
  max-width: 800px;
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  color: #000000;
  overflow: hidden;
}

.invoice-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: #f1f5f9;
  padding: 12px 24px;
  border-bottom: 1px solid #e2e8f0;
}

.invoice-sheet {
  background: #ffffff;
  padding: 30px;
  font-family: 'Kantumruy Pro', 'Battambang', sans-serif;
  color: #000000;
}

.invoice-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  gap: 20px;
}

.depot-logo-title {
  display: flex;
  gap: 15px;
  align-items: center;
}

.depot-texts {
  display: flex;
  flex-direction: column;
}

.depot-title {
  font-family: 'Moul', cursive, sans-serif;
  font-size: 18px;
  color: #f40101;
  font-weight: normal;
  margin-bottom: 4px;
}

.depot-subtitle {
  font-size: 12px;
  font-weight: 700;
  color: #000;
  margin-bottom: 4px;
}

.depot-phone {
  font-size: 12px;
  font-weight: 500;
  color: #000;
  letter-spacing: 0.2px;
}

.invoice-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 250px;
}

.meta-item {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  border-bottom: 1px dotted #ccc;
  padding-bottom: 2px;
}

.meta-label {
  font-weight: 600;
  color: #333;
}

.meta-val {
  font-weight: 500;
  color: #000;
  text-align: right;
}

.invoice-title-container {
  text-align: left;
  margin: 10px 0 20px 0;
  border-bottom: 3px double #000;
  padding-bottom: 4px;
}

.invoice-title {
  font-family: 'Moul', cursive, sans-serif;
  font-size: 22px;
  color: #000;
  font-weight: normal;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 11px;
}

.invoice-table th,
.invoice-table td {
  border: 1px solid #cbd5e1;
  padding: 6px 8px;
  color: #000000;
  vertical-align: middle;
}

.invoice-table th {
  background: #f8fafc;
  font-weight: bold;
  text-align: left;
}

.invoice-summary-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  margin-top: 15px;
  padding-right: 10px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  width: 200px;
  font-size: 12px;
  font-weight: 600;
}

.summary-val {
  text-align: right;
  font-family: var(--font-sans);
}

/* Scrollable table container to prevent long page scrolls in Admin panel */
.scrollable-table-wrapper {
  max-height: 480px;
  overflow-y: auto;
  position: relative;
}

.scrollable-table-wrapper th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card-bg-solid, #ffffff) !important;
  box-shadow: inset 0 -2px 0 var(--card-border);
}

/* Print View Overrides */
@media print {
  @page {
    size: A4;
    margin: 15mm 15mm 15mm 15mm;
  }

  body {
    background: white !important;
    color: #000000 !important;
    font-size: 11px !important;
  }

  body * {
    visibility: hidden;
  }

  #invoiceModal,
  #invoiceModal *,
  #bulkPrintContainer,
  #bulkPrintContainer * {
    visibility: visible;
  }

  #invoiceModal {
    position: absolute;
    left: 0;
    top: 0;
    width: 100% !important;
    height: auto;
    background: white !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    display: block !important;
  }

  #bulkPrintContainer {
    position: absolute;
    left: 0;
    top: 0;
    width: 100% !important;
    height: auto;
    background: white !important;
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .invoice-container {
    box-shadow: none !important;
    border-radius: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  .invoice-actions {
    display: none !important;
  }

  .invoice-sheet {
    width: 100% !important;
    max-width: 180mm !important; /* Fits standard A4 printable width */
    margin: 0 auto !important;
    padding: 10mm 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: white !important;
    box-sizing: border-box;
  }

  .print-page-break {
    page-break-after: always;
    break-after: page;
  }
}