/* Layout: sticky header with role-based tabs; each tab is a set of panels.
   Palette: ink-green neutrals, one teal accent, separate semantic colors for status. */
:root {
  --bg: #f2f5f4; --panel: #ffffff; --ink: #16211f; --muted: #5b6a67; --line: #dbe3e1; --hover: #edf2f1;
  --accent: #0f6b61; --accent-ink: #ffffff; --accent-soft: #dcf0ed;
  --good: #166f36; --good-soft: #e1f3e7;
  --warn: #855400; --warn-soft: #fbefcd;
  --bad: #b02318; --bad-soft: #fde5e2;
  --info: #1d4f91; --info-soft: #e2ecf8;
  --shadow: 0 1px 2px rgba(20, 40, 36, .06), 0 4px 14px rgba(20, 40, 36, .05);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1514; --panel: #172120; --ink: #e5eeec; --muted: #9bafaa; --line: #2a3836; --hover: #1e2b29;
    --accent: #3bb4a4; --accent-ink: #04211d; --accent-soft: #173733;
    --good: #62c987; --good-soft: #143222;
    --warn: #e8b84f; --warn-soft: #352b0f;
    --bad: #f58074; --bad-soft: #3b1b18;
    --info: #86b4f2; --info-soft: #182b44;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.55 "Segoe UI", "Noto Sans Arabic", Tahoma, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.3; text-wrap: balance; }
h3 { font-size: 16px; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.tbl td.num, .tbl th.num { display: table-cell; }
.code { display: block; font-size: 12px; color: var(--muted); direction: ltr; text-align: right; unicode-bidi: isolate; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- buttons & fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
  cursor: pointer; font-weight: 600; min-height: 38px; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn.xl { min-height: 52px; font-size: 18px; width: 100%; }
.icon-btn { border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.field.grow { flex: 1 1 200px; }
.input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); min-height: 38px;
}
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.input.big { min-height: 48px; font-size: 18px; border-width: 2px; border-color: var(--accent); }
.input.qty { width: 64px; text-align: center; padding: 4px; min-height: 32px; }
.input.price { width: 92px; padding: 4px 6px; min-height: 32px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row.center { align-items: center; }
.spacer { flex: 1; }

/* ---- shell */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 8px 20px; flex-wrap: wrap;
}
.brand { font-size: 18px; font-weight: 800; color: var(--accent); }
.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1 1 auto; }
.tab {
  padding: 8px 14px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600; white-space: nowrap;
}
.tab:hover { background: var(--hover); color: var(--ink); }
.tab.active { background: var(--accent-soft); color: var(--accent); }
.userbox { display: flex; align-items: center; gap: 8px; font-size: 13px; }
main { max-width: 1320px; margin: 0 auto; padding: 18px 20px 60px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.panel + .panel { margin-top: 16px; }
.panel > h3 { margin-bottom: 12px; }
.mt { margin-top: 16px; }
.wa { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }

/* ---- tables */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: right; font-size: 12.5px; color: var(--muted); font-weight: 700; padding: 8px 10px;
  border-bottom: 2px solid var(--line); white-space: nowrap; background: var(--panel);
}
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:hover td { background: var(--hover); }
.tbl tfoot td { font-weight: 800; border-top: 2px solid var(--line); border-bottom: 0; background: var(--hover); }
.tbl .c { text-align: center; }
.tbl .n { text-align: left; }
.tbl th.n { text-align: left; }
.tbl .empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.tbl .actions { white-space: nowrap; }
.tbl .actions .btn + .btn { margin-inline-start: 6px; }
.t-good { color: var(--good); font-weight: 700; }
.t-bad { color: var(--bad); font-weight: 700; }
.t-warn { color: var(--warn); font-weight: 700; }

/* ---- chips & KPI tiles */
.chip { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.mute { background: var(--hover); color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--line); background: var(--panel); }
.tile .lbl { font-size: 13px; font-weight: 700; color: var(--muted); }
.tile .val { font-size: 26px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.tile.good { background: var(--good-soft); border-color: transparent; } .tile.good .val { color: var(--good); }
.tile.bad { background: var(--bad-soft); border-color: transparent; } .tile.bad .val { color: var(--bad); }
.tile.warn { background: var(--warn-soft); border-color: transparent; } .tile.warn .val { color: var(--warn); }
.tile.info { background: var(--info-soft); border-color: transparent; } .tile.info .val { color: var(--info); }

/* ---- POS */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.pos-side { position: sticky; top: 70px; display: flex; flex-direction: column; gap: 12px; }
.panel.pos-side + .panel { margin-top: 0; }
.scanbar { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.results { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 12px; max-height: 260px; overflow-y: auto; }
.result { display: flex; justify-content: space-between; gap: 10px; width: 100%; padding: 8px 12px; border: 0; background: var(--panel); text-align: right; cursor: pointer; border-bottom: 1px solid var(--line); }
.result:hover { background: var(--hover); }
.sum-row, .sum-total { display: flex; justify-content: space-between; align-items: baseline; }
.sum-total { font-size: 18px; font-weight: 800; padding: 10px 12px; background: var(--accent-soft); border-radius: 8px; color: var(--accent); }
.sum-total strong { font-size: 30px; font-variant-numeric: tabular-nums; }
.qty-ctl { display: inline-flex; align-items: center; gap: 4px; }
.qty-ctl .btn { min-height: 32px; padding: 0 10px; }
.line-warn .input.qty { border-color: var(--bad); }

/* ---- forms & dialogs */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-start; }
.input-btn { display: flex; gap: 6px; }
.overlay { position: fixed; inset: 0; background: rgba(8, 16, 14, .55); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 50; overflow-y: auto; }
.dialog { background: var(--panel); border-radius: 12px; width: min(720px, 100%); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dialog-body { padding: 18px; }
.toasts { position: fixed; bottom: 20px; inset-inline-start: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 600; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); max-width: 360px; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.warn { background: var(--warn); color: #fff; }
.toast.good { background: var(--good); color: #fff; }

/* ---- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 24px; color: var(--accent); }
.login-err { background: var(--bad-soft); color: var(--bad); padding: 8px 12px; border-radius: 8px; font-weight: 600; }

/* ---- report */
.print-head { display: none; }
.chart-wrap { overflow-x: auto; direction: ltr; }
.chart-wrap svg { display: block; }
.axis { fill: var(--muted); font-size: 11px; }
.grid { stroke: var(--line); stroke-width: 1; }
.bar-s { fill: var(--accent); }
.bar-p { fill: var(--warn); }
.legend { display: flex; gap: 16px; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-inline-end: 6px; vertical-align: -1px; }
.legend .s { background: var(--accent); } .legend .p { background: var(--warn); }

/* ---- receipt */
.receipt { width: 300px; margin: 0 auto; font-size: 13px; color: #000; background: #fff; padding: 12px; }
.receipt h2 { text-align: center; font-size: 17px; }
.receipt .meta { text-align: center; margin: 4px 0 8px; font-size: 12px; }
.receipt table { width: 100%; border-collapse: collapse; }
.receipt td, .receipt th { padding: 3px 0; border-bottom: 1px dashed #888; font-size: 12.5px; }
.receipt th { text-align: right; }
.receipt td.num { display: table-cell; text-align: left; padding-inline: 4px; }
.receipt .tot { display: flex; justify-content: space-between; padding: 3px 0; }
.receipt .tot.big { font-weight: 800; font-size: 16px; border-top: 2px solid #000; margin-top: 4px; padding-top: 6px; }
.receipt .foot { text-align: center; margin-top: 10px; font-size: 12px; }
#print-area { display: none; }

/* ---- barcode label (sizes are set inline in mm) */
.lbl { box-sizing: border-box; overflow: hidden; background: #fff; color: #000; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: .5mm; font-family: Arial, "Segoe UI", Tahoma, sans-serif; text-align: center; }
.lbl .l-name { width: 100%; line-height: 1.1; font-weight: 700; overflow: hidden; }
.lbl .l-row { display: flex; align-items: baseline; justify-content: space-between; gap: 1mm; width: 100%; }
.lbl .l-row .l-name { flex: 1 1 auto; width: auto; min-width: 0; white-space: nowrap; text-overflow: ellipsis; text-align: start; }
.lbl .l-row .l-price { flex: none; white-space: nowrap; }
.lbl .l-shop { line-height: 1.1; }
.lbl .l-price { font-weight: 800; line-height: 1.1; }
.lbl svg { display: block; flex: none; overflow: visible; }
.lbl-prev-wrap { display: flex; justify-content: center; padding: 8px 0 12px; overflow-x: auto; }
.lbl-prev { direction: ltr; border: 1px dashed var(--line); background: #fff; overflow: hidden; flex: none; }
.lbl-title { text-align: center; margin: 0 0 14px; }

/* ---- responsive */
@media (max-width: 960px) {
  .pos { grid-template-columns: 1fr; }
  .pos-side { position: static; }
}
@media (max-width: 600px) {
  main { padding: 12px 12px 50px; }
  .topbar { padding: 8px 12px; }
}

/* ---- print */
@media print {
  :root {
    --bg: #fff; --panel: #fff; --ink: #000; --muted: #444; --line: #bbb; --hover: #f3f3f3;
    --accent: #0f6b61; --accent-soft: #e4f2ef; --good: #166f36; --good-soft: #e6f5ea;
    --warn: #855400; --warn-soft: #fbf1d6; --bad: #b02318; --bad-soft: #fdeae8; --info: #1d4f91; --info-soft: #e6eef9;
    --shadow: none; color-scheme: light;
  }
  body { background: #fff; font-size: 12px; }
  .noprint, .topbar, .toasts, .overlay { display: none !important; }
  main { max-width: none; padding: 0; }
  .panel { border: 1px solid #ccc; box-shadow: none; break-inside: avoid-page; padding: 10px; }
  .tile { break-inside: avoid; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .chip, .bar-s, .bar-p { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-head { display: block; margin-bottom: 12px; border-bottom: 2px solid #000; padding-bottom: 6px; }
  .print-head h2 { font-size: 18px; }
  .tbl th { background: #f0f0f0 !important; }
  .table-wrap, .chart-wrap { overflow: visible; }
  body.printing-receipt > *:not(#print-area) { display: none !important; }
  body.printing-receipt #print-area { display: block; }
  body.printing-label { background: #fff; margin: 0; }
  body.printing-label > *:not(#print-area) { display: none !important; }
  body.printing-label #print-area { display: block; direction: ltr; }
  body.printing-label .lbl { break-after: page; page-break-after: always; }
  body.printing-label .lbl:last-child { break-after: auto; page-break-after: auto; }
  @page { margin: 10mm; }
}
