@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Design Tokens ────────────────────────────────────────────── */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --surface-3: #e9ebee;

  --border: #e5e7eb;
  --border-subtle: #f0f1f3;
  --border-strong: #d1d5db;

  --text: #111827;
  --text-2: #374151;
  --text-3: #6b7280;
  --text-4: #9ca3af;

  --green: #16a34a;
  --green-light: #dcfce7;
  --green-border: #bbf7d0;

  --red: #dc2626;
  --red-light: #fee2e2;
  --red-border: #fecaca;

  --amber: #d97706;
  --amber-light: #fef3c7;
  --amber-border: #fde68a;

  --blue: #2563eb;
  --blue-light: #dbeafe;
  --blue-border: #93c5fd;

  --indigo: #4f46e5;
  --violet: #7c3aed;
  --pink: #db2777;
  --orange: #ea580c;
  --cyan: #0891b2;
  --teal: #0d9488;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', ui-monospace, monospace;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

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

body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.18);
}

::selection {
  background: rgba(37, 99, 235, 0.15);
}

/* ── Layout ───────────────────────────────────────────────────── */
.app {
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 32px 48px;
}

/* ── Navigation ───────────────────────────────────────────────── */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 56px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.nav-brand {
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 0.9375rem;
  letter-spacing: -0.02em;
}

.nav-links {
  display: flex;
  gap: 4px;
}

.nav-link {
  text-decoration: none;
  color: var(--text-3);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  transition:
    color 0.15s ease,
    background 0.15s ease;
}

.nav-link:hover {
  color: var(--text-2);
  background: var(--surface-2);
}

.nav-link.is-active {
  color: #ffffff;
  background: var(--text);
  font-weight: 600;
}

/* ── Hero / Page Header ───────────────────────────────────────── */
.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 32px;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: 4px;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
  color: var(--text);
}

.subhead {
  color: var(--text-3);
  font-size: 0.8125rem;
  margin-top: 4px;
  max-width: 480px;
  line-height: 1.5;
}

.status {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 200px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  background: var(--green-light);
  color: var(--green);
  border: 1px solid var(--green-border);
  letter-spacing: 0.02em;
}

.status-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-pill.disconnected {
  background: var(--red-light);
  color: var(--red);
  border-color: var(--red-border);
}

.status-pill.disconnected::before {
  background: var(--red);
  animation: none;
}

@keyframes pulse-dot {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

.status-metric {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8125rem;
}

.status-metric .label {
  color: var(--text-4);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

.status-metric .value {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 0.8125rem;
}

/* ── Summary Cards ────────────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin: 6px 0 2px;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text);
}

/* Card color variants */
.card--green {
  background: var(--green-light);
  border-color: var(--green-border);
}
.card--green .label {
  color: var(--green);
}

.card--red {
  background: var(--red-light);
  border-color: var(--red-border);
}
.card--red .label {
  color: var(--red);
}

.card--amber {
  background: var(--amber-light);
  border-color: var(--amber-border);
}
.card--amber .label {
  color: var(--amber);
}

.card--blue {
  background: var(--blue-light);
  border-color: var(--blue-border);
}
.card--blue .label {
  color: var(--blue);
}

.label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-3);
}

/* ── Panels ───────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: minmax(280px, 320px) 1fr minmax(280px, 360px);
  gap: 12px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  min-height: 420px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.panel h3 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.header-actions {
  display: flex;
  gap: 6px;
}

/* ── Ghost Buttons ────────────────────────────────────────────── */
.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-3);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.ghost:hover {
  color: var(--text-2);
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.ghost:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Provider Cards ───────────────────────────────────────────── */
.provider-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1;
  padding-right: 2px;
}

.provider-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: box-shadow 0.15s ease;
}

.provider-card:hover {
  box-shadow: var(--shadow);
}

.provider-card.others {
  border-style: dashed;
  background: var(--surface-2);
}

.provider-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.provider-card .name {
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
}

/* ── Status Pills ─────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.5625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

.pill::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.pill.closed {
  background: var(--green-light);
  color: var(--green);
}
.pill.closed::before {
  background: var(--green);
}

.pill.open {
  background: var(--red-light);
  color: var(--red);
}
.pill.open::before {
  background: var(--red);
}

.pill.half-open {
  background: var(--amber-light);
  color: var(--amber);
}
.pill.half-open::before {
  background: var(--amber);
}

.pill.inactive {
  background: var(--surface-2);
  color: var(--text-4);
}
.pill.inactive::before {
  background: var(--text-4);
}

.provider-card.provider-inactive {
  opacity: 0.55;
  border-style: dashed;
}

/* ── Card Subtitle Tags ──────────────────────────────────────── */
.card-subtitle {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.card-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.5;
}

.card-tag.currency {
  background: var(--blue-light);
  color: var(--blue);
}

.card-tag.method {
  background: var(--surface-2);
  color: var(--text-2);
}

.card-tag.dest {
  background: var(--amber-light);
  color: var(--amber);
}

.card-tag.country {
  background: var(--green-light);
  color: var(--green);
}

.pill.collapsed {
  background: var(--surface-2);
  color: var(--text-4);
}
.pill.collapsed::before {
  background: var(--text-4);
}

