:root {
  --bg: #f5f6f9;
  --surface: #ffffff;
  --surface-2: #f6f7fa;
  --line: #e2e6ee;
  --line-strong: #cfd6e4;
  --text: #0f1420;
  --muted: #5d6779;
  --brand: #4f46e5;
  --brand-hi: #4338ca;
  --brand-soft: #eef0fe;
  --on-brand: #ffffff;
  --ok: #067a52;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 12px 32px -12px rgba(16, 24, 40, .14);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0c12;
    --surface: #111520;
    --surface-2: #161b28;
    --line: #232937;
    --line-strong: #323a4d;
    --text: #eef1f7;
    --muted: #9aa4b8;
    --brand: #8b87f7;
    --brand-hi: #a29ef9;
    --brand-soft: #1b1d36;
    --on-brand: #0a0c12;
    --ok: #34d399;
    --danger: #f87171;
    --danger-soft: #2a1618;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 16px 40px -16px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { letter-spacing: -0.015em; }

.num { font-variant-numeric: tabular-nums; }

/* ---------- estrutura ---------- */

.topbar {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.brand .mark {
  width: 30px; height: 30px; flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--brand); color: var(--on-brand);
  font-size: .85rem; font-weight: 700;
}
.badge-secure {
  display: inline-flex; align-items: center; gap: 7px;
  color: var(--muted); font-size: .82rem; white-space: nowrap;
}
.badge-secure svg { flex: none; }

.layout {
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 24px 64px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 32px;
  align-items: start;
}

.page-title { margin: 0 0 4px; font-size: 1.6rem; }
.page-sub { margin: 0 0 28px; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.section + .section { margin-top: 20px; }
.section-head { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; }
.section-head h2 { margin: 0; font-size: 1.02rem; }
.step-n {
  width: 22px; height: 22px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  font-size: .74rem; font-weight: 700;
}
.section-body { padding: 22px; }

/* ---------- valor ---------- */

.amount-box {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
}
.amount-box:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.amount-box.invalid { border-color: var(--danger); }
.amount-box .cur { font-size: 1.5rem; color: var(--muted); }
#amount {
  flex: 1; min-width: 0; padding: 0;
  border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em;
}
#amount:focus { outline: none; }

.help { color: var(--muted); font-size: .8rem; margin: 8px 2px 0; }

.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.preset {
  min-height: 46px;
  padding: 12px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: inherit;
  font: inherit; font-weight: 600;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.preset:hover:not(:disabled) { border-color: var(--line-strong); }
.preset[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.preset:disabled { opacity: .45; cursor: not-allowed; }
.preset:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- metodos (Payment Element do Stripe) ---------- */

/* O Stripe desenha os campos dentro deste contentor; o que nos toca é dar-lhe
   espaço e um estado de carregamento enquanto não monta. */
#payment-element { min-height: 90px; }

.element-loading { color: var(--muted); font-size: .85rem; margin: 10px 2px 0; }
.element-loading[hidden] { display: none; }

/* ---------- campos ---------- */

.field { display: grid; gap: 6px; }
.field + .field { margin-top: 18px; }
.field label { font-size: .85rem; font-weight: 600; }
.field .help { color: var(--muted); font-size: .8rem; }
.input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* evita o zoom automatico no iOS */
}
.input::placeholder { color: var(--muted); opacity: .8; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.error-text { color: var(--danger); font-size: .8rem; }
.error-text[hidden] { display: none; }

.qty { display: flex; align-items: center; gap: 8px; }
.qty button {
  width: 44px; height: 44px; flex: none;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.15rem; line-height: 1;
  cursor: pointer;
}
.qty button:hover:not(:disabled) { background: var(--surface-2); }
.qty button:disabled { opacity: .45; cursor: not-allowed; }
.qty button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.qty .input { width: 88px; text-align: center; }
.qty .input::-webkit-outer-spin-button,
.qty .input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty .input { -moz-appearance: textfield; appearance: textfield; }

/* ---------- resumo ---------- */

.summary { position: sticky; top: 24px; }
.summary .section-body { padding: 20px; }
.summary h2 { margin: 0 0 14px; font-size: 1.02rem; }
.line { display: flex; justify-content: space-between; gap: 14px; }
.line + .line { margin-top: 10px; }
.line .k { color: var(--muted); font-size: .9rem; }
.line .v { font-weight: 600; font-size: .9rem; }
.line-item { padding-bottom: 14px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.line-item .k { color: var(--text); font-weight: 600; font-size: .95rem; }
.line-item .sub { display: block; color: var(--muted); font-size: .82rem; font-weight: 400; }
.total {
  margin-top: 14px; padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: baseline; gap: 14px;
}
.total .k { font-weight: 650; }
.total .v { font-size: 1.35rem; font-weight: 700; }

.btn {
  width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  padding: 15px 18px;
  border: 0; border-radius: 11px;
  background: var(--brand); color: var(--on-brand);
  font: inherit; font-size: 1rem; font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s ease, opacity .15s ease;
}
.btn:hover:not(:disabled) { background: var(--brand-hi); }
.btn:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn .spinner {
  width: 16px; height: 16px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.actions { margin-top: 18px; }

.alert {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--danger);
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: .87rem;
}
.alert[hidden] { display: none; }

.trust {
  margin-top: 18px;
  display: flex; flex-wrap: wrap; gap: 8px 18px;
  color: var(--muted); font-size: .8rem;
}
.trust span { display: inline-flex; align-items: center; gap: 6px; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.foot {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px 40px;
  color: var(--muted);
  font-size: .8rem;
  display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: space-between;
}

/* ---------- telemovel ---------- */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
    padding: 24px 16px 40px;
  }
  .summary { position: static; order: 2; }
  .form-col { order: 1; }
  .page-title { font-size: 1.35rem; }
  .page-sub { margin-bottom: 20px; }
  .section-body { padding: 18px 16px; }
  .topbar-inner { padding: 14px 16px; }
  .foot { padding: 0 16px 32px; }
  .brand { white-space: nowrap; }
  .badge-secure { font-size: .76rem; }
}

@media (max-width: 460px) {
  /* a mesma garantia aparece no resumo, por isso o topo fica só com a marca */
  .badge-secure span { display: none; }

}

@media (max-width: 340px) {
  .section-body { padding: 16px 13px; }
  .presets { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; }
  .btn .spinner { animation-duration: 2s; }
}

/* ---------- pagina de resultado ---------- */

.result-wrap { max-width: 520px; margin: 0 auto; padding: 48px 16px; }
.result { text-align: center; padding: 36px 28px; }
.result .icon {
  width: 56px; height: 56px; margin: 0 auto 16px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--brand-soft);
}
.result h1 { font-size: 1.3rem; margin: 0 0 8px; }
.result p { color: var(--muted); margin: 0 0 6px; }
.result .ref {
  margin: 18px 0 0; padding: 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2);
  font-size: .85rem;
}
.result .btn { margin-top: 22px; }

/* ---------- administracao ---------- */

.admin { max-width: 1080px; margin: 0 auto; padding: 32px 24px 56px; }
.admin-head-right { display: flex; align-items: center; gap: 12px; }

.btn-ghost {
  width: auto;
  padding: 9px 14px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-size: .88rem; font-weight: 600;
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }

.mode {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .72rem; font-weight: 700; letter-spacing: .03em;
  white-space: nowrap;
}
.mode-test { background: var(--brand-soft); color: var(--brand); }
.mode-live { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.mode[hidden] { display: none; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat .section-body { padding: 18px 20px; }
.stat-label { margin: 0 0 6px; color: var(--muted); font-size: .8rem; font-weight: 600; }
.stat-value { margin: 0; font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.stat-note { margin: 6px 0 0; color: var(--muted); font-size: .78rem; }

.admin-section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.admin-section-head h2 { margin: 0; font-size: 1.02rem; }
.muted { color: var(--muted); font-size: .8rem; }

/* A tabela rola dentro da própria caixa; a página nunca rola na horizontal. */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; min-width: 560px; }
.table th, .table td { padding: 10px 12px; text-align: left; white-space: nowrap; }
.table th {
  border-bottom: 1px solid var(--line);
  color: var(--muted); font-size: .76rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
}
.table td { border-bottom: 1px solid var(--line); }
.table tr:last-child td { border-bottom: 0; }
.table .right { text-align: right; }
.table code { font-size: .82em; color: var(--muted); }

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: .72rem; font-weight: 700;
}
.pill-ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.pill-wait { background: var(--brand-soft); color: var(--brand); }
.pill-off { background: var(--surface-2); color: var(--muted); }

.config { display: grid; grid-template-columns: max-content 1fr; gap: 10px 24px; margin: 0; }
.config dt { color: var(--muted); font-size: .85rem; }
.config dd { margin: 0; font-weight: 600; font-size: .88rem; }

@media (max-width: 640px) {
  .admin { padding: 24px 16px 40px; }
  .config { grid-template-columns: 1fr; gap: 2px; }
  .config dd { margin-bottom: 10px; }
  .btn-ghost { padding: 8px 12px; font-size: .82rem; }
}

/* ---------- admin: chaves ---------- */

.keys-intro { margin: 0 0 16px; max-width: 62ch; }
.keys-intro code { font-size: .92em; }
.keys-actions { display: flex; gap: 10px; margin-top: 18px; }
.keys-actions .btn { width: auto; padding: 11px 18px; font-size: .92rem; }
.ok-text { color: var(--ok); font-size: .85rem; margin: 12px 0 0; }
.ok-text[hidden] { display: none; }

.alert.warn {
  border-color: color-mix(in srgb, var(--danger) 55%, transparent);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--danger);
  margin-bottom: 20px;
}

#keys-form .input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88rem; }
#keys-form .input::placeholder { font-family: inherit; }
