/* ------------------------------------------------------------------ */
/* Theme tokens — light by default, dark when the user switches it on  */
/* ------------------------------------------------------------------ */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --hover: #f1f3f6;
  --border: #e6e8ec;
  --border-strong: #d5d9e0;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #6b7280;
  --accent: #0f766e;
  --accent-hover: #0d6560;
  --accent-ink: #ffffff;
  --accent-soft: #e6f4f2;
  --good: #15803d;
  --good-soft: #eaf6ee;
  --warn: #b45309;
  --warn-soft: #fdf4e6;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --bar: #14b8a6;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .04);
  --shadow-lg: 0 12px 40px rgba(17, 24, 39, .14);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1c2128;
  --hover: #222830;
  --border: #272d36;
  --border-strong: #343c47;
  --text: #e9ecf1;
  --text-2: #b4bbc7;
  --muted: #8b93a1;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-ink: #062521;
  --accent-soft: #13302d;
  --good: #4ade80;
  --good-soft: #142a1c;
  --warn: #fbbf24;
  --warn-soft: #2d2412;
  --bad: #f87171;
  --bad-soft: #321a1b;
  --bar: #2dd4bf;
  --shadow: none;
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 22px; }
h3 { font-size: 15px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------------ */
/* Controls                                                            */
/* ------------------------------------------------------------------ */
button, .btn {
  font: inherit; font-weight: 500; cursor: pointer; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 8px 14px; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
button:hover:not(:disabled), .btn:hover { background: var(--hover); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { color: var(--bad); }
button.danger:hover:not(:disabled) { background: var(--bad-soft); border-color: transparent; }
button.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
button.ghost:hover:not(:disabled) { background: var(--hover); color: var(--text); }
button.small, .btn.small { padding: 5px 10px; font-size: 13px; }
button.big { padding: 14px 18px; font-size: 16px; width: 100%; border-radius: 10px; }
.icon-btn { border: none; background: transparent; font-size: 20px; line-height: 1; padding: 6px 8px; color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 9px 11px; width: 100%; min-width: 0; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }
label { display: block; font-size: 13px; color: var(--text-2); font-weight: 500; }
label > input, label > select, label > textarea { margin-top: 6px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); cursor: pointer; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 4px; }
.error-box { background: var(--bad-soft); color: var(--bad); border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13px; }
.error-box:empty { display: none; }

/* ------------------------------------------------------------------ */
/* App shell: sidebar + content                                        */
/* ------------------------------------------------------------------ */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
  background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; min-width: 0; }
.logo {
  width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 15px; flex: none;
}
.brand-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 12px; color: var(--text-2); text-decoration: none;
  padding: 9px 12px; border-radius: var(--radius-sm); font-weight: 500; white-space: nowrap;
}
.nav a:hover { background: var(--hover); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.side-foot { border-top: 1px solid var(--border); padding-top: 12px; display: grid; gap: 10px; }
.me { display: flex; align-items: center; gap: 10px; padding: 0 6px; min-width: 0; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--hover); color: var(--text-2);
  display: grid; place-items: center; font-weight: 600; font-size: 13px; flex: none;
}
.me-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-role { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.side-actions { display: flex; gap: 4px; }
.net {
  display: flex; align-items: center; gap: 8px; justify-content: flex-start; width: 100%; white-space: normal; text-align: left;
  font-size: 12px; font-weight: 500; padding: 7px 10px; border: none; border-radius: var(--radius-sm); line-height: 1.3;
}
.net .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: currentColor; }
.net.ok { background: var(--good-soft); color: var(--good); }
.net.busy { background: var(--warn-soft); color: var(--warn); }
.net.busy .dot { animation: blink 1s infinite; }
.net.off { background: var(--bad-soft); color: var(--bad); }
.net:hover:not(:disabled) { filter: brightness(.97); }
.net.ok:hover { background: var(--good-soft); }
.net.busy:hover { background: var(--warn-soft); }
.net.off:hover { background: var(--bad-soft); }
@keyframes blink { 50% { opacity: .3; } }
.side-actions button { flex: 1; padding: 7px; }
main { padding: 28px 32px 48px; max-width: 1440px; width: 100%; }

