/* Saree & Garments Billing — styles */
:root {
  --bg: #f2f5f4; --surface: #ffffff; --surface2: #eaf0ef; --ink: #14201f; --muted: #5b6c6a;
  --line: #d6e0de; --accent: #0f5c58; --accent-ink: #ffffff; --accent-soft: #dcefed;
  --good: #157f3b; --warn: #b45309; --bad: #b42318; --warn-soft: #fdf0dc; --bad-soft: #fde6e3;
  --radius: 10px; --shadow: 0 1px 2px rgba(10,30,28,.08), 0 4px 14px rgba(10,30,28,.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", "Noto Sans Tamil", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1514; --surface: #152120; --surface2: #1c2c2b; --ink: #e6efee; --muted: #95aaa7;
    --line: #28403e; --accent: #3fb8af; --accent-ink: #06201e; --accent-soft: #17403d;
    --good: #4cc57a; --warn: #f0a24a; --bad: #ff8a7a; --warn-soft: #3a2a12; --bad-soft: #3d1a16;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
h2 { margin: 0 0 14px; font-size: 1.35rem; }
h3 { margin: 0 0 10px; font-size: 1.02rem; }
.muted { color: var(--muted); font-size: .88rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.grow { flex: 1; }

/* form controls */
label { display: block; margin: 10px 0 4px; font-size: .82rem; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
input, select, textarea {
  width: 100%; min-height: 42px; padding: 8px 10px; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { width: auto; min-height: 0; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; margin-top: 12px; }
.btn {
  min-height: 42px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer;
  color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
.btn:hover { background: var(--surface2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: .86rem; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; margin-top: 16px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.gap { gap: 8px; } .row.wrap { flex-wrap: wrap; } .row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); padding: 26px; border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.login-card h1 { margin: 0 0 4px; font-size: 1.5rem; }
.notice { padding: 8px 10px; border-radius: 8px; margin: 10px 0; font-size: .9rem; }
.notice.err { background: var(--bad-soft); color: var(--bad); }
.notice.ok { background: var(--accent-soft); color: var(--accent); }

/* shell */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px;
  padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
  background: var(--accent); color: var(--accent-ink);
}
.brand { font-weight: 800; letter-spacing: .01em; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav button, .bottomnav button {
  background: transparent; border: 0; color: inherit; font: inherit; font-weight: 600; cursor: pointer;
  padding: 8px 12px; border-radius: 8px; opacity: .85;
}
.nav button:hover { background: rgba(255,255,255,.14); opacity: 1; }
.nav button.on { background: rgba(255,255,255,.22); opacity: 1; }
.userbox { display: flex; gap: 8px; align-items: center; font-size: .88rem; }
.userbox .btn { color: var(--accent-ink); border-color: rgba(255,255,255,.4); min-height: 32px; }
.main { padding: 16px max(16px, env(safe-area-inset-left)) 90px max(16px, env(safe-area-inset-right)); max-width: 1400px; margin: 0 auto; }
.bottomnav { display: none; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h2 { margin: 0; }
.page-head input[type=search] { min-width: 200px; }

/* billing */
.bill-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.bill-left, .bill-right { min-width: 0; }
.bill-right { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); position: sticky; top: 64px; }
.scanbar { display: flex; gap: 8px; }
.scanbar input { font-size: 1.05rem; min-height: 48px; }
.scanbar .btn { white-space: nowrap; }
.cambox { margin-top: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
#reader { width: 100%; max-width: 440px; margin: 0 auto; overflow: hidden; border-radius: 8px; }
.cam-actions { display: flex; gap: 10px; justify-content: space-between; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.suggest { list-style: none; margin: 6px 0 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-height: 320px; overflow: auto; }
.suggest li { padding: 10px 12px; display: flex; justify-content: space-between; gap: 10px; cursor: pointer; border-bottom: 1px solid var(--line); }
.suggest li:last-child { border-bottom: 0; }
.suggest li:hover, .suggest li.hl { background: var(--accent-soft); }
.suggest small { color: var(--muted); display: block; }
.cart-wrap { margin-top: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cart { width: 100%; border-collapse: collapse; }
.cart th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px 8px; background: var(--surface2); }
.cart td { padding: 8px; border-top: 1px solid var(--line); vertical-align: middle; }
.cart input { min-height: 36px; padding: 4px 6px; width: 84px; }
.cart input.qty { width: 64px; text-align: center; }
.cart input.disc { width: 64px; }
.cart .iname b { display: block; }
.cart .iname small { color: var(--muted); }
.cart .low { color: var(--warn); font-weight: 600; }
.qty-wrap { display: flex; gap: 4px; align-items: center; }
.qty-wrap button { min-height: 36px; width: 34px; padding: 0; }
.empty { padding: 28px 14px; text-align: center; color: var(--muted); }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface2); border-radius: 9px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; font: inherit; font-weight: 700; padding: 9px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.totals { margin: 14px 0 4px; border-top: 1px dashed var(--line); padding-top: 8px; }
.totals > div { display: flex; justify-content: space-between; padding: 3px 0; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 1.5rem; font-weight: 800; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; color: var(--accent); }
.change { min-height: 22px; font-weight: 700; margin: 6px 0; }
.change.due { color: var(--bad); } .change.ok { color: var(--good); }
.bill-right .row.gap { margin-top: 10px; }

/* generic panels & tables */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.panel .btn.primary { margin-top: 14px; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat span { color: var(--muted); font-size: .8rem; font-weight: 600; }
.stat b { display: block; font-size: 1.4rem; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tbl-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.tbl { width: 100%; border-collapse: collapse; min-width: 560px; }
.tbl th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px; background: var(--surface2); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-top: 1px solid var(--line); }
.tbl td.act { white-space: nowrap; text-align: right; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .76rem; font-weight: 700; background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.chart { display: flex; align-items: flex-end; gap: 6px; height: 190px; padding-top: 10px; }
.chart .bar { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; font-size: .68rem; color: var(--muted); }
.chart .bar i { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.chart .bar span { margin-top: 4px; }
.list-row { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; }

/* dialogs */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(5,15,14,.55); }
.dlg { padding: 18px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
#dlgInvoice { width: min(760px, calc(100vw - 24px)); }
.inv-preview { margin-top: 12px; background: #fff; color: #111; border: 1px solid var(--line); border-radius: 8px; padding: 14px; overflow-x: auto; }

/* calculator */
.fab { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 30; width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font: 700 .9rem var(--font); box-shadow: 0 6px 18px rgba(0,0,0,.3); cursor: pointer; }
.calc { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 31; width: 292px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 14px 40px rgba(0,0,0,.35); padding: 12px; }
.calc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.calc-expr { min-height: 18px; text-align: right; color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calc-disp { text-align: right; font-size: 2rem; font-weight: 700; padding: 4px 6px 8px; font-variant-numeric: tabular-nums; overflow-x: auto; white-space: nowrap; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.calc-keys button { min-height: 46px; font: 600 1.1rem var(--font); border: 1px solid var(--line); background: var(--surface2); color: var(--ink); border-radius: 9px; cursor: pointer; }
.calc-keys button:active { filter: brightness(.9); }
.calc-keys .op { background: var(--accent-soft); color: var(--accent); }
.calc-keys .eq { background: var(--accent); color: var(--accent-ink); }
.calc-keys .fn { color: var(--bad); }
.calc-tabs { margin-bottom: 8px; }
.calc-tabs button { padding: 7px; font-size: .86rem; }
.calc label { margin: 8px 0 3px; }
.calc #mrpReader { width: 100%; overflow: hidden; border-radius: 8px; }
.calc .cambox { padding: 6px; margin-top: 6px; }
.mrp-out { margin-top: 12px; padding: 10px 12px; background: var(--accent-soft); border-radius: 10px; display: grid; gap: 2px; }
.mrp-out > span { font-size: .8rem; font-weight: 600; color: var(--accent); }
.mrp-out > b { font-size: 2rem; color: var(--accent); font-variant-numeric: tabular-nums; }
.mrp-out small { display: block; }
.calc-use { display: flex; gap: 6px; margin-top: 8px; }
.calc-use .btn { flex: 1; }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: 90vw; font-weight: 600; }
.toast.err { background: var(--bad); color: #fff; }

/* print */
#printArea { display: none; }
.bill-doc { font: 13px/1.4 Arial, sans-serif; color: #000; }
.bill-doc h1 { margin: 0; font-size: 20px; text-align: center; }
.bill-doc .c { text-align: center; }
.bill-doc table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.bill-doc th, .bill-doc td { padding: 4px 3px; border-bottom: 1px solid #bbb; text-align: left; font-size: 12px; }
.bill-doc th { border-top: 1px solid #000; border-bottom: 1px solid #000; }
.bill-doc .r { text-align: right; }
.bill-doc .tot td { border: 0; padding: 2px 3px; }
.bill-doc .grand td { font-size: 15px; font-weight: 700; border-top: 1px solid #000; }
.bill-doc.thermal { width: 76mm; font-size: 11px; }
.bill-doc.thermal th, .bill-doc.thermal td { font-size: 11px; }
.labels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3mm; }
.label { border: 1px dashed #999; padding: 2mm; text-align: center; font: 11px Arial, sans-serif; color: #000; break-inside: avoid; }
.label svg { width: 100%; height: 14mm; }
.label b { display: block; font-size: 11px; }
@media print {
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; }
  body { background: #fff; }
}

/* responsive */
@media (max-width: 1000px) {
  .bill-grid { grid-template-columns: 1fr; }
  .bill-right { position: static; }
  .two { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .nav { display: none; }
  .topbar { justify-content: space-between; }
  .brand { max-width: 60vw; }
  .userbox #userName { display: none; }
  .bottomnav {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 4px max(4px, env(safe-area-inset-left)) calc(4px + env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-right));
  }
  .bottomnav button { color: var(--muted); font-size: .72rem; padding: 8px 2px; opacity: 1; }
  .bottomnav button.on { color: var(--accent); background: var(--accent-soft); }
  .fab { bottom: calc(76px + env(safe-area-inset-bottom)); width: 52px; height: 52px; }
  .calc { right: 8px; left: 8px; width: auto; bottom: calc(136px + env(safe-area-inset-bottom)); max-width: 360px; margin-left: auto; }
  .toast { bottom: calc(150px + env(safe-area-inset-bottom)); }
  .scanbar { flex-direction: column; }
  .scanbar .btn { min-height: 46px; }
  /* cart rows become cards */
  .cart thead { display: none; }
  .cart, .cart tbody, .cart tr, .cart td { display: block; width: 100%; }
  .cart tr { padding: 10px; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
  .cart tr:first-child { border-top: 0; }
  .cart td { border: 0; padding: 0; }
  .cart td.iname, .cart td.amt { grid-column: 1 / -1; }
  .cart td[data-l]::before { content: attr(data-l); display: block; font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
  .cart input, .cart input.qty, .cart input.disc { width: 100%; }
  .cart td.amt { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
}
@media (max-width: 460px) {
  .grid3 { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
