:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f4f7fb;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --good: #16a34a;
  --good-bg: #ecfdf5;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --poor: #ea580c;
  --poor-bg: #fff7ed;
  --critical: #dc2626;
  --critical-bg: #fef2f2;
  --chart-good: #22c55e;
  --chart-warning: #f59e0b;
  --chart-critical: #ef4444;
  --chart-rtt: #3b82f6;
  --chart-jitter: #8b5cf6;
  --chart-loss: #ec4899;
  --chart-ice: #14b8a6;
  --chart-other: #64748b;
  --chart-axis: #64748b;
  --chart-axis-label: #475569;
  --info: #2563eb;
  --info-bg: #eff6ff;
  --overlay: rgba(15, 23, 42, 0.45);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 18px rgba(15, 23, 42, 0.05);
  --scroll-track: #e8eef4;
  --scroll-thumb: #9aabc2;
  --scroll-thumb-hover: #64748b;
  --radius: 12px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --control-h: 2.25rem;
  --nav-width: 4.15rem;
  --header-h: 4.25rem;
  --nav-bg: #0f172a;
  --nav-border: rgba(255, 255, 255, 0.08);
  --nav-icon: #94a3b8;
  --nav-icon-hover: #f8fafc;
  --nav-active-bg: color-mix(in srgb, var(--primary) 28%, #0f172a);
  --nav-active-icon: #ffffff;
  color-scheme: light;
  accent-color: var(--primary);
}

