:root {
  --navy: #24336A;
  --navy-dark: #1a2550;
  --secondary: #535D8A;
  --light: #C8CAD8;
  --bg: #f0f2f5;
  --card: #ffffff;
  --border: #dee2e6;
  --text: #2d3940;
  --muted: #666;
  --danger: #c82333;
  --success: #28a745;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  background: var(--navy);
  color: white;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}
header h1 { margin: 0; font-size: 18px; font-weight: 600; }
header nav { display: flex; align-items: center; gap: 18px; flex: 1; }
header nav a { color: white; text-decoration: none; opacity: 0.85; }
header nav a:hover, header nav a.active { opacity: 1; text-decoration: underline; }
header nav a.download-badge {
  opacity: 1;
  display: inline-flex;
  align-items: center;
  padding: 0;
}
header nav a.download-badge img {
  height: 36px;
  width: auto;
  display: block;
  transition: opacity 0.15s ease;
}
header nav a.download-badge:hover { text-decoration: none; }
header nav a.download-badge:hover img { opacity: 0.85; }
header .spacer { flex: 1; }
header #who { font-size: 13px; opacity: 0.8; }
header button {
  background: transparent;
  color: white;
  border: 1px solid rgba(255,255,255,0.4);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
}

main { padding: 24px; max-width: 1100px; margin: 0 auto; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 20px;
}
.card.narrow { max-width: 500px; }

h2 { margin: 0 0 16px 0; font-size: 20px; }

form label {
  display: block;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 500;
}
form input, form select {
  display: block;
  width: 100%;
  padding: 8px 10px;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
}
form small { color: var(--muted); font-weight: normal; }
fieldset {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 16px;
  margin-bottom: 16px;
}
fieldset legend { padding: 0 6px; color: var(--muted); font-size: 13px; }

button {
  background: var(--navy);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}
button:hover { background: var(--navy-dark); }
button.secondary {
  background: white;
  color: var(--navy);
  border: 1px solid var(--navy);
}
button.danger { background: var(--danger); }

.row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.row.between { justify-content: space-between; align-items: center; }
.row .grow { flex: 1 1 120px; }

.terminal-row {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 10px;
  background: #fafbfc;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.terminal-row + .terminal-row { margin-top: 4px; }
.terminal-row label { margin-bottom: 0; }
.terminal-row label.full { display: block; }
.terminal-row label.full select,
.terminal-row label.full input { width: 100%; }

.terminal-row-header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: end;
}
.terminal-row-header .grow input { width: 100%; }
.default-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  white-space: nowrap;
  padding-bottom: 8px;
}
.default-label input[type="radio"] {
  width: auto;
  margin: 0;
}
.remove-btn {
  align-self: end;
  padding: 8px 14px;
  font-size: 13px;
}

.provider-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.provider-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.provider-fields label small { font-weight: normal; }

.provider-help {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

#terminals-list { margin-bottom: 10px; }

.api-key-display {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin-bottom: 8px;
}
.api-key-display pre {
  flex: 1;
  margin: 0;
  min-width: 0;
  white-space: pre-wrap;
  word-break: break-all;
}
.api-key-display button {
  flex: 0 0 auto;
  align-self: stretch;
}
.copied {
  margin: 0 0 12px 0;
  font-size: 13px;
  color: var(--success);
  font-weight: 500;
}
.copied.error { color: var(--danger); }

/* Transactions filter bar */
.tx-filters {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto auto;
  gap: 8px;
  margin-bottom: 16px;
  align-items: end;
}
.tx-filters input,
.tx-filters select { padding: 8px 10px; font-size: 14px; }
.tx-filters .inline {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}
@media (max-width: 800px) {
  .tx-filters { grid-template-columns: 1fr 1fr; }
}

/* Sortable table headers */
table.sortable th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
}
table.sortable th.sortable:hover { color: var(--navy); }
table.sortable th.sort-asc::after  { content: ' ▲'; font-size: 10px; color: var(--navy); }
table.sortable th.sort-desc::after { content: ' ▼'; font-size: 10px; color: var(--navy); }

table.data tbody tr.clickable {
  cursor: pointer;
}
table.data tbody tr.clickable:hover {
  background: #f8f9fa;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(36, 51, 106, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  z-index: 1000;
  overflow-y: auto;
}
.modal-card {
  background: var(--card);
  border-radius: 8px;
  padding: 24px;
  max-width: 720px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-header h2 code {
  font-size: 13px;
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
}
button.ghost {
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  padding: 0 8px;
  line-height: 1;
}
button.ghost:hover { background: var(--bg); color: var(--text); }

.tx-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px 16px;
  margin: 16px 0;
}
.tx-detail-grid > div { min-width: 0; }
.tx-detail-grid label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.tx-detail-grid > div > div {
  font-size: 14px;
  word-break: break-word;
}
.tx-detail-grid .span2 { grid-column: span 2; }
.error-inline {
  color: var(--danger);
  font-weight: 500;
}
.error-inline:empty::before {
  content: '—';
  color: var(--muted);
  font-weight: normal;
}

.raw-section {
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  background: #f8f9fa;
}
.raw-section summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
}
.raw-section pre {
  margin: 8px 0 0 0;
  max-height: 360px;
  overflow: auto;
  font-size: 12px;
  user-select: text;
}

table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
table.data th { background: #f8f9fa; font-weight: 600; color: var(--muted); }
table.data tr:last-child td { border-bottom: none; }

.error { color: var(--danger); font-size: 13px; min-height: 1em; }
.muted { color: var(--muted); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}
.badge.active   { background: #d1fae5; color: #065f46; }
.badge.inactive { background: #f1f5f9; color: #475569; }
.badge.success  { background: #d1fae5; color: #065f46; }
.badge.failed   { background: #fee2e2; color: #991b1b; }
.badge.pending  { background: #fef3c7; color: #92400e; }
.badge.cancelled{ background: #f1f5f9; color: #475569; }
.badge.voided   { background: #e0e7ff; color: #3730a3; }
.badge.refunded { background: #fce7f3; color: #9d174d; }

pre {
  background: #f8f9fa;
  padding: 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  overflow-x: auto;
  user-select: all;
}
