/* ─── Design tokens ─────────────────────────────────────────────── */
:root {
  /* Surfaces */
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-alt: #fafbfc;
  --surface-sunken: #f1f3f9;

  /* Borders */
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --border-soft: #f1f5f9;

  /* Text */
  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --text-on-dark: #e2e8f0;

  /* Accents */
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --primary-ring: rgba(79, 70, 229, 0.18);

  /* Status palette (text · soft bg) */
  --ok: #166534;
  --ok-bg: #dcfce7;
  --warn: #92400e;
  --warn-bg: #fef3c7;
  --err: #991b1b;
  --err-bg: #fee2e2;
  --info: #1e40af;
  --info-bg: #dbeafe;

  /* Effects */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 40px -8px rgba(15, 23, 42, 0.18),
    0 4px 12px -2px rgba(15, 23, 42, 0.08);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --easing: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ─── Reset + base ──────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.15s var(--easing);
}
a:hover {
  color: var(--primary-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}
::selection {
  background: var(--primary-ring);
}

h1,
h2,
h3 {
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}
h1 {
  font-size: 26px;
  line-height: 1.2;
}
h2 {
  font-size: 18px;
}
h3 {
  font-size: 15px;
}

/* ─── Topbar ────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 32px;
  background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
  border-bottom: 1px solid #1f2937;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(180%) blur(8px);
}
.topbar .brand {
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.topbar .brand::before {
  content: '';
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background:
    radial-gradient(circle at 30% 30%, #818cf8 0%, transparent 50%),
    radial-gradient(circle at 70% 70%, #4f46e5 0%, transparent 60%),
    #1e1b4b;
  display: inline-block;
}
.topbar nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  margin-left: 32px;
}
.topbar nav a {
  color: var(--text-on-dark);
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 13px;
  transition: all 0.15s var(--easing);
}
.topbar nav a:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
  text-decoration: none;
}

/* ─── Container ─────────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 32px 80px;
}

/* ─── Page header ───────────────────────────────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  gap: 16px;
}
.page-header h1 {
  margin-top: 6px;
}
.page-header .meta {
  color: var(--text-muted);
  font-size: 13px;
  margin: 6px 0 0;
}
.page-header a.muted {
  display: inline-block;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 500;
}

/* ─── Typography helpers ────────────────────────────────────────── */
.lede {
  color: var(--text-muted);
  max-width: 720px;
  margin-bottom: 24px;
  font-size: 14px;
}
.muted {
  color: var(--text-muted);
  font-size: 13px;
}
.small {
  font-size: 12px;
  color: var(--text-muted);
}
.mono {
  font-family: 'JetBrains Mono', 'SF Mono', 'Menlo', ui-monospace, monospace;
  font-size: 12.5px;
  letter-spacing: -0.01em;
}

/* ─── Tables ────────────────────────────────────────────────────── */
.table {
  width: 100%;
  background: var(--surface);
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.table th {
  text-align: left;
  padding: 11px 16px;
  background: var(--surface-sunken);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
.table tbody tr {
  transition: background 0.12s var(--easing);
}
.table tbody tr:hover {
  background: var(--surface-alt);
}
.table tr:last-child td {
  border-bottom: none;
}
.table .actions {
  white-space: nowrap;
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}
.table--mapping input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
  font-size: 12px;
  background: var(--surface);
  transition: border-color 0.15s var(--easing), box-shadow 0.15s var(--easing);
}
.table--mapping input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

/* ─── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  line-height: 1;
  transition: all 0.15s var(--easing);
  box-shadow: var(--shadow-sm);
}
.btn:hover {
  background: var(--surface-alt);
  border-color: var(--text-subtle);
  text-decoration: none;
}
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-ring);
  border-color: var(--primary);
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.btn--primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn--primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
}
.btn--danger {
  background: #fff;
  border-color: #fecaca;
  color: #b91c1c;
}
.btn--danger:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}
.btn--small {
  padding: 5px 10px;
  font-size: 12px;
}
.btn--ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}
.btn--ghost:hover {
  background: var(--surface-sunken);
  border-color: transparent;
}

/* ─── Forms ─────────────────────────────────────────────────────── */
.form {
  background: var(--surface);
  padding: 28px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 720px;
  box-shadow: var(--shadow-sm);
}
.form fieldset {
  border: none;
  margin: 0 0 28px;
  padding: 0;
}
.form fieldset:last-of-type {
  margin-bottom: 0;
}
.form legend {
  font-weight: 600;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
  width: 100%;
}
.form label {
  display: block;
  margin-bottom: 16px;
}
.form label:last-child {
  margin-bottom: 0;
}
.form label > span {
  display: block;
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 6px;
}
.form label > span em {
  color: var(--text-subtle);
  font-style: normal;
  font-weight: 400;
  font-size: 11px;
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form input[type='text'],
.form input[type='email'],
.form input[type='password'] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--surface);
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.15s var(--easing), box-shadow 0.15s var(--easing);
}
.form input[type='text']:focus,
.form input[type='email']:focus,
.form input[type='password']:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
.form input::placeholder {
  color: var(--text-subtle);
}
.form small {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 6px;
}
.form code {
  background: var(--surface-sunken);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
  font-size: 11.5px;
  border: 1px solid var(--border-soft);
}
.form__actions {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  gap: 8px;
}

/* ─── Badges ────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--surface-sunken);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
}
.badge--ok {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: transparent;
}
.badge--err {
  background: var(--err-bg);
  color: var(--err);
  border-color: transparent;
}
.badge--pending {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: transparent;
}
.badge--muted {
  background: var(--surface);
  color: var(--text-muted);
  border-color: var(--border-strong);
  opacity: 0.85;
}

/* ─── Flash messages ────────────────────────────────────────────── */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid transparent;
}
.flash--success {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: rgba(22, 101, 52, 0.18);
}
.flash--error {
  background: var(--err-bg);
  color: var(--err);
  border-color: rgba(153, 27, 27, 0.18);
}
.flash--info {
  background: var(--info-bg);
  color: var(--info);
  border-color: rgba(30, 64, 175, 0.18);
}

