:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #66746d;
  --line: #dbe5dd;
  --paper: #f8faf8;
  --panel: rgba(255, 255, 255, 0.9);
  --field: #ffffff;
  --mint: #4fc08d;
  --mint-dark: #17694d;
  --coral: #f27b68;
  --gold: #e6a94e;
  --blue: #3f7cac;
  --shadow: 0 24px 70px rgba(23, 33, 27, 0.14);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #edf7f1;
  --muted: #a9b8b0;
  --line: #32463d;
  --paper: #101713;
  --panel: rgba(23, 33, 27, 0.92);
  --field: #18231e;
  --mint: #69d7a6;
  --mint-dark: #8be4bc;
  --coral: #ff917f;
  --gold: #f4c36b;
  --blue: #79aede;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--mint) 18%, transparent), transparent 34%),
    linear-gradient(225deg, color-mix(in srgb, var(--coral) 16%, transparent), transparent 30%),
    var(--paper);
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 850;
  text-decoration: none;
  min-width: 0;
}

.brand-link span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  margin-right: 12px;
  min-width: 0;
}

.topnav a {
  min-height: 40px;
  display: grid;
  place-items: center;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 750;
  text-decoration: none;
}

.topnav a:hover,
.topnav a:focus-visible {
  border-color: var(--line);
  color: var(--ink);
  outline: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--mint-dark);
  color: var(--paper);
  font-weight: 850;
  letter-spacing: 0;
}

.icon-button {
  min-width: 70px;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--mint);
  outline: none;
}

.checkout-shell {
  width: min(1120px, calc(100% - 32px));
  min-height: calc(100vh - 60px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(300px, 0.86fr) minmax(360px, 1.14fr);
  gap: 28px;
  align-items: center;
  padding: 24px 0 36px;
  min-width: 0;
}

body[data-view="admin"] .topbar,
body[data-view="admin"] .checkout-shell {
  width: min(1600px, calc(100% - 48px));
}

body[data-view="admin"] .checkout-shell {
  min-height: auto;
  grid-template-columns: 1fr;
  align-items: start;
  padding-top: 30px;
}

body[data-view="admin"] .brand-panel {
  display: none;
}

body[data-view="admin"] .checkout-panel {
  min-height: calc(100vh - 132px);
  padding: 32px;
}

body[data-view="admin"] .admin-view {
  gap: 24px;
}

.brand-panel,
.checkout-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 8px;
  min-width: 0;
}

.brand-panel {
  min-height: 640px;
  padding: 42px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.brand-panel::after {
  content: "";
  position: absolute;
  inset: auto -80px -90px auto;
  width: 260px;
  height: 260px;
  border: 28px solid color-mix(in srgb, var(--blue) 28%, transparent);
  transform: rotate(24deg);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--mint-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 18px;
  font-size: clamp(3rem, 6vw, 5.6rem);
  line-height: 0.95;
}

h2 {
  margin-bottom: 0;
  font-size: 1.45rem;
}

.brand-copy,
.result-copy {
  max-width: 430px;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.6;
}

.rail {
  margin-top: 52px;
  display: grid;
  gap: 12px;
  max-width: 360px;
}

.rail div,
.invoice-meta div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--field) 78%, transparent);
}

.rail span,
.invoice-meta span {
  color: var(--muted);
  font-size: 0.82rem;
}

.checkout-panel {
  min-height: 640px;
  padding: 28px;
  overflow: hidden;
}

.payment-form,
.result-view,
.lookup-view,
.admin-view {
  display: grid;
  gap: 20px;
  min-width: 0;
}

.is-hidden {
  display: none !important;
}

.form-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
}

.form-heading > div {
  flex: 1 1 auto;
  min-width: 0;
}

.amount-box {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  min-width: 0;
}

.amount-box > span {
  color: var(--muted);
  font-size: 0.86rem;
}

.amount-box div {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 10px;
}

.amount-box .single-input {
  grid-template-columns: 1fr;
}

.amount-box input,
.amount-box select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  background: var(--paper);
  color: var(--ink);
}

