:root {
  --bg: #f7f7f7;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #7c5cc4;
  --primary-text: #ffffff;
  --success: #059669;
  --danger: #dc2626;
  --warning: #d97706;
  --sidebar-bg: #ffffff;
  --sidebar-text: #374151;
  --sidebar-active: #f3effa;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}
[data-theme="dark"] {
  --bg: #0f1220;
  --card: #171a2b;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: #2a2e45;
  --primary: #6366f1;
  --primary-text: #ffffff;
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --sidebar-bg: #12142280;
  --sidebar-text: #d1d5db;
  --sidebar-active: #262b47;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); }
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 32px; width: 320px; }
.login-card h1 { margin: 0 0 20px; font-size: 1.4rem; text-align: center; }
.form-row { margin-bottom: 14px; display: flex; flex-direction: column; gap: 4px; }
.form-row label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
input, select, textarea { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text); font-size: 0.9rem; width: 100%; }
.btn { display: inline-block; padding: 9px 16px; border-radius: 8px; border: none; background: var(--primary); color: var(--primary-text); font-weight: 600; cursor: pointer; font-size: 0.9rem; text-decoration: none; }
.btn.secondary { background: var(--border); color: var(--text); }
.error { color: var(--danger); font-size: 0.85rem; }
.success { color: var(--success); font-size: 0.85rem; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 260px; background: var(--sidebar-bg); border-right: 1px solid var(--border); padding: 8px 0 16px; flex-shrink: 0; position: fixed; top: 0; left: 0; height: 100vh; overflow-y: auto; z-index: 60; transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: 2px 0 12px rgba(0,0,0,0.15); }
.sidebar.open { transform: translateX(0); }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: transparent; z-index: 55; }
.sidebar-overlay.open { display: block; }
.sidebar.open ~ .sidebar-overlay ~ .main { margin-left: 260px; }
@media (max-width: 768px) {
  .sidebar.open ~ .sidebar-overlay ~ .main { margin-left: 0; }
  .sidebar-overlay { background: rgba(0,0,0,0.35); }
}
.brand-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 18px 16px; }
.sidebar .brand { font-weight: 700; font-size: 1.1rem; }
.sidebar-close { background: none; border: none; color: var(--sidebar-text); font-size: 1.1rem; cursor: pointer; }
.hamburger { background: none; border: 1px solid var(--border); color: var(--text); border-radius: 8px; width: 36px; height: 36px; cursor: pointer; font-size: 1rem; display: inline-flex; align-items: center; justify-content: center; }
.right-panel { position: fixed; top: 0; right: 0; height: 100vh; width: 250px; background: var(--card); box-shadow: 0 0 35px rgba(154,161,171,0.25); padding: 20px 0; z-index: 999; transform: translateX(100%); transition: transform 0.25s ease; overflow-y: auto; }
.right-panel.open { transform: translateX(0); }
.right-panel a { display: flex; align-items: center; gap: 8px; height: 60px; padding: 0 20px; color: #7c5cc4; font-size: 0.875rem; text-decoration: none; border-bottom: 1px solid var(--border); }
.right-panel a:hover, .right-panel a.active { background: var(--sidebar-active); }
.right-panel-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.25); z-index: 998; display: none; }
.right-panel-overlay.open { display: block; }
.sidebar a { display: block; padding: 9px 18px; color: var(--sidebar-text); text-decoration: none; font-size: 0.88rem; }
.sidebar a:hover, .sidebar a.active { background: var(--sidebar-active); }
.sidebar .nav-icon { display: inline-block; width: 20px; }
.nav-parent { display: flex; align-items: center; width: 100%; padding: 9px 18px; background: none; border: none; color: var(--sidebar-text); font-size: 0.88rem; font-family: inherit; text-align: left; cursor: pointer; }
.nav-parent:hover { background: var(--sidebar-active); }
.nav-parent .chevron { margin-left: auto; transition: transform 0.15s; font-size: 0.75rem; }
.nav-group.open .nav-parent .chevron { transform: rotate(90deg); }
.nav-children { display: none; background: rgba(0,0,0,0.08); }
[data-theme="dark"] .nav-children { background: rgba(0,0,0,0.2); }
.nav-group.open .nav-children { display: block; }
.nav-children a { padding-left: 46px; font-size: 0.85rem; }
.quick-add-menu { display: none; }
.quick-add-menu a { padding: 8px 14px !important; color: var(--text) !important; }
.quick-add-menu a:hover { background: var(--sidebar-active); }
.nav-group.open .quick-add-menu { display: block; }
.main { flex: 1; min-width: 0; transition: margin-left 0.2s ease; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--border); }
.topbar .actions { display: flex; align-items: center; gap: 12px; }
.theme-toggle { cursor: pointer; border: 1px solid var(--border); background: var(--card); color: var(--text); border-radius: 8px; padding: 6px 10px; font-size: 0.85rem; }
.content { padding: 20px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }

.grid-6, .grid-4, .grid-3, .grid-2 { display: grid; gap: 14px; margin-bottom: 20px; grid-template-columns: repeat(1, 1fr); }
@media (min-width: 576px) {
  .grid-6, .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3, .grid-2 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 768px) {
  .grid-6 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1200px) {
  .grid-6 { grid-template-columns: repeat(6, 1fr); }
}
.stat, .card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.stat .value { font-size: 1.4rem; font-weight: 700; margin-top: 4px; }
.stat .label { color: var(--muted); font-size: 0.82rem; display: flex; align-items: center; gap: 6px; }

.stat2 { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.stat2-row { display: flex; align-items: center; gap: 10px; }
.stat2-icon { font-size: 1.4rem; line-height: 1; }
.stat2-value { font-size: 1.15rem; font-weight: 700; color: var(--text); }
.stat2-label { font-size: 0.85rem; font-weight: 700; margin-top: 6px; }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge.active { background: #16d39a; color: #fff; }
.badge.inactive { background: #ff7588; color: #fff; }
.toolbar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 16px; }

.list-toolbar-top { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.btn-teal { background: #17b8a6; color: #fff; }
.btn-purple-solid { background: #7c5cc4; color: #fff; }
.list-controls { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.list-controls .per-page { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); }
.list-controls .per-page select { width: auto; padding: 4px 8px; }
.list-controls .search-box input { width: 220px; }
.export-icons { display: flex; gap: 6px; }
.export-icons button { width: 34px; height: 34px; border: none; border-radius: 6px; color: #fff; cursor: pointer; font-size: 0.85rem; }
.export-pdf { background: #e83e8c; }
.export-excel { background: #ffc107; }
.export-print { background: #17a2b8; }
.export-delete { background: #dc3545; }
.export-cols { background: #7c5cc4; position: relative; }
.thumb-img { width: 32px; height: 32px; border-radius: 4px; object-fit: cover; background: var(--border); vertical-align: middle; }

.action-dropdown { position: relative; display: inline-block; }
.action-dropdown .action-menu { display: none; position: absolute; right: 0; top: 110%; background: var(--card); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,0.15); min-width: 120px; z-index: 50; }
.action-dropdown.open .action-menu { display: block; }
.action-dropdown .action-menu a, .action-dropdown .action-menu button { display: block; width: 100%; text-align: left; padding: 8px 14px; font-size: 0.85rem; color: var(--text); text-decoration: none; background: none; border: none; cursor: pointer; }
.action-dropdown .action-menu a:hover, .action-dropdown .action-menu button:hover { background: var(--sidebar-active); }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 2000; display: none; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal-box { background: var(--card); border-radius: 8px; width: 440px; max-width: 92vw; max-height: 90vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,0.3); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; font-size: 1.05rem; }
.modal-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--muted); }
.modal-body { padding: 18px; }
.modal-footer { padding: 12px 18px; border-top: 1px solid var(--border); text-align: right; }

/* ===== Demo-matched theme (measured from the reference POS) ===== */
:root { --text: #5e5873; --muted: #6e6b7b; --border: #ebe9f1; --shadow: 0 0 35px rgba(154,161,171,0.15); --sidebar-text: #5e5873; --sidebar-active: rgba(124,92,196,0.08); }
[data-theme="dark"] { --text: #e5e7eb; --muted: #9ca3af; --border: #2a2e45; --shadow: 0 1px 3px rgba(0,0,0,0.4); --sidebar-text: #d1d5db; --sidebar-active: #262b47; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--text); }
input, select, textarea { padding: 4px 8px; min-height: 31px; border: 1px solid #e4e6fc; border-radius: 4px; background: #fdfdff; color: #495057; font-size: 14px; }
select { border-color: #ddd; border-radius: 5px; font-weight: 300; }
input[type=checkbox], input[type=radio] { min-height: 0; }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea { background: var(--card); border-color: var(--border); color: var(--text); }
.btn { padding: 7.2px 12px; border-radius: 4px; font-weight: 400; font-size: 0.9rem; }
.btn.secondary { background: #ebe9f1; color: #5e5873; }
.action-dropdown > .btn.secondary { background: transparent; border: 1px solid var(--primary); color: var(--primary); }
.stat, .card, .stat2 { border: 0; border-radius: 5px; box-shadow: var(--shadow); }
table { font-size: 0.85rem; color: var(--muted); }
th { color: var(--muted); font-size: 0.85rem; font-weight: 600; text-transform: none; letter-spacing: 0; padding: 12px; }
td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.content h1 { font-size: 1.1rem; font-weight: 400; margin: 4px 0 14px; }
.topbar { margin: 15px 0; height: 61px; padding: 0 15px; border: 0; border-radius: 5px; box-shadow: 0 4px 24px 0 rgba(34,41,47,0.1); }
.hamburger { border: 1px solid var(--primary); color: var(--primary); border-radius: 5px; width: 40px; height: 40px; }
.content { padding: 0 0 50px; }
.main { padding: 0 15px; }
.nav-children { background: #f7f7f7; border-radius: 4px; margin: 5px 10px; padding: 10px 0; }
[data-theme="dark"] .nav-children { background: rgba(0,0,0,0.2); }
.nav-children a { padding: 5px 12px 5px 22px; margin: 0; color: #7d7d7d; font-size: 13px; background: transparent; }
.nav-children a:hover { background: transparent; color: var(--primary); }
.nav-children a.active { background: transparent; color: var(--primary); }
.sidebar a, .nav-parent { color: var(--sidebar-text); }
.sidebar a:hover, .nav-parent:hover { background: transparent; color: var(--primary); }
@media (min-width: 992px) {
  .sidebar { transform: none; width: 230px; border-right: 0; box-shadow: 0 0 15px 0 rgba(34,41,47,0.05); }
  .main { margin-left: 230px; }
  .sidebar.open ~ .sidebar-overlay ~ .main { margin-left: 230px; }
  body.nav-collapsed .sidebar { transform: translateX(-100%); }
  body.nav-collapsed .main, body.nav-collapsed .sidebar.open ~ .sidebar-overlay ~ .main { margin-left: 0; }
  .sidebar-close { display: none; }
  .sidebar-overlay, .sidebar-overlay.open { display: none !important; }
}
a[data-pos-btn] { width: auto !important; padding: 0 12px !important; font-size: 0.85rem; }
.list-controls .search-box { order: 2; }
.list-controls .export-icons { order: 3; }
.list-controls { flex-wrap: nowrap; }
.thumb-img { width: 50px; height: 50px; border-radius: 50%; }
.brand-row { padding: 14px 18px 12px; }
.form-row label { font-size: 0.9rem; font-weight: 400; color: var(--text); }

/* sortable table headers (arrows drawn with ::after so header text stays clean) */
th.sortable { cursor: pointer; white-space: nowrap; user-select: none; }
th.sortable::after { content: "\21C5"; margin-left: 6px; font-size: .78em; opacity: .4; float: right; }
th.sort-asc::after { content: "\2191"; opacity: 1; color: var(--primary); }
th.sort-desc::after { content: "\2193"; opacity: 1; color: var(--primary); }

/* phone layout (<768px): wrapped top bar, stacked list controls, scrollable tables, fitted popups */
@media (max-width: 767px) {
  .main { padding: 0 10px; }
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 10px; gap: 6px; margin: 10px 0; }
  .topbar > div:first-child { width: 100%; }
  .topbar .actions { width: 100%; flex-wrap: wrap; gap: 4px; }
  .topbar .actions .hamburger, .topbar .actions #quickAddToggle { width: 34px !important; height: 34px !important; border-color: transparent !important; background: transparent; }
  .topbar .actions #userToggle { width: auto !important; padding: 0 6px !important; }
  .topbar .actions #userToggle span { display: none; }
  a[data-pos-btn] { display: none !important; }
  .list-controls { flex-wrap: wrap; justify-content: center; text-align: center; }
  .list-controls .search-box { width: 100%; }
  .list-controls .search-box input { width: 100%; }
  .list-controls .export-icons { width: 100%; justify-content: center; }
  .list-toolbar-top { flex-wrap: wrap; }
  .card { padding: 10px; overflow-x: auto; }
  .modal-box, .modal-box[style] { width: 96vw !important; max-width: 96vw; }
  .modal-body { padding: 12px; }
  .content h1 { font-size: 1rem; }
  .ph-filter .form-row, .ph-filter .ph-name { flex: 1 1 100%; }
  .tbl-foot, .ph-foot { justify-content: center; }
}

/* print: only the table (like the reference's print view) */
@media print {
  .sidebar, .sidebar-overlay, .topbar, .right-panel, .right-panel-overlay, .list-toolbar-top, .list-controls, .tbl-foot, .ph-foot, .ph-tabs, .ph-filter .form-row, #colMenu, .modal-overlay, footer, .app-footer, p.success, p.error, .content > p > a.btn.secondary { display: none !important; }
  .main { margin-left: 0 !important; padding: 0 !important; }
  body { background: #fff !important; }
  .card { box-shadow: none !important; padding: 0 !important; }
  #prodTable th:first-child, #prodTable td:first-child, #prodTable th:last-child, #prodTable td:last-child,
  #brandTable th:first-child, #brandTable td:first-child, #brandTable th:last-child, #brandTable td:last-child,
  #catTable th:first-child, #catTable td:first-child, #catTable th:last-child, #catTable td:last-child,
  #adjTable th:first-child, #adjTable td:first-child, #adjTable th:last-child, #adjTable td:last-child,
  #scTable th:first-child, #scTable td:first-child, #scTable th:last-child, #scTable td:last-child,
  #purchTable th:first-child, #purchTable td:first-child, #purchTable th:last-child, #purchTable td:last-child,
  #saleTable th:first-child, #saleTable td:first-child, #saleTable th:last-child, #saleTable td:last-child { display: none !important; }
  .ph-pane table th:first-child, .ph-pane table td:first-child { display: none !important; }
  th.sortable::after { display: none; }
  .ph-pane.active .ph-pane-title { display: block; }
}

.print-only { display: none; }
@media print { .print-only { display: block; text-align: center; font-size: 1.2rem; font-weight: 600; margin: 4px 0 10px; } .pl-head { display: none !important; } .pl-filter { display: none !important; } }
@media print { .no-print { display: none !important; } }

#saleTable th, #saleTable td { padding: 10px 7px; }
