:root {
  --bg: #f5f8ff;
  --panel: #ffffff;
  --text: #1d2b4f;
  --muted: #7081a8;
  --border: #e4ebfb;
  --shadow: 0 12px 40px rgba(76, 101, 160, 0.12);
  --excellent: #39c9ff;
  --good: #3fca6b;
  --fair: #7fdc7f;
  --poor: #ffb84d;
  --bad: #ff7f62;
  --none: #e7edf9;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top left, #f7fbff, #eef3ff 38%, #f5f8ff 100%);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 28px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(228, 235, 251, 0.9);
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: white;
  background: linear-gradient(135deg, #39c9ff, #4f6eff);
  box-shadow: 0 10px 28px rgba(79, 110, 255, 0.35);
}

.brand-title {
  font-size: 22px;
  font-weight: 800;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--muted);
}

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

.nav-links a {
  text-decoration: none;
  color: #62739c;
  font-weight: 600;
}

.nav-links a.active {
  color: #1f5fff;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ghost-btn,
.search-wrap input {
  border-radius: 14px;
  border: 1px solid var(--border);
  background: white;
}

.ghost-btn {
  padding: 11px 16px;
  cursor: pointer;
  font-weight: 700;
  color: #1f5fff;
}

.status-pill {
  border-radius: 999px;
  padding: 10px 14px;
  background: #eff5ff;
  color: #496188;
  font-size: 13px;
}

.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px;
}

.hero {
  text-align: center;
  margin: 8px 0 26px;
}

.eyebrow {
  color: #4b6bb0;
  font-size: 14px;
  margin-bottom: 12px;
}

.hero h1 {
  margin: 0;
  font-size: 42px;
  line-height: 1.1;
}