/* ─── Cards & layout helpers ────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.error-box {
  background: var(--surface);
  border: 1px solid var(--err-bg);
  border-left: 3px solid var(--err);
  border-radius: var(--radius);
  padding: 24px 28px;
  box-shadow: var(--shadow-sm);
}
.error-box p:first-child {
  margin-top: 0;
}
.error-detail {
  background: var(--surface-sunken);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--border-soft);
}

.empty {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 56px 24px;
  text-align: center;
  color: var(--text-muted);
}
.empty p {
  margin: 6px 0;
}
.empty p:first-child {
  font-weight: 500;
  color: var(--text);
  font-size: 15px;
}

/* ─── Webhook info callout ──────────────────────────────────────── */
.webhook-info {
  position: relative;
  background: linear-gradient(135deg, var(--primary-soft) 0%, #f5f3ff 100%);
  border: 1px solid #e0e7ff;
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 24px;
  font-size: 13px;
  color: #312e81;
}
.webhook-info strong {
  color: #312e81;
  font-weight: 600;
}
.webhook-info p {
  margin: 8px 0;
}
.webhook-info code {
  background: var(--surface);
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid #e0e7ff;
  font-family: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
  font-size: 12px;
  color: #4338ca;
  word-break: break-all;
}
.webhook-info ul {
  margin: 8px 0 0 18px;
  padding: 0;
}
.webhook-info li {
  margin: 4px 0;
}

/* ─── Auth (login page) ─────────────────────────────────────────── */
.auth-card {
  max-width: 380px;
  margin: 80px auto;
  padding: 36px 36px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  position: relative;
}
.auth-card::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: var(--radius-lg);
  padding: 1px;
  background: linear-gradient(180deg, rgba(79, 70, 229, 0.15), transparent 40%);
  pointer-events: none;
  -webkit-mask:
    linear-gradient(#000, #000) content-box,
    linear-gradient(#000, #000);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
}
.auth-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
}
.auth-card .muted {
  margin: 0 0 24px;
}
.auth-card .stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.auth-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.auth-card input {
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s var(--easing), box-shadow 0.15s var(--easing);
}
.auth-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
.auth-card .btn {
  margin-top: 4px;
}
.auth-card .flash {
  margin-bottom: 16px;
}

/* ─── Topbar — sign-out button ──────────────────────────────────── */
.topbar nav .topbar-user {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-on-dark);
}
.topbar-user .avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
}
.btn-link {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-on-dark);
  cursor: pointer;
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  border-radius: 6px;
  transition: all 0.15s var(--easing);
}
.btn-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.18);
}

