:root {
  color-scheme: dark;
  --charcoal: #0a0a0b;
  --dark-gray: #1d1e21;
  --gray: #2d2e33;
  --light-gray: #a6a7ac;
  --white: #ffffff;
  --success: #4ade80;
  --danger: #f87171;
  --warning: #fbbf24;
  --info: #67e8f9;
  --focus: #60a5fa;
  --panel: #111214;
  --panel-raised: #17181b;
  --panel-hover: #1d1e21;
  --text-soft: #d6d9e0;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html {
  scrollbar-color: var(--gray) var(--charcoal);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 50% -15%, rgba(166, 167, 172, 0.12), transparent 42%),
    var(--bg);
  color: var(--text);
  font: 14px/1.45 "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a {
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

[hidden],
.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: -64px;
  left: 16px;
  z-index: 20;
  padding: 9px 13px;
  border: 1px solid var(--white);
  border-radius: 6px;
  background: var(--white);
  color: var(--charcoal);
  font-weight: 700;
}

.skip-link:focus {
  top: 16px;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 380px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
}

.login-logo {
  width: 56px;
  height: 56px;
  border-radius: 12px;
}

.login-card h1 {
  margin: 4px 0 0;
  font-size: 22px;
}

.login-subtitle,
.login-error {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.login-error {
  min-height: 19px;
  color: var(--danger);
}

.login-card label {
  align-self: flex-start;
  font-size: 12px;
  font-weight: 700;
}

.login-card input,
.filters input,
.filters select,
.live-alert-form textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--charcoal);
  color: var(--text);
}

.login-card input {
  padding: 11px;
}

.login-card button,
.filters button,
.dialog-footer > button:last-child,
.live-alert-actions button[type="submit"] {
  border: 1px solid var(--white);
  border-radius: 6px;
  background: var(--white);
  color: var(--charcoal);
  font-weight: 750;
}

.login-card button {
  width: 100%;
  margin-top: 4px;
  padding: 11px;
}

.login-card button:hover,
.filters button:hover,
.dialog-footer > button:last-child:hover,
.live-alert-actions button[type="submit"]:hover {
  border-color: var(--light-gray);
  background: var(--light-gray);
}

.dashboard-view {
  width: min(calc(100% - 28px), 1580px);
  margin: 0 auto;
  padding: 16px 0 36px;
}

.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 14px;
  border-bottom: 1px solid var(--border);
}

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

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 9px;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.05;
  letter-spacing: 0.04em;
}

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

.link-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-button:hover {
  color: var(--text);
}

