:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8f0;
  --text: #1b2433;
  --muted: #667085;
  --primary: #4338ca;
  --primary-600: #3730a3;
  --primary-50: #eef2ff;
  --on-primary: #ffffff;
  --success: #067647;
  --success-50: #ecfdf3;
  --warning: #b54708;
  --warning-50: #fffaeb;
  --danger: #c01048;
  --danger-50: #fff1f3;
  --info: #0e7090;
  --info-50: #ecfdff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 10px;
  --sidebar: 248px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1420; --surface: #171d2b; --surface-2: #1d2434; --border: #2a3346; --text: #e6e9f0; --muted: #98a2b3;
    --primary: #8b93ff; --primary-600: #a5abff; --primary-50: #23284a; --on-primary: #0f1420; --success: #4ade80; --success-50: #12291c;
    --warning: #fbbf24; --warning-50: #2c2410; --danger: #fb7185; --danger-50: #2f1520; --info: #67e8f9; --info-50: #102a31;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 32px rgba(0,0,0,.5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1420; --surface: #171d2b; --surface-2: #1d2434; --border: #2a3346; --text: #e6e9f0; --muted: #98a2b3;
  --primary: #8b93ff; --primary-600: #a5abff; --primary-50: #23284a; --on-primary: #0f1420; --success: #4ade80; --success-50: #12291c;
  --warning: #fbbf24; --warning-50: #2c2410; --danger: #fb7185; --danger-50: #2f1520; --info: #67e8f9; --info-50: #102a31;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 32px rgba(0,0,0,.5); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
svg { flex: none; vertical-align: -3px; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 .75em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 12.5px; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 16px; }
.pos { color: var(--success); }
.neg { color: var(--danger); }
.strong { font-weight: 650; }