:root[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #152033;
  --surface-2: #101a2b;
  --text: #e8eef8;
  --muted: #8b9bb3;
  --line: #27344c;
  --primary: #3b82f6;
  --primary-text: #f8fbff;
  --good: #4ade80;
  --good-bg: #10291f;
  --warning: #fbbf24;
  --warning-bg: #2a210d;
  --poor: #fb923c;
  --poor-bg: #2a180e;
  --critical: #f87171;
  --critical-bg: #2a1218;
  --chart-good: #22c55e;
  --chart-warning: #f59e0b;
  --chart-critical: #ef4444;
  --chart-rtt: #60a5fa;
  --chart-jitter: #a78bfa;
  --chart-loss: #f472b6;
  --chart-ice: #2dd4bf;
  --chart-other: #94a3b8;
  --chart-axis: #8b9bb3;
  --chart-axis-label: #c5d0e0;
  --info: #60a5fa;
  --info-bg: #10253f;
  --overlay: rgba(2, 6, 16, 0.72);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.28), 0 10px 22px rgba(0, 0, 0, 0.28);
  --scroll-track: #0c1626;
  --scroll-thumb: #3d5f94;
  --scroll-thumb-hover: #60a5fa;
  --nav-bg: #0a111c;
  --nav-border: #27344c;
  --nav-icon: #8b9bb3;
  --nav-icon-hover: #e8eef8;
  --nav-active-bg: color-mix(in srgb, var(--primary) 26%, #0a111c);
  --nav-active-icon: #93c5fd;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}
*::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}
*::-webkit-scrollbar-track {
  background: var(--scroll-track);
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 999px;
  border: 2px solid var(--scroll-track);
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
}
*::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}
body {
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  font-size: 14px;
}
h1 { margin: 0; font-size: 1.25rem; font-weight: 650; letter-spacing: -0.02em; }
h2 { margin: 0; font-size: 0.95rem; font-weight: 650; }
h3 { margin: 0 0 0.6rem; font-size: 0.82rem; font-weight: 650; letter-spacing: 0.02em; text-transform: uppercase; color: var(--muted); }
p { margin: 0; }
.muted, .subtitle, .hint { color: var(--muted); }
.app-shell {
  width: 100%;
  margin: 0;
  padding: var(--space-3) 1.25rem var(--space-6);
  flex: 1 0 auto;
}
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-4);
}
.btn, input, select {
  font: inherit;
  color: var(--text);
  background-color: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: var(--control-h);
  padding: 0 0.7rem;
  color-scheme: inherit;
  accent-color: var(--primary);
}
input[type="checkbox"],
input[type="radio"] {
  width: 1rem;
  height: 1rem;
  min-width: 1rem;
  min-height: 1rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  accent-color: var(--primary);
}
.btn:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
input::placeholder { color: var(--muted); opacity: 0.9; }
option {
  background-color: var(--surface);
  color: var(--text);
}
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 1.85rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235f6e80' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
  background-size: 0.85rem;
}
:root[data-theme="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2393a0b2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}
input[type="date"],
input[type="time"] {
  min-width: 9.5rem;
  padding-right: 0.45rem;
  font-variant-numeric: tabular-nums;
}
input[type="time"] { min-width: 7.25rem; }
input[type="date"]::-webkit-datetime-edit,
input[type="time"]::-webkit-datetime-edit {
  color: var(--text);
  padding: 0;
}
input[type="date"]::-webkit-datetime-edit-fields-wrapper,
input[type="time"]::-webkit-datetime-edit-fields-wrapper {
  padding: 0;
}
input[type="date"]::-webkit-datetime-edit-text,
input[type="time"]::-webkit-datetime-edit-text {
  color: var(--muted);
  padding: 0 0.12rem;
}
input[type="date"]::-webkit-datetime-edit-year-field:focus,
input[type="date"]::-webkit-datetime-edit-month-field:focus,
input[type="date"]::-webkit-datetime-edit-day-field:focus,
input[type="time"]::-webkit-datetime-edit-hour-field:focus,
input[type="time"]::-webkit-datetime-edit-minute-field:focus,
input[type="time"]::-webkit-datetime-edit-second-field:focus,
input[type="time"]::-webkit-datetime-edit-ampm-field:focus {
  background: var(--primary);
  color: var(--primary-text);
  outline: none;
  border-radius: 3px;
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  width: 1rem;
  height: 1rem;
  padding: 0;
  margin-left: 0.25rem;
  cursor: pointer;
  opacity: 1;
  border-radius: 4px;
  background-color: var(--muted);
  background-image: none;
  color: var(--muted);
}
input[type="date"]::-webkit-calendar-picker-indicator {
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cpath d='M16 2v4M8 2v4M3 10h18'/%3E%3C/svg%3E") center / 1rem no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cpath d='M16 2v4M8 2v4M3 10h18'/%3E%3C/svg%3E") center / 1rem no-repeat;
}
input[type="time"]::-webkit-calendar-picker-indicator {
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3.5 2'/%3E%3C/svg%3E") center / 1rem no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3.5 2'/%3E%3C/svg%3E") center / 1rem no-repeat;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="time"]::-webkit-calendar-picker-indicator:hover {
  background-color: var(--text);
}
.btn { cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; font-weight: 600; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.ghost { background: transparent; }
.btn:disabled, input:disabled, select:disabled { opacity: 0.55; cursor: not-allowed; }
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  background: var(--warning-bg);
  color: var(--warning);
}
.banner.error { background: var(--critical-bg); color: var(--critical); }
.kpi-row, .metric-row, .chart-row, .analysis-row, .viz-row {
  display: grid;
  gap: var(--space-3);
}
.kpi-row { grid-template-columns: repeat(5, minmax(140px, 1fr)); overflow-x: auto; }
.metric-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.chart-row { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: stretch; }
.analysis-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
}
.viz-row {
  grid-template-columns: minmax(0, 2fr) minmax(17rem, 1fr);
  align-items: stretch;
}
.viz-row > *, .chart-row > *, .analysis-row > * { min-width: 0; height: 100%; }
.chart-card, .network-health, .problem-breakdown {
  height: 100%;
  min-height: 18rem;
  display: flex;
  flex-direction: column;
}
.chart-card { container-type: inline-size; }
.chart-head, .chart-foot {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
  flex: none;
  position: relative;
  z-index: 2;
}
.chart-head { min-height: 2.8rem; }
.chart-head-actions { display: flex; align-items: flex-start; gap: 0.45rem; flex: none; }
.chart-head strong { color: var(--text); font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: 0.7rem; margin-top: 0.3rem; color: var(--muted); font-size: 0.72rem; min-height: 1rem; }
.legend-item { display: inline-flex; align-items: center; gap: 0.35rem; }
.swatch { width: 0.85rem; height: 0.2rem; border-radius: 2px; display: inline-block; background: var(--chart-rtt); }
.chart-svg, .chart-skel, .chart-card > .empty {
  width: 100%;
  height: 220px;
  min-height: 220px;
  flex: none;
}
.chart-svg { display: block; overflow: visible; }
@supports (height: 1cqi) {
  .chart-card > .chart-svg,
  .chart-card > .chart-skel,
  .chart-card > .empty {
    /* 248 / 640 matches the SVG viewBox so height grows with card width. */
    height: clamp(220px, 38.75cqi, min(46vh, 40rem));
  }
}
.quality-trend.chart-card > .chart-svg,
.quality-trend.chart-card > .chart-skel,
.quality-trend.chart-card > .empty {
  width: 100%;
  height: auto;
  min-height: 0;
  aspect-ratio: 640 / 248;
}
.network-health .chart-skel,
.problem-breakdown .chart-skel {
  flex: 1 1 auto;
  height: auto;
}
.chart-foot { color: var(--muted); font-size: 0.7rem; min-height: 1.1rem; }
.axis { stroke: var(--chart-axis); stroke-width: 1.25; }
.grid { stroke: var(--chart-axis); stroke-width: 1; stroke-dasharray: 3 4; opacity: 0.45; }
.axis-label { fill: var(--chart-axis-label); font-size: 10px; font-family: Inter, "Segoe UI", sans-serif; }
.link-btn {
  background: none;
  border: 0;
  padding: 0;
  min-height: 0;
  color: var(--primary);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
.link-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.metric-warning { color: var(--warning); font-weight: 650; }
.metric-critical { color: var(--critical); font-weight: 650; }
.numeric { font-variant-numeric: tabular-nums; text-align: right; }
.table-scroll thead th,
.telemetry-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: var(--surface);
  box-shadow: 0 1px 0 var(--line);
}
.telemetry-scroll thead th {
  background: var(--surface-2);
}
.sort-btn {
  font: inherit;
  color: inherit;
  font-weight: 650;
  background: none;
  border: 0;
  padding: 0;
  min-height: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  white-space: nowrap;
}
.sort-btn:hover { color: var(--text); }
.sort-btn span { font-size: 0.68rem; opacity: 0.7; }
.sort-btn.numeric { justify-content: flex-end; }
.telemetry-scroll {
  overflow: auto;
  max-height: 22rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.telemetry-scroll table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; }
