:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-hover: #15803d;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --sidebar-bg: #1e293b;
  --sidebar-hover: #334155;
  --sidebar-active: #2563eb;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-light: #64748b;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --radius: 12px;
}

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

body {
  font-family: 'Noto Sans Lao', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

#app {
  display: flex;
  min-height: 100vh;
}

/* ====== Sidebar ====== */
.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1000;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 1.2rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
}

.logo i {
  font-size: 1.5rem;
  color: var(--primary);
  background: rgba(255,255,255,0.1);
  padding: 0.4rem;
  border-radius: 8px;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: #cbd5e1;
  font-size: 1.2rem;
  cursor: pointer;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.25rem;
  border-radius: 8px;
  color: #cbd5e1;
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s;
  cursor: pointer;
}

.nav-item i {
  width: 1.5rem;
  text-align: center;
  font-size: 1.05rem;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.shop-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.shop-info > i {
  font-size: 2rem;
  color: #94a3b8;
}

.shop-name {
  font-weight: 600;
  color: #fff;
  font-size: 0.9rem;
}

.shop-role {
  font-size: 0.75rem;
  color: #94a3b8;
}

.restock-product-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.restock-product-row select {
  flex: 1;
  min-width: 0;
}

.restock-product-row input[type="text"] {
  flex: 1;
  min-width: 0;
}

.restock-product-row .r-delete {
  flex-shrink: 0;
  white-space: nowrap;
}

.server-status {
  margin-top: 0.3rem;
  font-size: 0.7rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.server-status.online {
  color: #4ade80;
  background: rgba(74, 222, 128, 0.12);
}

.server-status.offline {
  color: #fca5a5;
  background: rgba(248, 113, 113, 0.12);
}

/* ====== Main Content ====== */
.main-content {
  flex: 1;
  margin-left: 240px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--card-bg);
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

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

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--text);
  cursor: pointer;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 600;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-time {
  font-size: 0.9rem;
  color: var(--text-light);
}

.btn-icon {
  position: relative;
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-light);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 8px;
}

.btn-icon:hover {
  background: var(--bg);
  color: var(--text);
}

.badge {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  border-radius: 50%;
  min-width: 1rem;
  height: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

.pages-container {
  padding: 1.5rem;
  flex: 1;
}

.page {
  display: none;
}

.page.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

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

/* ====== Cards ====== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.card-header h3 {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-body {
  padding: 1.25rem;
}

/* ====== Buttons ====== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:hover:not(:disabled) { background: var(--success-hover); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-secondary {
  background: #e2e8f0;
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) { background: #cbd5e1; }

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
  justify-content: center;
  padding: 0.9rem;
  font-size: 1.05rem;
}

/* ====== Buttons (icon-only in tables) ====== */
.table-actions {
  display: flex;
  gap: 0.4rem;
}

.btn-action {
  padding: 0.4rem 0.6rem;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  background: transparent;
  transition: all 0.2s;
}

.btn-action.edit { color: var(--primary); }
.btn-action.edit:hover { background: var(--primary-light); }
.btn-action.delete { color: var(--danger); }
.btn-action.delete:hover { background: var(--danger-light); }
.btn-action.stock { color: var(--success); }
.btn-action.stock:hover { background: var(--success-light); }

/* ====== Search ====== */
.search-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  min-width: 250px;
}

.search-box input {
  flex: 1;
  min-width: 120px;
}

.search-box i {
  color: var(--text-light);
}

