:root {
  --primary: #1565C0;
  --primary-light: #1E88E5;
  --primary-dark: #0D47A1;
  --secondary: #2E7D32;
  --secondary-light: #43A047;
  --accent: #00ACC1;
  --bg: #F0F4F8;
  --card: #FFFFFF;
  --text: #263238;
  --text-light: #607D8B;
  --border: #E0E0E0;
  --danger: #E53935;
  --warning: #FB8C00;
  --success: #43A047;
  --sidebar-w: 260px;
  --topbar-h: 60px;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

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

body {
  font-family: 'Sarabun', 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  left: 0; top: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: #fff;
  z-index: 1000;
  overflow-y: auto;
  transition: transform 0.3s ease;
}
.sidebar-header {
  padding: 20px 16px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}
.sidebar-header .logo-icon { font-size: 36px; margin-bottom: 4px; }
.sidebar-header h3 { font-size: 14px; font-weight: 600; line-height: 1.4; }
.sidebar-nav { padding: 12px 0; }
.sidebar-nav .nav-section { padding: 8px 16px 4px; font-size: 11px; text-transform: uppercase; opacity: 0.5; letter-spacing: 1px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.1); color: #fff; }
.sidebar-nav a.active { background: rgba(255,255,255,0.15); color: #fff; border-left-color: #fff; font-weight: 600; }
.sidebar-nav a .icon { width: 20px; text-align: center; font-size: 16px; }

/* ===== TOPBAR ===== */
.topbar {
  position: fixed;
  top: 0; left: var(--sidebar-w);
  right: 0;
  height: var(--topbar-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 900;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left .menu-toggle { display: none; background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text); }
.topbar-left h2 { font-size: 18px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-right .user-info { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.topbar-right .user-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px; }

/* ===== MAIN CONTENT ===== */
.main-content {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  padding: 24px;
  min-height: calc(100vh - var(--topbar-h));
}

/* ===== CARDS ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: 16px; font-weight: 600; }

/* ===== SUMMARY CARDS ===== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.summary-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform 0.2s;
}
.summary-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.summary-card .icon-box {
  width: 56px; height: 56px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
}
.summary-card .icon-box.blue { background: #E3F2FD; color: var(--primary); }
.summary-card .icon-box.green { background: #E8F5E9; color: var(--secondary); }
.summary-card .icon-box.orange { background: #FFF3E0; color: var(--warning); }
.summary-card .icon-box.red { background: #FFEBEE; color: var(--danger); }
.summary-card .info h4 { font-size: 24px; font-weight: 700; color: var(--text); }
.summary-card .info p { font-size: 13px; color: var(--text-light); }

/* ===== TABLES ===== */
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
table th {
  background: #F5F7FA;
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-light);
  font-size: 13px;
  white-space: nowrap;
  border-bottom: 2px solid var(--border);
}
table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table tr:hover td { background: #F8FAFC; }
table .badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-success { background: #E8F5E9; color: var(--success); }
.badge-danger { background: #FFEBEE; color: var(--danger); }
.badge-warning { background: #FFF3E0; color: var(--warning); }
.badge-info { background: #E3F2FD; color: var(--primary); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--secondary); color: #fff; }
.btn-success:hover { background: #1B5E20; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #C62828; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #E65100; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: #F5F5F5; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn-icon { padding: 8px; width: 36px; height: 36px; justify-content: center; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; color: var(--text); }
.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
  background: #fff;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(21,101,192,0.1); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal {
  background: var(--card);
  border-radius: var(--radius);
  width: 90%; max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform 0.2s;
}
.modal-overlay.active .modal { transform: translateY(0); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-light); }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ===== POS PAGE ===== */
.pos-layout { display: grid; grid-template-columns: 1fr 380px; gap: 20px; height: calc(100vh - var(--topbar-h) - 48px); }
.pos-products { overflow-y: auto; }
.pos-cart { display: flex; flex-direction: column; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.pos-cart-header { padding: 16px; border-bottom: 1px solid var(--border); background: var(--primary); color: #fff; }
.pos-cart-items { flex: 1; overflow-y: auto; padding: 8px; }
.pos-cart-item { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; border-bottom: 1px solid #F0F0F0; }
.pos-cart-item:hover { background: #F8FAFC; }
.pos-cart-item .item-info { flex: 1; }
.pos-cart-item .item-name { font-size: 13px; font-weight: 500; }
.pos-cart-item .item-price { font-size: 12px; color: var(--text-light); }
.pos-cart-item .qty-controls { display: flex; align-items: center; gap: 4px; }
.pos-cart-item .qty-controls button { width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: 16px; display: flex; align-items: center; justify-content: center; }
.pos-cart-item .qty-controls span { min-width: 30px; text-align: center; font-weight: 600; }
.pos-cart-item .item-subtotal { font-weight: 600; font-size: 13px; white-space: nowrap; }
.pos-cart-item .remove-btn { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 16px; }
.pos-cart-footer { padding: 16px; border-top: 2px solid var(--border); }
.pos-cart-total { display: flex; justify-content: space-between; font-size: 20px; font-weight: 700; margin-bottom: 12px; color: var(--primary-dark); }
.pos-product-search { margin-bottom: 16px; display: flex; gap: 8px; }
.pos-product-search input { flex: 1; padding: 12px 16px; border: 2px solid var(--border); border-radius: 10px; font-size: 16px; }
.pos-product-search input:focus { border-color: var(--primary); }
.pos-product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.pos-product-card {
  background: var(--card);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}
.pos-product-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.pos-product-card .product-icon { font-size: 32px; margin-bottom: 8px; }
.pos-product-card .product-name { font-size: 13px; font-weight: 500; margin-bottom: 4px; line-height: 1.3; }
.pos-product-card .product-price { font-size: 15px; font-weight: 700; color: var(--primary); }
.pos-product-card .product-stock { font-size: 11px; color: var(--text-light); }
.pos-product-card.low-stock { border-color: var(--danger); }
.pos-product-card .stock-warning { color: var(--danger); font-size: 11px; font-weight: 600; }

/* ===== CASH PAYMENT ===== */
.cash-row { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.cash-row label { min-width: 80px; font-weight: 500; }
.cash-row input { flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 16px; text-align: right; }
.cash-row .change-amount { font-size: 18px; font-weight: 700; color: var(--secondary); }

/* ===== LOGIN PAGE ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary), var(--accent));
}
.login-box {
  background: var(--card);
  border-radius: 16px;
  padding: 40px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.login-box h2 { text-align: center; margin-bottom: 8px; color: var(--primary-dark); }
.login-box .subtitle { text-align: center; color: var(--text-light); margin-bottom: 24px; font-size: 14px; }

/* ===== CHARTS ===== */
.chart-container { position: relative; width: 100%; height: 280px; }
.chart-container canvas { width: 100% !important; height: 100% !important; }

/* ===== CASH COUNTING ===== */
.cash-denom-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.cash-denom-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px;
  background: #F8FAFC;
  border-radius: 8px;
}
.cash-denom-item label { min-width: 120px; font-weight: 500; }
.cash-denom-item input { width: 80px; padding: 8px; border: 1px solid var(--border); border-radius: 6px; text-align: center; font-size: 16px; }
.cash-denom-item .subtotal { font-weight: 600; min-width: 80px; text-align: right; }

/* ===== PRINT STYLES ===== */
@media print {
  .sidebar, .topbar, .no-print, .btn, .pos-cart-footer .btn { display: none !important; }
  .main-content { margin: 0 !important; padding: 16px !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd; }
  body { background: #fff; }
  .print-area { display: block !important; }
  .signature-line { margin-top: 40px; text-align: right; font-size: 14px; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .pos-layout { grid-template-columns: 1fr; height: auto; }
  .pos-cart { max-height: 400px; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .topbar { left: 0; }
  .topbar-left .menu-toggle { display: block; }
  .main-content { margin-left: 0; padding: 16px; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .summary-grid { grid-template-columns: 1fr; }
  .pos-product-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== RECEIPT ===== */
.receipt { max-width: 320px; margin: 0 auto; font-family: 'Courier New', monospace; font-size: 12px; }
.receipt h3 { text-align: center; font-size: 14px; }
.receipt .line { border-top: 1px dashed #000; margin: 8px 0; }
.receipt .row { display: flex; justify-content: space-between; margin: 2px 0; }
.receipt .total-row { font-weight: bold; font-size: 14px; border-top: 2px solid #000; padding-top: 4px; margin-top: 4px; }

/* ===== MISC ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-light); }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mt-2 { margin-top: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.empty-state { text-align: center; padding: 40px; color: var(--text-light); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.search-bar { position: relative; }
.search-bar input { padding-left: 40px; }
.search-bar .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-light); }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-header h2 { font-size: 22px; font-weight: 700; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; }
.tag-admin { background: #E3F2FD; color: var(--primary); }
.tag-staff { background: #E8F5E9; color: var(--secondary); }
.tag-member { background: #FFF3E0; color: var(--warning); }
.loading { text-align: center; padding: 40px; }
.category-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; background: #E3F2FD; color: var(--primary); font-size: 12px; font-weight: 500; }

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.3s ease; }
@keyframes slideIn { from { transform: translateX(-100%); } to { transform: translateX(0); } }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CCC; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #AAA; }

/* Overlay for mobile sidebar */
.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 999; display: none;
}
.sidebar-overlay.active { display: block; }
