/* Tattva POS. Tokens first; light by default, dark via the system or data-theme. */
:root {
  --bg: #fff9da; --surface: #fffdf0; --line: #e8dcb8; --fg: #3b2416; --muted: #6f5a46;
  --accent: #ab391c; --on-accent: #fff9da; --good: #2f6b3a; --good-bg: #e3efdc; --warn: #7a4f00; --warn-bg: #f8e7bf;
  --scrim: rgba(20, 10, 5, .5);
  --font: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d140d; --surface: #2a1d14; --line: #4a3527; --fg: #f6ecd0; --muted: #b9a284;
    --accent: #e0623f; --on-accent: #1d140d; --good: #8fd19b; --good-bg: #21362a; --warn: #f0c46a; --warn-bg: #3d2f12;
    --scrim: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1d140d; --surface: #2a1d14; --line: #4a3527; --fg: #f6ecd0; --muted: #b9a284;
  --accent: #e0623f; --on-accent: #1d140d; --good: #8fd19b; --good-bg: #21362a; --warn: #f0c46a; --warn-bg: #3d2f12;
  --scrim: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 15px; line-height: 1.4;
  padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px));
  overflow-x: hidden;
}
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
button {
  font: inherit; color: inherit; cursor: pointer; border: 0; background: none;
  min-height: 44px; min-width: 44px; border-radius: 10px; padding: 0;
}
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

/* Header */
header {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 0 8px; border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: .02em; color: var(--accent); font-size: 17px; margin-right: auto; }
.tabs {
  order: 3; flex: 1 0 100%; display: flex; gap: 4px; overflow-x: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px;
}
.tabs button { flex: 1 0 auto; padding: 0 14px; min-height: 44px; font-weight: 600; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--fg); color: var(--bg); }
@media (min-width: 600px) {
  .tabs { order: 0; flex: 0 1 auto; }
  .tabs button { flex: 0 0 auto; }
}
.iconbtn { position: relative; width: 44px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--surface); }
.iconbtn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.badge {
  position: absolute; top: -6px; right: -6px; background: var(--accent); color: var(--on-accent);
  font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px; display: grid; place-items: center; padding: 0 5px;
}
.plus { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.update { margin-top: 8px; border-radius: 10px; padding: 6px 6px 6px 12px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--good-bg); color: var(--good); }
.update[hidden] { display: none; }
.status { margin-top: 8px; border-radius: 10px; padding: 10px 12px; font-weight: 600; background: var(--warn-bg); color: var(--warn); }
.status.act { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 6px 6px 12px; }

/* Main */
main { display: grid; gap: 16px; padding-block: 12px 110px; min-width: 0; }
main.wide { padding-bottom: 24px; }
@media (min-width: 860px) {
  main.counter { grid-template-columns: minmax(0, 1fr) 360px; padding-bottom: 24px; }
}
.col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.cur { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.cur b { font-size: 20px; }
.cur span { color: var(--muted); font-size: 13px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.chips button { border: 1px solid var(--line); padding: 0 14px; white-space: nowrap; font-weight: 600; background: var(--surface); }
.chips button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.prod {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: left;
  display: flex; flex-direction: column; gap: 6px; min-height: 92px; position: relative; min-width: 0;
}
.prod:active { transform: scale(.97); }
.prod .n { font-weight: 700; line-height: 1.2; padding-right: 22px; overflow-wrap: anywhere; }
.prod .p { color: var(--muted); margin-top: auto; }
.prod .q {
  position: absolute; top: 8px; right: 8px; background: var(--accent); color: var(--on-accent);
  font-size: 12px; font-weight: 700; border-radius: 11px; min-width: 22px; height: 22px; padding: 0 4px; display: grid; place-items: center;
}

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 10px; align-self: start; min-width: 0; }
.side { display: none; }
@media (min-width: 860px) {
  .side { display: flex; position: sticky; top: 76px; }
  .bar { display: none !important; }
}
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row b { font-size: 18px; min-width: 0; overflow-wrap: anywhere; }
.lines { display: flex; flex-direction: column; gap: 2px; }
.line { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.line .n { min-width: 0; overflow-wrap: anywhere; }
.line small { display: block; color: var(--muted); }
.line .amt { min-width: 56px; text-align: right; font-weight: 700; }
.step { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; }
.step button { width: 44px; font-size: 20px; font-weight: 700; }
.step span { min-width: 22px; text-align: center; font-weight: 700; }
.tot { display: flex; justify-content: space-between; font-size: 20px; font-weight: 800; padding-top: 4px; }
.cta { background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 16px; width: 100%; min-height: 52px; }
.ghost { border: 1px solid var(--line); background: var(--surface); padding: 0 14px; font-weight: 600; }
.pair { display: flex; gap: 8px; }
.pair > * { flex: 1; }
.danger { color: var(--accent); }
.empty { color: var(--muted); text-align: center; padding: 18px 0; }

/* Phone order bar */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--fg); color: var(--bg);
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  display: flex; align-items: center; gap: 12px;
}
.bar .info { margin-right: auto; min-width: 0; }
.bar .info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .info small { display: block; opacity: .8; }
.bar button { background: var(--accent); color: var(--on-accent); font-weight: 700; padding: 0 18px; flex: none; }
.bar button:focus-visible { outline-color: var(--bg); }

