:root {
  --side: #1b2a41; --brand: #2456a6; --brand-2: #2f68c4; --brand-soft: #e8eef8; --beauty: #7a1f3d; --beauty-soft: #f6e9ee; --pro: #1f2a44; --pro-soft: #e6e9f2;
  --bg: #f4f6f9; --card: #fff; --ink: #1c2430; --muted: #5b6675; --line: #dde3ec;
  --ok: #1d7a4a; --ok-soft: #e3f3ea; --warn: #a86400; --warn-soft: #fdf1dc; --bad: #b3261e; --bad-soft: #fbe6e4;
  --r: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* Layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: #fff; padding: 16px 10px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px; }
.logo { font-weight: 700; font-size: 18px; letter-spacing: .5px; padding: 4px 10px 14px; }
.logo small { display: block; font-weight: 400; font-size: 11px; opacity: .75; letter-spacing: 0; }
.side a { color: #fff; text-decoration: none; padding: 9px 12px; border-radius: 8px; display: flex; align-items: center; gap: 10px; opacity: .88; }
.side a:hover { background: rgba(255,255,255,.1); opacity: 1; }
.side a.on { background: #fff; color: var(--side); opacity: 1; font-weight: 600; }
.side .grow { flex: 1; }
.side { overflow-y: auto; }
.navgroup { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; opacity: .55; padding: 12px 12px 4px; }
.side a { padding: 7px 12px; }
[data-href] { cursor: pointer; }
.permgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; }
.permgrid label { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; }
.status { font-weight: 700; font-size: 11px; padding: 2px 8px; border-radius: 99px; }
.status.PLANNED { background: #eef; color: #335; } .status.IN_PROGRESS { background: var(--warn-soft); color: var(--warn); }
.status.COMPLETED, .status.RECEIVED { background: var(--ok-soft); color: var(--ok); } .status.CANCELLED { background: #eee; color: #777; }
.status.OPEN { background: #eef; color: #335; } .status.PARTIAL { background: var(--warn-soft); color: var(--warn); }
.side .who { font-size: 12px; opacity: .8; padding: 8px 12px; }
.ico { width: 18px; text-align: center; }
main { padding: 22px 26px 60px; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.top h1 { margin: 0; font-size: 22px; flex: 1; }
.mobilebar { display: none; }

/* Cards & grids */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.sp { flex: 1; }
.mt { margin-top: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* Forms */
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
input, select, textarea { border: 1px solid #d6cfd2; border-radius: 8px; padding: 8px 10px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
input[type=number] { text-align: right; }
input.sm { padding: 5px 7px; }
.btn { border: 1px solid #d6cfd2; background: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; display: inline-flex; gap: 6px; align-items: center; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.big { padding: 12px 22px; font-size: 16px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid #d6cfd2; border-radius: 9px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 8px 14px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--brand); color: #fff; }

/* Tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid #f0ecee; vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #faf6f8; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Badges */
.b { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.b.beauty { background: var(--beauty-soft); color: var(--beauty); }
.b.pro { background: var(--pro-soft); color: var(--pro); }
.b.ok { background: var(--ok-soft); color: var(--ok); }
.b.warn { background: var(--warn-soft); color: var(--warn); }
.b.bad { background: var(--bad-soft); color: var(--bad); }
.b.grey { background: #eee; color: #555; }

/* Billing */
.billgrid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 14px; align-items: start; }
.sumcard { position: sticky; top: 14px; }
.sumline { display: flex; justify-content: space-between; padding: 4px 0; }
.sumline.total { font-size: 22px; font-weight: 800; border-top: 2px solid var(--ink); margin-top: 8px; padding-top: 10px; }
.lines td { padding: 6px; }
.lines input { width: 100%; }
.lines .q { width: 70px; } .lines .rt { width: 100px; } .lines .dc { width: 70px; }
.lines .pname { font-weight: 600; }
.hint { font-size: 11.5px; color: var(--muted); }
.hint.warn { color: var(--bad); font-weight: 600; }
.splitnote { background: var(--warn-soft); border: 1px solid #f0d49b; border-radius: 8px; padding: 8px 10px; font-size: 12.5px; margin-top: 10px; }

/* POS */
.scanbox { font-size: 20px; padding: 14px 16px; border-width: 2px; }
/* Camera scanner: a 📷 button beside each scan box, and the scanner window */
.scanrow { display: flex; gap: 8px; align-items: stretch; width: 100%; }
.scanrow > input { flex: 1; min-width: 0; width: auto !important; }
.camBtn { flex: none; min-width: 48px; justify-content: center; padding: 0 14px; font-size: 18px; }
.camBtn .camTxt { font-size: 14px; }
.camBig { width: 100%; justify-content: center; margin-bottom: 8px; }
@media (max-width: 520px) { .camBtn .camTxt { display: none; } }
.camframe { position: absolute; inset: 16% 14%; border: 3px solid rgba(255,255,255,.9); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0,0,0,.32); pointer-events: none; }
.camline { position: absolute; left: 16%; right: 16%; height: 2px; background: #ff3b30; box-shadow: 0 0 8px #ff3b30; pointer-events: none; animation: camscan 2s ease-in-out infinite; }
@keyframes camscan { 0%, 100% { top: 22%; } 50% { top: 76%; } }
.camflash { position: absolute; inset: 0; background: rgba(46,204,113,.55); opacity: 0; transition: opacity .2s; pointer-events: none; }
.paygrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.paybtn { justify-content: center; padding: 10px 8px; }
.payrow { padding: 6px 0; border-bottom: 1px dashed var(--line); flex-wrap: nowrap; }

/* Search dropdown */
.combo { position: relative; }
.combo input { width: 100%; }
.combo .menu { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 40; max-height: 340px; overflow: auto; }
.combo .opt { padding: 8px 12px; cursor: pointer; display: flex; gap: 10px; align-items: center; }
.combo .opt.act, .combo .opt:hover { background: var(--brand-soft); }
.combo .opt .sp { min-width: 0; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20,10,15,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; }
.modal { background: #fff; border-radius: 14px; width: min(720px, 100%); padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(1100px, 100%); }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 200; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.err { background: var(--bad); }

/* Charts */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.bars div { flex: 1; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.bars div:hover { opacity: 1; }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button { border: 0; background: none; padding: 8px 12px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--brand); border-color: var(--brand); }

/* Login */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, var(--side), #0e1726); }
.auth .card { width: min(380px, 100%); padding: 28px; }
.auth h1 { margin: 0 0 4px; color: var(--brand); }

@media (max-width: 1100px) {
  .billgrid { grid-template-columns: 1fr; }
  .sumcard { position: static; }
  .g5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 90; transform: translateX(-100%); transition: transform .2s; height: 100%; }
  .side.open { transform: none; }
  .mobilebar { display: flex; align-items: center; gap: 10px; background: var(--side); color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 50; }
  .mobilebar button { background: none; border: 0; color: #fff; font-size: 22px; }
  main { padding: 16px; }
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); position: relative; }
  .lines td { border: 0; padding: 0; }
  .lines td:first-child { grid-column: 1 / -1; padding-right: 36px; }
  .lines td:last-child { position: absolute; top: 6px; right: 0; }
  .lines td[data-l]::before { content: attr(data-l); display: block; font-size: 11px; color: var(--muted); text-align: left; }
  .lines .q, .lines .rt, .lines .dc { width: 100%; }
  .g2, .g3, .g4, .g5 { grid-template-columns: 1fr 1fr; }
  .hide-m { display: none; }
}
@media (max-width: 480px) { .g2, .g3, .g4, .g5 { grid-template-columns: 1fr; } }

/* Phones, tablets and iPads */
html { -webkit-text-size-adjust: 100%; }
.shell, .auth { min-height: 100dvh; }
.side { height: 100dvh; }
.grid > * { min-width: 0; }
.row > * { max-width: 100%; }
select { max-width: 100%; }
label.f > select, label.f > input { width: 100%; }
.tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabs button { flex: none; white-space: nowrap; }
.seg { max-width: 100%; flex-wrap: wrap; }
.modal-bg { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.scrim { display: none; position: fixed; inset: 0; background: rgba(10,16,28,.45); z-index: 80; }
.mobilebar button { min-width: 44px; min-height: 40px; }
main { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
.toast { bottom: calc(20px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); }
.hide-touch { display: inline; }
@media (max-width: 800px) {
  .side { inset: 0 auto 0 0; width: min(290px, 82vw); height: 100%; padding-top: calc(16px + env(safe-area-inset-top)); padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .side.open ~ .scrim { display: block; }
  .mobilebar { padding-top: calc(10px + env(safe-area-inset-top)); }
  [style*="grid-column:span"] { grid-column: 1 / -1 !important; }
  table:not(.lines) { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}
@media (max-width: 480px) {
  .modal-bg { padding: 12px 8px; }
  .modal { padding: 14px; }
  .payrow { flex-wrap: wrap; }
  .btn { white-space: normal; }
  .permgrid { grid-template-columns: 1fr; }
  .card { padding: 12px; }
  .auth .card { padding: 20px; }
}
/* iPhone and iPad zoom into any box with text under 16px, so touch screens use 16px. */
@media (max-width: 1100px), (pointer: coarse) {
  input, select, textarea { font-size: 16px; }
}
@media (pointer: coarse) {
  .btn { min-height: 42px; }
  .btn.sm { min-height: 38px; padding: 6px 11px; font-size: 13px; }
  .seg button, .tabs button { min-height: 42px; }
  .side a { padding: 11px 12px; }
  input[type=checkbox] { width: 22px; height: 22px; flex: none; }
  .hide-touch { display: none; }
}
/* A finger leaves the hover colour stuck on after a tap. */
@media (hover: none) {
  .btn:hover { border-color: #d6cfd2; }
  .btn.primary:hover { background: var(--brand); border-color: var(--brand); }
  tr.click:hover td { background: transparent; }
}
/* iPhone date boxes ignore their width unless the native look is off. */
@supports (-webkit-touch-callout: none) {
  input[type=date], input[type=month] { -webkit-appearance: none; appearance: none; min-height: 40px; width: 100%; max-width: 100%; }
}
