:root {
  --bg: #f1f1f3;
  --page-bg: #f1f1f3;
  --white: #ffffff;
  --border: #e4e4e8;
  --border-strong: #dcdce2;
  --text: #17181c;
  --text-dim: #6b6d78;
  --text-faint: #9a9ca6;
  --black: #101114;
  --black-hover: #26272c;
  --success-bg: #e8f7ee;
  --success: #1a8a4a;
  --danger-bg: #fdeceb;
  --danger: #d0362a;
  --warning-bg: #fef3e2;
  --warning: #b3730a;
  --radius: 16px;
  --radius-sm: 10px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--page-bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; }
code { font-family: var(--mono); }
h1, h2, h3, p { margin: 0; }

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 15%, #ffffff 0%, transparent 45%),
    radial-gradient(circle at 85% 85%, #ffffff 0%, transparent 45%),
    var(--page-bg);
}

.login-card {
  width: 400px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 36px 32px;
  box-shadow: 0 1px 2px rgba(16,17,20,0.04), 0 20px 44px rgba(16,17,20,0.06);
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.brand-mark {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 11px;
  background: var(--black);
  color: white;
  flex-shrink: 0;
}
.brand-mark.small { width: 28px; height: 28px; border-radius: 8px; }
.brand-title { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; color: var(--text); }
.brand-subtitle { font-size: 12px; color: var(--text-dim); margin-top: 1px; }

.field { margin-bottom: 16px; }
.field label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--text-dim);
  margin-bottom: 7px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-family: var(--mono);
}
.field label .optional {
  font-weight: 400; color: var(--text-faint); font-size: 11px;
  text-transform: none;
}
input[type="text"], input[type="password"], input[type="url"] {
  width: 100%;
  padding: 11px 13px;
  background: var(--white);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
  font-family: var(--font);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input.mono { font-family: var(--mono); font-size: 12.5px; }
input::placeholder { color: var(--text-faint); }
input:focus {
  outline: none;
  border-color: var(--black);
  box-shadow: 0 0 0 3px rgba(16,17,20,0.08);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary, .btn-dark, .btn-outline, .btn-ghost {
  cursor: pointer;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.1s, background 0.15s, opacity 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn-primary, .btn-dark {
  background: var(--black);
  color: white;
}
.btn-primary:hover, .btn-dark:hover { background: var(--black-hover); }
.btn-primary:active, .btn-dark:active { transform: scale(0.98); }
.btn-outline {
  background: var(--white);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.btn-outline:hover { background: #f7f7f8; border-color: #c9c9d1; }
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover { background: #ececef; color: var(--text); }
.btn-sm { padding: 7px 14px; font-size: 12.5px; border-radius: 999px; }
.btn-block { width: 100%; margin-top: 6px; padding: 12px; font-size: 14px; border-radius: var(--radius-sm); }

.btn-spinner {
  width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.form-error {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--danger-bg);
  border: 1px solid #f3c6c2;
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 12.5px;
}

/* ============================================================
   APP SHELL / TOPBAR
   ============================================================ */
.app-shell { min-height: 100vh; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(241, 241, 243, 0.85);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 13.5px;
  color: var(--text);
  font-family: var(--mono);
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.live-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--success);
  background: var(--success-bg);
  padding: 6px 12px;
  border-radius: 999px;
}
.live-chip .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
}
.worker-chip {
  font-size: 11px;
  color: var(--text-faint);
  padding: 6px 12px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--mono);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   PAGE CONTAINER / HEADER
   ============================================================ */
.page-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 40px 40px 80px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 32px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}
.page-header-text { flex: 1; min-width: 320px; }

.eyebrow-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text-dim);
  margin-bottom: 18px;
}
.eyebrow-badge .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-bg);
}

.page-title {
  font-size: 44px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 10px;
  line-height: 1.05;
}
.page-subtitle {
  font-size: 15.5px;
  color: var(--text-dim);
  max-width: 520px;
}

/* Pill segmented nav */
.pill-nav {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px;
  box-shadow: 0 1px 2px rgba(16,17,20,0.03);
  flex-shrink: 0;
}
.pill-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.pill-btn svg { width: 16px; height: 16px; opacity: 0.7; }
.pill-btn:hover { color: var(--text); }
.pill-btn.active {
  background: var(--black);
  color: white;
}
.pill-btn.active svg { opacity: 1; }
.pill-count {
  font-family: var(--mono);
  font-size: 10.5px;
  background: rgba(0,0,0,0.06);
  color: var(--text-dim);
  padding: 1px 7px;
  border-radius: 999px;
  margin-left: 2px;
}
.pill-btn.active .pill-count {
  background: rgba(255,255,255,0.18);
  color: white;
}

main { }
.tab-content { display: none; animation: fadeIn 0.25s ease; }
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   STANDALONE STAT CARDS (Overview top row)
   ============================================================ */
.stat-grid-standalone {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: 0 1px 2px rgba(16,17,20,0.03);
  transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(16,17,20,0.06); }
.stat-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.stat-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent) 12%, white);
  color: var(--accent);
}
.stat-icon svg { width: 18px; height: 18px; }
.stat-trend {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
}
.stat-card .stat-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; color: var(--text); margin-bottom: 6px; }
.stat-card .stat-label { font-size: 12px; color: var(--text-dim); font-weight: 500; }

/* ============================================================
   DASHBOARD GRID (main content + sidebar)
   ============================================================ */