.search-box input {
  border: none;
  outline: none;
  flex: 1;
  font-family: inherit;
  font-size: 0.9rem;
  background: transparent;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

/* ====== Stats ====== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
  transition: transform 0.2s;
}

.stat-card:hover {
  transform: translateY(-3px);
}

.stat-card.clickable {
  cursor: pointer;
}

.stat-card.clickable::after {
  content: '\f054';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  margin-left: auto;
  color: var(--text-light);
  font-size: 0.75rem;
  opacity: 0;
  transition: opacity 0.2s;
}

.stat-card.clickable:hover::after {
  opacity: 1;
}

.stat-icon {
  width: 3rem;
  height: 3rem;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.stat-sales .stat-icon { background: var(--success-light); color: var(--success); }
.stat-orders .stat-icon { background: var(--primary-light); color: var(--primary); }
.stat-products .stat-icon { background: var(--warning-light); color: var(--warning); }
.stat-lowstock .stat-icon { background: var(--danger-light); color: var(--danger); }
.stat-customers .stat-icon { background: var(--primary-light); color: var(--primary); }
.stat-month .stat-icon { background: #dcfce7; color: #16a34a; }
.stat-points .stat-icon { background: #fef3d6; color: #d97706; }

.stat-info h3 {
  font-size: 1.4rem;
  font-weight: 700;
}

.stat-info p {
  font-size: 0.85rem;
  color: var(--text-light);
}

.dashboard-content {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.chart-card .card-body {
  height: 280px;
  position: relative;
}

.chart-card canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.lowstock-alert-card {
  border-left: 4px solid var(--warning);
}

.expiry-alert-card {
  border-left: 4px solid var(--danger);
}

.product-expiry {
  font-size: 0.7rem;
  color: var(--text-light);
  text-align: center;
  line-height: 1.3;
}

.product-expiry.expired {
  color: var(--danger);
  font-weight: 600;
}

.product-expiry.soon {
  color: var(--warning);
  font-weight: 600;
}

/* ====== Recent / Low stock lists ====== */
.recent-sales-list,
.lowstock-list,
.history-list {
  max-height: 260px;
  overflow-y: auto;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
}

.list-item:last-child {
  border-bottom: none;
}

.list-item.clickable {
  cursor: pointer;
  transition: background 0.2s;
  padding-left: 0.4rem;
  padding-right: 0.4rem;
  border-radius: 8px;
}

.list-item.clickable:hover {
  background: var(--bg);
}

.list-item-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.list-item-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 8px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.list-item-avatar.danger {
  background: #fdecea;
  color: #e74c3c;
  animation: avatarPulse 1.4s ease-in-out infinite;
}

.list-item-avatar.warn {
  background: #fef3e0;
  color: #e67e22;
  animation: avatarPulseWarn 1.8s ease-in-out infinite;
}

@keyframes avatarPulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.45);
  }
  50% {
    transform: scale(1.08);
    box-shadow: 0 0 12px 3px rgba(231, 76, 60, 0.4);
  }
}

@keyframes avatarPulseWarn {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.06);
    box-shadow: 0 0 8px 2px rgba(230, 126, 34, 0.35);
  }
}

.list-item-title {
  font-weight: 600;
  font-size: 0.9rem;
}

.list-item-sub {
  font-size: 0.8rem;
  color: var(--text-light);
}

.list-item-amount {
  font-weight: 700;
  color: var(--success);
}

.list-item-danger {
  font-weight: 700;
  color: var(--danger);
}

.empty-state {
  color: var(--text-light);
  text-align: center;
  padding: 1.5rem;
  font-size: 0.9rem;
}

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

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

.pos-search-bar {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.pos-categories {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.pos-barcode-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 0.35rem 0.8rem;
  color: var(--primary);
}

.pos-barcode-row i {
  font-size: 1rem;
}

.pos-barcode-row input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.9rem;
  padding: 0.2rem 0;
}

.btn-scan-cam {
  border: none;
  background: var(--primary);
  color: #fff;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s;
}

.btn-scan-cam:hover {
  opacity: 0.85;
  transform: scale(1.05);
}

.category-btn {
  padding: 0.4rem 1rem;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 20px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  color: var(--text);
}

.category-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

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

.product-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 2px solid transparent;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

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

.product-card.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.product-card.disabled:hover {
  border-color: transparent;
  transform: none;
}

.product-emoji {
  font-size: 2.2rem;
  background: var(--bg);
  border-radius: 12px;
  padding: 0.6rem;
  width: 4.2rem;
  height: 4.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.product-emoji img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
}

.product-thumb {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  object-fit: cover;
  vertical-align: middle;
  margin-right: 0.4rem;
}

.barcode-sub {
  display: block;
  color: var(--text-light);
  font-size: 0.75rem;
  font-weight: 400;
  margin-top: 0.15rem;
}

.barcode-cell {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.85rem;
  color: var(--text-light);
  background: var(--bg);
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
}

.restock-img {
  width: 80px;
  height: 80px;
  border-radius: 12px;
  object-fit: cover;
  display: inline-block;
}

