/* ------------------------------------------------------------------ */
/*  Reset & base                                                     */
/* ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
               Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  background: #f2f4f8;
  color: #1a1a2e;
  padding: 2rem 1rem;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ------------------------------------------------------------------ */
/*  Container & cards                                                 */
/* ------------------------------------------------------------------ */
.container {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background: #fff;
  border-radius: 12px;
  padding: 1.75rem;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

.card-error { border-left: 4px solid #ef4444; }

/* ------------------------------------------------------------------ */
/*  Environment badge                                                 */
/* ------------------------------------------------------------------ */
.env-badge {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  align-self: center;
}

.env-test {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.env-production {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

/* ------------------------------------------------------------------ */
/*  Loading state                                                     */
/* ------------------------------------------------------------------ */
#loading {
  text-align: center;
  color: #6b7280;
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid #e5e7eb;
  border-top-color: #262aff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 0.75rem;
}

.spinner.small { width: 18px; height: 18px; border-width: 2px; display: inline-block; vertical-align: middle; margin: 0 0 0 0.5rem; }

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

/* ------------------------------------------------------------------ */
/*  Order summary                                                     */
/* ------------------------------------------------------------------ */
.line-item {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  font-size: 0.95rem;
}

.line-item.total {
  border-top: 1px solid #e5e7eb;
  margin-top: 0.25rem;
  padding-top: 0.75rem;
  font-weight: 600;
  font-size: 1.05rem;
}

/* ------------------------------------------------------------------ */
/*  Amount input                                                      */
/* ------------------------------------------------------------------ */
.amount-input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #1a1a2e;
  background: #fff;
  outline: none;
  transition: border-color 0.15s;
  -moz-appearance: textfield;
}

.amount-input::-webkit-outer-spin-button,
.amount-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.amount-input:focus {
  border-color: #262aff;
  box-shadow: 0 0 0 3px rgba(38,42,255,0.1);
}

/* ------------------------------------------------------------------ */
/*  PayFields input wrappers                                          */
/* ------------------------------------------------------------------ */
.payfields-input {
  width: 100%;
  max-width: 100%;
  min-height: 44px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  background: #fff;
  transition: border-color 0.15s;
  overflow: hidden;
  box-sizing: border-box;
}

.payfields-input:focus-within {
  border-color: #262aff;
  box-shadow: 0 0 0 3px rgba(38,42,255,0.1);
}

/* ------------------------------------------------------------------ */
/*  Modal overlay                                                     */
/* ------------------------------------------------------------------ */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-content {
  background: #fff;
  border-radius: 16px;
  padding: 2rem;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  animation: slideUp 0.25s ease;
  position: relative;
  overflow: hidden;
}

@media (max-width: 480px) {
  .modal-content { padding: 1.25rem; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: #9ca3af;
  cursor: pointer;
  padding: 0.25rem;
  transition: color 0.15s;
}

.modal-close:hover { color: #374151; }

/* ------------------------------------------------------------------ */
/*  Form fields                                                       */
/* ------------------------------------------------------------------ */
.field-group {
  margin-bottom: 1rem;
}

.field-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 0.35rem;
}

.field-row {
  display: flex;
  gap: 0.75rem;
  width: 100%;
}

.field-row .field-group {
  flex: 1;
  min-width: 0;
}

/* ------------------------------------------------------------------ */
/*  Button                                                            */
/* ------------------------------------------------------------------ */
.btn {
  width: 100%;
  padding: 0.85rem;
  border: none;
  border-radius: 8px;
  background: #262aff;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.5rem;
}

.btn:hover:not(:disabled) { background: #1d21cc; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: #e5e7eb;
  color: #374151;
}

.btn-secondary:hover:not(:disabled) { background: #d1d5db; }

.btn-sm {
  width: auto;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  display: inline-block;
}

/* ------------------------------------------------------------------ */
/*  Result card                                                       */
/* ------------------------------------------------------------------ */
.result-icon {
  font-size: 2.5rem;
  text-align: center;
  margin-bottom: 0.5rem;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
}

.result-table td {
  padding: 0.4rem 0;
  font-size: 0.9rem;
  border-bottom: 1px solid #f3f4f6;
}

.result-table tr:last-child td { border-bottom: none; }

.result-label {
  color: #6b7280;
  width: 40%;
}

.result-detail {
  color: #6b7280;
  font-size: 0.9rem;
  margin: 0.75rem 0;
}

#result-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* ------------------------------------------------------------------ */
/*  Status colours                                                    */
/* ------------------------------------------------------------------ */
.status-success { color: #22c55e; }
.status-declined { color: #ef4444; }
.status-failed { color: #ef4444; }
.status-pending { color: #f59e0b; }

/* ------------------------------------------------------------------ */
/*  Form error                                                        */
/* ------------------------------------------------------------------ */
.form-error {
  margin-top: 0.75rem;
  color: #ef4444;
  font-size: 0.9rem;
}

/* ------------------------------------------------------------------ */
/*  Transaction history                                               */
/* ------------------------------------------------------------------ */
.history-item {
  padding: 0.75rem;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}

.history-item:hover { background: #f9fafb; }

.history-item:last-child { margin-bottom: 0; }

.history-item .h-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-item .h-txn-id {
  font-family: monospace;
  font-size: 0.8rem;
  color: #6b7280;
}

.history-empty {
  text-align: center;
  color: #9ca3af;
  padding: 1.5rem 0;
}

#refresh-history {
  margin-top: 0.75rem;
}

/* ------------------------------------------------------------------ */
/*  Utility                                                           */
/* ------------------------------------------------------------------ */
h2 { font-size: 1.15rem; margin-bottom: 1rem; }
code { font-family: "SF Mono", "Menlo", monospace; font-size: 0.85rem; }
