:root {
  --bg: #f7f1e8;
  --surface: #ffffff;
  --surface-2: #fbf5ec;
  --ink: #2c2218;
  --ink-soft: #6b5c4a;
  --brown: #7b4b2a;
  --brown-dark: #5e3820;
  --tea: #b9823e;
  --green: #3f7d52;
  --green-soft: #e3f0e7;
  --danger: #c0392b;
  --line: #ead9c4;
  --shadow: 0 6px 20px rgba(94, 56, 32, 0.12);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior-y: contain;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  position: relative;
  background: var(--bg);
}

/* ---------------- screens ---------------- */
.screen { display: none; min-height: 100vh; flex-direction: column; padding-bottom: calc(76px + var(--safe-b)); }
.screen.active { display: flex; }

/* ---------------- home ---------------- */
.home-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px 12px;
}
.brand-mark { font-size: 84px; line-height: 1; filter: drop-shadow(0 8px 12px rgba(94,56,32,.25)); animation: bob 3s ease-in-out infinite; }
@keyframes bob { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-8px)} }
.brand-title { font-size: 40px; margin: 18px 0 6px; color: var(--brown-dark); letter-spacing: -0.5px; }
.brand-sub { margin: 0; color: var(--ink-soft); font-size: 16px; }
.home-actions { display: flex; flex-direction: column; gap: 12px; padding: 0 24px; }
.home-foot { text-align: center; color: var(--ink-soft); font-size: 13px; padding: 20px; margin: 0; }

/* ---------------- topbar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px;
  position: sticky;
  top: 0;
  background: var(--brown);
  color: #fff;
  z-index: 5;
}
.topbar h2 { margin: 0; font-size: 19px; font-weight: 600; }
.session-bar { justify-content: space-between; }
.session-bar h2 { font-size: 18px; line-height: 1.2; }
.s-creator { display: block; font-size: 12px; opacity: .85; margin-top: 1px; }
.s-creator:empty { display: none; }
.icon-btn {
  background: rgba(255,255,255,.15);
  border: none; color: #fff;
  width: 38px; height: 38px; border-radius: 50%;
  font-size: 22px; cursor: pointer; flex-shrink: 0;
  display: grid; place-items: center;
}
.admin-badge { background: var(--tea); color:#fff; font-size: 11px; font-weight: 700; padding: 5px 9px; border-radius: 20px; letter-spacing: .5px; }
.bar-right { display: flex; align-items: center; gap: 8px; }

.code-pill {
  margin-top: 6px;
  background: rgba(255,255,255,.18);
  border: 1px dashed rgba(255,255,255,.5);
  color: #fff; border-radius: 10px;
  padding: 4px 10px; font-size: 15px; font-weight: 700;
  letter-spacing: 3px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
}
.copy-hint { font-size: 11px; font-weight: 500; letter-spacing: 0; opacity: .85; display: inline-flex; align-items: center; gap: 4px; }
.copy-hint svg { width: 13px; height: 13px; }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------------- forms ---------------- */
.form { padding: 20px; display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--ink-soft); font-weight: 600; }
.field small { font-weight: 400; }
.field input, .field textarea {
  font: inherit; font-weight: 500; color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 12px; padding: 14px; width: 100%;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--tea); }
