/* ============================================================
   POS THG - Main Stylesheet
   Mobile-first, Touch-optimized
   ============================================================ */

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --sidebar-width: 220px;
  --header-height: 56px;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
  --transition: .15s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-tap-highlight-color: transparent; }
body { font-family: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; background: var(--gray-50); color: var(--gray-800); line-height: 1.5; min-height: 100vh; }
button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }
a { text-decoration: none; color: inherit; }
img { max-width: 100%; }
ul { list-style: none; }

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }

/* ---- LAYOUT ---- */
#app { display: flex; min-height: 100vh; }
#sidebar {
  width: var(--sidebar-width); min-height: 100vh; background: var(--gray-900);
  color: #fff; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; z-index: 100;
  transition: transform var(--transition);
}
#main-content { margin-left: var(--sidebar-width); flex: 1; min-height: 100vh; display: flex; flex-direction: column; }

/* ---- SIDEBAR ---- */
.sidebar-logo { padding: 18px 20px; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-logo .shop-name { font-size: 16px; font-weight: 700; color: #fff; }
.sidebar-logo .shop-sub { font-size: 11px; color: var(--gray-400); margin-top: 2px; }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-section { padding: 6px 20px 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: var(--gray-500); }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 20px;
  color: var(--gray-400); font-size: 14px; cursor: pointer; transition: all var(--transition);
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(37,99,235,.2); color: #fff; border-left-color: var(--primary); }
.nav-item .nav-icon { font-size: 18px; width: 22px; text-align: center; }
.nav-item .nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 20px; }
.sidebar-user { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-user .user-name { font-size: 13px; font-weight: 600; color: #fff; }
.sidebar-user .user-role { font-size: 11px; color: var(--gray-400); }
.sidebar-user .btn-logout { margin-top: 8px; width: 100%; padding: 7px; background: rgba(255,255,255,.07); color: var(--gray-300); border-radius: var(--radius-sm); font-size: 13px; transition: background var(--transition); }
.sidebar-user .btn-logout:hover { background: rgba(220,38,38,.3); color: #fff; }

/* ---- TOP BAR ---- */
#topbar {
  height: var(--header-height); background: #fff; border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; padding: 0 20px; gap: 12px;
  position: sticky; top: 0; z-index: 50; box-shadow: var(--shadow);
}
#topbar .page-title { font-size: 17px; font-weight: 700; flex: 1; }
#topbar .topbar-actions { display: flex; gap: 8px; }
.btn-menu-toggle { display: none; font-size: 22px; }

/* ---- PAGE CONTENT ---- */
.page { display: none; flex: 1; flex-direction: column; }
.page.active { display: flex; }
.page-body { flex: 1; padding: 20px; overflow-y: auto; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all var(--transition); border: none; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-ghost { background: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); }

/* ---- CARDS ---- */
.card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--gray-100); display: flex; align-items: center; gap: 10px; }
.card-title { font-size: 15px; font-weight: 700; flex: 1; }
.card-body { padding: 16px 18px; }

/* ---- STATS GRID ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: #fff; border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat-card .stat-label { font-size: 12px; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; }
.stat-card .stat-value { font-size: 22px; font-weight: 800; margin-top: 4px; color: var(--gray-800); }
.stat-card .stat-sub { font-size: 12px; color: var(--gray-400); margin-top: 2px; }
.stat-card.stat-blue { border-left: 4px solid var(--primary); }
.stat-card.stat-green { border-left: 4px solid var(--success); }
.stat-card.stat-orange { border-left: 4px solid var(--warning); }
.stat-card.stat-red { border-left: 4px solid var(--danger); }

/* ---- FORMS ---- */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 5px; }
.form-control {
  width: 100%; padding: 9px 12px; border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm); font-size: 14px; transition: border-color var(--transition);
  background: #fff;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.form-hint { font-size: 12px; color: var(--gray-400); margin-top: 3px; }

/* ---- TABLES ---- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { padding: 10px 12px; text-align: left; font-weight: 600; font-size: 12px; color: var(--gray-500); border-bottom: 1.5px solid var(--gray-200); white-space: nowrap; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.data-table tr:hover td { background: var(--gray-50); }
.data-table .actions { display: flex; gap: 4px; }

/* ---- BADGES ---- */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-blue { background: var(--primary-light); color: var(--primary); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* ---- MODAL ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
  padding: 16px; animation: fadeIn .15s ease;
}
.modal-overlay.hidden { display: none; }
.modal { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; gap: 10px; }
.modal-title { font-size: 16px; font-weight: 700; flex: 1; }
.modal-close { padding: 4px; color: var(--gray-400); font-size: 20px; }
.modal-close:hover { color: var(--gray-700); }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 8px; }