.method-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.method {
  min-height: 86px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  min-width: 0;
}

.method.active:hover,
.method.active:focus-visible {
  border-color: var(--mint);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--mint) 20%, transparent);
  outline: none;
}

.method.is-loading {
  cursor: wait;
  opacity: 0.72;
  position: relative;
}

.method.is-loading::after {
  content: "";
  width: 18px;
  height: 18px;
  margin-left: auto;
  border: 2px solid color-mix(in srgb, var(--mint-dark) 30%, transparent);
  border-top-color: var(--mint-dark);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.method.disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.method-icon {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: color-mix(in srgb, var(--mint) 18%, transparent);
  color: var(--mint-dark);
  font-size: 0.76rem;
  font-weight: 900;
}

.method small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.method strong,
.method small {
  overflow-wrap: anywhere;
}

.invoice-card {
  margin-top: 22px;
  display: grid;
  gap: 18px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  min-width: 0;
}

.invoice-topline {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
}

.status-badge {
  flex: 0 0 auto;
  padding: 8px 10px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--gold) 22%, transparent);
  color: var(--gold);
  font-size: 0.84rem;
  font-weight: 800;
}

.status-badge.paid {
  background: color-mix(in srgb, var(--mint) 20%, transparent);
  color: var(--mint-dark);
}

.status-badge.processing {
  background: color-mix(in srgb, var(--blue) 22%, transparent);
  color: var(--blue);
}

.status-badge.expired,
.status-badge.invalid {
  background: color-mix(in srgb, var(--coral) 20%, transparent);
  color: var(--coral);
}

.qr-frame {
  display: grid;
  place-items: center;
  min-height: 300px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.qr-frame img {
  width: min(360px, 100%);
  height: auto;
}

.invoice-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.invoice-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

#qrEncodedField {
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: right;
}

.invoice-actions,
.result-actions {
  display: grid;
  gap: 10px;
}

.checkout-link,
.secondary-link {
  display: grid;
  place-items: center;
  min-height: 48px;
  padding: 12px 16px;
  border-radius: 8px;
  font-weight: 800;
  text-decoration: none;
}

.button-link {
  width: 100%;
  border: 0;
  cursor: pointer;
}

.form-heading .admin-sync-button {
  flex: 0 0 auto;
  width: auto;
  min-width: 132px;
}

.admin-view .form-heading h2 {
  white-space: nowrap;
}

.admin-sync-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.checkout-link {
  background: var(--mint-dark);
  color: var(--paper);
}

.secondary-link {
  border: 1px solid var(--line);
  color: var(--ink);
}

.checkout-link:hover,
.checkout-link:focus-visible {
  filter: brightness(0.95);
  outline: none;
}

.secondary-link:hover,
.secondary-link:focus-visible {
  border-color: var(--mint);
  outline: none;
}

.message {
  min-height: 24px;
  margin: 16px 0 0;
  color: var(--muted);
}

.message.error {
  color: var(--coral);
}

.lookup-result {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  min-width: 0;
}

.lookup-result dl {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px 14px;
  margin: 0;
}

.lookup-result dt {
  color: var(--muted);
}

.lookup-result dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 750;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.stat-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.stat-card strong {
  display: block;
  margin-top: 6px;
  font-size: 1.35rem;
}

.webhook-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--field) 70%, transparent);
  min-width: 0;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  min-width: 0;
}

.section-heading h3 {
  margin: 0;
  font-size: 1.05rem;
}

.webhook-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
}

.webhook-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.webhook-card span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.webhook-card strong {
  display: block;
  margin-top: 5px;
  font-size: 1.2rem;
}

.webhook-status {
  font-weight: 800;
}

.webhook-status.updated {
  color: var(--mint-dark);
}

.webhook-status.invalid_signature,
.webhook-status.invalid_json,
.webhook-status.missing_invoice_id {
  color: var(--coral);
}

.webhook-status.no_local_order {
  color: var(--gold);
}