/* Sheets */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .scrim { align-items: center; } }
.sheet {
  background: var(--bg); color: var(--fg); width: 100%; max-width: 480px; max-height: 92%; overflow: auto;
  border-radius: 18px 18px 0 0; display: flex; flex-direction: column; gap: 12px;
  padding: 16px max(16px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
@media (min-width: 640px) { .sheet { border-radius: 18px; } }
.sheet h2 { font-size: 20px; }
.olist { display: flex; flex-direction: column; gap: 8px; }
.orow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.orow.on { border-color: var(--accent); }
.orow .t { font-weight: 700; }
.orow small { color: var(--muted); display: block; line-height: 1.35; overflow-wrap: anywhere; }
.orow .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.orow .acts button { padding: 0 10px; }
@media (max-width: 400px) {
  .orow { grid-template-columns: minmax(0, 1fr); }
  .orow .acts { justify-content: flex-start; }
}
.pay { font-weight: 700; color: var(--accent); }

/* Pay and fix sheets */
.line.two { grid-template-columns: minmax(0, 1fr) auto; }
.methods { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.methods.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.methods button { border: 2px solid var(--line); background: var(--surface); font-weight: 700; min-height: 56px; padding: 0 8px; }
.methods button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick button { border: 1px solid var(--line); background: var(--surface); padding: 0 14px; font-weight: 600; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.split input[readonly] { background: var(--surface); }
.msg:empty { display: none; }

/* Paid tab */
.tools { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.tools label { flex: 0 1 200px; }
.tools button { min-height: 48px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; min-width: 0; }
.tile small { color: var(--muted); display: block; }
.tile b { font-size: 22px; }
.pill { font-size: 12px; font-weight: 700; border-radius: 999px; padding: 3px 9px; white-space: nowrap; }
.pill.cash { background: var(--warn-bg); color: var(--warn); }
.pill.upi { background: var(--good-bg); color: var(--good); }
.paidrow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.paidrow .info { min-width: 0; }
.paidrow .t { font-weight: 700; overflow-wrap: anywhere; }
.paidrow small { color: var(--muted); display: block; line-height: 1.35; overflow-wrap: anywhere; }
.paidrow .refunded { color: var(--accent); font-weight: 600; margin-top: 4px; }
.paidrow .pills { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.paidrow .end { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.paidrow .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.check { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--bg); padding: 0 10px; font-size: 13px; font-weight: 600; }
.check[aria-pressed="true"] { background: var(--good-bg); color: var(--good); border-color: transparent; }
@media (max-width: 400px) {
  .paidrow { grid-template-columns: minmax(0, 1fr); }
  .paidrow .end { flex-direction: row; justify-content: space-between; align-items: center; }
}

/* Products tab: list left, form right on wide screens */
@media (min-width: 860px) {
  main.two { grid-template-columns: minmax(0, 1fr) 360px; }
  .pform { position: sticky; top: 76px; }
}
.pform h2, .changes h2, .refused h2 { font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.chips.wrap { flex-wrap: wrap; overflow-x: visible; color: var(--fg); font-size: 15px; }
.group { margin: 6px 0 0; font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.prow.off { opacity: .6; }
.prow .t, .drow .t, .rrow .t { overflow-wrap: anywhere; }
.drow .acts { align-items: center; }
.drow .acts b { font-size: 16px; margin-right: 4px; }
.note { font-size: 12px; color: var(--muted); }

/* Deleted tab */
.changes, .refused { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.clist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.clist li { padding: 10px 0; border-bottom: 1px dashed var(--line); overflow-wrap: anywhere; }
.rrow { border-color: var(--warn); }
.signout { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); }

/* Forms and states */
label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
input[type=email], input[type=password], input[type=text], input[type=number], input[type=date] {
  font: inherit; font-size: 18px; color: var(--fg); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; min-height: 48px; width: 100%;
}
.state { border-radius: 10px; padding: 10px 12px; font-weight: 600; }
.state.good { background: var(--good-bg); color: var(--good); }
.state.warn { background: var(--warn-bg); color: var(--warn); }
.login { max-width: 400px; margin: 12vh auto 0; padding: 20px; }
.login h1 { color: var(--accent); font-size: 24px; font-weight: 800; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  max-width: calc(100vw - 32px); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 30; font-weight: 600;
  pointer-events: none; /* never blocks a tap on what is under it */
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } .prod:active { transform: none; } }
