:root {
  --bg: #fff5f7;
  --surface: #ffffff;
  --text: #2a1a22;
  --muted: #7a6670;
  --line: #f0dbe2;
  --accent: #e8467c;
  --accent-ink: #ffffff;
  --accent-soft: #fde4ec;
  --error: #c62828;
  --mine: #dcf8c6;
  --theirs: #ffffff;
  --shadow: 0 8px 30px rgba(120, 30, 60, .08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17111a;
    --surface: #221a26;
    --text: #f3e9ef;
    --muted: #a894a2;
    --line: #3a2d3f;
    --accent: #ff6b9a;
    --accent-ink: #1a0f14;
    --accent-soft: #3a2230;
    --error: #ff8a80;
    --mine: #1f4d3a;
    --theirs: #2d2432;
    --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
[hidden] { display: none !important; }
a { color: var(--accent); }

.wrap { max-width: 520px; margin: 0 auto; padding: 24px 16px 48px; }

.brand { text-align: center; margin: 8px 0 24px; }
.brand .logo { font-size: 44px; text-decoration: none; display: inline-block; }
.brand h1 { margin: 4px 0; font-size: 30px; letter-spacing: -.02em; }
.brand.small { display: flex; align-items: center; gap: 10px; justify-content: center; }
.brand.small .logo { font-size: 28px; }
.brand.small h1 { font-size: 22px; }
.tagline { margin: 0; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px 20px;
  box-shadow: var(--shadow);
}
.card.center { text-align: center; }
.card h2 { margin: 0 0 8px; font-size: 21px; }

.field { margin-bottom: 18px; }
label { display: block; font-weight: 600; margin-bottom: 6px; }
input, textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 120px; }
.phone-row { display: flex; gap: 8px; }
.phone-row input { flex: 1; min-width: 0; }
.pick {
  flex: none;
  font: inherit;
  font-size: 14px;
  border: 1.5px solid var(--accent);
  background: var(--accent-soft);
  color: var(--text);
  border-radius: 12px;
  padding: 0 12px;
  cursor: pointer;
}
.hint { display: block; color: var(--muted); font-size: 13px; margin-top: 6px; }
.counter { text-align: right; }
.error { color: var(--error); font-size: 14px; margin: 0 0 12px; }
.fineprint { color: var(--muted); font-size: 13px; text-align: center; margin: 12px 0 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn {
  display: inline-block;
  width: 100%;
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  padding: 14px 18px;
  border-radius: 14px;
  border: 1.5px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  margin-top: 8px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .6; cursor: progress; }

.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 24px; text-align: center; font-size: 12px; color: var(--muted); }
.steps b { display: grid; place-items: center; width: 28px; height: 28px; margin: 0 auto 4px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); }

