:root {
  color-scheme: light dark;
  --ink: #18202a;
  --muted: #66717d;
  --paper: #f4f1e8;
  --card-bg: #fffdf8;
  --line: #d8d2c5;
  --accent: #5b4cf0;
  --accent-dark: #4436cb;
  --success: #087443;
  --danger: #b42318;
  --warning: #9a6700;
  --info: #1a56db;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(91, 76, 240, .13), transparent 28rem),
    radial-gradient(circle at 88% 20%, rgba(20, 184, 166, .12), transparent 30rem),
    var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell { width: min(920px, calc(100% - 32px)); margin: 0 auto; padding: 56px 0 72px; }

header { margin-bottom: 28px; }
.eyebrow { margin: 0 0 10px; color: var(--accent); font-size: 13px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
h1 { margin: 0; max-width: 760px; font: 700 clamp(36px, 7vw, 68px)/.98 Georgia, serif; letter-spacing: -.045em; }
.lede { max-width: 680px; margin: 18px 0 0; color: var(--muted); line-height: 1.7; }

.card {
  position: relative;
  margin-top: 20px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 253, 248, .92);
  box-shadow: 0 18px 55px rgba(38, 43, 53, .08);
}

.step-badge {
  position: absolute; top: 24px; right: 26px;
  color: #aaa293; font: 700 22px Georgia, serif;
}

h2 { margin: 0 0 22px; font-size: 22px; }

.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.three-cols { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.address-grid { display: grid; grid-template-columns: 1.4fr .7fr .8fr .6fr; gap: 12px; }

label {
  display: block;
  margin-bottom: 14px;
  color: #3c4650;
  font-size: 13px;
  font-weight: 700;
}

input, textarea, select {
  width: 100%;
  margin-top: 7px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  padding: 12px 13px;
}

textarea { resize: vertical; min-height: 60px; font-family: 'SF Mono', Consolas, monospace; font-size: 0.8rem; }
select { cursor: pointer; }

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 76, 240, .12);
  outline: none;
}

#pay-button, #query-button {
  display: block;
  width: 100%;
  margin-top: 28px;
  border: 0;
  border-radius: 14px;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: .02em;
  transition: transform .15s, box-shadow .15s, opacity .15s;
  box-shadow: 0 4px 14px rgba(91, 76, 240, .25);
}

#pay-button:hover, #query-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(91, 76, 240, .35);
}

#pay-button:disabled, #query-button:disabled { cursor: not-allowed; opacity: .52; transform: none; }

.secondary-actions {
  margin-top: 14px;
  text-align: center;
}

.invoices-link {
  display: inline-block;
  padding: 12px 28px;
  border: 2px solid var(--accent);
  border-radius: 14px;
  color: var(--accent);
  font-weight: 800;
  font-size: .95rem;
  text-decoration: none;
  transition: background .15s, color .15s;
}

.invoices-link:hover {
  background: var(--accent);
  color: #fff;
}

.auto-fetch {
  display: inline-block;
  margin-top: 6px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 6px 14px;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  cursor: pointer;
}

.auto-fetch:hover { border-color: var(--accent); color: var(--accent); }
.auto-fetch:disabled { opacity: .5; cursor: not-allowed; }

.session-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.session-actions .auto-fetch,
.session-link {
  flex: 1;
  display: inline-flex;
  margin: 0;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 14px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: .8rem;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
  white-space: nowrap;
}

.session-actions .auto-fetch:hover,
.session-link:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(91, 76, 240, .05);
}

.session-actions .auto-fetch:disabled { opacity: .5; cursor: not-allowed; }

/* ── Steps ──────────────────────────────────────────────── */
.steps {
  margin-top: 24px;
  padding: 20px 22px;
  border-radius: 14px;
  background: rgba(255, 253, 248, .85);
  border: 1px solid var(--line);
}

.step-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 0;
  font-size: 0.88rem;
}

.step-item + .step-item { border-top: 1px solid rgba(216, 210, 197, .5); }

.step-num {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 800;
  color: #fff;
  background: var(--muted);
}

.step-item.running .step-num { background: var(--accent); }
.step-item.ok .step-num { background: var(--success); }
.step-item.error .step-num { background: var(--danger); }
.step-item.action .step-num { background: var(--warning); }

.step-body { flex: 1; }
.step-name { font-weight: 700; color: var(--ink); }
.step-detail { font-size: 0.78rem; color: var(--muted); margin-top: 2px; word-break: break-all; }
.step-item.error .step-detail { color: var(--danger); }
.step-item.ok .step-detail { color: var(--success); }

/* ── Result ──────────────────────────────────────────────── */
.result {
  margin-top: 20px;
  padding: 18px 22px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.6;
}

.result.success {
  background: #e8f5ef;
  border: 1px solid #86c9a9;
  color: #135631;
}

.result.error {
  background: #fdecea;
  border: 1px solid #e09090;
  color: #721c24;
}

.result.info {
  background: #eaf0ff;
  border: 1px solid #99b9f5;
  color: #1a3780;
}

.result code {
  display: block;
  margin-top: 4px;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(0,0,0,.06);
  font-size: 0.78rem;
  word-break: break-all;
}

/* ── Notice ──────────────────────────────────────────────── */
.notice {
  margin-top: 20px;
  padding: 16px 18px;
  border-left: 4px solid #dd9d22;
  background: rgba(255, 253, 248, .7);
  color: #5d5140;
  line-height: 1.6;
  font-size: 0.85rem;
}

.notice code { padding: 2px 5px; border-radius: 5px; background: #e7e2d8; }

.hidden { display: none !important; }

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 640px) {
  .shell { padding-top: 34px; }
  .card { padding: 24px 20px; }
  .two-cols, .three-cols { grid-template-columns: 1fr; gap: 0; }
  .address-grid { grid-template-columns: 1fr 1fr; }
  .session-actions { flex-direction: column; gap: 8px; }
  .session-actions .auto-fetch, .session-link { flex: none; }
}