/* ---- TOAST ---- */
#toast-container { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--gray-900); color: #fff; padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 14px; box-shadow: var(--shadow-lg); min-width: 240px; max-width: 360px;
  display: flex; align-items: center; gap: 8px; animation: slideIn .2s ease;
}
.toast.toast-success { background: var(--success); }
.toast.toast-error { background: var(--danger); }
.toast.toast-warning { background: var(--warning); }
.toast-icon { font-size: 16px; flex-shrink: 0; }
.toast-msg { flex: 1; }
.toast-close { font-size: 16px; opacity: .7; cursor: pointer; }

/* ---- LOGIN PAGE ---- */
#login-page {
  position: fixed; inset: 0; background: linear-gradient(135deg, var(--gray-900) 0%, #1e3a5f 100%);
  display: flex; align-items: center; justify-content: center; z-index: 9998;
}
#login-page.hidden { display: none; }
.login-box { background: #fff; border-radius: 16px; padding: 36px 32px; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); }
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo .logo-icon { font-size: 48px; }
.login-logo h1 { font-size: 22px; font-weight: 800; color: var(--gray-900); margin-top: 8px; }
.login-logo p { font-size: 13px; color: var(--gray-500); }

/* ---- POS SCREEN ---- */
#pos-screen {
  display: none; position: fixed; inset: 0; background: var(--gray-50);
  z-index: 200; flex-direction: column;
}
#pos-screen.active { display: flex; }
.pos-topbar {
  height: 54px; background: var(--gray-900); color: #fff;
  display: flex; align-items: center; padding: 0 12px; gap: 10px; flex-shrink: 0;
}
.pos-topbar .pos-title { font-size: 15px; font-weight: 700; flex: 1; }
.pos-body { flex: 1; display: flex; overflow: hidden; }
.pos-products-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.pos-cart-panel { width: 340px; background: #fff; border-left: 1px solid var(--gray-200); display: flex; flex-direction: column; }

/* Product Search & Filter */
.pos-search-bar { padding: 10px 12px; background: #fff; border-bottom: 1px solid var(--gray-200); display: flex; gap: 8px; }
.pos-search-bar .search-input { flex: 1; padding: 8px 12px; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm); font-size: 14px; }
.pos-search-bar .search-input:focus { outline: none; border-color: var(--primary); }
.category-tabs { display: flex; gap: 6px; padding: 8px 12px; overflow-x: auto; background: #fff; border-bottom: 1px solid var(--gray-100); flex-shrink: 0; }
.category-tabs::-webkit-scrollbar { display: none; }
.cat-tab { padding: 5px 14px; border-radius: 20px; font-size: 13px; white-space: nowrap; background: var(--gray-100); color: var(--gray-600); cursor: pointer; transition: all var(--transition); }
.cat-tab.active { background: var(--primary); color: #fff; }
.cat-tab:hover:not(.active) { background: var(--gray-200); }

/* Product Grid */
.products-grid { flex: 1; overflow-y: auto; padding: 10px 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; align-content: start; }
.product-card {
  background: #fff; border-radius: var(--radius); padding: 12px 10px; text-align: center;
  cursor: pointer; transition: all var(--transition); box-shadow: var(--shadow);
  border: 2px solid transparent; user-select: none;
}
.product-card:hover { border-color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.product-card:active { transform: scale(.97); }
.product-card.out-of-stock { opacity: .5; cursor: not-allowed; }
.product-card .prod-name { font-size: 13px; font-weight: 600; color: var(--gray-800); line-height: 1.3; margin-bottom: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.product-card .prod-price { font-size: 14px; font-weight: 800; color: var(--primary); }
.product-card .prod-stock { font-size: 11px; color: var(--gray-400); margin-top: 2px; }
.product-card .prod-stock.low { color: var(--warning); }
.product-card .prod-stock.out { color: var(--danger); }

/* Cart Panel */
.cart-header { padding: 12px 14px; border-bottom: 1px solid var(--gray-100); display: flex; align-items: center; gap: 8px; }
.cart-title { font-size: 15px; font-weight: 700; flex: 1; }
.cart-count { background: var(--primary); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 20px; }
.cart-items { flex: 1; overflow-y: auto; }
.cart-item { padding: 10px 14px; border-bottom: 1px solid var(--gray-100); }
.cart-item-top { display: flex; align-items: center; gap: 6px; }
.cart-item-name { flex: 1; font-size: 13px; font-weight: 600; color: var(--gray-800); }
.cart-item-remove { color: var(--gray-400); font-size: 16px; padding: 2px; }
.cart-item-remove:hover { color: var(--danger); }
.cart-item-bottom { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.qty-control { display: flex; align-items: center; gap: 4px; }
.qty-btn { width: 28px; height: 28px; border-radius: var(--radius-sm); background: var(--gray-100); font-size: 16px; font-weight: 700; color: var(--gray-700); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.qty-btn:hover { background: var(--primary-light); color: var(--primary); }
.qty-input { width: 44px; text-align: center; padding: 3px; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; }
.cart-item-price { font-size: 13px; font-weight: 700; color: var(--primary); margin-left: auto; }
.cart-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--gray-400); padding: 40px 20px; }
.cart-empty .empty-icon { font-size: 48px; margin-bottom: 8px; }

/* Cart Footer */
.cart-footer { padding: 12px 14px; border-top: 1px solid var(--gray-200); }
.cart-subtotal { display: flex; justify-content: space-between; font-size: 13px; color: var(--gray-600); margin-bottom: 4px; }
.cart-discount-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.discount-input { width: 70px; padding: 4px 8px; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm); font-size: 13px; text-align: right; }
.cart-total { display: flex; justify-content: space-between; font-size: 18px; font-weight: 800; color: var(--gray-900); padding-top: 8px; border-top: 1px solid var(--gray-200); margin-bottom: 10px; }
.cart-total .total-vnd { color: var(--primary); }
.btn-checkout { background: var(--success); color: #fff; border: none; width: 100%; padding: 14px; border-radius: var(--radius); font-size: 16px; font-weight: 700; cursor: pointer; transition: background var(--transition); }
.btn-checkout:hover { background: #15803d; }
.btn-checkout:disabled { opacity: .5; cursor: not-allowed; }

/* Payment Modal */
.payment-methods { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.pay-method-btn {
  padding: 10px; text-align: center; border-radius: var(--radius-sm);
  border: 2px solid var(--gray-200); cursor: pointer; transition: all var(--transition);
  font-size: 13px; font-weight: 600;
}
.pay-method-btn:hover { border-color: var(--primary); }
.pay-method-btn.selected { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.pay-method-btn .pm-icon { font-size: 22px; display: block; margin-bottom: 4px; }

/* QR Payment */
.qr-payment-box { text-align: center; padding: 16px; background: var(--gray-50); border-radius: var(--radius); }
.qr-payment-box img { max-width: 200px; border-radius: var(--radius-sm); }
.qr-payment-box .qr-amount { font-size: 20px; font-weight: 800; color: var(--primary); margin-top: 8px; }
.qr-payment-box .qr-note { font-size: 12px; color: var(--gray-500); margin-top: 4px; }

/* ---- INVENTORY ---- */
.stock-indicator { display: inline-flex; align-items: center; gap: 4px; }
.stock-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.stock-dot.ok { background: var(--success); }
.stock-dot.low { background: var(--warning); }
.stock-dot.out { background: var(--danger); }

/* ---- LOADING ---- */
.loading-overlay { position: fixed; inset: 0; background: rgba(255,255,255,.8); z-index: 9990; display: flex; align-items: center; justify-content: center; }
.loading-overlay.hidden { display: none; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--gray-200); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }

/* ---- ANIMATIONS ---- */
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0 } to { transform: translateX(0); opacity: 1 } }
@keyframes spin { to { transform: rotate(360deg) } }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .5 } }

/* ---- SEARCH & FILTER BAR ---- */
.filter-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.search-box { position: relative; flex: 1; min-width: 200px; }
.search-box input { width: 100%; padding: 8px 12px 8px 36px; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm); font-size: 14px; }
.search-box input:focus { outline: none; border-color: var(--primary); }
.search-box .search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--gray-400); }