.role { font-size: 11px; text-transform: capitalize; padding: 2px 9px; border-radius: 99px; font-weight: 600; }
.role.admin { background: var(--bad-soft); color: var(--bad); }
.role.manager { background: var(--warn-soft); color: var(--warn); }
.role.cashier { background: var(--good-soft); color: var(--good); }

.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h2 { margin-right: auto; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input[type=search], .toolbar input[type=text] { max-width: 300px; }
.toolbar select, .toolbar input[type=date] { width: auto; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card h3 { margin-bottom: 14px; }

/* ------------------------------------------------------------------ */
/* Tables                                                              */
/* ------------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 500; background: transparent; }
tbody tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tbody tr:hover td { background: var(--surface-2); }
tr.inactive td { opacity: .5; }
td.actions { text-align: right; white-space: nowrap; }
td.actions button { margin-left: 2px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.badge { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 99px; font-weight: 500; white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.neutral { background: var(--hover); color: var(--text-2); }
.pos { color: var(--good); }
.negv { color: var(--bad); }

/* ------------------------------------------------------------------ */
/* Login                                                               */
/* ------------------------------------------------------------------ */
.login-card { width: 100%; max-width: 380px; padding: 32px; box-shadow: var(--shadow-lg); border: none; }
.login-card .logo { width: 44px; height: 44px; font-size: 18px; margin-bottom: 18px; }
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card form { display: grid; gap: 14px; margin-top: 22px; }

/* ------------------------------------------------------------------ */
/* Point of sale                                                       */
/* ------------------------------------------------------------------ */
.pos-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; align-items: start; }
.pos-search { position: relative; margin-bottom: 14px; }
.pos-search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.pos-search input { font-size: 15px; padding: 13px 14px 13px 42px; border-radius: 10px; background: var(--surface); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.chip { padding: 6px 14px; border-radius: 99px; font-size: 13px; background: transparent; color: var(--text-2); }
.chip.active { background: var(--text); border-color: var(--text); color: var(--surface); }
.chip.active:hover { background: var(--text) !important; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(164px, 1fr)); gap: 12px; }
.tile {
  display: flex; flex-direction: column; align-items: stretch; text-align: left; gap: 4px; padding: 14px;
  min-height: 108px; white-space: normal; border-radius: var(--radius); border-color: var(--border);
}
.tile:hover:not(:disabled) { border-color: var(--accent); background: var(--surface) !important; box-shadow: 0 0 0 3px var(--accent-soft); }
.tile .t-name { font-weight: 600; line-height: 1.3; }
.tile .t-sku { font-size: 12px; color: var(--muted); }
.tile .t-foot { display: flex; justify-content: space-between; align-items: end; margin-top: auto; gap: 6px; padding-top: 8px; }
.tile .t-price { font-weight: 700; font-size: 15px; }
.tile .t-stock { font-size: 12px; color: var(--muted); }
.cart { position: sticky; top: 24px; display: flex; flex-direction: column; max-height: calc(100vh - 48px); overflow: hidden; }
.cart-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.cart-head h3 { margin: 0; }
.cart-lines { overflow-y: auto; flex: 1; min-height: 140px; }
.cart-line { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.cart-line .name { font-weight: 500; }
.cart-line .line-right { display: flex; align-items: center; gap: 2px; }
.qty { display: inline-flex; justify-self: start; align-items: center; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.qty button { border: none; border-radius: 0; padding: 4px 10px; background: transparent; }
.qty input { width: 42px; text-align: center; padding: 4px 0; border: none; border-radius: 0; box-shadow: none !important; -moz-appearance: textfield; }
.qty input::-webkit-outer-spin-button, .qty input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cart-foot { padding: 16px 18px; border-top: 1px solid var(--border); display: grid; gap: 10px; background: var(--surface-2); }
.sum-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--text-2); }
.sum-row strong, .sum-row .num { color: var(--text); }
.sum-row.total { font-size: 24px; font-weight: 700; color: var(--text); padding: 4px 0; }
.sum-row input { width: 120px; text-align: right; padding: 7px 10px; }
.sum-row label { font-size: 14px; color: var(--text-2); font-weight: 400; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button { font-size: 13px; padding: 8px 6px; }
.seg button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick button { flex: 1; }

/* ------------------------------------------------------------------ */
/* Purchases                                                           */
/* ------------------------------------------------------------------ */
.picker { position: relative; margin-top: 6px; }
.picker > svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.picker input { padding-left: 38px; }
.picker-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); max-height: 300px; overflow-y: auto;
}
.picker-results button {
  display: flex; justify-content: space-between; gap: 12px; width: 100%; border: none; border-radius: 0;
  border-bottom: 1px solid var(--border); padding: 10px 12px; text-align: left; white-space: normal; font-weight: 400;
}
.picker-results button:last-child { border-bottom: none; }
.pu-table input { width: 96px; text-align: right; padding: 6px 8px; }
.pu-table td, .pu-table th { padding: 8px 12px; }
.pu-total { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 16px; }
.pu-total strong { font-size: 20px; }