/* ─── Modal ─────────────────────────────────────────────────────── */
.modal[hidden] {
  display: none !important;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  animation: fadeIn 0.15s var(--easing);
}
.modal__panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  padding: 28px;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.18s var(--easing);
}
.modal__panel h2 {
  margin: 0 0 6px;
  font-size: 18px;
}
.modal__panel .muted {
  margin: 0 0 18px;
}
.modal__secret {
  display: flex;
  align-items: stretch;
  gap: 8px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.modal__secret code {
  flex: 1;
  font-family: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
  font-size: 12px;
  word-break: break-all;
  user-select: all;
  display: block;
  align-self: center;
  color: var(--text);
  background: transparent;
  border: none;
  padding: 0;
}
.modal__copy {
  flex-shrink: 0;
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.modal__copy.is-copied {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: rgba(22, 101, 52, 0.18);
}
.modal__hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 20px;
}
.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Error modal — visually distinct from the webhook-secret modal */
.modal--error .modal__panel {
  border-top: 4px solid var(--err);
  padding-top: 24px;
}
.modal__icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--err-bg);
  color: var(--err);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  margin-bottom: 12px;
}
.modal__action-required {
  background: var(--surface-sunken);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 16px 0;
  font-size: 13px;
  color: var(--text);
}
.modal__action-required strong {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.modal__action-required ol {
  margin: 0;
  padding-left: 20px;
}
.modal__action-required li {
  margin: 4px 0;
}
.modal__details {
  margin-top: 4px;
  font-size: 12px;
}
.modal__details summary {
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
  padding: 4px 0;
}
.modal__details summary:hover {
  color: var(--text);
}
.modal__details pre {
  margin: 8px 0 0;
  background: var(--surface-sunken);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
  font-size: 11.5px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 160px;
  overflow: auto;
}

/* ─── Misc ──────────────────────────────────────────────────────── */
code {
  font-family: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
  font-size: 0.92em;
}
strong {
  font-weight: 600;
}

/* Tighter table cells on smaller screens */
@media (max-width: 720px) {
  .container {
    padding: 20px 16px 60px;
  }
  .topbar {
    padding: 12px 16px;
  }
  .table th,
  .table td {
    padding: 10px 12px;
  }
  .form {
    padding: 20px;
  }
  .topbar nav {
    margin-left: 16px;
  }
}

/* ─── Event list grid ───────────────────────────────────────────── */
.event-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.event-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px 20px;
  text-decoration: none;
  color: inherit;
  transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}
.event-card:hover {
  border-color: var(--primary, #6366f1);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.08);
  transform: translateY(-1px);
}
.event-card__title strong {
  display: block;
  font-size: 16px;
  margin-bottom: 4px;
}
.event-card__stats {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--text-muted);
}
.event-card__stats strong {
  color: var(--text);
  font-weight: 600;
}
.event-card__meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid var(--border-soft);
  padding-top: 10px;
}

/* ─── Stat row (per-event header counts) ────────────────────────── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 16px 0 28px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px 18px;
}
.stat__value {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.2;
}
.stat__label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Section headers between tables on the event-detail page */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 28px 0 8px;
}
.section-header h2 {
  margin: 0;
  font-size: 17px;
}

.btn--small {
  padding: 4px 10px;
  font-size: 12px;
}