.telemetry-scroll th,
.telemetry-scroll td {
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 0.75rem;
  white-space: nowrap;
  vertical-align: middle;
  height: 2.4rem;
}
.telemetry-scroll th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 650;
  box-shadow: 0 1px 0 var(--line);
}
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: pulse 1.2s ease-in-out infinite;
  border-radius: 8px;
  min-height: 5.5rem;
}
@keyframes pulse { to { background-position: -200% 0; } }
#blazor-error-ui {
  background: var(--critical-bg);
  color: var(--critical);
  bottom: 0;
  display: none;
  left: 0;
  padding: 0.6rem 1.25rem;
  position: fixed;
  width: 100%;
  z-index: 1000;
}

@media (max-width: 1200px) {
  .analysis-row { grid-template-columns: 1fr 1fr; }
  .analysis-row > :last-child { grid-column: 1 / -1; }
}
@media (max-width: 1100px) {
  .chart-row, .viz-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  .metric-row { grid-template-columns: 1fr 1fr; }
  .kpi-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .chart-row, .viz-row, .analysis-row { grid-template-columns: 1fr; }
  .analysis-row > :last-child { grid-column: auto; }
  .chart-card > .chart-svg,
  .chart-card > .chart-skel,
  .chart-card > .empty {
    height: clamp(200px, 38.75cqi, 16.5rem);
  }
  .quality-trend.chart-card > .chart-svg,
  .quality-trend.chart-card > .chart-skel,
  .quality-trend.chart-card > .empty {
    width: 100%;
    height: auto;
    min-height: 0;
    aspect-ratio: 640 / 248;
  }
}
@media (max-width: 560px) {
  .kpi-row, .metric-row, .chart-row, .viz-row, .analysis-row { grid-template-columns: 1fr; }
  .app-shell { padding: 0.7rem 0.75rem 1.25rem; }
}