.hero-subtitle {
  margin: 14px auto 0;
  max-width: 760px;
  color: var(--muted);
  font-size: 16px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.metric-card {
  position: relative;
  overflow: hidden;
  padding: 24px;
  min-height: 156px;
  border-radius: 24px;
  color: white;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
}

.metric-card::before,
.metric-card::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.metric-card::before {
  width: 120px;
  height: 120px;
  right: -22px;
  top: -22px;
}

.metric-card::after {
  width: 160px;
  height: 160px;
  right: 40px;
  bottom: -80px;
}

.metric-blue { background: linear-gradient(135deg, #376dff, #2258e8); }
.metric-green { background: linear-gradient(135deg, #23cb7f, #0ead67); }
.metric-sky { background: linear-gradient(135deg, #49bfff, #2f8cff); }
.metric-emerald { background: linear-gradient(135deg, #24d08e, #08b775); }

.metric-label {
  position: relative;
  z-index: 1;
  font-size: 15px;
  opacity: 0.95;
}

.metric-value {
  position: relative;
  z-index: 1;
  margin-top: 18px;
  font-size: 42px;
  font-weight: 800;
}

.metric-sub {
  position: relative;
  z-index: 1;
  margin-top: 8px;
  font-size: 14px;
  opacity: 0.92;
}

.metric-icon {
  position: relative;
  z-index: 1;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.18);
  font-size: 22px;
  font-weight: 800;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin-bottom: 24px;
}

.controls-panel,
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.panel-title {
  font-size: 18px;
  font-weight: 800;
}

.panel-subtitle,
.tiny-meta {
  color: var(--muted);
  font-size: 13px;
}

.matrix-toolbar {
  margin-bottom: 10px;
}

.matrix-provider-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid #e6eefc;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  color: #6880ab;
  font-size: 13px;
  font-weight: 700;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 18px;
  margin-top: 14px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #50658d;
  font-size: 14px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
}

.legend-dot.excellent { background: var(--excellent); }
.legend-dot.good { background: var(--good); }
.legend-dot.fair { background: var(--fair); }
.legend-dot.poor { background: var(--poor); }
.legend-dot.bad { background: var(--bad); }
.legend-dot.none { background: var(--none); }

.search-wrap input {
  width: 300px;
  padding: 12px 14px;
  font-size: 14px;
  outline: none;
}

.timeline-header,
.model-row {
  display: grid;
  grid-template-columns: minmax(320px, 1.6fr) 110px 110px 1fr;
  gap: 14px;
  align-items: center;
}

.timeline-header {
  padding: 14px 8px 14px;
  color: #7a89aa;
  font-size: 13px;
  font-weight: 700;
  border-bottom: 1px solid #edf2ff;
  margin-bottom: 10px;
}

.site-module {
  border: 1px solid #e7eefc;
  border-radius: 26px;
  padding: 18px;
  background: linear-gradient(180deg, #ffffff, #fafdff);
  box-shadow: 0 12px 30px rgba(36, 64, 116, 0.06);
}

.site-module-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.site-module-title {
  font-size: 22px;
  font-weight: 800;
  color: #22365e;
}

.site-module-subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.site-module-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.site-stat-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 13px;
  border-radius: 999px;
  border: 1px solid #e6eefc;
  background: white;
  color: #60779f;
  font-size: 13px;
  font-weight: 700;
}

.site-timeline-header {
  margin-top: 4px;
}

.timeline-grid,
.timeline-slots {
  display: grid;
  grid-template-columns: repeat(8, minmax(26px, 1fr));
  gap: 8px;
}

.rows-container {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.provider-group-rows {
  display: grid;
  gap: 12px;
}

.model-row {
  padding: 14px 10px;
  border: 1px solid #edf2ff;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffffff, #fbfdff);
}

.model-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.model-indicator {
  width: 5px;
  align-self: stretch;
  border-radius: 999px;
}

.model-text {
  min-width: 0;
}

.model-name {
  font-weight: 800;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.compact-meta {
  gap: 10px 12px;
}

.meta-warning {
  color: #cb5033;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 96px;
  padding: 10px 12px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 14px;
}

.badge.excellent { background: rgba(57, 201, 255, 0.14); color: #1399cb; }
.badge.good { background: rgba(63, 202, 107, 0.14); color: #118b41; }
.badge.fair { background: rgba(127, 220, 127, 0.18); color: #3e9646; }
.badge.poor { background: rgba(255, 184, 77, 0.2); color: #bf7b16; }
.badge.bad { background: rgba(255, 127, 98, 0.18); color: #cb5033; }
.badge.none { background: rgba(231, 237, 249, 0.9); color: #7381a4; }

.token-text {
  font-weight: 800;
  color: #43516f;
}

.slot {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  border: 2px solid var(--none);
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.slot.excellent { border-color: var(--excellent); box-shadow: inset 0 0 0 1px rgba(57, 201, 255, 0.12), 0 8px 20px rgba(57, 201, 255, 0.1); }
.slot.good { border-color: var(--good); }
.slot.fair { border-color: var(--fair); }
.slot.poor { border-color: var(--poor); }
.slot.bad { border-color: var(--bad); }
.slot.none { background: #f8faff; }

.slot span {
  font-size: 11px;
  font-weight: 800;
  color: #6f7e9d;
}

.failures-list {
  display: grid;
  gap: 12px;
}

.failure-item {
  border: 1px solid #edf2ff;
  border-radius: 18px;
  padding: 14px 16px;
  background: #fcfdff;
}

.failure-title {
  font-weight: 700;
}

.failure-meta,
.failure-message {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.empty-state {
  padding: 34px 12px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 1180px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .timeline-header,
  .model-row {
    grid-template-columns: minmax(280px, 1fr) 110px 100px;
  }

  .timeline-header .timeline-grid,
  .model-row .timeline-slots {
    grid-column: 1 / -1;
  }
}

.primary-btn {
  padding: 11px 16px;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, #3a73ff, #2357e8);
  box-shadow: 0 10px 24px rgba(58, 115, 255, 0.25);
}

.hidden {
  display: none !important;
}

.admin-panel {
  scroll-margin-top: 90px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.admin-card {
  border: 1px solid #edf2ff;
  border-radius: 20px;
  background: #fbfdff;
  padding: 18px;
}

.admin-card h3 {
  margin: 0 0 14px;
}

.provider-create-card {
  grid-column: span 2;
}

.stack-form {
  display: grid;
  gap: 12px;
}

.stack-form input,
.stack-form select,
.stack-form textarea,
.provider-preview input {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
  padding: 12px 14px;
  font-size: 14px;
  background: white;
}

.stack-form textarea {
  resize: vertical;
  min-height: 120px;
  font-family: inherit;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

.provider-form-actions,
.provider-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.provider-preview {
  margin-top: 18px;
  display: grid;
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid #edf2ff;
}

.preview-model-list {
  display: grid;
  gap: 10px;
  max-height: 420px;
  overflow: auto;
}

.preview-model-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid #eef3ff;
  background: #fafcff;
}

.preview-model-row input[type='checkbox'] {
  width: 18px;
  height: 18px;
}

.preview-source {
  color: var(--muted);
}

.admin-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.admin-list-card {
  margin-top: 18px;
}

.admin-list-head,
.provider-head,
.provider-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-provider-list {
  display: grid;
  gap: 16px;
}

.provider-card {
  border: 1px solid #edf2ff;
  border-radius: 20px;
  padding: 16px;
  background: white;
}

.provider-title-row h4 {
  margin: 0;
  font-size: 18px;
}

.provider-meta,
.empty-inline {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}

.provider-actions,
.chip-actions,
.modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.small-btn,
.chip-btn,
.danger-btn {
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: white;
  cursor: pointer;
  font-weight: 700;
  color: #4064a0;
}

.danger-btn,
.danger-inline {
  color: #c84141;
  border-color: #ffd6d6;
  background: #fff8f8;
}

.model-chip-wrap {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.model-chip {
  display: grid;
  gap: 8px;
  border: 1px solid #eef3ff;
  border-radius: 16px;
  padding: 12px 14px;
  background: #fafcff;
}

.muted-chip {
  opacity: 0.72;
}

.chip-meta {
  color: var(--muted);
  font-size: 13px;
}

.route-arrow {
  color: #3a73ff;
  font-weight: 700;
}

.mini-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.mini-badge.good { background: rgba(63, 202, 107, 0.14); color: #118b41; }
.mini-badge.bad { background: rgba(255, 127, 98, 0.18); color: #cb5033; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(14, 24, 44, 0.46);
  backdrop-filter: blur(6px);
}

.modal-card {
  position: relative;
  width: min(460px, calc(100vw - 28px));
  border-radius: 24px;
  background: white;
  box-shadow: 0 24px 60px rgba(15, 30, 70, 0.26);
  padding: 22px;
}

.modal-title {
  font-size: 22px;
  font-weight: 800;
}

.modal-subtitle {
  margin: 8px 0 16px;
  color: var(--muted);
}

@media (max-width: 860px) {
  .topbar,
  .controls-panel,
  .table-toolbar,
  .admin-toolbar,
  .admin-list-head,
  .provider-head,
  .provider-title-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .page {
    padding: 18px;
  }

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

  .provider-create-card {
    grid-column: span 1;
  }

  .site-module-hero {
    flex-direction: column;
    align-items: flex-start;
  }

  .preview-model-row {
    grid-template-columns: auto 1fr;
  }

  .preview-model-row .route-arrow {
    display: none;
  }

  .search-wrap input {
    width: 100%;
  }

  .timeline-header,
  .model-row {
    grid-template-columns: 1fr;
  }
}