/* ---- MOBILE RESPONSIVE ---- */
@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  #main-content { margin-left: 0; }
  .btn-menu-toggle { display: flex; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .pos-cart-panel { position: fixed; bottom: 0; right: 0; left: 0; width: 100%; height: 50vh; border-left: none; border-top: 1px solid var(--gray-200); z-index: 10; transition: transform .2s ease; }
  .pos-cart-panel.cart-hidden { transform: translateY(100%); }
  .pos-products-panel { padding-bottom: 56px; }
  .products-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .page-body { padding: 14px; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .products-grid { grid-template-columns: repeat(3, 1fr); }
  .payment-methods { grid-template-columns: 1fr 1fr; }
  .modal { max-width: 100%; margin: 0; border-bottom-left-radius: 0; border-bottom-right-radius: 0; position: fixed; bottom: 0; left: 0; right: 0; max-height: 90vh; }
  .modal-overlay { align-items: flex-end; padding: 0; }
}
/* ---- SIDEBAR OVERLAY (mobile) ---- */
#sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 99; }
#sidebar-overlay.active { display: block; }

/* ---- QUICK AMOUNT BUTTONS (POS Payment) ---- */
.quick-amounts { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.quick-amt-btn {
  flex: 1; min-width: 60px; padding: 7px 4px; background: var(--gray-100);
  border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; color: var(--gray-700);
  cursor: pointer; transition: all var(--transition); border: 1.5px solid transparent; text-align: center;
}
.quick-amt-btn:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.quick-amt-btn:active { transform: scale(.96); }
.quick-amt-btn.btn-exact { background: var(--success-light); color: var(--success); flex: 2; }
.quick-amt-btn.btn-exact:hover { background: var(--success); color: #fff; }

/* ---- MOBILE ONLY (shown only on small screens) ---- */
.mobile-only { display: none; }
@media (max-width: 768px) { .mobile-only { display: inline-flex; } }

/* ---- KEYBOARD SHORTCUT HINT ---- */
.kbd-hint { font-size: 10px; color: var(--gray-500); background: var(--gray-100); border-radius: 3px; padding: 1px 4px; }

/* Number formatting */
.text-money { font-weight: 700; color: var(--primary); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
.text-sm { font-size: 12px; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* ---- FEATURE: Permission Matrix ---- */
.permission-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.permission-item { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--gray-100); border-radius: 8px; }
.permission-item label { cursor: pointer; font-size: 0.9rem; flex: 1; }
.permission-item input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--primary); flex-shrink: 0; }

/* ---- FEATURE: Invoice Template Editor ---- */
.template-editor-wrap { display: grid; grid-template-columns: 1fr 280px; gap: 16px; }
.template-textarea { width: 100%; height: 400px; font-family: 'Courier New', monospace; font-size: 13px; padding: 12px; border: 1px solid var(--gray-300); border-radius: 8px; background: #1a1a2e; color: #e0e0e0; resize: vertical; line-height: 1.5; }
.template-textarea:focus { outline: none; border-color: var(--primary); }
.template-variables { background: var(--gray-100); border-radius: 8px; padding: 12px; }
.template-variables h4 { margin-bottom: 8px; font-size: 0.85rem; color: var(--gray-600); }
.var-chip { display: inline-block; background: var(--primary); color: white; padding: 3px 8px; border-radius: 4px; font-size: 0.75rem; margin: 3px; cursor: pointer; font-family: monospace; transition: opacity 0.15s; }
.var-chip:hover { opacity: 0.8; }
.receipt-preview { font-family: 'Courier New', monospace; font-size: 12px; width: 300px; margin: 0 auto; padding: 16px; border: 1px dashed #ccc; background: white; color: black; white-space: pre-wrap; line-height: 1.6; }
@media (max-width: 768px) { .template-editor-wrap { grid-template-columns: 1fr; } .template-textarea { height: 280px; } }

/* ---- FEATURE: User Management Buttons ---- */
.btn-icon { background: none; border: none; cursor: pointer; padding: 4px 8px; border-radius: 6px; font-size: 1rem; transition: background 0.2s; line-height: 1; }
.btn-icon:hover { background: var(--gray-200); }
.btn-icon.btn-danger:hover { background: rgba(220,38,38,0.12); }
.user-status-active { color: #10b981; }
.user-status-inactive { color: #dc2626; }

/* ---- FEATURE: Modal Tabs ---- */
.modal-tabs { display: flex; border-bottom: 1px solid var(--gray-200); margin-bottom: 16px; gap: 0; }
.modal-tab-btn { padding: 8px 16px; background: none; border: none; cursor: pointer; color: var(--gray-500); border-bottom: 2px solid transparent; transition: all 0.2s; font-size: 14px; white-space: nowrap; }
.modal-tab-btn:hover { color: var(--gray-700); }
.modal-tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.modal-tab-panel { animation: fadeIn 0.15s ease; }

/* ---- FEATURE: Discount Type Toggle ---- */
.discount-type-toggle { display: flex; border: 1px solid var(--gray-300); border-radius: 6px; overflow: hidden; flex-shrink: 0; }
.disc-type-btn { padding: 4px 10px; font-size: 13px; font-weight: 600; background: var(--gray-100); color: var(--gray-600); border: none; cursor: pointer; transition: all .15s; }
.disc-type-btn:hover { background: var(--gray-200); }
.disc-type-btn.active { background: var(--primary); color: #fff; }

/* ---- FEATURE: Dual Notes Section ---- */
.notes-section { margin-top: 12px; border-top: 1px solid var(--gray-200); padding-top: 12px; }

/* ---- FEATURE: Barcode scan button in POS search ---- */
.pos-search-bar { display: flex; gap: 8px; align-items: center; }
.btn-scan-barcode { flex-shrink: 0; width: 40px; height: 40px; border-radius: 8px; background: var(--gray-700); color: #fff; font-size: 18px; display: flex; align-items: center; justify-content: center; border: none; cursor: pointer; transition: background .15s; }
.btn-scan-barcode:hover { background: var(--gray-600); }

/* ---- FEATURE: Product Options Modal ---- */
.option-group-block { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--gray-100); }
.option-group-block:last-child { border-bottom: none; }
.option-group-label { font-size: 13px; font-weight: 600; color: var(--gray-600); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .3px; }
.option-choices-row { display: flex; flex-wrap: wrap; gap: 8px; }
.option-choice-chip { padding: 6px 14px; border: 2px solid var(--gray-200); border-radius: 20px; font-size: 13px; cursor: pointer; transition: all .15s; background: #fff; color: var(--gray-700); user-select: none; }
.option-choice-chip:hover { border-color: var(--primary); color: var(--primary); }
.option-choice-chip.active { border-color: var(--primary); background: var(--primary); color: #fff; font-weight: 600; }

/* ---- FEATURE: Cart item options label ---- */
.cart-item-options { font-size: 11px; color: var(--primary); margin: 2px 0 4px; padding: 0 4px; font-style: italic; }

/* ---- FEATURE: Barcode in product table ---- */
.barcode-mini-wrap { display: flex; align-items: center; }
.barcode-mini { height: 28px; max-width: 100px; }

/* ---- FEATURE: Option Groups Admin ---- */
.option-groups-checklist { border: 1px solid var(--gray-200); border-radius: 8px; padding: 10px 14px; max-height: 160px; overflow-y: auto; background: var(--gray-50); }
.choices-list { display: flex; flex-direction: column; gap: 4px; }
.choice-row { display: flex; align-items: center; gap: 10px; padding: 5px 8px; background: var(--gray-50); border-radius: 6px; }
.choice-row span:first-child { flex: 1; font-size: 14px; }
.btn-xs { padding: 2px 8px; font-size: 12px; }
.mb-3 { margin-bottom: 12px; }

/* ---- FEATURE: Scanner modal video ---- */
#scanner-reader video { border-radius: 8px; }
#scanner-reader { min-height: 200px; background: #000; border-radius: 8px; }

/* ---- FEATURE: Bulk selection toolbar ---- */
.bulk-toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 10px;
  padding: 10px 14px; margin-bottom: 12px; font-size: 13px;
}
.bulk-toolbar #bulk-count {
  font-weight: 700; color: var(--primary); min-width: 80px;
}
.bulk-toolbar .form-control { padding: 4px 8px; font-size: 12px; }

/* Checkbox column: don't shrink rows visually */
.data-table td:first-child input[type="checkbox"],
.data-table th:first-child input[type="checkbox"] {
  width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary);
}
.data-table tr:has(.prod-cb:checked),
.data-table tr:has(.cat-cb:checked) {
  background: #eff6ff !important;
}

/* Import preview table */
#import-preview .data-table th,
#import-preview .data-table td { padding: 5px 8px; font-size: 12px; }

/* ============================================================
   MOBILE BOTTOM NAVIGATION
   ============================================================ */
#mobile-bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  background: #fff; border-top: 1px solid var(--gray-200);
  box-shadow: 0 -2px 8px rgba(0,0,0,.08);
  padding-bottom: env(safe-area-inset-bottom);
}
#mobile-bottom-nav .nav-tabs {
  display: flex; height: 56px;
}
#mobile-bottom-nav .nav-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 10px; color: var(--gray-500); cursor: pointer;
  transition: color var(--transition); padding: 4px 0; border: none; background: none;
  font-family: inherit;
}
#mobile-bottom-nav .nav-tab .tab-icon { font-size: 20px; line-height: 1; }
#mobile-bottom-nav .nav-tab.active { color: var(--primary); }
#mobile-bottom-nav .nav-tab.pos-tab {
  background: var(--primary); color: #fff; border-radius: 50%;
  width: 48px; height: 48px; margin: -12px auto 0; 0; margin-bottom: 10px; }
.batch-details   { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.batch-detail    { display: flex; gap: 8px; align-items: baseline; }
.detail-label    { color: var(--gray-500); min-width: 80px; }
.batch-notes     { font-size: 12px; color: var(--gray-500); margin-top: 6px; }
.batch-card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* Requirements panel (check batch) */
.requirements-panel {
  border-radius: 10px;
  padding: 14px;
  font-size: 13px;
}
.req-ok   { background: #f0fdf4; border: 1.5px solid #6ee7b7; }
.req-fail { background: #fff7ed; border: 1.5px solid #fbbf24; }
.req-header { font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.req-table th, .req-table td { font-size: 12px; padding: 6px 8px; }

/* Utility */
.fw-bold   { font-weight: 700; }
.text-danger  { color: #dc2626 !important; }
.text-success { color: #16a34a !important; }
.text-warning { color: #d97706 !important; }

/* Modal sizes */
.modal-xl .modal-box { max-width: 860px; width: 95vw; }

/* Form helpers */
.form-check-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: flex-end;
  padding-bottom: 6px;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray-400);
  font-size: 14px;
}

/* ============================================================
   POS v2 — Per-item Discount & Note
   ============================================================ */

/* Discount tag badge on item name */
.cart-item-disc-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  background: #fef3c7;
  color: #b45309;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  vertical-align: middle;
}

/* Note preview line */
.cart-item-note {
  font-size: 11px;
  color: var(--gray-500);
  margin: 2px 0 2px 2px;
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Discounted price highlight */
.cart-item-price.discounted {
  color: var(--danger);
}

/* Action buttons (% and ✍) next to price */
.cart-item-act-btn {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  background: var(--gray-100);
  color: var(--gray-600);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
  flex-shrink: 0;
}
.cart-item-act-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* Inline discount input row */
.item-disc-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 4px 2px;
  background: #fffbeb;
  border-radius: var(--radius-sm);
  margin-top: 4px;
}
.item-disc-row.hidden { display: none; }

/* Inline % / ₫ toggle buttons */
.idb {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  background: var(--gray-100);
  color: var(--gray-600);
  cursor: pointer;
  border: 1px solid var(--gray-200);
  transition: all var(--transition);
}
.idb.active {
  background: var(--warning);
  color: #fff;
  border-color: var(--warning);
}

/* Discount value input */
.item-disc-inp {
  flex: 1;
  min-width: 0;
  padding: 3px 6px;
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  background: #fff;
}
.item-disc-inp:focus { outline: none; border-color: var(--warning); }

/* Discount preview (e.g. -5,000đ) */
.item-disc-preview {
  font-size: 12px;
  font-weight: 700;
  color: var(--danger);
  white-space: nowrap;
  min-width: 40px;
  text-align: right;
}

/* Note input row */
.item-note-row {
  padding: 4px 4px 2px;
  margin-top: 4px;
}
.item-note-row.hidden { display: none; }

.item-note-inp {
  width: 100%;
  padding: 5px 8px;
  border: 1.5px solid var(--gray-200);
  border-radius: 6px;
  font-size: 13px;
  background: #f0fdf4;
}
.item-note-inp:focus {
  outline: none;
  border-color: var(--success);
  background: #fff;
}

/* ============================================================
   Products Slide Panel (C1)
   ============================================================ */
.products-layout {
  display: flex;
  gap: 0;
  position: relative;
  min-height: 400px;
}
.products-main-area {
  flex: 1;
  min-width: 0;
  transition: width var(--transition);
}
.product-edit-panel {
  width: 0;
  overflow: hidden;
  background: #fff;
  border-left: 2px solid var(--gray-200);
  transition: width .25s ease;
  flex-shrink: 0;
  position: relative;
}
.products-layout.panel-open .product-edit-panel {
  width: 420px;
  overflow-y: auto;
}
@media (max-width: 900px) {
  .products-layout.panel-open .product-edit-panel {
    width: 100%;
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    z-index: 200;
    border-left: none;
    box-shadow: -4px 0 24px rgba(0,0,0,.15);
  }
}
.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--gray-200);
  background: var(--gray-50);
  position: sticky;
  top: 0;
  z-index: 5;
}
.panel-title { flex: 1; font-size: 15px; font-weight: 700; }
.btn-panel-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--gray-200);
  color: var(--gray-600);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  flex-shrink: 0;
}
.btn-panel-close:hover { background: var(--danger-light); color: var(--danger); }
.panel-body { padding: 16px 18px; }

/* ── Tile +/- quantity controls (A1) ──────────────────────── */
.product-card { position: relative; }
.product-card.in-cart { outline: 2px solid var(--primary); }
.tile-qty-controls {
  position: absolute; top: 4px; right: 4px; z-index: 2;
  display: flex; align-items: center; gap: 2px;
  background: rgba(255,255,255,0.95); border-radius: 20px;
  padding: 2px 4px; box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
.tile-qty-btn {
  width: 22px; height: 22px; border-radius: 50%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; line-height: 1;
  background: var(--primary); color: #fff; padding: 0;
}
.tile-qty-btn:hover { opacity: 0.85; }
.tile-qty-minus { background: #ef4444; }
.tile-qty-count {
  min-width: 18px; text-align: center; font-weight: 700;
  font-size: 12px; color: var(--primary);
}

/* ── Parked orders badge ────────────────────────────────── */
.pos-badge {
  background: #ef4444; color: #fff; border-radius: 50%;
  width: 16px; height: 16px; font-size: 10px;
  display: flex; align-items: center; justify-content: center;
}
.parked-order-row:last-child { border-bottom: none !important; }

/* ── Customers CRM (B2) ─────────────────────────────────── */
.pos-cust-dropdown {
  position: absolute; top: 100%; left: 0; right: 40px; z-index: 9999;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12); max-height: 200px; overflow-y: auto;
  display: none;
}
.pos-cust-item {
  padding: 8px 12px; cursor: pointer; font-size: 13px;
  border-bottom: 1px solid #f3f4f6;
}
.pos-cust-item:hover { background: #f0f9ff; }
.pos-cust-item:last-child { border-bottom: none; }

/* ── Permission toggles (Phân quyền) ─────────────────────── */
.perm-toggle {
  display: inline-flex; align-items: center; cursor: pointer;
  position: relative; width: 36px; height: 20px;
}
.perm-toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.perm-dot {
  position: absolute; inset: 0;
  background: #d1d5db; border-radius: 20px; transition: background .2s;
}
.perm-dot::after {
  content: ''; position: absolute;
  left: 3px; top: 3px; width: 14px; height: 14px;
  background: #fff; border-radius: 50%; transition: transform .2s;
}
.perm-toggle input:checked ~ .perm-dot { background: #10b981; }
.perm-toggle input:checked ~ .perm-dot::after { transform: translateX(16px); }
.perm-toggle.is-default .perm-dot { background: #9ca3af; }
.perm-toggle.is-default input:checked ~ .perm-dot { background: #6366f1; }

/* ── Commission page ─────────────────────────────────────── */
.stat-card {
  background: var(--card-bg, #1f2937); border-radius: 12px;
  padding: 16px 20px; border: 1px solid rgba(255,255,255,.08);
  border-left: 4px solid var(--card-color, #6366f1);
}
.stat-card .stat-value { font-size: 22px; font-weight: 700; color: #f9fafb; }
.stat-card .stat-label { font-size: 12px; color: #9ca3af; margin-top: 4px; }

/* ═══════════════════════════════════════════════════════════
   SIDEBAR — Compact collapsible redesign
   ═══════════════════════════════════════════════════════════ */

/* Sidebar toggle button */
.sidebar-toggle-btn {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px;
  background: rgba(255,255,255,.08); border: none; cursor: pointer;
  color: #fff; font-size: 16px; transition: background .15s;
  flex-shrink: 0;
}
.sidebar-toggle-btn:hover { background: rgba(255,255,255,.18); }

/* Nav section headers — collapsible with chevron */
.nav-section {
  display: flex; align-items: center; justify-content: space-between;
  user-select: none;
}
.nav-section::after {
  content: '›'; font-size: 14px; color: rgba(255,255,255,.35);
  transform: rotate(90deg); transition: transform .2s;
  margin-right: 4px;
}
.nav-section.nav-section-collapsed::after { transform: rotate(0deg); }
.nav-section[id] { cursor: pointer; }
.nav-section[id]:hover { background: rgba(255,255,255,.06); border-radius: 6px; }

/* Hide nav items in collapsed group */
.nav-item.nav-group-hidden { display: none !important; }

/* Sidebar collapsed (icon-only) mode */
#sidebar.sidebar-collapsed { width: 58px; }
#sidebar.sidebar-collapsed .sidebar-nav-label,
#sidebar.sidebar-collapsed .sidebar-username,
#sidebar.sidebar-collapsed #sidebar-role,
#sidebar.sidebar-collapsed #sidebar-branch-name,
#sidebar.sidebar-collapsed .nav-section { display: none; }
#sidebar.sidebar-collapsed .nav-item { justify-content: center; padding: 10px 0; }
#sidebar.sidebar-collapsed .nav-item .nav-icon { margin-right: 0; font-size: 18px; }
#sidebar.sidebar-collapsed ~ .main-content { margin-left: 58px; }

/* Branch name badge in sidebar */
#sidebar-branch-name {
  font-size: 11px; color: rgba(255,255,255,.6);
  padding: 3px 12px; display: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Branch switcher link */
#sidebar-branch-switcher {
  font-size: 11px; color: #60a5fa; cursor: pointer;
  padding: 0 12px 6px; display: none;
}
#sidebar-branch-switcher:hover { text-decoration: underline; }

/* ═══════════════════════════════════════════════════════════
   BRANCH SELECTION SCREEN (after login)
   ═══════════════════════════════════════════════════════════ */
#branch-selection-page {
  position: fixed; inset: 0; z-index: 9000;
  background: #f1f5f9; overflow-y: auto;
}
.branch-sel-header {
  background: #1e293b; color: #fff;
  padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
  position: sticky; top: 0; z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.branch-sel-logo {
  font-size: 20px; font-weight: 700; color: #fff; letter-spacing: -.3px;
}
.branch-search-input {
  padding: 7px 12px; border-radius: 8px; border: 1px solid #334155;
  background: #334155; color: #fff; font-size: 13px; width: 220px;
  outline: none;
}
.branch-search-input::placeholder { color: #94a3b8; }
.branch-search-input:focus { border-color: #60a5fa; }
.branch-sel-body { padding: 28px 24px; max-width: 1100px; margin: 0 auto; }
.branch-sel-title {
  font-size: 15px; font-weight: 600; color: #374151;
  margin-bottom: 20px;
}
.branch-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.branch-card {
  background: #fff; border-radius: 14px; padding: 20px 16px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08); border: 2px solid transparent;
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; position: relative; transition: box-shadow .2s, border-color .2s;
  cursor: default;
}
.branch-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.12); }
.branch-card-active { border-color: #2563eb; box-shadow: 0 0 0 3px #dbeafe; }
.branch-card-badge {
  position: absolute; top: 10px; left: 10px;
  background: #2563eb; color: #fff; font-size: 10px;
  padding: 2px 8px; border-radius: 20px; font-weight: 600;
}
.branch-card-options {
  position: absolute; top: 10px; right: 10px;
}
.branch-opt-btn {
  background: none; border: none; cursor: pointer;
  font-size: 16px; color: #9ca3af; padding: 2px 6px; border-radius: 6px;
  transition: background .15s, color .15s;
}
.branch-opt-btn:hover { background: #f3f4f6; color: #374151; }
.branch-card-avatar {
  width: 64px; height: 64px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.branch-card-name {
  font-size: 14px; font-weight: 600; color: #1f2937;
  text-align: center; word-break: break-word;
}
.branch-card-meta {
  font-size: 12px; color: #6b7280; text-align: center;
  min-height: 16px;
}
.branch-card-btn {
  margin-top: 6px; width: 100%; font-size: 13px;
  padding: 7px 0; border-radius: 8px;
}
.btn-outline {
  background: #fff; border: 1.5px solid #2563eb; color: #2563eb;
  font-weight: 600; cursor: pointer; transition: background .15s, color .15s;
}
.btn-outline:hover { background: #2563eb; color: #fff; }
.btn-warning {
  background: #f59e0b; color: #fff; border: none;
  font-weight: 600; cursor: pointer; border-radius: 8px;
  padding: 7px 14px; font-size: 13px; transition: background .15s;
}
.btn-warning:hover { background: #d97706; }