.filters {
  display: grid;
  grid-template-columns: minmax(330px, 1.35fr) minmax(150px, 0.55fr) minmax(170px, 0.6fr) auto;
  gap: 12px;
  align-items: end;
  margin: 12px 0 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.filters label {
  display: grid;
  gap: 5px;
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 700;
}

.filters input,
.filters select {
  height: 36px;
  padding: 7px 10px;
}

.date-range {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 7px;
  align-items: center;
}

.date-range > span {
  color: var(--muted);
}

.filters .filter-hint {
  color: var(--muted);
  font-size: 10px;
  font-weight: 400;
}

.filters button {
  height: 36px;
  padding: 0 18px;
  white-space: nowrap;
}

.dashboard-section {
  min-width: 0;
  margin-top: 10px;
}

.panel {
  overflow: clip;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.section-heading {
  min-height: 43px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.section-heading h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: -0.015em;
}

.refresh-status {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.overview {
  margin-top: 10px;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.tile {
  min-height: 88px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 14px 18px;
  border-right: 1px solid var(--border);
  background: linear-gradient(135deg, var(--panel), var(--dark-gray));
}

.tile:last-child {
  border-right: 0;
}

.tile-label,
.tile-detail {
  color: var(--muted);
  font-size: 11px;
}

.tile-value {
  font-size: 25px;
  line-height: 1.12;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
}

.tile-success .tile-value {
  color: var(--success);
}

.tile-danger .tile-value {
  color: var(--danger);
}

.dashboard-grid {
  display: grid;
  align-items: start;
  gap: 10px;
}

.primary-grid {
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
}

.diagnostics-grid {
  grid-template-columns: minmax(0, 1.55fr) minmax(460px, 0.9fr);
}

.operations-grid {
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) minmax(310px, 0.72fr);
}

.split-charts,
.hardware-layout,
.diagnostic-charts {
  display: grid;
  align-items: start;
}

.split-charts {
  grid-template-columns: minmax(270px, 0.75fr) minmax(380px, 1.25fr);
}

.hardware-layout {
  grid-template-columns: minmax(270px, 0.85fr) minmax(350px, 1.15fr);
}

.diagnostic-charts {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.chart-card {
  min-width: 0;
  padding: 12px;
  border-right: 1px solid var(--border);
}

.chart-card:last-child {
  border-right: 0;
}

.card-heading {
  min-height: 25px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.chart-card h3,
.chart-card h4 {
  margin: 0;
}

.chart-card h3 {
  font-size: 12px;
  font-weight: 650;
}

.chart-card h4 {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.chart-plot {
  position: relative;
  min-width: 0;
}

.chart-plot > canvas {
  width: 100%;
  height: 220px;
  display: block;
}

.hardware-charts {
  display: grid;
  gap: 8px;
}

.hardware-charts > div + div {
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.hardware-charts .card-heading {
  min-height: 15px;
  margin: 0;
}

.hardware-charts .chart-plot > canvas {
  height: 110px;
}

.split-charts .chart-plot > canvas {
  height: 270px;
}

.split-charts .distribution-content .chart-plot > canvas {
  height: 230px;
}

.diagnostic-charts .chart-plot > canvas {
  height: 230px;
}

.distribution-content {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 12px;
}

.distribution-content .chart-plot {
  width: min(100%, 230px);
  aspect-ratio: 1;
}

.distribution-content .chart-plot > canvas {
  width: 100%;
  height: 100%;
}

.chart-legend {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.legend-row {
  min-width: 0;
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  font-size: 11px;
}

.legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.legend-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-value {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chart-tooltip {
  position: absolute;
  z-index: 8;
  min-width: 150px;
  max-width: min(280px, calc(100% - 16px));
  display: grid;
  gap: 2px;
  padding: 9px 11px;
  border: 1px solid #3d4657;
  border-radius: 6px;
  background: #0b0d12f2;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  color: var(--text-soft);
  font-size: 11px;
  pointer-events: none;
  transform: translate(-50%, -100%);
}

.chart-tooltip strong {
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 12px;
}

.chart-tooltip.tooltip-below {
  transform: translate(-50%, 0);
}

.chart-tooltip span:last-child {
  color: var(--muted);
}

.csv-link {
  color: var(--muted);
  font-size: 10px;
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}

.csv-link:hover {
  color: var(--text);
}

.incident-panel,
.operations-grid > .panel {
  display: flex;
  flex-direction: column;
}

.incident-panel .table-scroll,
.operations-grid .table-scroll {
  flex: 1;
}

.table-scroll {
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
  white-space: nowrap;
}

.data-table th,
.data-table td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.data-table tbody tr {
  transition: background 140ms ease;
}

.data-table tbody tr:hover,
.data-table tbody tr:focus-within {
  background: var(--panel-hover);
}

.data-table td.failure-code {
  color: var(--danger);
  font-weight: 700;
}

.data-table td.summary-cell {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table .empty-row {
  padding: 28px;
  color: var(--muted);
  text-align: center;
  white-space: normal;
}

.details-button,
.icon-button,
.secondary-button {
  border: 1px solid var(--border);
  border-radius: 5px;
  background: transparent;
  color: var(--text-soft);
}

.details-button {
  min-width: 29px;
  min-height: 27px;
  padding: 3px 7px;
  line-height: 1;
}

.details-button:hover,
.icon-button:hover,
.secondary-button:hover {
  border-color: var(--light-gray);
  background: var(--panel-hover);
  color: var(--text);
}

.live-alert-form {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 12px;
}

.live-alert-templates {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--charcoal);
  color: var(--muted);
  padding: 5px 9px;
  font-size: 10px;
}

.chip:hover {
  border-color: var(--warning);
  color: var(--text);
}

.live-alert-form textarea {
  min-height: 104px;
  padding: 10px;
  resize: vertical;
}

.live-alert-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}

.live-alert-counter {
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.live-alert-actions {
  display: flex;
  gap: 7px;
}

.live-alert-actions button[type="submit"] {
  height: 32px;
  padding: 0 14px;
}

.live-alert-status-active {
  color: var(--warning);
  font-weight: 700;
}

.dashboard-footnote {
  margin: 17px 0 0;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}

.detail-dialog {
  width: min(calc(100% - 28px), 820px);
  max-height: min(calc(100vh - 32px), 860px);
  padding: 0;
  overflow: hidden;
  border: 1px solid #3c3e45;
  border-radius: 8px;
  background: var(--panel-raised);
  color: var(--text);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.72);
}

.detail-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(3px);
}

.dialog-shell {
  max-height: inherit;
  display: flex;
  flex-direction: column;
}

.dialog-header,
.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
}

.dialog-header {
  border-bottom: 1px solid var(--border);
}

.dialog-kind {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.dialog-header h2 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 19px;
}

.icon-button {
  width: 34px;
  height: 34px;
  font-size: 22px;
  line-height: 1;
}

.detail-meta {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin: 0;
  border-bottom: 1px solid var(--border);
}

.detail-meta > div {
  min-width: 0;
  padding: 11px 13px;
  border-right: 1px solid var(--border);
}

.detail-meta > div:last-child {
  border-right: 0;
}

.detail-meta dt,
.detail-section h3 {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
}

.detail-meta dd {
  margin: 0;
  overflow: hidden;
  color: var(--text-soft);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-content {
  overflow: auto;
}

.detail-section {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}

.detail-section p,
.detail-section pre,
.detail-section ul {
  margin: 0;
}

.detail-section p,
.detail-section li {
  color: var(--text-soft);
  font-size: 12px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.detail-section ul {
  display: grid;
  gap: 4px;
  padding-left: 18px;
}

.detail-section pre {
  max-height: 260px;
  overflow: auto;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--charcoal);
  color: var(--text-soft);
  font: 11px/1.5 "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  white-space: pre-wrap;
}

.dialog-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

.dialog-footer button {
  min-height: 34px;
  padding: 0 14px;
}

@media (max-width: 1280px) {
  .primary-grid,
  .diagnostics-grid {
    grid-template-columns: 1fr;
  }

  .operations-grid {
    grid-template-columns: 1fr 1fr;
  }

  .operations-grid > :last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 880px) {
  .filters {
    grid-template-columns: 1fr 1fr;
  }

  .tiles {
    grid-template-columns: 1fr 1fr;
  }

  .tile:nth-child(2) {
    border-right: 0;
  }

  .tile:nth-child(-n + 2) {
    border-bottom: 1px solid var(--border);
  }

  .split-charts,
  .hardware-layout,
  .diagnostic-charts,
  .operations-grid {
    grid-template-columns: 1fr;
  }

  .operations-grid > :last-child {
    grid-column: auto;
  }

  .chart-card {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .chart-card:last-child {
    border-bottom: 0;
  }

  .detail-meta {
    grid-template-columns: 1fr 1fr;
  }

  .detail-meta > div {
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 560px) {
  .dashboard-view {
    width: min(calc(100% - 16px), 1580px);
    padding-top: 8px;
  }

  .filters,
  .tiles {
    grid-template-columns: 1fr;
  }

  .filters button {
    width: 100%;
  }

  .date-range {
    grid-template-columns: 1fr;
  }

  .date-range > span {
    display: none;
  }

  .tile {
    min-height: 78px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .tile:last-child {
    border-bottom: 0;
  }

  .distribution-content .chart-plot {
    max-width: 260px;
    margin: 0 auto;
  }

  .chart-legend {
    grid-template-columns: 1fr 1fr;
  }

  .detail-meta {
    grid-template-columns: 1fr;
  }

  .detail-meta > div {
    border-right: 0;
  }

  .dialog-footer {
    flex-direction: column;
  }

  .dialog-footer button {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
