:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #eef3f4;
  --ink: #182022;
  --muted: #607074;
  --line: #d8e0e2;
  --teal: #0c8f8f;
  --teal-2: #096f72;
  --amber: #b87913;
  --green: #21865b;
  --red: #c2413f;
  --blue: #326aa8;
  --shadow: 0 16px 40px rgba(24, 32, 34, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button,
input,
table,
pre {
  font: inherit;
}

.app-shell {
  width: min(1500px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 74px;
  border-bottom: 1px solid var(--line);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border: 1px solid #a8c9c9;
  border-radius: 8px;
  background: #e7f3f2;
  color: var(--teal-2);
}

.brand-mark svg,
.icon-button svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1;
  letter-spacing: 0;
}

.brand p {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(680px, 55vw);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.switch {
  position: relative;
  display: inline-flex;
  width: 48px;
  height: 28px;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: #cdd7da;
  border: 1px solid #bcc9cc;
  transition: background 180ms ease, border-color 180ms ease;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(24, 32, 34, 0.18);
  transition: transform 180ms ease;
}

.switch input:checked + span {
  background: var(--teal);
  border-color: var(--teal);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
}

.icon-button:hover {
  border-color: #aab8bb;
  background: #f9fbfb;
}

.icon-button.is-spinning svg {
  animation: spin 700ms linear infinite;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 82px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

#liveDot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(33, 134, 91, 0.12);
}

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

.summary-strip article,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-strip article {
  min-height: 112px;
  padding: 16px 18px;
}

.summary-strip span,
.panel-title span,
th,
.row-meta,
.status-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.summary-strip strong {
  display: block;
  margin-top: 12px;
  font-size: clamp(26px, 4vw, 42px);
  line-height: 0.95;
  letter-spacing: 0;
}

.summary-strip small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(360px, 1.6fr) minmax(280px, 0.95fr);
  gap: 12px;
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.panel {
  min-width: 0;
  padding: 16px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
  margin-bottom: 14px;
}

h2 {
  font-size: 16px;
  line-height: 1.1;
  letter-spacing: 0;
}

.worker-rows,
.hardware-rows {
  display: grid;
  gap: 10px;
}

.worker-row,
.hardware-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.hardware-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.lane-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
}

.lane-icon.cpu {
  color: #194f83;
  background: #e7f0fa;
}

.lane-icon.cuda {
  color: #1c6b4b;
  background: #e7f5ee;
}

.lane-icon.igpu {
  color: #7a520f;
  background: #fbf0dc;
}

.row-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 700;
}

.row-title span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-meta {
  margin-top: 5px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  text-transform: capitalize;
}

.status-chip.training,
.status-chip.submitted {
  color: #116342;
  background: #ddf3e9;
}

.status-chip.waiting,
.status-chip.driver-basic {
  color: #79500c;
  background: #fbefd6;
}

.status-chip.degraded,
.status-chip.unavailable,
.status-chip.error {
  color: #9b2f2e;
  background: #fae2e1;
}

.status-chip.stale,
.status-chip.missing {
  color: #536166;
  background: #edf1f2;
}

.chart-panel {
  min-height: 346px;
}

#normCanvas {
  display: block;
  width: 100%;
  height: 280px;
}

.table-wrap {
  overflow: auto;
  max-height: 338px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th {
  position: sticky;
  top: 0;
  padding: 10px 12px;
  background: #f6f9f9;
  text-align: left;
  font-weight: 800;
  text-transform: uppercase;
}

td {
  padding: 11px 12px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  white-space: nowrap;
}

tbody tr:hover {
  background: #f8fbfb;
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.tag.cpu {
  color: #194f83;
  background: #e7f0fa;
}

.tag.cuda {
  color: #1c6b4b;
  background: #e7f5ee;
}

.tag.igpu,
.tag.waiting {
  color: #79500c;
  background: #fbefd6;
}

.tag.error,
.tag.degraded {
  color: #9b2f2e;
  background: #fae2e1;
}

.logs-panel {
  margin-top: 12px;
}

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f9f9;
}

.tab {
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.tab.is-active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(24, 32, 34, 0.12);
}

pre {
  min-height: 220px;
  max-height: 360px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  background: #12191a;
  color: #d6e2df;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1100px) {
  .summary-strip,
  .layout-grid,
  .lower-grid {
    grid-template-columns: 1fr 1fr;
  }

  .worker-panel {
    grid-column: 1;
    grid-row: 1;
  }

  .hardware-panel {
    grid-column: 2;
    grid-row: 1;
  }

  .chart-panel,
  .logs-panel {
    grid-column: 1 / -1;
  }

  .chart-panel {
    grid-row: 2;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100vw - 20px, 1500px);
    padding-top: 10px;
  }

  .topbar,
  .brand {
    align-items: flex-start;
  }

  .topbar {
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .brand p {
    max-width: calc(100vw - 96px);
    white-space: normal;
  }

  .summary-strip,
  .layout-grid,
  .lower-grid {
    grid-template-columns: 1fr;
  }

  .worker-panel,
  .hardware-panel,
  .chart-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .summary-strip article {
    min-height: 96px;
  }
}

@media (max-width: 520px) {
  .worker-row {
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: start;
  }

  .worker-row .status-chip {
    grid-column: 2;
    justify-self: start;
    min-width: 0;
    height: 24px;
    margin-top: 4px;
  }

  .lane-icon {
    width: 34px;
    height: 34px;
  }

  .row-title {
    font-size: 14px;
  }

  .row-meta {
    line-height: 1.35;
  }

  .panel-title {
    align-items: flex-start;
  }

  .top-actions {
    gap: 6px;
  }

  .live-pill {
    min-width: 38px;
    width: 38px;
    padding: 0;
    justify-content: center;
  }

  .live-pill strong {
    display: none;
  }
}