.img-upload {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.img-preview {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  color: var(--text-light);
  background: var(--bg);
  overflow: hidden;
}

.img-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.barcode-input-row {
  display: flex;
  gap: 0.5rem;
}

.barcode-input-row input {
  flex: 1;
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.product-name {
  font-weight: 600;
  font-size: 0.85rem;
  text-align: center;
  line-height: 1.3;
  min-height: 2.2em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-price {
  font-weight: 700;
  color: var(--success);
  font-size: 0.9rem;
}

.product-stock {
  font-size: 0.75rem;
  color: var(--text-light);
}

.product-stock.low {
  color: var(--danger);
  font-weight: 600;
}

/* ====== Cart ====== */
.pos-cart {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.cart-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.cart-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.cart-header h3 {
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 1.25rem;
}

.empty-cart {
  text-align: center;
  padding: 2rem 0;
  color: var(--text-light);
}

.empty-cart i {
  font-size: 3rem;
  color: var(--border);
  display: block;
  margin-bottom: 0.75rem;
}

.cart-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.cart-item-thumb {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  object-fit: cover;
  margin-right: 0.5rem;
  float: left;
}

.cart-item-info {
  flex: 1;
  min-width: 0;
}

.cart-item-name {
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cart-item-price {
  font-size: 0.75rem;
  color: var(--text-light);
}

.cart-item-qty {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.qty-btn {
  width: 1.5rem;
  height: 1.5rem;
  border: none;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.qty-value {
  min-width: 1.5rem;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
}

.cart-item-total {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
  min-width: 4rem;
  text-align: right;
}

.cart-item-delete {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.25rem;
}

.cart-summary {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

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

.cart-total {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--success);
}

.cart-actions {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.cart-payment-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.cart-payment-row label {
  font-size: 0.9rem;
  font-weight: 500;
}

.cart-payment-row input {
  width: 130px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  text-align: right;
}

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

.change-amount {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
}

.btn-checkout {
  font-size: 1.1rem;
  padding: 0.9rem;
}

/* ====== Tables ====== */
.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--text-light);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: var(--bg);
}

.stock-badge {
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.stock-badge.ok { background: var(--success-light); color: var(--success); }
.stock-badge.low { background: var(--warning-light); color: var(--warning); }
.stock-badge.out { background: var(--danger-light); color: var(--danger); }

.stock-badge.out:not(.expiry-badge) {
  animation: stockPulseOut 1.4s ease-in-out infinite;
}

.stock-badge.low:not(.expiry-badge) {
  animation: stockPulseLow 1.8s ease-in-out infinite;
}

@keyframes stockPulseOut {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.45);
  }
  50% {
    transform: scale(1.08);
    box-shadow: 0 0 10px 2px rgba(231, 76, 60, 0.4);
  }
}

@keyframes stockPulseLow {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.06);
    box-shadow: 0 0 8px 2px rgba(230, 126, 34, 0.35);
  }
}

.expiry-badge.expired {
  animation: expiryPulse 1.4s ease-in-out infinite;
}

.expiry-badge.soon {
  animation: expiryPulseSoon 1.8s ease-in-out infinite;
}

@keyframes expiryPulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.45);
  }
  50% {
    transform: scale(1.08);
    box-shadow: 0 0 10px 2px rgba(231, 76, 60, 0.4);
  }
}

@keyframes expiryPulseSoon {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.06);
    box-shadow: 0 0 8px 2px rgba(230, 126, 34, 0.35);
  }
}

/* ====== Reports ====== */
.report-period-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.report-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-light);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

.report-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.report-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.report-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.report-date-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.report-date-display {
  font-size: 1rem;
  font-weight: 600;
  min-width: 200px;
  text-align: center;
  padding: 0.4rem 0.75rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.report-actions-right {
  display: flex;
  gap: 0.5rem;
}

/* ====== Report Stats ====== */
.report-stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.report-stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  box-shadow: var(--shadow);
}

