/* ==========================================================================
   SMARTMART OS — design system
   §4: large buttons, large text, high contrast, colour-coded status, touch-first.
   Dark UI by default: less glare under store lighting, and it makes the
   colour-coded status signals (green/yellow/red) read instantly.
   ========================================================================== */

:root {
  /* surfaces */
  --bg:        #0b1017;
  --surface:   #131a24;
  --surface-2: #1b242f;
  --surface-3: #26313e;
  --line:      #2e3a49;

  /* text */
  --text:      #f1f5f9;
  --text-dim:  #94a3b8;
  --text-mute: #64748b;

  /* brand — teal primary, amber for money */
  --brand:     #14b8a6;
  --brand-ink: #042f2a;
  --money:     #f59e0b;

  /* status (§45 alert levels) */
  --green:  #22c55e;
  --yellow: #eab308;
  --orange: #f97316;
  --red:    #ef4444;

  --radius:   14px;
  --radius-sm: 10px;
  --tap: 56px;            /* minimum touch target */

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans Thai',
          'Sarabun', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, monospace;

  --shadow: 0 10px 30px rgba(0,0,0,.45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 17px; line-height: 1.45;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

/* --------------------------------------------------------- app shell ----- */

#app { display: flex; flex-direction: column; height: 100%; }

.screen { display: none; flex: 1; min-height: 0; flex-direction: column; }
.screen.active { display: flex; }

/* --------------------------------------------------------- top bar ------- */

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0; min-height: 60px;
}
.topbar .who { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.topbar .who b { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .who span { font-size: 13px; color: var(--text-dim); }
.topbar .spacer { flex: 1; }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-mute); flex-shrink: 0; }
.pill.online  .dot { background: var(--green);  box-shadow: 0 0 8px var(--green); }
.pill.syncing .dot { background: var(--yellow); animation: pulse 1s infinite; }
.pill.offline .dot { background: var(--red);    box-shadow: 0 0 8px var(--red); }
.pill.shift-on  { border-color: color-mix(in srgb, var(--green) 45%, var(--line)); }
.pill.shift-off { border-color: color-mix(in srgb, var(--red) 45%, var(--line)); color: var(--text-dim); }

@keyframes pulse { 50% { opacity: .35; } }

/* --------------------------------------------------------- POS layout --- */

.pos-body { flex: 1; display: flex; min-height: 0; }

.cart-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.cart-list { flex: 1; overflow-y: auto; padding: 8px; -webkit-overflow-scrolling: touch; }

.cart-empty {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  color: var(--text-mute); text-align: center; padding: 24px;
}
.cart-empty svg { opacity: .35; }

.cart-row {
  display: grid; grid-template-columns: 1fr auto auto;
  gap: 4px 12px; align-items: center;
  padding: 12px 14px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.cart-row.flash { animation: flash .5s ease-out; }
@keyframes flash {
  from { background: color-mix(in srgb, var(--brand) 35%, var(--surface)); transform: scale(1.015); }
  to   { background: var(--surface); transform: none; }
}
.cart-row .nm { font-weight: 600; grid-column: 1; }
.cart-row .meta { grid-column: 1; font-size: 13px; color: var(--text-dim); }
.cart-row .sub { grid-column: 2; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 19px; }
.cart-row .qty-ctl { grid-column: 3; grid-row: 1 / span 2; display: flex; align-items: center; gap: 2px; }
.qbtn {
  width: 40px; height: 40px; border-radius: 9px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 22px; font-weight: 700; line-height: 1;
  display: grid; place-items: center;
}
.qbtn:active { background: var(--surface-3); }
.qbtn.del { color: var(--red); font-size: 18px; }
.cart-row .qn { min-width: 30px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

/* total bar */
.total-bar {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 14px 18px; background: var(--surface-2);
  border-top: 1px solid var(--line); flex-shrink: 0;
}
.total-bar .lbl { font-size: 15px; color: var(--text-dim); font-weight: 600; }
.total-bar .amt {
  font-size: 38px; font-weight: 800; color: var(--money);
  font-variant-numeric: tabular-nums; letter-spacing: -.5px;
}
.total-bar .cnt { font-size: 14px; color: var(--text-dim); }

/* --------------------------------------------------------- action grid -- */

.actions {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  padding: 8px; background: var(--surface); border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.abtn {
  min-height: 76px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  font-size: 14px; font-weight: 700; text-align: center; padding: 6px;
  transition: transform .06s, background .12s;
}
.abtn:active { transform: scale(.965); background: var(--surface-3); }
.abtn svg { width: 26px; height: 26px; }
.abtn.pay {
  grid-column: span 2; background: var(--brand); color: var(--brand-ink);
  border-color: transparent; font-size: 20px; font-weight: 800;
}
.abtn.pay:active { background: color-mix(in srgb, var(--brand) 85%, #000); }
.abtn.pay:disabled { opacity: .4; }
.abtn.danger { color: var(--orange); }
.abtn:disabled { opacity: .4; }
.abtn .badge {
  position: absolute; top: 6px; right: 8px; min-width: 20px; height: 20px;
  border-radius: 10px; background: var(--red); color: #fff;
  font-size: 12px; font-weight: 700; display: grid; place-items: center; padding: 0 5px;
}
.abtn { position: relative; }

/* --------------------------------------------------------- generic ui --- */

.btn {
  min-height: var(--tap); padding: 0 22px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line);
  font-weight: 700; font-size: 17px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn.danger  { background: var(--red); color: #fff; border-color: transparent; }
.btn.ghost   { background: transparent; }
.btn.block   { width: 100%; }
.btn:disabled { opacity: .45; pointer-events: none; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; min-height: var(--tap); padding: 10px 14px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-size: 18px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--brand); outline-offset: -1px;
}
.field input.big { font-size: 30px; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }

.center-pane {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 24px; overflow-y: auto;
}
.card {
  width: 100%; max-width: 460px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 4px; font-size: 24px; }
.card .sub { color: var(--text-dim); font-size: 15px; margin-bottom: 20px; }

/* --------------------------------------------------------- pin pad ------ */

.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pinpad button {
  min-height: 68px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 28px; font-weight: 700;
}
.pinpad button:active { background: var(--surface-3); transform: scale(.96); }
.pinpad button.wide { grid-column: span 2; }
.pin-dots { display: flex; gap: 12px; justify-content: center; margin: 18px 0 22px; }
.pin-dots i {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--text-mute); transition: .15s;
}
.pin-dots i.on { background: var(--brand); border-color: var(--brand); transform: scale(1.15); }
.shake { animation: shake .35s; }
@keyframes shake {
  25% { transform: translateX(-9px); } 75% { transform: translateX(9px); }
}

/* --------------------------------------------------------- lists -------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; padding: 10px; }
.tile {
  min-height: 96px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  padding: 12px; display: flex; flex-direction: column;
  justify-content: space-between; text-align: left; gap: 6px;
}
.tile:active { background: var(--surface-2); transform: scale(.97); }
.tile .tn { font-weight: 700; font-size: 15px; }
.tile .tp { color: var(--money); font-weight: 800; font-variant-numeric: tabular-nums; }
.tile[data-color] { border-left: 4px solid var(--brand); }

.rows { padding: 8px; overflow-y: auto; flex: 1; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; margin-bottom: 8px; text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.row:active { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 700; }
.row .s { font-size: 13px; color: var(--text-dim); }
.row .r { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.row.sev-green  { border-left: 4px solid var(--green); }
.row.sev-yellow { border-left: 4px solid var(--yellow); }
.row.sev-orange { border-left: 4px solid var(--orange); }
.row.sev-red    { border-left: 4px solid var(--red); }

.empty { padding: 48px 24px; text-align: center; color: var(--text-mute); }

/* --------------------------------------------------------- modal -------- */

.modal-back {
  position: fixed; inset: 0; background: rgba(3,7,12,.78);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 100;
}
.modal {
  width: 100%; max-width: 440px; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.modal.wide { max-width: 720px; }
.modal h3 { margin: 0 0 6px; font-size: 22px; }
.modal .sub { color: var(--text-dim); font-size: 15px; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }

/* --------------------------------------------------------- toast -------- */

#toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 24px; z-index: 200; display: flex; flex-direction: column;
  gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  padding: 13px 20px; border-radius: 999px; font-weight: 700; font-size: 16px;
  background: var(--surface-3); border: 1px solid var(--line);
  box-shadow: var(--shadow); animation: rise .2s;
}
.toast.ok   { background: var(--green); color: #04240f; border-color: transparent; }
.toast.err  { background: var(--red);   color: #fff; border-color: transparent; }
.toast.warn { background: var(--yellow); color: #2a2000; border-color: transparent; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* --------------------------------------------------------- payment ------ */

.pay-total {
  text-align: center; padding: 20px;
  background: var(--surface-2); border-radius: var(--radius); margin-bottom: 16px;
}
.pay-total .l { font-size: 15px; color: var(--text-dim); font-weight: 600; }
.pay-total .v {
  font-size: 46px; font-weight: 800; color: var(--money);
  font-variant-numeric: tabular-nums; letter-spacing: -1px;
}
.cash-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-bottom: 14px; }
.cash-grid button {
  min-height: 66px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 21px; font-weight: 800; font-variant-numeric: tabular-nums;
}
.cash-grid button:active { background: var(--surface-3); transform: scale(.96); }
.cash-grid button.exact { grid-column: span 3; background: var(--surface-3); font-size: 18px; }
.change-box {
  text-align: center; padding: 22px; border-radius: var(--radius);
  background: var(--green); color: #04240f; margin: 14px 0;
}
.change-box .l { font-size: 16px; font-weight: 700; opacity: .8; }
.change-box .v { font-size: 52px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.change-box.short { background: var(--red); color: #fff; }

/* --------------------------------------------------------- receipt ------ */

.receipt {
  font-family: var(--mono); font-size: 13px; line-height: 1.6;
  background: #fff; color: #000; padding: 16px; border-radius: 8px;
  max-height: 46vh; overflow-y: auto; white-space: pre-wrap;
}

/* --------------------------------------------------------- owner -------- */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; padding: 10px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.kpi .k { font-size: 13px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.kpi .v { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 4px; }
.kpi .v.money { color: var(--money); }
.kpi .d { font-size: 13px; color: var(--text-mute); }
.kpi.alert-red    { border-color: var(--red); }
.kpi.alert-yellow { border-color: var(--yellow); }

.tabs { display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.tabs button {
  padding: 9px 16px; border-radius: 999px; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 14px; font-weight: 700; color: var(--text-dim);
}
.tabs button.on { background: var(--brand); color: var(--brand-ink); border-color: transparent; }

.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-wrap { overflow-x: auto; padding: 10px; }

.neg { color: var(--red); }
.pos { color: var(--green); }
.mono { font-family: var(--mono); font-size: 13px; }

/* --------------------------------------------------------- misc --------- */

.hint {
  padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14px;
  background: color-mix(in srgb, var(--yellow) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--yellow) 35%, var(--line));
  color: #fde68a; margin-bottom: 14px;
}
.hint.info {
  background: color-mix(in srgb, var(--brand) 14%, var(--surface));
  border-color: color-mix(in srgb, var(--brand) 35%, var(--line));
  color: #99f6e4;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#camera-wrap { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; }
#camera-wrap video { width: 100%; display: block; max-height: 46vh; object-fit: cover; }
#camera-wrap .frame {
  position: absolute; inset: 22% 10%; border: 3px solid var(--brand);
  border-radius: 10px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35);
}

/* phones: 2-col action grid */
@media (max-width: 560px) {
  .actions { grid-template-columns: repeat(3, 1fr); }
  .abtn.pay { grid-column: span 3; }
  .total-bar .amt { font-size: 32px; }
  body { font-size: 16px; }
}

/* tablets landscape: fast keys beside cart */
@media (min-width: 900px) {
  .pos-body .side-pane {
    width: 340px; border-left: 1px solid var(--line);
    display: flex; flex-direction: column; background: var(--surface);
  }
  .pos-body .side-pane h4 {
    margin: 0; padding: 12px 14px; font-size: 13px; color: var(--text-dim);
    text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--line);
  }
  .pos-body .side-pane .tiles { overflow-y: auto; }
}
.side-pane { display: none; }

@media print {
  body { background: #fff; }
  .topbar, .actions, .modal-actions, #toasts { display: none !important; }
  .receipt { max-height: none; border: 0; }
}