.amount { font-size: 30px; font-weight: 700; margin: 0 0 12px; }
.qr { width: 100%; max-width: 280px; height: auto; background: #fff; padding: 12px; border-radius: 16px; border: 1px solid var(--line); }
.proof { width: 100%; border-radius: 12px; border: 1px solid var(--line); margin: 8px 0; }
.countdown { font-weight: 600; }
.spinner { width: 42px; height: 42px; margin: 8px auto 16px; border: 4px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Chat ---------- */
.chat-body { height: 100dvh; }
.chat { display: flex; flex-direction: column; height: 100dvh; max-width: 720px; margin: 0 auto; background: var(--bg); }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.avatar { width: 40px; height: 40px; display: grid; place-items: center; font-size: 22px; background: var(--accent-soft); border-radius: 50%; }
.chat-title { font-weight: 700; }
.chat-sub { font-size: 12px; color: var(--muted); }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.confess-card { background: var(--accent-soft); border: 1px dashed var(--accent); border-radius: 16px; padding: 14px 16px; margin-bottom: 4px; }
.confess-label { font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.confess-text { white-space: pre-wrap; word-wrap: break-word; }
.sys { text-align: center; font-size: 12px; color: var(--muted); margin: 6px 0; }
.sys.pad { padding: 16px; }
.msg { max-width: 80%; padding: 8px 12px 6px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.msg.mine { align-self: flex-end; background: var(--mine); border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; background: var(--theirs); border-bottom-left-radius: 4px; }
.msg time { display: block; text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; }
.chat-input { display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
.chat-input textarea { min-height: 44px; max-height: 140px; resize: none; border-radius: 22px; padding: 10px 16px; }
.send { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 18px; cursor: pointer; align-self: flex-end; }

/* ---------- Dashboard owner ---------- */
:root { --ok: #1b8a4b; --ok-soft: #dff3e6; --warn: #b26a00; --warn-soft: #fff1d6; --bad: #c62828; --bad-soft: #fde2e2; --info: #1565c0; --info-soft: #e1ecfb; }
@media (prefers-color-scheme: dark) {
  :root { --ok: #6fd69a; --ok-soft: #1c3527; --warn: #ffc266; --warn-soft: #3a2c14; --bad: #ff8a80; --bad-soft: #3d1c1c; --info: #8ab8ff; --info-soft: #1b2a40; }
}
.wrap.narrow { max-width: 380px; padding-top: 12vh; }
.admin { background: var(--bg); }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-brand { font-weight: 700; font-size: 18px; }
.topbar-brand small { font-weight: 600; font-size: 12px; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 99px; margin-left: 4px; }
.link-btn { font: inherit; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; }
.link-btn:hover { color: var(--text); }
.admin-wrap { max-width: 1200px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.admin-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); align-items: start; }
@media (max-width: 860px) { .admin-grid { grid-template-columns: minmax(0, 1fr); } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 17px; }
.center { text-align: center; }
.pad { padding: 20px; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px; background: var(--line); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.ok::before, .badge.warn::before, .badge.bad::before { content: "● "; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; word-break: break-all; }
.btn.sm { width: auto; padding: 8px 14px; font-size: 14px; border-radius: 10px; margin-top: 0; }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.stack { display: grid; gap: 8px; margin-top: 10px; }
.stack input { padding: 10px 12px; }
.test-box, .log-box { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted); }
.pair-code { font: 700 34px/1.2 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .12em; margin: 4px 0 8px; color: var(--text); }
.howto { text-align: left; font-size: 14px; color: var(--muted); padding-left: 20px; margin: 12px 0; }
.log { list-style: none; margin: 8px 0 0; padding: 0; max-height: 240px; overflow-y: auto; font-size: 12.5px; }
.log li { display: grid; grid-template-columns: 64px 1fr; gap: 8px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; }
.log .lvl-warn span { color: var(--warn); }
.log .lvl-error span { color: var(--bad); }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: grid; gap: 2px; }
.stat span { font-size: 12.5px; color: var(--muted); }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
.stat small { font-size: 12px; color: var(--muted); }
.stat.warn b { color: var(--bad); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 99px; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; }
.chips button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.table-wrap { overflow-x: auto; }
.orders { width: 100%; border-collapse: collapse; font-size: 14px; }
.orders th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.orders td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.orders code { display: block; font-size: 11px; }
.who { white-space: nowrap; font-variant-numeric: tabular-nums; }
.msg-cell { min-width: 200px; max-width: 360px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; white-space: pre-wrap; word-wrap: break-word; }
.clamp.open { display: block; }
.tick { white-space: nowrap; color: var(--muted); }
.tick.read { color: #34b7f1; }
.actions { white-space: nowrap; }
.actions .btn + .btn { margin-left: 6px; }
.orders .error { margin: 4px 0 0; max-width: 220px; }

/* Tabel jadi kartu di layar kecil */
@media (max-width: 640px) {
  .orders thead { display: none; }
  .orders, .orders tbody, .orders tr, .orders td { display: block; width: 100%; }
  .orders tr { border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; margin-bottom: 10px; }
  .orders td { border: 0; padding: 4px 0; max-width: none; }
}

/* ---------- Navigasi & pengaturan owner ---------- */
.topbar { gap: 12px; }
.topnav { display: flex; gap: 4px; margin-right: auto; margin-left: 12px; }
.topnav a { color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600; padding: 6px 12px; border-radius: 10px; }
.topnav a:hover { color: var(--text); }
.topnav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
@media (max-width: 520px) { .topbar-brand small { display: none; } .topnav { margin-left: 0; } }

.alert { border-radius: 12px; padding: 10px 14px; font-size: 14px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert a { color: inherit; font-weight: 700; }
.alert code { font-size: 12px; }

.settings-wrap { max-width: 760px; }
.settings #groups { display: grid; gap: 16px; }
.setting { padding: 12px 0; border-top: 1px solid var(--line); }
.setting:first-of-type { border-top: 0; padding-top: 0; }
.setting-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.setting-head label { margin-bottom: 6px; }
.src { font-size: 11px; color: var(--muted); white-space: nowrap; }
.setting input[type="text"], .setting input[type="url"], .setting input[type="number"] { padding: 10px 12px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 14px; }
.setting.invalid input { border-color: var(--bad); }
.field-error { display: block; color: var(--bad); font-size: 13px; margin-top: 4px; }
.masked { -webkit-text-security: disc; }
.secret-row { display: flex; gap: 8px; align-items: center; }
.secret-row input { flex: 1; min-width: 0; }
.danger-text { color: var(--bad); }
.ok-text { color: var(--ok); }
.test-msg { margin: 8px 0 0; }
.test-msg:empty { display: none; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }
.save-bar { position: sticky; bottom: 0; display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 16px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.save-bar p { margin: 0; margin-right: auto; }
.pw-form { max-width: 360px; }
.pw-form label { font-weight: 500; font-size: 14px; display: grid; gap: 4px; }
.kv code { font-size: 13px; word-break: break-all; }