.report-stat-icon {
  width: 2.8rem;
  height: 2.8rem;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.report-stat-icon.sales { background: var(--success-light); color: var(--success); }
.report-stat-icon.orders { background: var(--primary-light); color: var(--primary); }
.report-stat-icon.profit { background: #fef3c7; color: #d97706; }
.report-stat-icon.avg { background: #f3e8ff; color: #7c3aed; }

.report-stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.2;
}

.report-stat-label {
  font-size: 0.78rem;
  color: var(--text-light);
  margin-top: 0.1rem;
}

.report-stat-compare {
  font-size: 0.72rem;
  font-weight: 600;
  margin-top: 0.15rem;
}

.report-stat-compare.up { color: var(--success); }
.report-stat-compare.down { color: var(--danger); }
.report-stat-compare.neutral { color: var(--text-light); }

.reports-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 1.25rem;
}

/* ====== Top Products ====== */
.top-products-list {
  max-height: 280px;
  overflow-y: auto;
}

.top-product-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.top-product-item:last-child {
  border-bottom: none;
}

.top-product-rank {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
  background: var(--bg);
  color: var(--text-light);
}

.top-product-rank.gold { background: #fef3c7; color: #d97706; }
.top-product-rank.silver { background: #e2e8f0; color: #64748b; }
.top-product-rank.bronze { background: #fed7aa; color: #c2410c; }

.top-product-info {
  flex: 1;
  min-width: 0;
}

.top-product-name {
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-product-qty {
  font-size: 0.78rem;
  color: var(--text-light);
}

.top-product-revenue {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--success);
  white-space: nowrap;
}

.report-history-count {
  font-size: 0.8rem;
  color: var(--text-light);
  font-weight: 500;
}

.report-filter {
  margin-bottom: 1rem;
}

.report-filter label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.4rem;
}

.report-filter input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
}

.report-summary {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.report-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px dashed var(--border);
}

.report-item strong {
  font-size: 1.1rem;
}

/* ====== Settings ====== */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

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

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.4rem;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
}

.seg-group {
  display: flex;
  gap: 0.5rem;
}

.btn-seg {
  flex: 1;
  padding: 0.55rem 1rem;
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: 8px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
  transition: all 0.2s;
}

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

.btn-seg.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.cam-hint {
  text-align: center;
  color: var(--text-light);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.cam-error {
  text-align: center;
  color: #e74c3c;
  font-size: 0.85rem;
  margin-top: 0.5rem;
  line-height: 1.4;
}

.modal-cam {
  max-width: 460px;
}

.modal-cam video {
  width: 100%;
  border-radius: 12px;
  background: #000;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 2px solid var(--primary);
}

/* ====== Modal ====== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

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

.modal-header h3 {
  font-size: 1.05rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-light);
}

.modal-body {
  padding: 1.25rem;
}

.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* ====== Receipt ====== */
.modal-receipt {
  max-width: 380px;
}

.receipt {
  padding: 1.5rem 1.25rem;
  font-size: 0.85rem;
  background: #fff;
}

.receipt-header {
  text-align: center;
  border-bottom: 1px dashed #999;
  padding-bottom: 0.75rem;
  margin-bottom: 0.75rem;
}

.receipt-header h3 {
  font-size: 1.1rem;
  margin-bottom: 0.25rem;
}

.receipt-header p {
  color: #555;
  font-size: 0.8rem;
  line-height: 1.5;
}

.receipt-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: #555;
  margin-bottom: 0.5rem;
}

.receipt-items {
  border-top: 1px dashed #999;
  border-bottom: 1px dashed #999;
  padding: 0.5rem 0;
  margin: 0.5rem 0;
}

.receipt-item {
  display: flex;
  justify-content: space-between;
  padding: 0.2rem 0;
}

.receipt-total {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.5rem 0;
}

.receipt-total .grand-total {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: 1.1rem;
  border-top: 2px solid #333;
  padding-top: 0.5rem;
}

/* ====== Toast ====== */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--card-bg);
  border-radius: 8px;
  padding: 0.8rem 1.2rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  animation: slideIn 0.3s ease;
  border-left: 4px solid var(--primary);
}

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

.toast i {
  font-size: 1.1rem;
}

.toast.success i { color: var(--success); }
.toast.error i { color: var(--danger); }
.toast.warning i { color: var(--warning); }

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

.toast.hide {
  animation: slideOut 0.3s ease forwards;
}

@keyframes slideOut {
  to { transform: translateX(100%); opacity: 0; }
}

