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

:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface-2: #1a1a26;
  --surface-3: #22222e;
  --border: #2a2a3a;
  --border-subtle: #1e1e2e;
  --text: #e8e8ed;
  --text-secondary: #8888a0;
  --text-muted: #55556a;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --hot: #ef4444;
  --hot-bg: rgba(239, 68, 68, 0.12);
  --warm: #f59e0b;
  --warm-bg: rgba(245, 158, 11, 0.12);
  --nurture: #3b82f6;
  --nurture-bg: rgba(59, 130, 246, 0.12);
  --sent: #16a34a;
  --delivered: #059669;
  --opened: #7c3aed;
  --clicked: #2563eb;
  --failed: #dc2626;
  --bounced: #6b7280;
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 150ms ease;
  --font: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

html {
  font-size: 14px;
}

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

/* Login */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
}

.login-card h1 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  letter-spacing: -0.02em;
}

.login-card p {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}

.login-card input {
  width: 100%;
  padding: 0.625rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  outline: none;
  transition: border-color var(--transition);
}

.login-card input:focus {
  border-color: var(--accent);
}

.login-card input::placeholder {
  color: var(--text-muted);
}

.login-card button {
  width: 100%;
  margin-top: 1rem;
  padding: 0.625rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
}

.login-card button:hover {
  background: var(--accent-hover);
}

.login-error {
  color: var(--failed);
  font-size: 0.8125rem;
  margin-top: 0.75rem;
  display: none;
}

/* Shell */
.shell {
  display: none;
  min-height: 100vh;
}

.shell.active {
  display: flex;
  flex-direction: column;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.topbar-brand .logo {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
  color: #fff;
}

.topbar-brand span {
  font-weight: 600;
  font-size: 0.9375rem;
  letter-spacing: -0.02em;
}

.topbar-brand .env-badge {
  font-size: 0.6875rem;
  padding: 0.125rem 0.5rem;
  background: var(--surface-3);
  color: var(--text-muted);
  border-radius: 999px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar-actions .refresh-indicator {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius);
  padding: 0.375rem 0.625rem;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
}

.btn-icon:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

/* Tabs */
.tab-bar {
  display: flex;
  gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  flex-shrink: 0;
}

.tab-btn {
  padding: 0.75rem 1.25rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  top: 1px;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab-btn .count {
  margin-left: 0.375rem;
  font-size: 0.6875rem;
  padding: 0.0625rem 0.4375rem;
  background: var(--surface-3);
  border-radius: 999px;
  color: var(--text-muted);
  font-weight: 400;
}

/* Main content */
.main {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h2 {
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-body {
  padding: 1.25rem;
}

/* Stats row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}

.stat-card .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}

.stat-card .sub {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.375rem;
}

.stat-card.hot { border-top: 2px solid var(--hot); }
.stat-card.warm { border-top: 2px solid var(--warm); }
.stat-card.nurture { border-top: 2px solid var(--nurture); }

/* Table */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  padding: 0.625rem 1rem;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 0.625rem 1rem;
  font-size: 0.8125rem;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

tbody tr {
  transition: background var(--transition);
}

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

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

.clickable {
  cursor: pointer;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.badge.hot {
  background: var(--hot-bg);
  color: var(--hot);
}

.badge.warm {
  background: var(--warm-bg);
  color: var(--warm);
}

.badge.nurture {
  background: var(--nurture-bg);
  color: var(--nurture);
}

.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 500;
}

.badge-status::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.badge-status.sent { color: var(--sent); background: rgba(22, 163, 74, 0.1); }
.badge-status.delivered { color: var(--delivered); background: rgba(5, 150, 105, 0.1); }
.badge-status.opened { color: var(--opened); background: rgba(124, 58, 237, 0.1); }
.badge-status.clicked { color: var(--clicked); background: rgba(37, 99, 235, 0.1); }
.badge-status.failed { color: var(--failed); background: rgba(220, 38, 38, 0.1); }
.badge-status.bounced { color: var(--bounced); background: rgba(107, 114, 128, 0.1); }
.badge-status.active { color: var(--sent); background: rgba(22, 163, 74, 0.1); }
.badge-status.paused { color: var(--warm); background: var(--warm-bg); }
.badge-status.completed { color: var(--accent); background: rgba(99, 102, 241, 0.1); }

/* Score */
.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-variant-numeric: tabular-nums;
}

.score-pill .num {
  font-weight: 600;
  font-size: 0.8125rem;
  font-family: var(--font-mono);
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-subtle);
}

.pagination .info {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.pagination .btns {
  display: flex;
  gap: 0.5rem;
}

.pagination button {
  padding: 0.375rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  font-family: var(--font);
  transition: all var(--transition);
}

.pagination button:hover:not(:disabled) {
  border-color: var(--text-muted);
  color: var(--text);
}

.pagination button:disabled {
  opacity: 0.3;
  cursor: default;
}

/* Search */
.search-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.search-bar input {
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.8125rem;
  font-family: var(--font);
  width: 240px;
  outline: none;
  transition: border-color var(--transition);
}

.search-bar input:focus {
  border-color: var(--accent);
}

.search-bar input::placeholder {
  color: var(--text-muted);
}

/* Pipeline grid */
.pipeline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.pipeline-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.25rem;
  text-align: center;
  transition: border-color var(--transition);
}

.pipeline-card:hover {
  border-color: var(--text-muted);
}

.pipeline-card .stage-name {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  margin-bottom: 0.75rem;
}

.pipeline-card .stage-count {
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* Detail modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  align-items: flex-start;
  justify-content: center;
  padding: 3rem 1.5rem;
  overflow-y: auto;
}

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

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
}

.modal-header h2 {
  font-size: 0.9375rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 1.25rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.detail-item .label {
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.25rem;
}

.detail-item .value {
  font-size: 0.875rem;
  font-weight: 500;
}

.detail-section {
  margin-top: 1.25rem;
}

.detail-section h3 {
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-secondary);
}

/* Empty state */
.empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Loading */
.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

.loading::after {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 0.5rem;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 768px) {
  .topbar { padding: 0 1rem; }
  .tab-bar { padding: 0 1rem; overflow-x: auto; }
  .main { padding: 1rem; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .pipeline-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .search-bar input { width: 160px; }
}

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr; }
  .tab-btn { padding: 0.75rem 0.75rem; font-size: 0.75rem; }
}

/* Timestamp */
.ts {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

/* Mono */
.mono {
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

/* Channel badge */
.badge-channel {
  display: inline-flex;
  padding: 0.125rem 0.4375rem;
  border-radius: var(--radius);
  font-size: 0.6875rem;
  font-weight: 500;
  background: var(--surface-3);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
