:root {
  --bg: #f3f5f7; --panel: #ffffff; --text: #1b2631; --muted: #64748b; --line: #e3e8ee;
  --brand: #0f766e; --brand-dark: #0b5c56; --brand-soft: #e1f3f1;
  --warn: #b45309; --warn-soft: #fef3c7; --danger: #b91c1c; --danger-soft: #fee2e2;
  --ok: #15803d; --ok-soft: #dcfce7; --info: #1d4ed8; --info-soft: #dbeafe; --gray-soft: #e9edf2;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1418; --panel: #162026; --text: #e6edf3; --muted: #8aa0b2; --line: #263540;
    --brand: #2dd4bf; --brand-dark: #5eead4; --brand-soft: #123a38;
    --warn: #fbbf24; --warn-soft: #3b2f0d; --danger: #f87171; --danger-soft: #3d1717;
    --ok: #4ade80; --ok-soft: #143323; --info: #93c5fd; --info-soft: #172a4a; --gray-soft: #22313b;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", "Noto Sans Bengali", "Nirmala UI", "Kalpurush", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
}
html[lang="bn"] body { font-family: "Noto Sans Bengali", "Nirmala UI", "Kalpurush", Inter, system-ui, sans-serif; line-height: 1.65; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }

/* Layout */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; padding: .25rem .5rem 1rem; line-height: 1.2; }
.brand svg { flex: none; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: .72rem; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { padding: .55rem .75rem; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 500; display: block; }
.nav a:hover { background: var(--gray-soft); }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; gap: .75rem; align-items: center; justify-content: flex-end; padding: .75rem 1.5rem; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.topbar .who { margin-right: auto; color: var(--muted); }
.topbar select { width: auto; }
.shop-pick select { font-weight: 600; border-color: #0f766e; }
.shop-tag { font-weight: 600; color: #0f766e; }
#view { padding: 1.5rem; max-width: 1200px; width: 100%; }

/* Components */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .85rem; margin-bottom: 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); }
.card .label { color: var(--muted); font-size: .85rem; }
.card .value { font-size: 1.8rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.card.warn .value { color: var(--warn); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; align-items: start; }
.toolbar { display: flex; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }
.toolbar .grow { flex: 1; min-width: 160px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; white-space: nowrap; }
html[lang="bn"] th { text-transform: none; letter-spacing: 0; font-size: .85rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--gray-soft); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.delta-pos { color: var(--ok); font-weight: 600; }
.delta-neg { color: var(--danger); font-weight: 600; }

/* Forms */
input, select, textarea { width: 100%; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .nav a:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.field { display: block; margin-bottom: .8rem; }
.field > span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .25rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .5rem .95rem; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { background: var(--gray-soft); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #04201d; } }
.btn.danger { color: var(--danger); }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.form-error { color: var(--danger); background: var(--danger-soft); padding: .5rem .75rem; border-radius: 8px; margin: .5rem 0 0; }

/* Dialog */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 2rem)); background: var(--panel); color: var(--text); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
dialog.wide { width: min(780px, calc(100vw - 2rem)); }
dialog::backdrop { background: rgba(10, 18, 24, .5); }
.dlg header { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); }
.dlg header h2 { margin: 0; }
.dlg .x { border: 0; background: none; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--muted); }
.dlg-body { padding: 1rem 1.1rem 0; max-height: 70vh; overflow-y: auto; }
.dlg .form-error { margin: .5rem 1.1rem 0; }
.dlg footer { display: flex; justify-content: flex-end; gap: .5rem; padding: 1rem 1.1rem; flex-wrap: wrap; }
.line-row { display: grid; grid-template-columns: 1fr 110px auto; gap: .5rem; margin-bottom: .5rem; align-items: center; }
.meta { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.meta div span { display: block; color: var(--muted); font-size: .8rem; }

/* Toast */
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; }
.toast { background: var(--text); color: var(--bg); padding: .65rem 1rem; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); max-width: 340px; }
.toast.error { background: var(--danger); color: #fff; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background: radial-gradient(800px 420px at 85% 0%, rgba(18, 181, 214, .4), transparent 60%), radial-gradient(700px 420px at 0% 100%, rgba(31, 79, 181, .7), transparent 60%), #0b1f4b; }
.mark { display: inline-grid; place-items: center; flex: none; border-radius: 10px; color: #fff; font-weight: 700; line-height: 1; letter-spacing: .02em; }
.login { width: min(400px, 100%); }
.login .brand { padding-left: 0; font-size: 1.15rem; margin-bottom: .5rem; }
.login .brand img { width: 56px; height: 56px; }
.login .brand .mark { border-radius: 14px; }
.login .lang { margin-top: 1rem; }
.hint { font-size: .85rem; color: var(--muted); margin-top: 1rem; }

/* Mobile */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: .6rem; }
  .brand { padding-bottom: .5rem; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 2px; }
  .nav a { white-space: nowrap; }
  #view { padding: 1rem; }
  .topbar { padding: .6rem 1rem; }
  .line-row { grid-template-columns: 1fr 90px auto; }
}

