/* MIPOS Mobile — phone first, works on tablets and desktops too. */
:root {
  --brand: #0f5c8c; --brand-ink: #fff; --accent: #e8a33d;
  --bg: #f3f5f8; --card: #fff; --ink: #18212b; --muted: #66727f; --line: #dde3ea;
  --ok: #1d7a46; --ok-bg: #e5f4ea; --err: #b42318; --err-bg: #fdecea;
  --radius: 12px; --tap: 48px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11161c; --card: #1a2129; --ink: #e8edf2; --muted: #9aa6b2; --line: #2b3540;
          --ok-bg: #143323; --err-bg: #3a1714; --ok: #6fd39a; --err: #ff8a80; color-scheme: dark; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink);
       padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
a { color: var(--brand); }
@media (prefers-color-scheme: dark) { a { color: #6bb8e8; } }
h2 { margin: 0 0 4px; font-size: 1.25rem; }
h3 { margin: 20px 16px 8px; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
main { max-width: 760px; margin: 0 auto; padding: 12px 12px 24px; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px; background: var(--brand); color: var(--brand-ink);
          padding: calc(10px + env(safe-area-inset-top)) 12px 10px; min-height: 52px; }
.topbar h1 { flex: 1; margin: 0; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar a { color: var(--brand-ink); text-decoration: none; }
.topbar .back { font-size: 2rem; line-height: 1; padding: 0 8px 4px 0; }
.topbar .who { font-size: .85rem; opacity: .9; }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--line);
          padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.tabbar a { flex: 1; text-align: center; padding: 6px 0 8px; font-size: .75rem; color: var(--muted); text-decoration: none; }
.tabbar a span { display: block; font-size: 1.3rem; line-height: 1.3; }
.tabbar a.on { color: var(--brand); font-weight: 600; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin: 0 0 12px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.muted { color: var(--muted); margin: 4px 0 12px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }
.bad { color: var(--err); }
.neg { color: var(--err); }
.hint { margin: 12px 0 6px; color: var(--muted); }
.hello { margin: 4px 4px 12px; color: var(--muted); }

label { display: block; margin: 0 0 12px; font-size: .9rem; color: var(--muted); }
input, select, textarea { display: block; width: 100%; margin-top: 4px; font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: var(--tap); }
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
label.check { display: flex; align-items: center; gap: 8px; }
label.check input { width: auto; min-height: 0; margin: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); padding: 0 16px; border-radius: 10px;
       border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; min-height: 54px; font-size: 1.05rem; margin-top: 8px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.busy { opacity: .7; pointer-events: none; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.actions .btn { flex: 1 1 140px; }

.msg { padding: 12px 14px; border-radius: 10px; margin: 0 0 12px; }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.msg.err { background: var(--err-bg); color: var(--err); }
#toast { position: fixed; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 40; max-width: 600px; margin: 0 auto;
         box-shadow: 0 4px 16px rgba(0,0,0,.2); }

/* login */
body.login { padding-bottom: 0; }
body.login .topbar { display: none; }
.login-card { max-width: 380px; margin: 12vh auto 0; }
.brand { display: flex; align-items: center; gap: 12px; font-size: 1.3rem; font-weight: 700; margin-bottom: 20px; }
.brand small { display: block; font-size: .85rem; font-weight: 400; color: var(--muted); }

/* home */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { display: flex; flex-direction: column; justify-content: flex-end; min-height: 108px; padding: 14px; border-radius: var(--radius);
        background: var(--card); color: var(--ink); text-decoration: none; border-top: 5px solid var(--brand); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.tile b { font-size: 1.05rem; }
.tile span { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.t-pos { border-color: #1d7a46; } .t-inv { border-color: #0f5c8c; } .t-crn { border-color: #b42318; } .t-quo { border-color: #7a4bb5; }
.t-rec { border-color: #e8a33d; } .t-enq { border-color: #2a8a94; } .t-stk { border-color: #6b7a2a; } .t-doc { border-color: #5b6470; }
.t-chk { border-color: #999; } .t-cus { border-color: #c2410c; }

/* lists */
.results { list-style: none; margin: 0 0 12px; padding: 0; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.results:empty { display: none; }
.results li { border-bottom: 1px solid var(--line); }
.results li:last-child { border-bottom: 0; }
.results li > a, .results li > div, #itemresults li, #custresults li {
  display: grid; grid-template-columns: 1fr auto; gap: 0 12px; padding: 12px 14px; color: var(--ink); text-decoration: none; cursor: pointer; }
.results b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.results span { grid-column: 1; font-size: .85rem; color: var(--muted); }
.results em { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-style: normal; font-weight: 600; font-variant-numeric: tabular-nums; }
.results li.none { padding: 14px; color: var(--muted); display: block; }

.searchrow { display: flex; gap: 8px; margin: 0 0 10px; }
.searchrow input { margin: 0; flex: 1; }
.findrow { display: flex; gap: 8px; }
.findrow select, .findrow input { margin: 0; }
.findrow select { flex: 0 0 40%; }
.period { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.period label { flex: 1 1 130px; margin: 0; }

/* customer */
.balance { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.balance b { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.aged { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; margin: 12px 0; }
.aged div { background: var(--bg); border-radius: 8px; padding: 6px 8px; }
.aged dt { font-size: .75rem; color: var(--muted); }
.aged dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.facts { margin: 12px 0 0; }
.facts div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.facts div:last-child { border-bottom: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; word-break: break-word; }

/* sale */
.custbar { display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: 12px 14px; margin: 0 0 10px; border: 0; border-radius: var(--radius);
           background: var(--card); color: var(--ink); font: inherit; text-align: left; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.06); border-left: 5px solid var(--brand); }
.cust-name { font-weight: 700; }
.cust-sub { font-size: .85rem; color: var(--muted); }
.k-credit .custbar { border-left-color: #b42318; } .k-quote .custbar { border-left-color: #7a4bb5; }
#itemresults { position: relative; z-index: 2; box-shadow: 0 6px 18px rgba(0,0,0,.12); max-height: 50vh; overflow-y: auto; }
.cart { list-style: none; margin: 0 0 12px; padding: 0; }
.cart li { background: var(--card); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.l-top { display: flex; justify-content: space-between; gap: 8px; }
.l-code { font-size: .8rem; color: var(--muted); }
.l-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stepper button { width: 40px; height: 42px; border: 0; background: var(--bg); color: var(--ink); font-size: 1.2rem; cursor: pointer; }
.stepper input { width: 56px; min-height: 42px; margin: 0; border: 0; border-radius: 0; text-align: center; padding: 0 4px; }
.l-price { display: flex; align-items: center; gap: 4px; margin: 0; flex: 1; }
.l-price input { margin: 0; min-height: 42px; text-align: right; padding: 0 8px; }
.l-total { min-width: 76px; text-align: right; font-variant-numeric: tabular-nums; }
.x { border: 0; background: none; color: var(--muted); font-size: 1.5rem; line-height: 1; cursor: pointer; padding: 0 4px; }
.checkout { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.checkout .btn.ghost { width: 100%; margin-top: 8px; border: 0; color: var(--muted); }
.totals div { display: flex; justify-content: space-between; padding: 2px 0; color: var(--muted); }
.totals b { font-variant-numeric: tabular-nums; color: var(--ink); }
.totals .grand { font-size: 1.35rem; color: var(--ink); padding: 8px 0; border-top: 1px solid var(--line); margin-top: 6px; }
.ref { margin-top: 10px; }
.paygrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin: 0 0 12px; }
.paygrid button { min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.paygrid button:disabled { opacity: .35; }
.paygrid button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.change { text-align: right; margin: 0 0 8px; }
.change b { font-size: 1.2rem; }

/* sheet (customer picker) */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-body { background: var(--bg); width: 100%; max-width: 760px; height: 85vh; border-radius: 16px 16px 0 0; padding: 12px; overflow-y: auto;
              padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-body > .btn { width: 100%; margin: 8px 0; }

/* documents and statements */
.paper { background: #fff; color: #111; border-radius: var(--radius); padding: 18px; font-size: .92rem; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.paper .doc-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; border-bottom: 2px solid #111; padding-bottom: 10px; }
.doc-title { text-align: right; margin-left: auto; }
@media (max-width: 520px) { .doc-title { text-align: left; margin-left: 0; flex-basis: 100%; } }
.doc-to { padding: 10px 0; }
.paper table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.lines th { text-align: left; border-bottom: 1px solid #111; padding: 6px 4px; font-size: .8rem; }
.lines td { padding: 6px 4px; border-bottom: 1px solid #ddd; vertical-align: top; }
.lines td small { display: block; color: #666; }
.lines tr.sub td { color: #555; }
.lines tfoot td { padding-top: 10px; font-weight: 600; border: 0; }
.r { text-align: right; white-space: nowrap; }
.sums { margin-top: 10px; }
.sums td { padding: 4px; }
.sums .grand td { font-size: 1.15rem; font-weight: 700; border-top: 2px solid #111; }
.aging { margin-top: 16px; text-align: center; }
.aging th, .aging td { border: 1px solid #ccc; padding: 6px 4px; font-size: .8rem; }
.doc-foot { margin-top: 16px; color: #666; font-size: .8rem; text-align: center; }
.paper.slip { max-width: 380px; margin: 0 auto; }

.report { min-height: 200px; font: 12px/1.3 ui-monospace, Consolas, monospace; margin-top: 16px; }
pre { white-space: pre-wrap; word-break: break-word; font-size: .8rem; background: var(--bg); padding: 8px; border-radius: 8px; }

@media (min-width: 700px) {
  .k-invoice main, .k-credit main, .k-quote main { max-width: 1100px; display: grid; grid-template-columns: 1fr 360px; gap: 16px; }
  #sale { display: contents; }
  #sale > .checkout { grid-column: 2; grid-row: 1 / span 6; align-self: start; position: sticky; top: 64px; }
  #sale > :not(.checkout) { grid-column: 1; }
}

@media print {
  @page { margin: 12mm; }
  body { background: #fff; padding: 0; }
  .no-print, .topbar, .tabbar, .actions, .msg { display: none !important; }
  main { padding: 0; max-width: none; }
  .paper { box-shadow: none; padding: 0; border-radius: 0; }
}
.card > input { margin-bottom: 8px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 12px 0; } .pager span { color: var(--muted); font-size: .9rem; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
details { margin: 0 0 12px; } details summary { cursor: pointer; color: var(--brand); padding: 6px 0 10px; }
.tag { display: inline-block; font-size: .75rem; padding: 1px 6px; border-radius: 6px; background: var(--line); color: var(--muted); margin-left: 6px; }
.kindgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 4px; }
.kindgrid button { min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line); border-left: 5px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.kindgrid .kb-invoice { border-left-color: #0f5c8c; }
.kindgrid .kb-credit { border-left-color: #b42318; } .kindgrid .kb-quote { border-left-color: #7a4bb5; }
.kindgrid button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
#kindhint { margin-top: 6px; min-height: 1.2em; font-size: .9rem; }
.k-invoice .custbar { border-left-color: #0f5c8c; }

/* ---------------------------------------------------------------- dashboard */
:root { --series-1: #2a78d6; --series-1-wash: #e7f0fb; --up: #1d7a46; --down: #b42318; }
@media (prefers-color-scheme: dark) { :root { --series-1: #3987e5; --series-1-wash: #1d3047; --up: #6fd39a; --down: #ff8a80; } }
.ranges { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 12px; padding-bottom: 2px; scrollbar-width: none; }
.ranges a { flex: 0 0 auto; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
            text-decoration: none; font-size: .9rem; }
.ranges a.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.hero { display: flex; flex-direction: column; gap: 4px; }
.hero-num { font-size: 2.6rem; line-height: 1.1; font-weight: 650; letter-spacing: -.01em; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 12px; }
.stats .card { margin: 0; }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat b { font-size: 1.35rem; font-weight: 650; }
a.stat { color: var(--ink); text-decoration: none; }
.stat-label { font-size: .85rem; color: var(--muted); }
.stat-sub { font-size: .8rem; color: var(--muted); }
.delta { font-size: .8rem; font-weight: 600; }
.delta.up { color: var(--up); } .delta.down { color: var(--down); } .delta.flat { color: var(--muted); font-weight: 400; }
.chart-title { font-size: 1rem; margin: 0; }
.chart-sub { margin: 2px 0 8px; font-size: .85rem; color: var(--muted); }
svg.viz { display: block; width: 100%; height: auto; overflow: visible; }
svg.viz .bar { fill: var(--series-1); }
svg.viz .grid { stroke: var(--line); stroke-width: 1; }
svg.viz .axis { stroke: var(--muted); stroke-width: 1; opacity: .6; }
svg.viz .tick { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
svg.viz .hit { fill: transparent; cursor: default; outline: none; }
svg.viz .hit:hover, svg.viz .hit:focus { fill: var(--series-1-wash); fill-opacity: .55; }
.hbars { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.hbars li { outline: none; border-radius: 6px; }
.hbars li:focus-visible { box-shadow: 0 0 0 2px var(--brand); }
.hb-top { display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; }
.hb-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.hb-top b { flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.hb-sub { display: block; font-size: .75rem; color: var(--muted); }
.hb-track { display: block; height: 10px; margin-top: 4px; }
.hb-bar { display: block; height: 10px; min-width: 2px; background: var(--series-1); border-radius: 0 4px 4px 0; }
.hbars li:hover .hb-bar, .hbars li:focus .hb-bar { filter: brightness(1.12); }
.tableview { margin-top: 8px; font-size: .85rem; } .tableview summary { color: var(--brand); cursor: pointer; }
.tableview table { width: 100%; border-collapse: collapse; margin-top: 6px; font-variant-numeric: tabular-nums; }
.tableview td, .tableview th { padding: 4px 0; border-bottom: 1px solid var(--line); text-align: left; } .tableview .r { text-align: right; }
#viztip { position: fixed; z-index: 30; pointer-events: none; background: var(--ink); color: var(--card); font-size: .85rem; font-weight: 600;
          padding: 6px 10px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.18); max-width: 260px; }
@media (min-width: 900px) { .dash main { max-width: 1100px; } .dash .stats { grid-template-columns: repeat(4, 1fr); } }
.t-dash { border-color: #2a78d6; }
