:root {
  --bg: #0f172a;
  --card: #111827;
  --muted: #94a3b8;
  --text: #e5e7eb;
  --primary: #6d28d9;
  --primary-600: #7c3aed;
  --primary-700: #5b21b6;
  --danger: #ef4444;
  --success: #22c55e;
  --border: #1f2937;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: linear-gradient(180deg, #0b1020, var(--bg));
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.6);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 { margin: 0; font-size: 18px; }
.topbar a { color: var(--muted); text-decoration: none; }
.topbar a:hover { color: var(--text); }

main { max-width: 920px; margin: 24px auto; padding: 0 16px; }

.card {
  background: linear-gradient(180deg, #0f1220, var(--card));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.card.header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.muted { color: var(--muted); }
.hidden { display: none !important; }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  padding: 16px;
  margin: 16px auto;
}
.keypad button {
  height: 72px;
  width: 72px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text);
  background: radial-gradient(120% 120% at 50% 10%, #111a33 0%, #0b1020 60%, #070b16 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05), 0 6px 14px rgba(0,0,0,0.35);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
  outline: none;
  transition: transform 0.08s ease, box-shadow 0.12s ease, background 0.2s ease;
}
.keypad button:focus { outline: none; }
.keypad button:hover { transform: translateY(-1px); box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 10px 18px rgba(0,0,0,0.45); }
.keypad button:active { transform: scale(0.95); box-shadow: inset 0 2px 6px rgba(0,0,0,0.6), 0 2px 8px rgba(0,0,0,0.25); }

.keypad .primary {
  background: radial-gradient(120% 120% at 50% 10%, #6d28d9 0%, #5b21b6 60%, #3b147a 100%);
  border-color: #4c1d95;
}
.keypad .primary:hover { filter: brightness(1.05); }
.keypad .primary:active { filter: brightness(0.98); }

.keypad .secondary {
  background: radial-gradient(120% 120% at 50% 10%, #0f172a 0%, #0a0f1e 60%, #070b16 100%);
  color: var(--muted);
}

@media (hover: none) {
  .keypad button:hover { transform: none; }
}

.pin-display {
  width: 260px;
  min-height: 56px;
  text-align: center;
  padding: 16px;
  margin: 16px auto;
  border-radius: 12px;
  border: 1px dashed var(--border);
  font-size: 24px;
  letter-spacing: 6px;
}
.pin-display.success {
  border: 1px solid #14532d;
  background: #052e1b;
  color: #dcfce7;
}
.pin-status { text-align: center; margin-top: 8px; color: var(--muted); }
.pin-status .spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid #94a3b8; border-top-color: transparent; border-radius: 50%; animation: spin 1s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.primary {
  background: var(--primary);
  color: white;
  border: 0;
  padding: 10px 14px;
  border-radius: 10px;
}
.primary:hover { background: var(--primary-600); }
.secondary {
  background: #0a0f1e;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 10px;
}
.secondary:hover { background: #0f1325; }

.toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.toggle input { accent-color: var(--primary); }

.links-list, .users-list { list-style: none; padding: 0; margin: 0; }
.links-list li, .users-list li {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 10px;
}
.links-list li { display: block; }
.links-list .link-top { padding-bottom: 10px; border-bottom: 1px dashed var(--border); }
.links-list .link-bottom { padding-top: 10px; }
.links-list li + li, .users-list li + li { margin-top: 8px; }
.links-list .url { color: #93c5fd; word-break: break-all; }
.empty-state { color: var(--muted); }
.empty { opacity: 0.9; }

.badge { padding: 4px 8px; border-radius: 999px; font-size: 16px; border: 1px solid var(--border); color: var(--muted); }
.danger { color: #fecaca; border-color: #7f1d1d; background: #450a0a; }
/* status colors */
.status-succeeded { color: #dcfce7; background: #14532d; border-color: #166534; }
.status-processing { color: #ede9fe; background: #312e81; border-color: #3730a3; }
.status-requires { color: #ffedd5; background: #7c2d12; border-color: #9a3412; }
.status-inactive { color: #e5e7eb; background: #1f2937; border-color: #374151; }
.status-unknown { color: #e5e7eb; background: #111827; border-color: #1f2937; }

.icon-button { background: transparent; border: 0; color: var(--muted); font-size: 16px; }
.icon-button:hover { color: var(--text); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: grid; place-items: center; }
.modal-content {
  width: min(680px, 92vw);
  background: linear-gradient(180deg, #0f1220, var(--card));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  position: relative;
}
#confirm-title { margin-top: 0; }
.modal-content.confirm { width: min(460px, 92vw); }
#modal-close { position: absolute; top: 10px; right: 10px; }

label span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type="text"], input[type="password"], input[type="number"], input[type="email"], input[type="tel"], textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0b1020;
  color: var(--text);
}
input[readonly] { opacity: 0.8; }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }

/* Mobile responsive styles - iPhone 15 Pro Max and modern devices */
@media (max-width: 640px) {
  html { -webkit-text-size-adjust: 100%; }
  body { padding-bottom: env(safe-area-inset-bottom); }
  .grid { grid-template-columns: 1fr; }
  main { padding: 0 12px; margin: 16px auto; padding-top: max(16px, env(safe-area-inset-top)); }
  .card { padding: 16px; margin-bottom: 12px; border-radius: 12px; }
  .card.header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .topbar { padding: 12px 14px; flex-wrap: wrap; padding-top: max(12px, env(safe-area-inset-top)); }
  .topbar h1 { font-size: 16px; }
  .topbar nav { font-size: 14px; }
  .keypad button { padding: 18px 0; font-size: 22px; min-height: 56px; }
  .primary, .secondary { padding: 12px 16px; font-size: 15px; min-height: 44px; width: 100%; }
  .actions { width: 100%; flex-direction: column; }
  .actions > * { width: 100%; }
  .toggle { width: 100%; justify-content: space-between; padding: 8px 0; }
  .modal { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .modal-content { width: calc(100vw - 24px); max-width: none; padding: 16px; margin: 12px; max-height: calc(100vh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .modal-content.confirm { width: calc(100vw - 24px); }
  .pin-display { width: 100%; max-width: 200px; margin: 16px auto; font-size: 18px; }
  .links-list li { padding: 12px; }
  .links-list .link-top { flex-wrap: wrap; gap: 8px; }
  .links-list .link-bottom { gap: 8px; }
  .links-list .link-bottom > div { flex-direction: column; align-items: flex-start; gap: 8px; }
  .links-list .link-bottom .actionsWrap { width: 100%; flex-direction: column; margin-left: 0 !important; }
  .links-list .link-bottom .actionsWrap button { width: 100%; }
  .links-list .link-bottom .linkRow { flex-direction: column; align-items: stretch; }
  .links-list .link-bottom .leftWrap { width: 100%; margin-bottom: 8px; }
  .links-list .url { word-break: break-all; font-size: 14px; }
  .badge { font-size: 13px; padding: 6px 10px; }
  .summary { padding: 12px; }
  .summary-row { font-size: 14px; padding: 10px 0; }
  .summary-row.total { font-size: 16px; }
  h2 { font-size: 20px; }
  h3 { font-size: 18px; }
  input[type="text"], input[type="password"], input[type="number"], input[type="email"], input[type="tel"], textarea {
    padding: 12px; font-size: 16px; /* Prevents zoom on iOS */
  }
  .buttons { flex-direction: column; }
  .buttons button { width: 100%; }
  .buttons.end { flex-direction: column-reverse; }
}

@media (max-width: 400px) {
  main { padding: 0 8px; }
  .card { padding: 12px; }
  .keypad button { padding: 20px 0; font-size: 24px; min-height: 60px; }
  .topbar { padding: 10px 12px; }
  .topbar h1 { font-size: 14px; }
  .badge { font-size: 12px; padding: 4px 8px; }
}

.buttons { display: flex; gap: 8px; margin-top: 12px; }
.buttons.end { justify-content: flex-end; }
.error { color: #fecaca; background: #3f1d1d; border: 1px solid #7f1d1d; border-radius: 10px; padding: 10px; margin-top: 10px; }

.admin-link { color: #c084fc; }

/* checkout-style summary */
.summary { margin-top: 12px; }
.summary-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; border-bottom: 1px dashed var(--border);
}
.summary-row:last-child { border-bottom: 0; }
.summary-row.total { font-size: 18px; font-weight: 700; }
.summary-row.small { font-size: 12px; }