.webhook-status.retry_scheduled,
.webhook-status.update_failed,
.webhook-status.retry_failed {
  color: var(--gold);
}

.muted,
td small {
  color: var(--muted);
}

td small {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
  white-space: normal;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

body[data-view="admin"] table {
  min-width: 1180px;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.82rem;
}

td {
  font-size: 0.9rem;
}

td code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
  white-space: normal;
  word-break: break-all;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ink: #edf7f1;
    --muted: #a9b8b0;
    --line: #32463d;
    --paper: #101713;
    --panel: rgba(23, 33, 27, 0.92);
    --field: #18231e;
    --mint: #69d7a6;
    --mint-dark: #8be4bc;
    --coral: #ff917f;
    --gold: #f4c36b;
    --blue: #79aede;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  }
}

@media (max-width: 860px) {
  .topbar,
  .checkout-shell {
    width: min(100% - 24px, 1120px);
  }

  body[data-view="admin"] .topbar,
  body[data-view="admin"] .checkout-shell {
    width: min(100% - 24px, 1120px);
  }

  .checkout-shell {
    grid-template-columns: 1fr;
    gap: 18px;
    padding: 18px 0 28px;
  }

  .brand-panel,
  .checkout-panel {
    min-height: auto;
  }

  .brand-panel {
    padding: 28px;
    min-height: auto;
  }

  .rail {
    margin-top: 28px;
  }
}

@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .webhook-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

}

@media (max-width: 560px) {
  .topbar,
  .checkout-shell {
    width: min(100% - 20px, 1120px);
  }

  .topbar {
    padding-top: 10px;
    align-items: start;
    gap: 10px;
    flex-wrap: wrap;
  }

  .topnav {
    order: 3;
    width: 100%;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .brand-panel {
    padding: 24px;
  }

  .brand-panel::after {
    display: none;
  }

  .checkout-panel {
    padding: 18px;
  }

  body[data-view="admin"] .checkout-panel {
    min-height: auto;
    padding: 18px;
  }

  .method-grid,
  .invoice-meta,
  .amount-box div,
  .lookup-result dl {
    grid-template-columns: 1fr;
  }

  .brand-copy,
  .result-copy {
    font-size: 1rem;
  }

  .rail {
    max-width: none;
  }

  .rail div,
  .invoice-meta div {
    align-items: start;
    flex-direction: column;
    gap: 6px;
  }

  .invoice-meta strong,
  #qrEncodedField {
    width: 100%;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .invoice-topline,
  .form-heading {
    align-items: start;
    flex-direction: column;
  }

  .form-heading .admin-sync-button {
    width: 100%;
  }

  h1 {
    font-size: 2.75rem;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .webhook-summary {
    grid-template-columns: minmax(0, 1fr);
  }

}

@media (max-width: 640px) {
  body[data-view="admin"] .table-wrap {
    border: 0;
    background: transparent;
    overflow: visible;
  }

  body[data-view="admin"] table,
  body[data-view="admin"] thead,
  body[data-view="admin"] tbody,
  body[data-view="admin"] tr,
  body[data-view="admin"] td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  body[data-view="admin"] thead {
    display: none;
  }

  body[data-view="admin"] tr {
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--field);
  }

  body[data-view="admin"] td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--line);
    white-space: normal;
    overflow-wrap: anywhere;
    text-align: right;
  }

  body[data-view="admin"] td:last-child {
    border-bottom: 0;
  }

  body[data-view="admin"] td::before {
    content: attr(data-label);
    flex: 0 0 92px;
    color: var(--muted);
    font-weight: 750;
    text-align: left;
  }
}

@media (max-width: 380px) {
  .topbar,
  .checkout-shell,
  body[data-view="admin"] .topbar,
  body[data-view="admin"] .checkout-shell {
    width: min(100% - 14px, 1120px);
  }

  .checkout-panel,
  body[data-view="admin"] .checkout-panel {
    padding: 14px;
  }

  .brand-panel {
    padding: 18px;
  }

  h1 {
    font-size: 2.35rem;
  }
}