/* ------------------------------------------------------------------ */
/* Reports                                                             */
/* ------------------------------------------------------------------ */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { padding: 16px 18px; }
.kpi .label { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.report-grid .wide { grid-column: 1 / -1; }
.report-grid .sum-row { padding: 6px 0; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 220px; overflow: visible; }
.chart .gridline { stroke: var(--border); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: var(--bar); }
.chart .bar.hover { fill: var(--accent); }
.tooltip {
  position: absolute; pointer-events: none; background: var(--text); color: var(--surface); padding: 6px 10px; border-radius: 6px;
  font-size: 12px; white-space: nowrap; transform: translate(-50%, -115%); display: none; z-index: 2;
}
.meter { height: 6px; background: var(--hover); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.meter > span { display: block; height: 100%; background: var(--bar); border-radius: 99px; }

/* ------------------------------------------------------------------ */
/* Modal                                                               */
/* ------------------------------------------------------------------ */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 18, 22, .45); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .12s; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 520px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: pop .14s; }
.modal.wide { max-width: 880px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px 6px; }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 14px 22px 22px; overflow-y: auto; display: grid; gap: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding-top: 4px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }

/* ------------------------------------------------------------------ */
/* Receipt                                                             */
/* ------------------------------------------------------------------ */
.receipt { font-family: "Cascadia Mono", ui-monospace, Consolas, monospace; font-size: 13px; max-width: 340px; margin: 0 auto; width: 100%; color: var(--text); background: var(--surface-2); border-radius: var(--radius-sm); padding: 16px; }
.receipt .r-center { text-align: center; }
.receipt .r-row { display: flex; justify-content: space-between; gap: 8px; }
.receipt hr { border: none; border-top: 1px dashed var(--border-strong); margin: 10px 0; }
.receipt .r-big { font-weight: 700; font-size: 15px; }
.void-stamp { text-align: center; color: var(--bad); font-weight: 700; border: 2px solid var(--bad); padding: 4px; margin: 6px 0; letter-spacing: .1em; }
.change-due { text-align: center; padding: 14px; border-radius: var(--radius); background: var(--accent-soft); color: var(--accent); }
.change-due .label { font-size: 13px; font-weight: 500; }
.change-due .value { font-size: 30px; font-weight: 700; }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(16px); opacity: 0; transition: .18s;
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; z-index: 100; pointer-events: none;
  max-width: calc(100vw - 32px); box-shadow: var(--shadow-lg); font-weight: 500;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { background: var(--bad); color: #fff; }

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */
@media (max-width: 1100px) {
  .pos-layout { grid-template-columns: minmax(0, 1fr) 340px; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center;
    padding: 10px 16px; border-right: none; border-bottom: 1px solid var(--border); gap: 8px;
  }
  .brand { padding: 0; flex: 1; }
  .nav { order: 3; flex-basis: 100%; flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .nav a { padding: 7px 10px; gap: 8px; }
  .side-foot { border-top: none; padding-top: 0; display: flex; align-items: center; }
  .net { width: auto; }
  .net span:last-child { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .me > div:last-child { display: none; }
  main { padding: 20px 16px 40px; }
  .pos-layout { grid-template-columns: 1fr; }
  .cart { position: static; max-height: none; }
  .report-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
  .toolbar input[type=search], .toolbar input[type=text] { max-width: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

@media print {
  body { background: #fff; }
  body > *:not(.modal-backdrop) { display: none !important; }
  .modal-backdrop { position: static; background: none; padding: 0; display: block; }
  .modal { box-shadow: none; border: none; max-height: none; }
  .modal-head, .modal-actions, .no-print, .change-due { display: none !important; }
  .receipt { color: #000; background: none; }
}
