:root {
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-surface-alt: #f0f2f5;
  --color-border: #dde2e8;
  --color-text: #1a2029;
  --color-text-muted: #667085;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-primary-light: #eaf1ff;
  --color-success: #16a34a;
  --color-success-light: #e8f8ee;
  --color-warning: #d97706;
  --color-warning-light: #fef3e0;
  --color-danger: #dc2626;
  --color-danger-light: #fdeaea;
  --color-info: #0891b2;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.16);
  --sidebar-width: 232px;
  --topbar-height: 60px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --color-bg: #0f1420;
  --color-surface: #171d2b;
  --color-surface-alt: #1e2536;
  --color-border: #2a3244;
  --color-text: #e7ebf3;
  --color-text-muted: #97a2b8;
  --color-primary: #3b82f6;
  --color-primary-dark: #2563eb;
  --color-primary-light: #1c2942;
  --color-success-light: #10301f;
  --color-warning-light: #3a2a10;
  --color-danger-light: #3a1a1a;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0 0 4px; font-weight: 700; }
p { margin: 0 0 8px; }
a { color: var(--color-primary); }
button { font-family: inherit; }
table { border-collapse: collapse; width: 100%; }
input, select, textarea { font-family: inherit; }

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

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--color-border);
}
.sidebar-brand .logo-emoji { font-size: 26px; }
.sidebar-brand strong { display: block; font-size: 15px; line-height: 1.2; }
.sidebar-brand span { display: block; font-size: 11px; color: var(--color-text-muted); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 12px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.15s, color 0.15s;
}
.nav-item .nav-icon { font-size: 18px; width: 22px; text-align: center; }
.nav-item:hover { background: var(--color-surface-alt); color: var(--color-text); }
.nav-item.active { background: var(--color-primary-light); color: var(--color-primary-dark); }
.sidebar-footer { padding: 14px; border-top: 1px solid var(--color-border); }