/* Invoice preview (the invoice itself always looks like white paper) */
.inv-wrap { background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: auto; margin-bottom: 1rem; }

/* Scan receipt */
.scan-grid { display: grid; grid-template-columns: minmax(200px, 260px) 1fr; gap: 1rem; align-items: start; }
.scan-grid > form { min-width: 0; }
.preview { position: sticky; top: 1rem; }
.preview img { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.dropzone { text-align: center; border-style: dashed; }
.flag { background: var(--warn-soft); color: var(--warn); padding: .5rem .75rem; border-radius: 8px; margin: .4rem 0; font-size: .92rem; }
.flag.note { background: var(--info-soft); color: var(--info); }
.rc-lines td { padding: .35rem .4rem; }
.rc-lines select { min-width: 190px; }
.rc-lines .desc { max-width: 190px; color: var(--muted); font-size: .88rem; }
.totals { margin: .5rem 0 .75rem auto; width: min(340px, 100%); }
.totals div { display: flex; justify-content: space-between; gap: 1rem; padding: .25rem 0; }
.totals .due { font-weight: 700; font-size: 1.05rem; border-top: 2px solid var(--text); margin-top: .3rem; padding-top: .45rem; }
.check { display: flex; gap: .6rem; align-items: flex-start; margin: .8rem 0; cursor: pointer; }
.check input { width: auto; margin-top: .3rem; }
@media (max-width: 860px) { .scan-grid { grid-template-columns: 1fr; } .preview { position: static; } }
.rc-lines select { max-width: 170px; }
.rc-lines input[name=qty] { width: 64px !important; }
.rc-lines input[name=price] { width: 90px !important; }

/* v1.4: files, reports, printing */
.file-frame { width: 100%; height: 70vh; border: 0; background: #fff; }
.file-img { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto; }
.toolbar label.inline { display: inline-flex; align-items: center; gap: .5rem; }
.bar { display: inline-block; height: .7rem; border-radius: 3px; background: var(--brand); vertical-align: middle; min-width: 0; }
.report-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: baseline; margin-bottom: .8rem; font-size: 1.1rem; }
.report-head span { color: var(--muted); }
tfoot th { text-align: left; border-top: 2px solid var(--line); }
tfoot th.num { text-align: right; }
@media print {
  .sidebar, .topbar, .no-print, #toasts, dialog { display: none !important; }
  .app { display: block; }
  body { background: #fff; }
  .panel, .card { box-shadow: none; break-inside: avoid; }
  .bar { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .btn { border: 0; padding: 0; background: none; }
}

#rp { max-width: 200px; }
a.btn { text-decoration: none; color: inherit; display: inline-block; }

/* v1.5: reader choice, free reader text */
.engine { display: grid; gap: .6rem; }
.engine .check { align-items: flex-start; }
.rawtext { white-space: pre-wrap; font-size: .8rem; max-height: 320px; overflow: auto; margin: .6rem 0 0; }
details.panel summary { cursor: pointer; font-weight: 600; }
.muted.small { font-size: .85rem; }
tr.row-warn td { background: rgba(200, 60, 40, .08); }
.navbadge { display: inline-block; min-width: 1.35rem; margin-left: .5rem; padding: 0 .4rem; border-radius: 999px; background: #c0392b; color: #fff; font-size: .72rem; line-height: 1.35rem; text-align: center; font-weight: 600; }
.po-line { grid-template-columns: 1fr 90px 110px auto; }
@media (max-width: 720px) { .po-line { grid-template-columns: 1fr 80px 90px auto; } }

/* Viewer accounts: the server refuses every change; these only hide the buttons that would fail. */
body.viewer [data-act^="add-"], body.viewer [data-act^="edit-"], body.viewer [data-act^="del-"], body.viewer [data-act^="new-"],
body.viewer [data-act="adjust"], body.viewer [data-act="reorder-po"], body.viewer [data-act="start-count"], body.viewer [data-act="po-clear-supplier"],
body.viewer dialog [data-do]:not([data-do="close"]):not([data-do="print"]) { display: none !important; }

.demo-badge { background: #b45309; color: #fff; border-radius: 999px; padding: .15rem .7rem; font-size: .8rem; font-weight: 600; }

td.num { white-space: nowrap; }

tr.sel td{background:rgba(45,212,191,.10)}
.tfwrap{display:inline-flex;align-items:center;gap:.5rem;flex:1 1 260px;max-width:420px}.tfwrap input{flex:1;min-width:0}.tfcount{white-space:nowrap}tr[hidden]{display:none}

tr.grp th{background:rgba(127,127,127,.12);text-align:left}tr.grp th.num{text-align:right}

/* MRS: scan / find, serial numbers, barcode labels, touch screens */
.lk-input { font-size: 1.15rem; padding: .7rem .8rem; min-width: 12rem; }
.lk-card { margin-top: 1rem; }
.chip { display: inline-block; padding: 2px 9px; border: 1px solid var(--line); border-radius: 99px; font-size: .88rem; margin: 0 2px 4px 0; }
.cambox { position: relative; max-width: 420px; margin: .6rem 0; border-radius: 10px; overflow: hidden; background: #000; }
.cambox[hidden] { display: none; }
.cambox video { width: 100%; display: block; max-height: 300px; object-fit: cover; }
.camline { position: absolute; left: 8%; right: 8%; top: 50%; height: 2px; background: rgba(239, 68, 68, .85); box-shadow: 0 0 8px rgba(239, 68, 68, .9); }
.bc { width: 100%; height: 46px; display: block; }
#labelarea { display: none; }
@media print {
  body.print-labels .app, body.print-labels dialog { display: none !important; }
  body.print-labels { background: #fff; }
  body.print-labels #labelarea { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3mm; padding: 4mm; }
  .lbl { border: 1px dashed #999; padding: 2mm 3mm; break-inside: avoid; color: #000; font-family: Arial, sans-serif; text-align: center; }
  .lbl-name { font-size: 9pt; font-weight: 700; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .lbl-code { font: 8pt monospace; }
  .lbl-price { font-size: 11pt; font-weight: 700; }
  .bc { height: 12mm; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
@media (pointer: coarse) {
  .btn, input, select, textarea { min-height: 44px; font-size: 16px; }
  .nav a { padding: .7rem .9rem; }
}

/* counter sale screen */
.pos { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 1rem; align-items: start; }
.pos-res { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .75rem; }
.pos-res .btn { text-align: left; }
.pos-pay { position: sticky; top: 1rem; display: flex; flex-direction: column; gap: .6rem; }
.pos-total { display: flex; justify-content: space-between; align-items: baseline; font-size: 1.1rem; }
.pos-total b { font-size: 2.2rem; }
.pos-quick { display: flex; gap: .35rem; flex-wrap: wrap; }
.pos-change { font-size: 1.3rem; min-height: 1.6rem; }
.pos-go { font-size: 1.2rem; padding: .9rem 1rem; }
.pos-done { margin: 0 0 .75rem; padding: .75rem 1rem; border: 2px solid #15803d; border-radius: 8px; background: #f0fdf4; }
.pos-bigchange { font-size: 1.6rem; font-weight: 700; color: #15803d; }
@media (max-width: 800px) { .pos { grid-template-columns: 1fr; } .pos-pay { position: static; } }
.btn[hidden] { display: none; }

.pwshow { display: flex; gap: .5rem; align-items: center; justify-content: flex-start; font-size: .9rem; color: var(--muted, #667085); margin: -.35rem 0 .8rem; cursor: pointer; }
.pwshow input { width: auto; margin: 0; }