.code-input { text-transform: uppercase; letter-spacing: 8px; text-align: center; font-size: 24px; font-weight: 800; }
.join-banner {
  margin: 0; padding: 12px 14px; background: var(--green-soft); color: var(--green);
  border-radius: 12px; font-size: 14px; font-weight: 600; text-align: center;
}
.form.link-join .code-field { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -8px; }
.chip {
  background: var(--surface); border: 1.5px solid var(--line);
  border-radius: 20px; padding: 8px 14px; font-size: 13px; font-weight: 600;
  color: var(--brown); cursor: pointer;
}
.chip:active { background: var(--tea); color: #fff; }

/* ---------------- buttons ---------------- */
.btn {
  font: inherit; font-weight: 700; border: none; border-radius: 12px;
  padding: 13px 18px; cursor: pointer; transition: transform .06s ease;
}
.btn:active { transform: scale(.97); }
.btn-lg { padding: 16px; font-size: 17px; }
.btn-block { width: 100%; margin-top: 16px; }
.btn-primary { background: var(--brown); color: #fff; box-shadow: var(--shadow); }
.btn-ghost { background: var(--surface); color: var(--brown); border: 1.5px solid var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 8px 12px; font-size: 14px; border-radius: 10px; }

/* ---------------- tab content / sections ---------------- */
.tab-content { padding: 18px 16px; flex: 1; }
.tab-content.hidden { display: none; }
.section-title { margin: 4px 0 12px; font-size: 16px; color: var(--brown-dark); }
.hint { margin: -6px 0 14px; font-size: 13px; color: var(--ink-soft); }

/* ---------------- quick items grid ---------------- */
.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.quick-item {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 16px 12px; text-align: center; cursor: pointer; position: relative; box-shadow: var(--shadow);
}
.quick-item .qi-emoji { font-size: 30px; display: block; }
.quick-item .qi-name { display: block; margin-top: 6px; font-weight: 700; font-size: 15px; }
.quick-item .qi-qty {
  position: absolute; top: -8px; right: -8px;
  background: var(--green); color: #fff; min-width: 26px; height: 26px;
  border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 800;
  box-shadow: var(--shadow);
}

/* ---------------- order / list rows ---------------- */
.row {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; margin-bottom: 10px; display: flex; align-items: center; gap: 12px;
}
.row .row-main { flex: 1; min-width: 0; }
.row .row-title { font-weight: 700; font-size: 15px; }
.row .row-sub { color: var(--ink-soft); font-size: 13px; margin-top: 2px; }
.row .row-amt { font-weight: 800; color: var(--brown-dark); white-space: nowrap; }

.stepper { display: flex; align-items: center; gap: 0; background: var(--surface-2); border-radius: 10px; border: 1px solid var(--line); }
.stepper button {
  width: 36px; height: 36px; border: none; background: transparent; font-size: 22px;
  color: var(--brown); cursor: pointer; font-weight: 700;
}
.stepper .val { min-width: 28px; text-align: center; font-weight: 800; }

.empty { text-align: center; color: var(--ink-soft); padding: 40px 16px; font-size: 14px; }
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }

.bill-total {
  margin-top: 16px; padding: 16px; background: var(--brown); color: #fff;
  border-radius: 14px; display: flex; justify-content: space-between; font-size: 18px; font-weight: 800;
}

/* ---------------- price inputs ---------------- */
.price-row { display: flex; align-items: center; gap: 10px; }
.price-row .price-name { flex: 1; font-weight: 700; }
.price-row .rupee { position: relative; }
.price-row input {
  width: 110px; font: inherit; font-weight: 700; text-align: right;
  border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px 10px 26px;
  background: var(--surface);
}
.price-row .rupee::before { content: "₹"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); font-weight: 700; }
.price-row input:focus { outline: none; border-color: var(--tea); }

/* ---------------- stats ---------------- */
.stat-row { display: flex; gap: 10px; padding: 0 0 14px; }
.stat { flex: 1; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 22px; color: var(--brown-dark); }
.stat span { font-size: 12px; color: var(--ink-soft); }

/* member group card (admin) */
.member-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.member-card .mc-head { display: flex; justify-content: space-between; align-items: center; font-weight: 800; }
.member-card .mc-items { margin-top: 8px; }
.member-card .mc-item { display: flex; justify-content: space-between; font-size: 14px; padding: 3px 0; color: var(--ink-soft); }
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 12px; }
.badge.paid { background: var(--green-soft); color: var(--green); }
.badge.pending { background: #fde7e4; color: var(--danger); }

.tag-toggle { cursor: pointer; }

/* ---------------- tabbar ---------------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b); z-index: 6;
}
.tab {
  flex: 1; background: none; border: none; cursor: pointer; padding: 10px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 20px; color: var(--ink-soft);
}
.tab svg { width: 22px; height: 22px; }
.tab span { font-size: 11px; font-weight: 700; }
.tab.active { color: var(--brown); }
.tab.active span { color: var(--brown); }

/* ---------------- modal ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(44,34,24,.5);
  display: grid; place-items: end center; z-index: 20; padding: 0;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface); width: 100%; max-width: 480px;
  border-radius: 20px 20px 0 0; padding: 22px 20px calc(22px + var(--safe-b));
  animation: slideup .22s ease;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal h3 { margin: 0 0 14px; color: var(--brown-dark); }
.modal .field { margin-bottom: 14px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

/* ---------------- toast ---------------- */
.toast {
  position: fixed; bottom: calc(90px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 24px;
  font-size: 14px; font-weight: 600; z-index: 30; box-shadow: var(--shadow);
  max-width: 90%; text-align: center;
}
.toast.hidden { display: none; }

.closed-banner { background: #fde7e4; color: var(--danger); text-align: center; padding: 8px; font-size: 13px; font-weight: 700; }
.hidden { display: none !important; }