/* ---------------- Topbar ---------------- */
.topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-size: 17px; font-weight: 700; }
.menu-toggle { display: none; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--color-text); }
.conn-indicator {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 999px;
}
.conn-indicator.online { color: var(--color-success); background: var(--color-success-light); }
.conn-indicator.offline { color: var(--color-warning); background: var(--color-warning-light); }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.page-root { flex: 1; padding: 20px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: var(--radius-md);
  padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: filter 0.15s, background 0.15s; white-space: nowrap;
}
.btn:active { filter: brightness(0.94); }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-surface-alt); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-border); }
.btn-success { background: var(--color-success); color: #fff; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-warning { background: var(--color-warning); color: #fff; }
.btn-outline { background: transparent; border-color: var(--color-border); color: var(--color-text); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-lg { padding: 14px 22px; font-size: 16px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-icon { padding: 8px; width: 34px; height: 34px; }

/* ---------------- Cards / layout ---------------- */
.card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow-sm);
}
.card-title { font-size: 14px; color: var(--color-text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 6px; }
.grid { display: grid; gap: 16px; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
.stat-card { display: flex; flex-direction: column; gap: 4px; }
.stat-value { font-size: 26px; font-weight: 800; }
.stat-sub { font-size: 12px; color: var(--color-text-muted); }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.section-header h2 { font-size: 20px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.page-subtitle { color: var(--color-text-muted); font-size: 13px; margin-top: -2px; }

/* ---------------- Forms ---------------- */
.form-group { margin-bottom: 14px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 160px; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--color-text-muted); }
input[type="text"], input[type="number"], input[type="search"], input[type="date"],
input[type="password"], input[type="tel"], input[type="month"], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  font-size: 14px; background: var(--color-surface); color: var(--color-text);
}
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--color-primary); outline-offset: -1px; }
.field-error { color: var(--color-danger); font-size: 12px; margin-top: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.input-search-wrap { position: relative; }
.input-search-wrap input { padding-left: 34px; }
.input-search-wrap .search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--color-text-muted); }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius-lg); background: var(--color-surface); }
table.data-table { min-width: 640px; }
.data-table th, .data-table td { text-align: left; padding: 11px 14px; font-size: 13.5px; border-bottom: 1px solid var(--color-border); }
.data-table th { background: var(--color-surface-alt); font-weight: 700; color: var(--color-text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; position: sticky; top: 0; }
.data-table tbody tr:hover { background: var(--color-surface-alt); }
.data-table tbody tr:last-child td { border-bottom: none; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }
.empty-state { text-align: center; padding: 50px 20px; color: var(--color-text-muted); }
.pagination { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 14px; }

/* ---------------- Badges ---------------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-success { background: var(--color-success-light); color: var(--color-success); }
.badge-warning { background: var(--color-warning-light); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-light); color: var(--color-danger); }
.badge-muted { background: var(--color-surface-alt); color: var(--color-text-muted); }
.badge-info { background: var(--color-primary-light); color: var(--color-primary-dark); }

/* ---------------- Modal ---------------- */
#modal-root { position: fixed; inset: 0; z-index: 100; display: none; }
#modal-root.open { display: block; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 20, 32, 0.5); display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.modal-box { background: var(--color-surface); border-radius: var(--radius-lg); width: 100%; max-width: 480px; box-shadow: var(--shadow-lg); max-height: 92vh; display: flex; flex-direction: column; }
.modal-box.modal-lg { max-width: 760px; }
.modal-box.modal-xl { max-width: 980px; }
.modal-header { padding: 18px 20px; border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 17px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close-x { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--color-text-muted); }

/* ---------------- Toast ---------------- */
#toast-container { position: fixed; top: 16px; right: 16px; left: 16px; z-index: 200; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; max-width: 340px; margin-left: auto; }
.toast { background: var(--color-text); color: #fff; padding: 12px 16px; border-radius: var(--radius-md); font-size: 13.5px; box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(-8px); transition: opacity 0.2s, transform 0.2s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: #15803d; }
.toast-error { background: #b91c1c; }
.toast-warning { background: #b45309; }
.toast-info { background: #1e3a8a; }

/* ---------------- Loading ---------------- */
.global-loading { position: fixed; inset: 0; background: rgba(15,20,32,0.35); z-index: 300; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: #fff; }
.global-loading.show { display: flex; }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 4px solid rgba(255,255,255,0.3); border-top-color: #fff; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 13px; font-weight: 600; }
.boot-screen { position: fixed; inset: 0; background: var(--color-bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 500; }
.boot-screen .logo-emoji { font-size: 44px; }

/* ---------------- POS ---------------- */
.pos-layout { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
.pos-search-results { max-height: 60vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.pos-product-card { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border: 1px solid var(--color-border); border-radius: var(--radius-md); cursor: pointer; background: var(--color-surface); }
.pos-product-card:hover { border-color: var(--color-primary); background: var(--color-primary-light); }
.pos-product-card .pname { font-weight: 700; font-size: 14px; }
.pos-product-card .pmeta { font-size: 12px; color: var(--color-text-muted); }
.pos-product-card .pprice { font-weight: 800; color: var(--color-primary-dark); }
.pos-product-card.disabled { opacity: 0.5; cursor: not-allowed; }
.cart-panel { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 12px; }
.cart-items { max-height: 40vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.cart-item { display: flex; align-items: center; gap: 8px; padding: 10px; border: 1px solid var(--color-border); border-radius: var(--radius-md); }
.cart-item .ci-info { flex: 1; min-width: 0; }
.cart-item .ci-name { font-weight: 700; font-size: 13.5px; }
.cart-item .ci-price { font-size: 12px; color: var(--color-text-muted); }
.qty-stepper { display: flex; align-items: center; gap: 6px; }
.qty-stepper button { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--color-border); background: var(--color-surface-alt); cursor: pointer; font-weight: 700; }
.qty-stepper input { width: 46px; text-align: center; padding: 4px; }
.cart-totals { border-top: 1px dashed var(--color-border); padding-top: 12px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.cart-totals .row { display: flex; justify-content: space-between; }
.cart-totals .grand { font-size: 20px; font-weight: 800; }
.remove-item-btn { background: none; border: none; color: var(--color-danger); cursor: pointer; font-size: 16px; }

#print-area { position: fixed; left: -99999px; top: 0; }

/* ---------------- Receipt ---------------- */
.receipt { font-family: 'Courier New', monospace; width: 100%; max-width: 300px; margin: 0 auto; font-size: 13px; }
.receipt .center { text-align: center; }
.receipt hr { border: none; border-top: 1px dashed #000; margin: 8px 0; }
.receipt table { width: 100%; font-size: 12px; }
.receipt td { padding: 2px 0; vertical-align: top; }

/* ---------------- Misc ---------------- */
.text-muted { color: var(--color-text-muted); }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.flex { display: flex; } .items-center { align-items: center; } .gap-8 { gap: 8px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--color-border); margin-bottom: 16px; }
.tab-btn { padding: 10px 16px; background: none; border: none; cursor: pointer; font-weight: 700; font-size: 14px; color: var(--color-text-muted); border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.chip-list { display: flex; gap: 8px; flex-wrap: wrap; }
.warning-banner { background: var(--color-warning-light); color: var(--color-warning); border: 1px solid var(--color-warning); border-radius: var(--radius-md); padding: 12px 14px; font-size: 13.5px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; max-width: 100%; box-sizing: border-box; }
.warning-banner > * { min-width: 0; overflow-wrap: break-word; }
.kv-list { display: flex; flex-direction: column; gap: 8px; }
.kv-list .kv-row { display: flex; justify-content: space-between; font-size: 13.5px; padding: 6px 0; border-bottom: 1px solid var(--color-border); }
.quick-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