.dash-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}
.dash-main { min-width: 0; }
.dash-side { display: flex; flex-direction: column; gap: 20px; }

/* ============================================================
   PANELS
   ============================================================ */
.panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(16,17,20,0.03);
}
.dash-main .panel:last-child { margin-bottom: 0; }
.dash-side .panel:last-child { margin-bottom: 0; }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.panel-header.compact { padding: 18px 20px; }
.panel-eyebrow {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 6px;
}
.panel-header h3 { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.panel-desc { margin: 4px 0 0; font-size: 12.5px; color: var(--text-dim); }

/* Vertical promo panel (sidebar) */
.promo-panel-v {
  padding: 22px 20px;
}
.promo-panel-v .promo-icon {
  width: 42px; height: 42px;
  border-radius: 11px;
  background: var(--black);
  color: white;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}
.promo-panel-v .promo-icon svg { width: 20px; height: 20px; }
.promo-panel-v .promo-title { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.promo-panel-v .promo-desc { font-size: 12px; color: var(--text-dim); line-height: 1.55; margin-bottom: 16px; }

/* Bar chart (Overview - Request Volume) */
.chart-wrap { padding: 20px 24px 24px; }
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 140px;
}
.bar-chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 6px;
}
.bar-chart-bar {
  width: 100%;
  max-width: 22px;
  background: var(--black);
  border-radius: 4px 4px 0 0;
  min-height: 3px;
  transition: opacity 0.15s;
}
.bar-chart-bar:hover { opacity: 0.7; }
.bar-chart-label {
  font-size: 9.5px;
  font-family: var(--mono);
  color: var(--text-faint);
}
.chart-empty {
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 12.5px;
}

/* Key health list (sidebar) */
.key-health-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}
.key-health-item:last-child { border-bottom: none; }
.key-health-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.key-health-dot.healthy { background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); }
.key-health-dot.failed { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }
.key-health-dot.disabled { background: var(--text-faint); box-shadow: 0 0 0 3px #ececef; }
.key-health-info { flex: 1; min-width: 0; }
.key-health-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.key-health-preview {
  font-size: 10.5px;
  font-family: var(--mono);
  color: var(--text-faint);
}
.key-health-status {
  font-size: 10px;
  font-family: var(--mono);
  text-transform: uppercase;
  font-weight: 600;
  flex-shrink: 0;
}
.key-health-status.healthy { color: var(--success); }
.key-health-status.failed { color: var(--danger); }
.key-health-status.disabled { color: var(--text-faint); }

/* ============================================================
   TOOLBAR (search + filters, above tables)
   ============================================================ */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: #fafafb;
  flex-wrap: wrap;
}
.search-input {
  flex: 1;
  min-width: 220px;
  max-width: 360px;
  padding: 9px 14px !important;
  font-size: 12.5px !important;
  border-radius: 999px !important;
}
.toolbar-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.toolbar-stats strong { color: var(--text); font-weight: 700; }
.toolbar-stats .success-text strong { color: var(--success); }
.toolbar-stats .danger-text strong { color: var(--danger); }
.dot-sep { color: var(--border-strong); }

.filter-chips { display: flex; gap: 6px; }
.chip {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--white);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip:hover { background: #f3f3f5; }
.chip.active {
  background: var(--black);
  color: white;
  border-color: var(--black);
}

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 14px 24px;
  font-size: 12.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  color: var(--text-faint);
  font-weight: 600;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--mono);
  background: #fafafb;
}
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: #fafafb; }
tr:last-child td { border-bottom: none; }
td code {
  background: #f0f0f2;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  color: #45464e;
  border: 1px solid var(--border);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-family: var(--mono);
}
.badge::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
}
.badge.active, .badge.success { background: var(--success-bg); color: var(--success); }
.badge.inactive { background: #ececef; color: var(--text-dim); }
.badge.failed, .badge.error { background: var(--danger-bg); color: var(--danger); }

.row-actions { display: flex; gap: 6px; }
.row-actions button {
  padding: 6px 12px;
  font-size: 11.5px;
  border-radius: 999px;
}
.row-actions .danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #f3c6c2;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
}
.row-actions .danger:hover { background: #fbdcd9; }

/* Skeleton loaders */
.skeleton-row {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, #ececef 25%, #f7f7f8 37%, #ececef 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 17, 20, 0.35);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  width: 420px;
  box-shadow: 0 24px 60px rgba(16,17,20,0.18);
}
.modal h3 { margin: 0 0 18px; font-size: 16px; font-weight: 700; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ============================================================
   TOASTS
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 300;
}
.toast {
  min-width: 280px;
  max-width: 360px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  background: var(--white);
  border: 1px solid var(--border);
  box-shadow: 0 12px 30px rgba(16,17,20,0.12);
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast-icon { flex-shrink: 0; margin-top: 1px; }
.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--danger); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1200px) {
  .dash-grid { grid-template-columns: 1fr; }
  .dash-side { flex-direction: row; flex-wrap: wrap; }
  .dash-side .panel { flex: 1; min-width: 260px; }
}
@media (max-width: 900px) {
  .page-container { padding: 28px 18px 60px; }
  .page-title { font-size: 32px; }
  .pill-nav { flex-wrap: wrap; border-radius: 16px; }
  .stat-grid-standalone { grid-template-columns: repeat(2, 1fr); }
  .toolbar { flex-direction: column; align-items: stretch; }
  .search-input { max-width: none; }
  .dash-side { flex-direction: column; }
}
