:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-soft: #fbfdff;
  --border: #dfe6ef;
  --border-strong: #cfd8e3;
  --text: #111827;
  --muted: #6b7280;
  --muted-strong: #4b5563;
  --shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 6px 18px rgba(15, 23, 42, 0.06);
  --ok: #10b981;
  --warn: #f59e0b;
  --unstable: #f97316;
  --bad: #ef4444;
  --unknown: #cbd5e1;
  --blue: #3b82f6;
  --blue-soft: #eff6ff;
}

html.dark {
  color-scheme: dark;
  --bg: #0b1120;
  --panel: #151d30;
  --panel-soft: #101827;
  --border: #243049;
  --border-strong: #30405f;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --muted-strong: #d1d5db;
  --shadow: 0 16px 30px rgba(0, 0, 0, 0.28);
  --shadow-soft: 0 10px 20px rgba(0, 0, 0, 0.22);
  --blue-soft: rgba(59, 130, 246, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(18px);
  background: color-mix(in srgb, var(--panel) 78%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 92%, transparent);
}

.topbar-inner,
.dashboard {
  width: min(1800px, 100%);
  margin: 0 auto;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 20px;
}

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

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-mark-core {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.12);
}

.brand-copy {
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.brand-subline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}

.brand-subtitle {
  color: var(--muted);
}

.sync-dot,
.state-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
  flex-shrink: 0;
}

.sync-dot.normal,
.state-dot.normal {
  background: var(--ok);
}

.sync-dot.degraded,
.state-dot.degraded {
  background: var(--warn);
}

.sync-dot.unstable,
.state-dot.unstable {
  background: var(--unstable);
}

.sync-dot.down,
.state-dot.down {
  background: var(--bad);
}

.sync-dot.stale,
.state-dot.stale,
.sync-dot.unknown,
.state-dot.unknown {
  background: var(--unknown);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-meta {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--blue) 20%, var(--border));
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.topbar-link:hover {
  filter: brightness(0.98);
}

.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.dashboard {
  padding: 20px;
}

.notice {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 13px;
}

.notice.warning {
  border-color: #fdba74;
  background: #fff7ed;
  color: #c2410c;
}

.announcement-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.announcement-card {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow-soft);
}

.announcement-card.warning {
  border-color: #fdba74;
  background: #fff7ed;
}

.announcement-card.critical {
  border-color: #fca5a5;
  background: #fef2f2;
}

.announcement-title {
  font-size: 13px;
  font-weight: 700;
}