/* ====== Responsive ====== */
@media (max-width: 1100px) {
  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }
  .pos-layout {
    grid-template-columns: 1fr 320px;
  }
  .report-stats-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-toggle {
    display: block;
  }
  .mobile-menu-btn {
    display: block;
  }
  .main-content {
    margin-left: 0;
  }
  .pos-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .pos-cart {
    height: 400px;
  }
  .dashboard-content,
  .reports-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }
  .report-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .report-date-nav {
    justify-content: center;
  }
  .report-actions-right {
    justify-content: center;
  }
}

@media (max-width: 600px) {
  .stats-row {
    grid-template-columns: 1fr;
  }
  .pages-container {
    padding: 1rem;
  }
  .page-header {
    flex-direction: column;
    align-items: stretch;
  }
  .search-box {
    min-width: 0;
    width: 100%;
  }
  .report-period-tabs {
    flex-wrap: wrap;
  }
  .report-stats-row {
    grid-template-columns: 1fr;
  }
  .report-date-display {
    min-width: 0;
    font-size: 0.9rem;
  }
}

/* ====== ໜ້າຈໍເຂົ້າສູ່ລະບົບ ====== */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 2990;
  display: none;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a73e8 0%, #0e3d7c 60%, #062344 100%);
  padding: 1rem;
}
.login-overlay.active {
  display: flex;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  text-align: center;
  animation: loginPop 0.35s ease-out;
}
@keyframes loginPop {
  from { transform: scale(0.92) translateY(12px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}
.login-logo {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1a73e8, #0e3d7c);
  color: #fff;
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  box-shadow: 0 8px 20px rgba(26, 115, 232, 0.4);
}
.login-card h2 {
  font-size: 1.3rem;
  color: #1a2b4d;
  margin-bottom: 0.25rem;
}
.login-sub {
  color: #667;
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
}
.login-card .form-group {
  text-align: left;
}
.login-btn {
  width: 100%;
  margin-top: 0.5rem;
  font-size: 1rem;
  padding: 0.75rem;
}
.login-hint {
  margin-top: 1.25rem;
  font-size: 0.78rem;
  color: #889;
  background: #f4f6fb;
  border-radius: 8px;
  padding: 0.5rem;
}

/* ====== ຜູ້ໃຊ້ງານ ====== */
.logout-btn {
  margin-top: 1rem;
  width: 100%;
  justify-content: center;
}
.user-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.self-badge {
  background: #e8f0fe;
  color: var(--primary);
  font-size: 0.72rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  margin-left: 0.25rem;
  white-space: nowrap;
}
.role-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  display: inline-block;
}
.role-badge.admin { background: #f3e8ff; color: #7c3aed; }
.role-badge.cashier { background: #dcfce7; color: #16a34a; }
.change-password-box {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid #eee;
}
.change-password-box h4 {
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  color: #334;
}

.btn-sm {
  padding: 0.35rem 0.8rem;
  font-size: 0.82rem;
  border-radius: 8px;
}

/* ====== ແຖບກຸ່ມຜູ້ໃຊ້ ====== */
.user-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.user-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid #e3e8f0;
  border-radius: 999px;
  background: #fff;
  color: #556;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.user-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.user-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.user-tab[data-user-filter="admin"]:hover {
  border-color: #7c3aed;
  color: #7c3aed;
}
.user-tab[data-user-filter="admin"].active {
  background: #7c3aed;
  border-color: #7c3aed;
  color: #fff;
}
.user-tab[data-user-filter="cashier"]:hover {
  border-color: #16a34a;
  color: #16a34a;
}
.user-tab[data-user-filter="cashier"].active {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
}
.user-tab-count {
  min-width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border-radius: 999px;
  background: #eef1f7;
  color: #556;
  font-size: 0.75rem;
  font-weight: 700;
}
.user-tab.active .user-tab-count {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}
.user-tab[data-user-filter="admin"] .user-tab-count {
  background: #f3e8ff;
  color: #7c3aed;
}
.user-tab[data-user-filter="admin"].active .user-tab-count {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}
.user-tab[data-user-filter="cashier"] .user-tab-count {
  background: #dcfce7;
  color: #16a34a;
}
.user-tab[data-user-filter="cashier"].active .user-tab-count {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

/* ====== ລູກຄ້າ ====== */
.search-box .search-btn,
.search-box .clear-btn {
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  flex-shrink: 0;
}
.points-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fef3d6;
  color: #d97706;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}