.provider-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 12px;
  font-size: 0.75rem;
  color: var(--text-3);
}

.provider-metrics span {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.weight-bar {
  height: 3px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}

.weight-bar span {
  display: block;
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* ── Filters ──────────────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 6px;
  align-items: center;
}

.filters input,
.filters select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.15s ease;
}

.filters input:focus,
.filters select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.filters input::placeholder {
  color: var(--text-4);
}

/* ── Event Stream ─────────────────────────────────────────────── */
.event-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  flex: 1;
  max-height: 580px;
  padding-right: 4px;
}

.event-item {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  transition: all 0.12s ease;
  border-left: 3px solid var(--surface-3);
}

.event-item:hover {
  background: var(--surface-2);
  border-top-color: var(--border);
  border-right-color: var(--border);
  border-bottom-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.event-item.type-route-start {
  border-left-color: var(--text-4);
}
.event-item.type-route-decision {
  border-left-color: var(--green);
}
.event-item.type-eligibility-summary {
  border-left-color: var(--cyan);
}
.event-item.type-eligibility-result {
  border-left-color: var(--violet);
}
.event-item.type-metrics-outcome {
  border-left-color: var(--blue);
}
.event-item.type-weights-update {
  border-left-color: var(--amber);
}
.event-item.type-breaker-state_change {
  border-left-color: var(--red);
}
.event-item.type-webhook-pending {
  border-left-color: var(--orange);
}
.event-item.type-webhook-result {
  border-left-color: var(--pink);
}

.event-item header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.event-item .type {
  font-weight: 600;
  font-size: 0.6875rem;
  color: var(--text);
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}

.event-item header span:last-child {
  font-size: 0.625rem;
  color: var(--text-4);
  font-variant-numeric: tabular-nums;
}

.event-item .meta {
  font-size: 0.6875rem;
  color: var(--text-3);
  display: grid;
  gap: 1px;
  line-height: 1.5;
}

.event-item .meta strong {
  color: var(--text-2);
  font-weight: 500;
}

/* ── Event Inspector ──────────────────────────────────────────── */
.event-detail {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  line-height: 1.65;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 300px;
  flex: 1;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
}

/* ── Overview Page ────────────────────────────────────────────── */
.overview-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
}

.overview-toolbar .label {
  white-space: nowrap;
}

.overview-toolbar select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-family: var(--font-sans);
  min-width: 280px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.overview-toolbar select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.chart-panel {
  min-height: 380px;
}

.chart-panel .panel-header {
  border-bottom: none;
  padding-bottom: 4px;
  margin-bottom: 8px;
}

.chart-panel canvas {
  width: 100% !important;
  height: 270px !important;
}

/* ── Transactions Table ───────────────────────────────────────── */
.transactions-panel {
  margin-top: 12px;
  min-height: auto;
}

.table-wrap {
  overflow-x: auto;
}

.txn-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.txn-table thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.txn-table thead th:first-child {
  border-radius: var(--radius-sm) 0 0 0;
}

.txn-table thead th:last-child {
  border-radius: 0 var(--radius-sm) 0 0;
}

.txn-table tbody td {
  padding: 10px 16px;
  color: var(--text-2);
  border-bottom: 1px solid var(--border-subtle);
  font-variant-numeric: tabular-nums;
}

.txn-table tbody tr:hover {
  background: var(--surface-2);
}

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

.txn-table tbody td {
  word-break: break-word;
  white-space: normal;
}

.txn-id {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text);
  word-break: break-all;
}

.txn-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.txn-badge.success {
  background: var(--green-light);
  color: var(--green);
}

.txn-badge.failed {
  background: var(--red-light);
  color: var(--red);
}

.txn-badge.pending {
  background: var(--amber-light);
  color: var(--amber);
}

.txn-badge.unknown {
  background: var(--surface-2);
  color: var(--text-4);
}

.txn-empty {
  text-align: center;
  padding: 32px 16px !important;
  color: var(--text-4) !important;
  font-size: 0.8125rem;
}

/* ── Dashboard Provider Grid ──────────────────────────────────── */
.dashboard-provider-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.dashboard-provider-grid .provider-card {
  min-height: auto;
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .grid {
    grid-template-columns: 1fr 1fr;
  }
  .grid .panel:last-child {
    grid-column: 1 / -1;
  }
  .dashboard-provider-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 900px) {
  .app {
    padding: 0 16px 32px;
  }

  .grid,
  .overview-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-provider-grid {
    grid-template-columns: 1fr;
  }

  .grid .panel:last-child {
    grid-column: auto;
  }

  .hero {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
    padding: 20px;
  }

  .status {
    width: 100%;
    min-width: unset;
  }

  .filters {
    flex-direction: column;
    width: 100%;
  }

  .filters input,
  .filters select {
    width: 100%;
  }

  h1 {
    font-size: 1.25rem;
  }

  .summary-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
  }

  .top-nav {
    height: auto;
    padding: 12px 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .txn-table {
    font-size: 0.75rem;
  }

  .txn-table thead th,
  .txn-table tbody td {
    padding: 8px 10px;
  }
}
