:root {
  --saffron: #e8590c;
  --saffron-600: #c94a07;
  --saffron-50: #fff1e6;
  --maroon: #7a1f1f;
  --marigold: #f59f00;
  --bg: #faf5ee;
  --surface: #ffffff;
  --surface-2: #f6eee4;
  --ink: #2b1d14;
  --muted: #7a6a5c;
  --line: #eadccb;
  --ok: #2b8a3e;
  --ok-bg: #e6f4ea;
  --danger: #c92a2a;
  --danger-bg: #fdeaea;
  --shadow: 0 1px 2px rgba(60, 30, 10, .06), 0 4px 16px rgba(60, 30, 10, .06);
  --radius: 14px;
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --saffron: #ff7a2e; --saffron-600: #ff9150; --saffron-50: #3a2415; --maroon: #f0a3a3; --marigold: #ffc043;
    --bg: #17120e; --surface: #221b15; --surface-2: #2c231b; --ink: #f4ebe1; --muted: #b3a494; --line: #3a2f25;
    --ok: #69db7c; --ok-bg: #1d3323; --danger: #ff8787; --danger-bg: #3b1d1d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --saffron: #ff7a2e; --saffron-600: #ff9150; --saffron-50: #3a2415; --maroon: #f0a3a3; --marigold: #ffc043;
  --bg: #17120e; --surface: #221b15; --surface-2: #2c231b; --ink: #f4ebe1; --muted: #b3a494; --line: #3a2f25;
  --ok: #69db7c; --ok-bg: #1d3323; --danger: #ff8787; --danger-bg: #3b1d1d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--saffron); }
[hidden] { display: none !important; }

/* ---------- Shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(135deg, var(--saffron), #d9480f);
  color: #fff;
}
.topbar .icon-btn { color: #fff; }
.tb-title { flex: 1; min-width: 0; }
.tb-title h1 { font-size: 17px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-chip {
  margin-top: 2px; border: 0; background: rgba(255, 255, 255, .2); color: #fff;
  padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.book-chip::after { content: " ▾"; }
main {
  max-width: 720px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom));
}
body.no-tabs main { padding-bottom: 32px; }
body.bare main { padding: 0; max-width: none; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600;
}
.tabs a svg { width: 24px; height: 24px; }
.tabs a.active { color: var(--saffron); }
.tabs a.fab span.plus {
  width: 48px; height: 48px; border-radius: 50%; margin-top: -22px;
  background: var(--saffron); color: #fff; display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(232, 89, 12, .4);
}
.icon-btn {
  border: 0; background: transparent; padding: 6px; border-radius: 8px; cursor: pointer;
  display: inline-grid; place-items: center; color: var(--ink);
}
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- Building blocks ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 15px; margin: 0 0 10px; }
.section-title {
  font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); margin: 20px 4px 8px;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }

.hero {
  background: linear-gradient(135deg, #7a1f1f, #c2410c 60%, #f59f00);
  color: #fff; border: 0; position: relative; overflow: hidden;
}
.hero .label { opacity: .85; font-size: 13px; }
.hero .big { font-size: 32px; font-weight: 800; letter-spacing: -.01em; margin: 2px 0 6px; }
.hero .meta { display: flex; gap: 16px; font-size: 13px; opacity: .95; flex-wrap: wrap; }
.progress { height: 8px; background: rgba(255, 255, 255, .25); border-radius: 99px; overflow: hidden; margin-top: 12px; }
.progress > div { height: 100%; background: #fff; border-radius: 99px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat .v { font-size: 20px; font-weight: 800; }
.stat .k { font-size: 12px; color: var(--muted); }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; cursor: pointer;
  background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left;
}
.list-item:last-child { border-bottom: 0; }
.list-item:active { background: var(--surface-2); }
.list-item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .amt { font-weight: 700; white-space: nowrap; }
.list-item.void .title, .list-item.void .amt { text-decoration: line-through; color: var(--muted); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: var(--saffron-50); color: var(--saffron); display: grid; place-items: center; font-weight: 700;
}
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }

.badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); text-transform: uppercase; letter-spacing: .03em;
}
.badge.cash { background: #e6f4ea; color: #2b8a3e; }
.badge.upi { background: #e7f0ff; color: #1c5dcc; }
.badge.cheque { background: #f3e8ff; color: #7b3fbf; }
.badge.online { background: #fff4d6; color: #a15c00; }
.badge.admin { background: var(--saffron-50); color: var(--saffron); }
.badge.open { background: var(--ok-bg); color: var(--ok); }
.badge.cancelled, .badge.closed, .badge.inactive { background: var(--danger-bg); color: var(--danger); }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.input, select.input, textarea.input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); outline: none; font-size: 16px;
}
.input:focus { border-color: var(--saffron); box-shadow: 0 0 0 3px rgba(232, 89, 12, .15); }
.input-prefix { display: flex; align-items: stretch; }
.input-prefix > b {
  display: grid; place-items: center; padding: 0 12px; border: 1px solid var(--line); border-right: 0;
  border-radius: 10px 0 0 10px; background: var(--surface-2); font-weight: 600; color: var(--muted);
}
.input-prefix .input { border-radius: 0 10px 10px 0; }
.otp-input { letter-spacing: .5em; text-align: center; font-size: 22px; font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 10px; padding: 12px 18px; font-weight: 700; cursor: pointer;
  background: var(--saffron); color: #fff; text-decoration: none; min-height: 46px;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:hover { background: var(--saffron-600); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.whatsapp { background: #25d366; color: #fff; }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: 13px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--saffron); color: #fff; border-color: var(--saffron); }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 10px; padding: 4px; }
.segmented button { border: 0; background: transparent; padding: 10px; border-radius: 8px; font-weight: 700; cursor: pointer; color: var(--muted); }
.segmented button.on { background: var(--surface); color: var(--saffron); box-shadow: var(--shadow); }

.alert { border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }
.alert.warn { background: #fff4d6; color: #7a4a00; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.err { background: var(--danger-bg); color: var(--danger); }
.alert.info { background: var(--saffron-50); color: var(--ink); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100dvh; display: flex; flex-direction: column; }
.login-hero {
  background: linear-gradient(160deg, #7a1f1f, #d9480f 55%, #f59f00);
  color: #fff; text-align: center; padding: calc(48px + env(safe-area-inset-top)) 24px 56px;
  border-radius: 0 0 32px 32px;
}
.login-hero img { width: 84px; height: 84px; object-fit: contain; background: #fff; border-radius: 50%; padding: 8px; }
.login-hero .om { font-size: 48px; line-height: 1; }
.login-hero h1 { font-size: 22px; margin: 12px 0 4px; }
.login-hero p { margin: 0; opacity: .9; }
.login-card { max-width: 420px; width: calc(100% - 32px); margin: -28px auto 24px; }

/* ---------- Receipt frame ---------- */
.receipt-frame { width: 100%; border: 0; display: block; min-height: 520px; background: transparent; border-radius: var(--radius); }

/* ---------- Dialog / toast ---------- */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(480px, calc(100vw - 24px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(20, 10, 5, .45); }
dialog .dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 0; }
dialog .dlg-head h3 { margin: 0; font-size: 17px; }
dialog .dlg-body { padding: 14px 18px 18px; max-height: 70vh; overflow: auto; }
dialog .dlg-foot { display: flex; gap: 10px; padding: 0 18px 18px; }
dialog .dlg-foot .btn { flex: 1; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #2b1d14; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

.spinner {
  width: 28px; height: 28px; border-radius: 50%; margin: 40px auto;
  border: 3px solid var(--line); border-top-color: var(--saffron); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.qr-box { display: grid; place-items: center; padding: 12px; background: #fff; border-radius: 12px; }
.qr-box img, .qr-box canvas { width: 200px !important; height: 200px !important; }

.upload-preview { width: 72px; height: 72px; object-fit: contain; border: 1px dashed var(--line); border-radius: 10px; background: #fff; }