/* ---------- Layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); background: var(--surface); border-right: 1px solid var(--border); position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 40; transition: transform .2s; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 750; font-size: 17px; letter-spacing: -.01em; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, var(--primary), #7c3aed); display: grid; place-items: center; color: #fff; font-size: 15px; flex: none; }
.brand small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.nav { overflow-y: auto; padding: 4px 10px 20px; flex: 1; }
.nav-group { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-50); color: var(--primary); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.main { margin-left: var(--sidebar); flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 60px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 0 20px; position: sticky; top: 0; z-index: 30; }
.topbar .title { font-weight: 650; font-size: 16px; }
.content { padding: 22px; max-width: 1400px; width: 100%; }
.menu-btn { display: none; }
.backdrop { display: none; }
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .backdrop.open { display: block; position: fixed; inset: 0; background: rgba(15, 20, 32, .45); z-index: 35; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 0 12px; }
  .hide-sm { display: none !important; }
}

/* ---------- Cards / grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 18px; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .split { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 550; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.stat .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 550; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-600); }
.btn-danger { color: var(--danger); }
.btn-danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-lg { height: 46px; padding: 0 20px; font-size: 15px; }
.btn-block { width: 100%; }
.icon-btn { width: 36px; padding: 0; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.req { color: var(--danger); }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 11px; min-height: 38px; transition: border-color .15s, box-shadow .15s; }
textarea { min-height: 78px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50); }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; min-height: 0; accent-color: var(--primary); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.input-group { display: flex; }
.input-group > :first-child { border-radius: 8px 0 0 8px; }
.input-group > :last-child { border-radius: 0 8px 8px 0; margin-left: -1px; }
.search { position: relative; }
.search input { padding-left: 34px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters > * { width: auto; }
.filters .search { flex: 1; min-width: 200px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; background: var(--surface-2); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--border); gap: 10px; flex-wrap: wrap; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.green { background: var(--success-50); color: var(--success); border-color: transparent; }
.badge.amber { background: var(--warning-50); color: var(--warning); border-color: transparent; }
.badge.red { background: var(--danger-50); color: var(--danger); border-color: transparent; }
.badge.blue { background: var(--info-50); color: var(--info); border-color: transparent; }
.badge.purple { background: var(--primary-50); color: var(--primary); border-color: transparent; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a, .tabs button { padding: 10px 14px; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs a.active, .tabs button.active { color: var(--primary); border-bottom-color: var(--primary); text-decoration: none; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; color: var(--text); }
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }

/* ---------- Modal / toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 20, 32, .5); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; z-index: 100; overflow-y: auto; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; animation: pop .18s; }
.modal.lg { max-width: 820px; }
.modal.sm { max-width: 420px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { background: #1b2433; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 550; animation: pop .2s; max-width: 420px; }
.toast.error { background: #c01048; }
.toast.ok { background: #067647; }
.alert { padding: 12px 14px; border-radius: 10px; border: 1px solid transparent; font-weight: 500; }
.alert.warn { background: var(--warning-50); color: var(--warning); }
.alert.error { background: var(--danger-50); color: var(--danger); }
.alert.info { background: var(--info-50); color: var(--info); }
.alert.ok { background: var(--success-50); color: var(--success); }
.banner { padding: 10px 20px; font-weight: 600; text-align: center; }
.banner.warn { background: var(--warning-50); color: var(--warning); }
.banner.error { background: var(--danger-50); color: var(--danger); }

/* ---------- POS ---------- */
.pos-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .pos-layout { grid-template-columns: 1fr; } }
.pos-search { position: relative; }
.pos-search input { height: 48px; font-size: 16px; padding-left: 42px; }
.pos-search svg { left: 14px; width: 20px; height: 20px; }
.dropdown { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); z-index: 20; max-height: 380px; overflow-y: auto; }
.dropdown .opt { padding: 10px 14px; display: flex; justify-content: space-between; gap: 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.dropdown .opt:last-child { border-bottom: 0; }
.dropdown .opt:hover, .dropdown .opt.active { background: var(--primary-50); }
.cart td { padding: 8px 10px; }
.cart input { min-height: 32px; padding: 4px 8px; }
.cart .qty { width: 70px; }
.cart .price { width: 110px; }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.totals .grand { font-size: 24px; font-weight: 750; }
.pay-methods { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.pay-methods button { height: 42px; padding: 0 6px; font-size: 13px; white-space: normal; line-height: 1.15; }
.pay-line { display: grid; grid-template-columns: 110px 1fr auto; gap: 8px; align-items: center; margin-top: 8px; }

/* ---------- Charts ---------- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; min-width: 0; }
.bars .fill { width: 100%; max-width: 34px; background: var(--primary); border-radius: 5px 5px 2px 2px; min-height: 2px; opacity: .85; }
.bars .bar:hover .fill { opacity: 1; }
.bars .lbl { font-size: 10.5px; color: var(--muted); white-space: nowrap; }

/* ---------- Auth / landing ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero { background: linear-gradient(150deg, #312e81, #4338ca 55%, #7c3aed); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-hero h1 { font-size: 38px; line-height: 1.15; letter-spacing: -.02em; max-width: 520px; }
.auth-hero p { color: rgba(255,255,255,.82); font-size: 16px; max-width: 480px; }
.feature-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 24px; margin-top: 28px; max-width: 560px; }
.feature-list div { display: flex; gap: 10px; align-items: flex-start; color: rgba(255,255,255,.92); }
.feature-list svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 32px 20px; background: var(--surface); }
.auth-box { width: 100%; max-width: 400px; }
.auth-box h2 { font-size: 24px; margin-bottom: 6px; }
@media (max-width: 900px) { .auth-wrap { grid-template-columns: 1fr; } .auth-hero { padding: 32px 20px; } .auth-hero h1 { font-size: 28px; } .feature-list { grid-template-columns: 1fr; } }

/* ---------- Print frame ---------- */
.print-frame { position: fixed; width: 0; height: 0; border: 0; right: 0; bottom: 0; }
.loading { padding: 60px; text-align: center; color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }
.pos-inputs { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
@media (max-width: 640px) { .pos-inputs { grid-template-columns: 1fr; } }
