*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #f5f7fa;
  color: #1a1a2e;
}

/* Layout */
.topbar {
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  padding: 0 24px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
  height: 56px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0;
}

.topbar .logo-btn {
  display: flex;
  align-items: center;
  padding-right: 24px;
  border: none;
  border-right: 1px solid #e5e7eb;
  margin-right: 8px;
  background: transparent;
  cursor: pointer;
  border-radius: 0;
  transition: opacity .12s;
}

.topbar .logo-btn:hover {
  opacity: 0.75;
}

.topbar .logo-btn img {
  height: 26px;
}

.nav-tabs {
  display: flex;
  gap: 2px;
  padding: 0 8px;
  flex: 1;
}

.nav-tab {
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  font-size: .85rem;
  color: #666;
  transition: all .15s;
  white-space: nowrap;
}

.nav-tab:hover {
  background: #f0f0f0;
  color: #333;
}

.nav-tab.active {
  background: #4361ee;
  color: #fff;
}

.user-menu {
  position: relative;
  margin-left: auto;
}

.avatar-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid #e5e7eb;
  background: #4361ee;
  color: #fff;
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s;
}

.avatar-btn:hover {
  border-color: #4361ee;
}

.dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: 44px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,.12);
  min-width: 240px;
  padding: 8px 0;
  z-index: 100;
  border: 1px solid #e5e7eb;
}

.dropdown.open {
  display: block;
}

.dropdown-header {
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
}

.dropdown-header .name {
  font-weight: 600;
  font-size: .9rem;
  color: #1a1a2e;
}

.dropdown-header .email {
  font-size: .8rem;
  color: #888;
  margin-top: 2px;
}

