:root {
  --bg: #f6f1e9;
  --card: #fffdf9;
  --ink: #1f1a14;
  --muted: #6f655a;
  --line: #e4dacb;
  --accent: #9a4a1c;
  --accent-ink: #fff;
  --ok: #157a3c;
  --ok-bg: #1c9a4c;
  --bad: #b3261e;
  --wait-bg: #efe6d6;
  --radius: 22px;
  --tap: 64px;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button, a, summary { touch-action: manipulation; } /* no double-tap zoom eating repeated keypad taps */
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
}
[hidden] { display: none !important; }

.screen { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px 0; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 1px 2px rgba(60, 40, 20, .05), 0 12px 32px rgba(60, 40, 20, .06);
}
.brand { margin: 0 0 20px; font-size: 28px; letter-spacing: -.02em; }
.brand.small { font-size: 18px; color: var(--muted); font-weight: 600; margin-bottom: 12px; }
.label { display: block; font-size: 15px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }

.text-input {
  width: 100%; height: var(--tap); font-size: 20px; padding: 0 18px;
  border: 1.5px solid var(--line); border-radius: 14px; background: #fff; color: var(--ink);
  -webkit-user-select: text; user-select: text;
}
.text-input:focus { outline: none; border-color: var(--accent); }

.btn {
  display: flex; align-items: center; justify-content: center; width: 100%;
  min-height: var(--tap); font-size: 22px; font-weight: 700; border: 0; border-radius: 16px;
  cursor: pointer; transition: transform .08s ease, opacity .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; }
.btn-primary { background: var(--accent); color: var(--accent-ink); margin-top: 16px; }
.btn-success { background: var(--ok-bg); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); border: 1.5px solid var(--line); }

.error { color: var(--bad); min-height: 1.4em; margin: 10px 0 0; font-weight: 600; }

/* Amount */
.amount-display {
  display: flex; align-items: baseline; gap: 12px;
  border-bottom: 2px solid var(--line); padding-bottom: 8px; margin-bottom: 16px;
}
.amount-input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink);
  font-size: clamp(48px, 9vw, 76px); font-weight: 700; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums; padding: 0; outline: none;
}
.currency { font-size: 26px; font-weight: 700; color: var(--muted); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.keypad button {
  height: 72px; font-size: 30px; font-weight: 600; border: 0; border-radius: 16px;
  background: var(--wait-bg); color: var(--ink); cursor: pointer;
}
.keypad button:active { background: var(--line); }

/* QR */
.qr-card { text-align: center; display: flex; flex-direction: column; gap: 14px; }
.status {
  border-radius: 16px; padding: 18px 16px; font-size: 26px; font-weight: 800; letter-spacing: -.01em;
  transition: background-color .25s ease, color .25s ease;
}
.status.waiting { background: var(--wait-bg); color: var(--ink); }
.status.offline { background: #e2e2e2; color: #444; }
.status.paid { background: var(--ok-bg); color: #fff; font-size: 32px; }
.status.failed { background: var(--bad); color: #fff; }
.qr { width: min(100%, 360px, 48dvh); aspect-ratio: 1; margin: 0 auto; transition: opacity .25s ease; }
.qr svg, .qr img { width: 100%; height: 100%; display: block; }
.qr.done { opacity: .15; }
.qr-amount { margin: 0; font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; }
.hint { margin: 0; color: var(--muted); }
.actions { display: grid; gap: 10px; }

/* Sales */
.sales { width: 100%; max-width: 560px; margin: 0 auto 16px; }
.sales details { background: var(--card); border: 1px solid var(--line); border-radius: 16px; }
.sales summary {
  list-style: none; display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; font-weight: 700; cursor: pointer; min-height: 56px;
}
.sales summary::-webkit-details-marker { display: none; }
.sales-total { font-variant-numeric: tabular-nums; }
.sales-list { list-style: none; margin: 0; padding: 0 20px; max-height: 30dvh; overflow-y: auto; }
.sales-list li {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 12px; align-items: center;
  padding: 10px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.sales-list .note { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sales-list .st-paid { color: var(--ok); font-weight: 700; }
.sales-list .st-failed { color: var(--bad); font-weight: 700; }
.sales-list .st-waiting { color: var(--muted); }
.csv-link { display: block; padding: 16px 20px; color: var(--accent); font-weight: 700; text-decoration: none; border-top: 1px solid var(--line); }

/* Landscape iPad: amount + keypad side by side is not needed; keep QR card compact */
@media (orientation: landscape) and (max-height: 900px) {
  .screen { padding: 12px 0; }
  .card { padding: 20px 24px; }
  .keypad button { height: 60px; }
  .qr { width: min(100%, 300px, 46dvh); }
}