.announcement-body {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted-strong);
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.announcement-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-height: 34px;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--blue) 18%, var(--border));
  background: color-mix(in srgb, var(--blue-soft) 68%, var(--panel));
  color: var(--blue-strong);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.announcement-action:hover {
  background: color-mix(in srgb, var(--blue-soft) 82%, var(--panel));
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.kpi-card,
.chart-card,
.group-section,
.model-card,
.modal-panel {
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.kpi-card {
  padding: 16px;
  min-height: 124px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.kpi-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.kpi-value {
  margin-top: 10px;
  font-size: 34px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.05em;
}

.kpi-value-ok {
  color: var(--ok);
}

.kpi-value-bad {
  color: var(--bad);
}

.kpi-detail {
  font-size: 12px;
  color: var(--muted);
}

.kpi-card-ring {
  align-items: flex-start;
}

.kpi-ring-slot {
  min-height: 68px;
}

.ring-stat {
  position: relative;
  width: 58px;
  height: 58px;
}

.ring-stat svg {
  display: block;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: color-mix(in srgb, var(--border-strong) 72%, transparent);
  stroke-width: 5;
}

.ring-fill {
  fill: none;
  stroke-width: 5;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s ease;
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-value {
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.ring-label {
  margin-top: 3px;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.chart-card {
  padding: 16px;
}

.chart-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.chart-title {
  font-size: 14px;
  font-weight: 700;
}

.chart-subtitle {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

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

.chart-row {
  display: grid;
  gap: 6px;
}

.chart-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chart-row-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 12px;
  font-weight: 600;
}

.chart-row-value {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted-strong);
  white-space: nowrap;
}

.chart-track {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--border) 72%, transparent);
  overflow: hidden;
}

.chart-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.28s ease;
}

.chart-fill.availability {
  background: linear-gradient(90deg, #3b82f6 0%, #6366f1 100%);
}

.chart-fill.latency {
  background: linear-gradient(90deg, #10b981 0%, #3b82f6 100%);
}

.chart-empty,
.history-empty,
.empty-state p {
  font-size: 13px;
  color: var(--muted);
}

.toolbar {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.pill-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pill-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 8px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 600;
}

.pill-button:hover {
  border-color: var(--border-strong);
}

.pill-button.is-active {
  border-color: transparent;
  background: var(--blue);
  color: #ffffff;
}

.pill-count {
  opacity: 0.72;
}

.sort-box {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.sort-label {
  font-size: 12px;
  color: var(--muted);
}

.sort-select {
  min-height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 0 36px 0 14px;
}

.group-list {
  margin-top: 18px;
  display: grid;
  gap: 22px;
}

.page-footer {
  margin-top: 22px;
  padding: 18px 20px 26px;
  border-top: 1px solid color-mix(in srgb, var(--border) 92%, transparent);
}

.page-footer-note {
  font-size: 13px;
  line-height: 1.7;
  color: var(--muted-strong);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.group-section {
  padding: 18px;
}

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.group-heading {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.group-name {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.group-badges {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.group-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--border) 92%, transparent);
  background: color-mix(in srgb, var(--panel-soft) 88%, transparent);
  color: var(--muted-strong);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.group-state-badge.normal {
  background: rgba(16, 185, 129, 0.12);
  color: #047857;
  border-color: rgba(16, 185, 129, 0.2);
}

.group-state-badge.degraded {
  background: rgba(245, 158, 11, 0.14);
  color: #b45309;
  border-color: rgba(245, 158, 11, 0.22);
}

.group-state-badge.unstable {
  background: rgba(249, 115, 22, 0.14);
  color: #c2410c;
  border-color: rgba(249, 115, 22, 0.22);
}

.group-state-badge.down {
  background: rgba(239, 68, 68, 0.14);
  color: #b91c1c;
  border-color: rgba(239, 68, 68, 0.22);
}

.group-state-badge.unknown,
.group-state-badge.stale {
  background: rgba(148, 163, 184, 0.16);
  color: #64748b;
  border-color: rgba(148, 163, 184, 0.22);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 12px;
}

.model-card {
  padding: 16px;
  height: 100%;
  display: flex;
  flex-direction: column;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    border-color 0.18s ease;
  outline: none;
}

.model-card:hover,
.model-card:focus-visible {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--blue) 30%, var(--border));
  box-shadow: var(--shadow);
}

.model-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.model-card-title-block {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.model-card-title {
  min-width: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  word-break: break-word;
}

.model-card-group-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 22px;
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--border) 92%, transparent);
  background: color-mix(in srgb, var(--blue-soft) 72%, var(--panel));
  color: var(--muted-strong);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.normal {
  background: rgba(16, 185, 129, 0.14);
  color: #047857;
}

.status-pill.degraded {
  background: rgba(245, 158, 11, 0.14);
  color: #b45309;
}

.status-pill.unstable {
  background: rgba(249, 115, 22, 0.14);
  color: #c2410c;
}

.status-pill.down {
  background: rgba(239, 68, 68, 0.14);
  color: #b91c1c;
}

.status-pill.unknown {
  background: rgba(148, 163, 184, 0.18);
  color: #64748b;
}

html.dark .status-pill.normal {
  color: #6ee7b7;
}

html.dark .status-pill.degraded {
  color: #fcd34d;
}

html.dark .status-pill.unstable {
  color: #fdba74;
}

html.dark .status-pill.down {
  color: #fca5a5;
}

.model-card-main {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.model-card-ring {
  display: flex;
  align-items: center;
  justify-content: center;
}

.model-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 8px;
}

.metric-cell,
.modal-metric,
.modal-hero-metric {
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--border) 88%, transparent);
  background: var(--panel-soft);
  padding: 10px 12px;
  min-width: 0;
  min-height: 84px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.metric-label,
.section-title {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.metric-value,
.modal-metric-value,
.modal-hero-value {
  margin-top: 7px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.model-card-meta,
.modal-tags {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 4px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--border) 82%, transparent);
  color: var(--muted-strong);
  font-size: 10px;
  font-weight: 600;
}

.timeline-head,
.section-head {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 11px;
  color: var(--muted);
}

.history-bars {
  margin-top: 8px;
  display: flex;
  gap: 2px;
  align-items: flex-end;
  min-height: 42px;
  min-width: 0;
  overflow: hidden;
}

.history-bar {
  flex: 1 1 0;
  min-width: 0;
  width: 100%;
  height: 42px;
  border: none;
  border-radius: 2px;
  background: var(--unknown);
  padding: 0;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  display: block;
  transition:
    transform 0.12s ease,
    opacity 0.12s ease;
}

.history-bar:hover,
.history-bar:focus-visible {
  transform: scaleY(1.12);
  opacity: 0.82;
  outline: none;
}

.history-bar.normal {
  background: var(--ok);
}

.history-bar.degraded {
  background: var(--warn);
}

.history-bar.unstable {
  background: var(--unstable);
}

.history-bar.down {
  background: var(--bad);
}

.history-bar.unknown {
  background: var(--unknown);
}

.empty-state {
  border-radius: 16px;
  border: 1px dashed var(--border-strong);
  background: var(--panel);
  padding: 28px 18px;
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.history-tooltip {
  position: fixed;
  z-index: 80;
  max-width: 260px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #1e293b;
  color: #e5e7eb;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
  font-size: 11px;
  line-height: 1.6;
  white-space: pre-line;
  pointer-events: none;
}

html.dark .history-tooltip {
  background: #f3f4f6;
  color: #111827;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative;
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 40px);
  margin: 20px auto;
  overflow-y: auto;
  padding: 22px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-right: 40px;
}

.modal-kicker {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.modal-title {
  margin: 8px 0 0;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.modal-hero-metric {
  min-width: 116px;
}

.modal-metrics {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.modal-section {
  margin-top: 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  padding: 14px;
}

.modal-copy {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted-strong);
}

.source-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.source-card {
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--border) 88%, transparent);
  background: color-mix(in srgb, var(--panel) 78%, var(--panel-soft));
  padding: 12px;
}

.source-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.source-card-title {
  min-width: 0;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  word-break: break-word;
}

.source-metric-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.source-metric {
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--border) 84%, transparent);
  background: var(--panel-soft);
  padding: 9px 10px;
}

.source-metric-value {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}

.source-card-footer {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.source-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.source-card-time,
.source-empty {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

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

.modal-history {
  min-height: 56px;
}

body.modal-open {
  overflow: hidden;
}

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

@media (max-width: 900px) {
  .chart-grid,
  .modal-metrics,
  .source-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-inner,
  .toolbar,
  .group-header,
  .modal-header {
    align-items: flex-start;
  }

  .topbar-inner,
  .toolbar,
  .group-header {
    flex-direction: column;
  }

  .sort-box {
    margin-left: 0;
  }
}

@media (max-width: 640px) {
  .dashboard,
  .topbar-inner {
    padding-left: 14px;
    padding-right: 14px;
  }

  .dashboard {
    padding-top: 14px;
    padding-bottom: 28px;
  }

  .kpi-grid,
  .chart-grid,
  .card-grid,
  .modal-metrics,
  .source-grid,
  .source-metric-grid {
    grid-template-columns: 1fr;
  }

  .model-card-main {
    grid-template-columns: 1fr;
  }

  .model-card-ring {
    justify-content: flex-start;
  }

  .history-bar {
    height: 34px;
  }

  .modal-panel {
    width: calc(100vw - 16px);
    margin: 8px auto;
    max-height: calc(100vh - 16px);
    padding: 18px;
  }

  .history-tooltip {
    max-width: calc(100vw - 24px);
  }
}