.dropdown-header .badge {
  margin-top: 6px;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: .88rem;
  color: #444;
  cursor: pointer;
  transition: background .1s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.dropdown-item:hover {
  background: #f5f7fa;
}

.dropdown-item svg {
  width: 18px;
  height: 18px;
  color: #888;
  flex-shrink: 0;
}

.dropdown-divider {
  height: 1px;
  background: #f0f0f0;
  margin: 4px 0;
}

.dropdown-item.danger {
  color: #ef4444;
}

.dropdown-item.danger svg {
  color: #ef4444;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: .75rem;
  font-weight: 600;
}

.badge-outline {
  background: transparent;
  color: #475569;
  border: 1px solid #cbd5e1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 500;
}

.badge-super_admin {
  background: #fce7f3;
  color: #be185d;
}

.badge-admin {
  background: #ede9fe;
  color: #7c3aed;
}

.badge-viewer {
  background: #fef3c7;
  color: #92400e;
}

.badge-user {
  background: #e0f2fe;
  color: #0284c7;
}

/* Webhook event lifecycle badges (event_status) */
.badge-received { background: #e0f2fe; color: #0369a1; }
.badge-processing { background: #dbeafe; color: #1d4ed8; }
.badge-completed { background: #ecfdf5; color: #047857; }
.badge-ignored { background: #f3f4f6; color: #6b7280; }

/* SQS operation badges (sqs_message_log.status + webhook_event.sqs_status) */
.badge-enqueued { background: #fef9c3; color: #a16207; }
.badge-deleted { background: #ecfdf5; color: #047857; }
.badge-dlq_moved { background: #1f2937; color: #f3f4f6; }
.badge-retry { background: #fce7f3; color: #a21caf; }

/* Claim submission status badges */
.badge-queued { background: #fef9c3; color: #a16207; }
.badge-submitted { background: #e0e7ff; color: #4338ca; }
.badge-accepted { background: #dcfce7; color: #15803d; }
.badge-rejected { background: #fee2e2; color: #b91c1c; }
.badge-failed { background: #fecaca; color: #991b1b; }
.badge-dlq { background: #1f2937; color: #f3f4f6; }

/* Skipped — not an error, not a success. Neutral grey to distinguish from
   red failure badges and green accepted badges. Used on claim_status,
   webhook_event.claim_status, and sqs_status (preflight short-circuit). */
.badge-skipped { background: #f3f4f6; color: #4b5563; border: 1px solid #d1d5db; }

/* Provider badges */
.badge-CAIR {
  background: #f0fdfa;
  color: #0f766e;
  font-family: monospace;
  letter-spacing: .02em;
}

/* Filter bar */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  padding: 16px;
  margin-bottom: 16px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  align-items: end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.filter-group.grow {
  grid-column: span 2;
}

.filter-group label {
  font-size: .72rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.filter-group input[type="text"],
.filter-group input[type="date"],
.filter-group select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: .85rem;
  background: #fff;
}

.filter-group select[multiple] {
  padding: 4px;
  font-size: .78rem;
}

.filter-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* Pagination footer */
.pagination-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px 4px;
  gap: 12px;
  flex-wrap: wrap;
  font-size: .85rem;
  color: #475569;
}

.pagination-footer .page-info {
  font-variant-numeric: tabular-nums;
}

.pagination-footer .page-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.pagination-footer select {
  padding: 4px 6px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: .85rem;
  background: #fff;
}

.pagination-footer button {
  padding: 4px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  font-size: .85rem;
  cursor: pointer;
}

.pagination-footer button[disabled] {
  opacity: .5;
  cursor: not-allowed;
}

/* Row drawer */
.row-drawer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s;
  z-index: 100;
}

.row-drawer.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .4);
}

.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(720px, 100%);
  background: #fff;
  box-shadow: -8px 0 24px rgba(0, 0, 0, .12);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .22s ease-out;
}

.row-drawer.open .drawer-panel {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid #e5e7eb;
  background: #fafbfc;
}

.drawer-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-right: auto; /* pushes actions + close to the right */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.drawer-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.drawer-actions:empty {
  display: none;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  font-size: .85rem;
}

.drawer-section {
  margin-bottom: 20px;
}

.drawer-section-title {
  font-size: .75rem;
  text-transform: uppercase;
  font-weight: 700;
  color: #64748b;
  margin-bottom: 8px;
  letter-spacing: .04em;
}

.drawer-json {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px;
  border-radius: 0 0 8px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: .78rem;
  line-height: 1.5;
  white-space: pre;
  word-break: normal;
  max-height: 420px;
  overflow: auto;
  margin: 0;
}

/* ── JSON viewer ─────────────────────────── */
.json-viewer {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  overflow: hidden;
  background: #0f172a;
}

.json-viewer.empty {
  color: #94a3b8;
  font-size: .82rem;
  padding: 12px;
  background: #f1f5f9;
  border-color: #e2e8f0;
}

.json-viewer-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 6px 8px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
}

.json-viewer-copy {
  color: #cbd5e1;
  border-color: #475569;
  background: transparent;
}

.json-viewer-copy:hover {
  background: #334155;
  color: #f8fafc;
}

.json-viewer-body {
  border-radius: 0;
}

/* Token colours (One Dark-ish, tuned for #0f172a background) */
.json-viewer .json-key      { color: #93c5fd; }
.json-viewer .json-string   { color: #86efac; }
.json-viewer .json-number   { color: #fca5a5; }
.json-viewer .json-boolean  { color: #c4b5fd; font-weight: 600; }
.json-viewer .json-null     { color: #94a3b8; font-style: italic; }

.drawer-meta-table {
  width: 100%;
  font-size: .82rem;
}

.drawer-meta-table td {
  padding: 4px 8px 4px 0;
}

.drawer-meta-table td:first-child {
  color: #64748b;
  width: 160px;
  font-weight: 600;
}

/* ── SQS Timeline (claim drawer) ──────────── */
.timeline {
  list-style: none;
  padding: 0;
  margin: 0;
  position: relative;
}

/* Vertical rail that connects the dots. Absolutely positioned so it
 * threads behind each marker; the first/last item crop it visually via
 * padding + border-radius on the dots. */
.timeline::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: #e2e8f0;
  border-radius: 2px;
}

.timeline-item {
  position: relative;
  padding: 0 0 14px 28px;
  min-height: 28px;
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-marker {
  position: absolute;
  left: 1px;
  top: 6px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #10b981;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 2px #d1fae5;
}

.timeline-item.is-error .timeline-marker {
  background: #dc2626;
  box-shadow: 0 0 0 2px #fecaca;
}

.timeline-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px 12px;
}

.timeline-item.is-error .timeline-card {
  border-color: #fecaca;
  background: #fef8f8;
}

.timeline-card__head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.timeline-time {
  font-size: .78rem;
  color: #64748b;
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

.timeline-card__body {
  margin-top: 4px;
  font-size: .8rem;
  color: #475569;
}

.timeline-card__body .mono {
  color: #334155;
}

.timeline-card__error {
  margin-top: 8px;
  padding: 6px 10px;
  background: #fef2f2;
  border-left: 3px solid #dc2626;
  border-radius: 4px;
  font-size: .8rem;
  color: #991b1b;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Settings hub layout */
.settings-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  align-items: start;
}

.settings-sidebar {
  position: sticky;
  top: 88px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-sidebar-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid #f1f5f9;
}

.settings-sidebar-group:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.settings-sidebar-label {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #94a3b8;
  letter-spacing: .06em;
  padding: 8px 10px 4px;
}

.settings-sidebar-item {
  background: transparent;
  border: none;
  padding: 8px 10px;
  text-align: left;
  font-size: .88rem;
  color: #475569;
  cursor: pointer;
  border-radius: 6px;
  font-weight: 500;
  transition: background .12s, color .12s;
}

.settings-sidebar-item:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.settings-sidebar-item.active {
  background: #eef1ff;
  color: #4361ee;
  font-weight: 600;
}

.settings-content {
  min-width: 0;
}

.settings-pane {
  display: block;
}

.settings-pane.hidden {
  display: none;
}

@media (max-width: 900px) {
  .settings-layout {
    grid-template-columns: 1fr;
  }
  .settings-sidebar {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    overflow-x: auto;
  }
  .settings-sidebar-group {
    flex-direction: row;
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
    gap: 4px;
  }
  .settings-sidebar-label {
    display: none;
  }
}

.container {
  max-width: 1800px;
  margin: 0 auto;
  padding: 24px 64px;
}

@media (max-width: 900px) {
  .container {
    padding: 24px 20px;
  }
}

/* Cards */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.stat-card .label {
  font-size: .8rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.stat-card .value {
  font-size: 1.8rem;
  font-weight: 700;
  margin-top: 4px;
}

.panel {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  padding: 24px;
  margin-bottom: 24px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.panel-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.panel-meta {
  font-size: .78rem;
  color: #64748b;
}

/* Queue-health metric tiles (home dashboard) */
.metric-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.metric-tile {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-left: 4px solid #10b981;
  border-radius: 8px;
  padding: 12px 14px;
}

.metric-tile__label {
  font-size: .72rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 6px;
}

.metric-tile__value {
  font-size: 1.4rem;
  font-weight: 600;
  color: #0f172a;
  font-variant-numeric: tabular-nums;
}

.metric-tile__err {
  color: #dc2626;
  font-size: .8rem;
  cursor: help;
}

.metric-tile.metric-warn {
  border-left-color: #f59e0b;
  background: #fffbeb;
}

.metric-tile.metric-warn .metric-tile__value {
  color: #92400e;
}

.metric-tile.metric-alert {
  border-left-color: #dc2626;
  background: #fef2f2;
}

.metric-tile.metric-alert .metric-tile__value {
  color: #991b1b;
}

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}

th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid #eee;
  color: #888;
  font-weight: 600;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .3px;
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
}

tr:hover td {
  background: #fafafa;
}

.status {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: .78rem;
  font-weight: 600;
}

.status-accepted, .status-submitted {
  background: #d1fae5;
  color: #065f46;
}

.status-queued, .status-processing {
  background: #fef3c7;
  color: #92400e;
}

.status-failed, .status-error, .status-rejected {
  background: #fee2e2;
  color: #991b1b;
}

/* Buttons */
button {
  cursor: pointer;
}

.btn {
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
  line-height: 1.2;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(67, 97, 238, .28);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
}

.btn-sm {
  padding: 5px 12px;
  font-size: .8rem;
}

.btn-primary {
  background: #4361ee;
  color: #fff;
  border-color: #4361ee;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
}

.btn-primary:hover {
  background: #3a56d4;
  border-color: #3a56d4;
  box-shadow: 0 2px 6px rgba(67, 97, 238, .28);
}

.btn-danger {
  background: #ef4444;
  color: #fff;
  border-color: #ef4444;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
}

.btn-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
  box-shadow: 0 2px 6px rgba(220, 38, 38, .28);
}

.btn-ghost {
  background: #ffffff;
  border-color: #d1d5db;
  color: #334155;
}

.btn-ghost:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
  color: #0f172a;
}

/* Label + icon composite. Icons sit before the label with consistent
 * alignment; size inherits via currentColor + width scales with font-size. */
.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-icon svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* Forms */
.form-row {
  display: flex;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: .8rem;
  font-weight: 600;
  color: #555;
}

.form-group input, .form-group select {
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: .9rem;
}

.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: #4361ee;
}

.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: .85rem;
  margin-bottom: 16px;
}

.alert-error {
  background: #fee;
  color: #c0392b;
  border: 1px solid #f5c6cb;
}

.alert-success {
  background: #eafaf1;
  color: #27ae60;
  border: 1px solid #a9dfbf;
}

.hidden {
  display: none;
}

.icon-btn {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  border-radius: 6px;
  transition: background .1s;
  color: #666;
}

.icon-btn:hover {
  background: #f0f0f0;
}

.icon-btn.danger {
  color: #ef4444;
}

.icon-btn.danger:hover {
  background: #fee;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  vertical-align: middle;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  min-width: 360px;
  max-width: 440px;
  box-shadow: 0 16px 48px rgba(0,0,0,.15);
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

.empty {
  text-align: center;
  color: #999;
  padding: 40px 0;
}

.mono {
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: .82rem;
}

.truncate {
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.text-muted {
  color: #999;
  font-size: .82rem;
}
