:root {
  --bg: #f3efe6;
  --bg-2: #e7efea;
  --ink: #1c241f;
  --muted: #5c6b62;
  --brand: #1a5c3a;
  --brand-2: #0f3d28;
  --accent: #c45c26;
  --card: #fffdf8;
  --line: #d5d0c4;
  --danger: #9b2c2c;
  --ok: #1a5c3a;
  --radius: 18px;
  --font: "Segoe UI", "Avenir Next", "Trebuchet MS", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, #dceee3 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #f6e4d4 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

body { padding-bottom: calc(76px + var(--safe-b)); }

#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; }

.hidden { display: none !important; }

.screen { padding: 16px 16px 24px; }

.brand {
  margin: 0 0 8px;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--brand);
}

h1 {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.15;
  letter-spacing: -0.03em;
}

h2.subhead {
  margin: 28px 0 12px;
  font-size: 1.1rem;
}

.hint, .meta, .label {
  color: var(--muted);
  font-size: 0.95rem;
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  position: relative;
  z-index: 6;
}

.biz-name {
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  font: inherit;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--brand);
  max-width: 100%;
}

.top-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  max-width: 48%;
  position: relative;
  z-index: 7;
}

.account-chip {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 10px 14px;
  min-height: 44px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  position: relative;
  z-index: 8;
  pointer-events: auto;
  touch-action: manipulation;
}

.account-chip.is-admin {
  color: var(--brand);
  border-color: #9ccbb3;
  background: #e7f4ec;
}

.total {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink);
  text-align: right;
  pointer-events: none;
}

.actions {
  position: sticky;
  bottom: calc(76px + var(--safe-b));
  margin-top: 16px;
  display: grid;
  gap: 10px;
  padding-top: 8px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  z-index: 2;
}

.user-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.78rem;
  font-weight: 700;
}
.badge-trial { background: #fff3d6; color: #8a5a00; }
.badge-active { background: #e7f4ec; color: var(--brand); }
.badge-inactive { background: #f8e8e8; color: var(--danger); }

.cart-line {
  min-height: 1.4em;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.95rem;
}

.item-grid, .template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.item-btn, .template-btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--radius);
  min-height: 92px;
  padding: 14px;
  text-align: left;
  font: inherit;
  box-shadow: 0 1px 0 rgba(28, 36, 31, 0.04);
}

.item-btn:active, .template-btn:active, .btn:active, .tab:active, .chip:active {
  transform: scale(0.98);
}

.item-btn .name, .template-btn .name {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.item-btn .price, .template-btn .desc {
  color: var(--muted);
  font-size: 0.92rem;
}

.item-btn.is-lain {
  border-style: dashed;
  background: transparent;
}

.item-btn .qty-badge {
  display: inline-block;
  margin-top: 8px;
  background: var(--brand);
  color: #fff;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.85rem;
  font-weight: 700;
}

.btn {
  border: 0;
  border-radius: 16px;
  padding: 14px 16px;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:disabled {
  opacity: 0.45;
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.btn-xl {
  min-height: 64px;
  font-size: 1.25rem;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.95rem;
}

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(480px, 100%);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  padding: 8px 8px calc(8px + var(--safe-b));
  background: rgba(255, 253, 248, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.tab {
  border: 0;
  background: transparent;
  border-radius: 14px;
  min-height: 52px;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
}

.tab.active {
  background: var(--bg-2);
  color: var(--brand);
}

.onboard { padding-top: 28px; }
.onboard .hint { margin: 8px 0 20px; }
.template-grid { margin-bottom: 20px; }
.template-btn.selected {
  border-color: var(--brand);
  box-shadow: inset 0 0 0 2px var(--brand);
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.field span, .label { font-weight: 600; color: var(--muted); }

.field input,
.field textarea {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  font: inherit;
  font-size: 1.15rem;
  background: var(--card);
}

.field textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.4;
}

.form-block { margin-top: 8px; }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 18px;
}

.chip {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 700;
}

.chip.selected {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.stats {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 0;
  font-size: 1.05rem;
}

.stat strong { font-size: 1.25rem; }
.stat-emphasis {
  border-top: 1px dashed var(--line);
  margin-top: 6px;
  padding-top: 14px;
}
.stat-emphasis strong { color: var(--brand); font-size: 1.45rem; }

.list { display: grid; gap: 8px; }

.list-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.list-item .left { min-width: 0; }
.list-item .title {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item .sub { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.list-item .amount { font-weight: 800; white-space: nowrap; }
.list-item.out .amount { color: var(--danger); }

.edit-items { display: grid; gap: 10px; margin-bottom: 12px; }

.buyer-row {
  display: grid;
  grid-template-columns: 1.4fr 0.9fr;
  gap: 10px;
  margin-bottom: 8px;
}

.pay-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.pay-label {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.82rem;
  margin-right: 2px;
}

.pay-opt {
  border: 1px solid var(--line);
  background: var(--card, #fff);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
}

.pay-opt.active {
  background: var(--brand, #1a5c3a);
  border-color: var(--brand, #1a5c3a);
  color: #fff;
}

.stat-split {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.3;
}

.field.compact { margin-bottom: 0; }
.field.compact span { font-size: 0.82rem; }
.field.compact input {
  padding: 12px;
  font-size: 1.05rem;
}

.edit-row {
  display: grid;
  grid-template-columns: 1fr 88px 72px auto;
  gap: 8px;
  align-items: center;
}

.edit-row input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  background: var(--card);
  min-width: 0;
}

.btn-danger {
  background: #f8e8e8;
  color: var(--danger);
  border: 1px solid #efc9c9;
}

.modal-card-tall {
  max-height: min(88dvh, 720px);
  overflow: auto;
}

.modal-actions.stack {
  grid-template-columns: 1fr;
  margin-top: 16px;
}

.subhead.tight { margin-top: 12px; margin-bottom: 8px; font-size: 1rem; }

.admin-tpl-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.admin-tpl-card .title { font-weight: 700; }
.admin-tpl-card .sub { color: var(--muted); font-size: 0.88rem; margin-top: 2px; }

.hint.center { text-align: center; margin-top: 18px; }
button.linkish {
  border: 0;
  background: none;
  color: var(--brand);
  font: inherit;
  font-weight: 700;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 24, 0.45);
  display: grid;
  place-items: end center;
  padding: 16px;
  z-index: 40;
}

.modal-card {
  width: min(480px, 100%);
  background: var(--card);
  border-radius: 20px 20px 16px 16px;
  padding: 18px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 16px;
  font-weight: 600;
}

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(90px + var(--safe-b));
  background: var(--brand-2);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-weight: 700;
  z-index: 50;
  max-width: min(420px, calc(100% - 24px));
  text-align: center;
}

@media (min-width: 481px) {
  body { padding-top: 12px; }
  #app {
    border: 1px solid var(--line);
    border-radius: 24px;
    overflow: hidden;
    background: rgba(255, 253, 248, 0.55);
    min-height: calc(100dvh - 24px);
  }
}
