:root {
  --ui-border-color: #d9e1eb;
  --ui-border-color-hover: #adbbcc;
  --accent-color: #c6e90d;
  --ui-background-hover: #f9f9f9;
  --ui-border: 1px solid var(--ui-border-color);
  --topbar-control-height: 42px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f5f7fa;
  color: #152033;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  gap: 10px;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  height: 100vh;
  padding: 10px;
}

.app-shell.is-chart-focused,
.app-shell.is-summary-hidden {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.topbar {
  align-items: center;
  background: #ffffff;
  border: var(--ui-border);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(21, 32, 51, 0.08);
  display: flex;
  gap: 10px;
  min-height: 58px;
  padding: 8px 10px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  align-items: center;
  color: inherit;
  display: flex;
  gap: 10px;
  min-width: 180px;
  text-decoration: none;
  margin-right: -10px;
}

.brand-logo {
  display: block;
  flex: 0 0 auto;
  height: 34px;
  object-fit: contain;
  width: 48px;
  margin-left: 2px;
}

.brand:focus-visible {
  outline: 2px solid #1f6fdb;
  outline-offset: 4px;
}

h1 {
  font-size: clamp(1rem, 1.6vw, 1.35rem);
  letter-spacing: 0;
  line-height: 1.1;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-spacer {
  flex: 1 1 auto;
  min-width: 24px;
}

.dropdown {
  position: relative;
}

.gpu-selector {
  flex: 0 0 220px;
  width: 220px;
}

.dropdown-trigger,
.primary-action,
.dropdown-panel button {
  border-radius: 7px;
  font-weight: 750;
  min-height: 36px;
}

.dropdown-trigger {
  align-items: center;
  background: #f9fbfd;
  border: var(--ui-border);
  color: #1f2f46;
  display: inline-flex;
  gap: 8px;
  height: var(--topbar-control-height);
  justify-content: space-between;
  max-width: 360px;
  min-width: 190px;
  padding: 0 10px;
}

.dropdown-trigger::after {
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #53657d;
  content: "";
  flex: 0 0 auto;
}

.gpu-trigger {
  max-width: 220px;
  min-width: 220px;
  width: 220px;
}

.gpu-trigger [data-gpu-summary] {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-trigger {
  min-width: 160px;
}

.host-info-trigger {
  align-items: center;
  background: #f9fbfd;
  border: var(--ui-border);
  border-radius: 7px;
  color: #1f2f46;
  display: inline-flex;
  flex: 0 0 var(--topbar-control-height);
  font-size: 1rem;
  font-weight: 850;
  height: var(--topbar-control-height);
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: var(--topbar-control-height);
}

.host-info-trigger:hover,
.host-info-trigger:focus-visible {
  background: #eef5ff;
  border-color: var(--ui-border-color-hover);
  color: #1f6fdb;
  outline: none;
}

.dropdown-panel {
  background: #ffffff;
  border: var(--ui-border);
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(21, 32, 51, 0.16);
  display: none;
  min-width: 250px;
  padding: 10px;
  position: absolute;
  top: calc(100% + 8px);
  z-index: 40;
}

.dropdown.is-open .dropdown-panel {
  display: block;
}

.gpu-panel {
  left: 0;
  max-width: min(860px, calc(100vw - 24px));
  width: 760px;
}

.chart-panel {
  left: 0;
  width: 220px;
}

.time-panel {
  display: none;
  flex-direction: column;
  gap: 8px;
  right: 0;
  width: 120px;
  min-width: 100px;
}

.dropdown.is-open .time-panel {
  display: flex;
}

.dropdown-actions {
  align-items: center;
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.dropdown-actions button,
.dropdown-panel button {
  background: #eef3f8;
  border: var(--ui-border);
  color: #25364f;
  padding: 6px 10px;
}

.host-control {
  align-items: center;
  display: flex;
  flex: 0 1 auto;
  max-width: 400px;
  min-width: 220px;
  width: fit-content;
}

.host-select-label {
  align-items: center;
  background: #f9fbfd;
  border: var(--ui-border);
  border-radius: 7px;
  color: #1f2f46;
  display: inline-flex;
  font-weight: 750;
  gap: 8px;
  height: var(--topbar-control-height);
  justify-content: space-between;
  max-width: 400px;
  min-width: 220px;
  position: relative;
  width: fit-content;
}

.host-select-label::after {
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #53657d;
  content: "";
  pointer-events: none;
  position: absolute;
  right: 10px;
}

.host-select-label select {
  appearance: none;
  background: transparent;
  border: 0;
  color: inherit;
  font-weight: 750;
  height: 100%;
  min-width: 0;
  overflow: hidden;
  padding: 0 28px 0 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.host-select-label select:focus {
  outline: none;
}

.host-select-label:focus-within {
  outline: 2px solid #1f6fdb;
  outline-offset: 2px;
}

.device-list {
  display: grid;
  gap: 6px;
  max-height: min(360px, calc(100vh - 120px));
  overflow: auto;
}

.chart-list {
  display: grid;
  gap: 4px;
}

.device-option {
  align-items: center;
  border-radius: 7px;
  display: grid;
  gap: 8px;
  grid-template-columns: auto 10px minmax(0, 1fr);
  min-height: 34px;
  padding: 6px 8px;
}

.chart-option {
  align-items: center;
  border-radius: 7px;
  display: flex;
  gap: 8px;
  min-height: 34px;
  padding: 6px 8px;
}

.device-option:hover,
.chart-option:hover {
  background: #f5f8fc;
}

.device-option input,
.chart-option input {
  margin: 0;
}

.color-dot,
.tooltip-swatch {
  border-radius: 50%;
  height: 10px;
  width: 10px;
}

.gpu-summary-text,
.badge-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-option span:last-child {
  overflow-wrap: anywhere;
}

.gpu-summary {
  align-items: center;
  display: inline-flex;
  gap: 6px;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

.gpu-mini-badge,
.gpu-badge {
  align-items: center;
  border-radius: 999px;
  color: #ffffff;
  display: inline-flex;
  font-size: 0.74rem;
  font-weight: 850;
  line-height: 1;
  min-height: 22px;
  padding: 5px 8px;
  white-space: nowrap;
}

.gpu-mini-badge {
  max-width: 80px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gpu-badge {
  font-size: 0.78rem;
  margin-right: 8px;
}

.control-section {
  align-items: center;
  background: #f9fbfd;
  border: var(--ui-border);
  border-radius: 8px;
  display: flex;
  gap: 6px;
  height: var(--topbar-control-height);
  padding: 0 0 0 6px;
}

.control-section > .dropdown {
  align-items: stretch;
  display: flex;
  height: 100%;
}

.control-input-label {
  align-items: center;
  border-radius: 7px;
  cursor: text;
  display: flex;
  gap: 5px;
  height: 100%;
  padding: 0 8px;
  transition: background-color 120ms ease, color 120ms ease;
}

.control-input-label:hover,
.control-input-label:focus-within {
  background: #eef5ff;
  color: #1f6fdb;
}

.control-input-label span {
  color: #405169;
  font-size: 0.86rem;
  font-weight: 650;
  white-space: nowrap;
}

.control-input-label:hover span,
.control-input-label:focus-within span {
  color: #1f6fdb;
}

.control-input-label input {
  -moz-appearance: textfield;
  background: transparent;
  border: 0;
  color: #152033;
  font-weight: 850;
  min-height: 28px;
  padding: 0;
  text-align: right;
  width: 30px;
  text-align: center;
}

.control-input-label:hover input,
.control-input-label:focus-within input {
  color: #0d4f9e;
}

.refresh-input-label input {
  width: 34px;
}

.control-input-label input::-webkit-inner-spin-button,
.control-input-label input::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
}

.control-input-label input:focus {
  outline: none;
}

select {
  background: #f9fbfd;
  border: var(--ui-border);
  border-radius: 7px;
  color: #152033;
  min-height: 36px;
  padding: 7px 10px;
  width: 100%;
}

.status-indicator {
  align-items: center;
  display: flex;
  flex: 0 0 auto;
  margin-left: 6px;
  position: relative;
}

.status-dot {
  appearance: none;
  background: #9aa8ba;
  border: 0;
  border-radius: 50%;
  cursor: help;
  flex: 0 0 auto;
  height: 10px;
  padding: 0;
  width: 10px;
}

.status-dot:focus-visible {
  outline: 2px solid #1f6fdb;
  outline-offset: 4px;
}

.status-dot.is-ok {
  background: #179a63;
}

.status-dot.is-warn {
  background: #d58a00;
}

.status-dot.is-error {
  background: #cc3348;
}

.status-tooltip {
  background: #152033;
  border-radius: 7px;
  box-shadow: 0 12px 30px rgba(21, 32, 51, 0.2);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 700;
  left: var(--status-tooltip-x, 50%);
  line-height: 1.2;
  max-width: min(260px, calc(100vw - 24px));
  opacity: 0;
  padding: 7px 9px;
  pointer-events: none;
  position: fixed;
  text-align: center;
  top: var(--status-tooltip-y, 0);
  transform: translate(-50%, 4px);
  transition: opacity 120ms ease, transform 120ms ease;
  white-space: nowrap;
  z-index: 60;
}

.status-tooltip::after {
  border-bottom: 5px solid #152033;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  content: "";
  left: 50%;
  position: absolute;
  bottom: 100%;
  transform: translateX(-50%);
}

.status-indicator:hover .status-tooltip,
.status-indicator:focus-within .status-tooltip {
  opacity: 1;
  transform: translate(-50%, 0);
}

.refresh-panel {
  display: none;
  flex-direction: column;
  gap: 8px;
  right: 0;
  width: 120px;
  min-width: 100px;
}

.dropdown.is-open .refresh-panel {
  display: flex;
}

.primary-action {
  align-items: center;
  background: #1f6fdb;
  border: 0;
  border-radius: 0 7px 7px 0;
  color: #ffffff;
  display: inline-flex;
  font-weight: 750;
  justify-content: center;
  align-self: stretch;
  height: 100%;
  line-height: 1;
  min-height: 0;
  padding: 0 14px;
  white-space: nowrap;
}

.muted {
  color: #6d7d91;
}

.summary {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  min-height: 0;
}

.app-shell.is-chart-focused .summary,
.app-shell.is-summary-hidden .summary {
  display: none;
}

.summary-card {
  background: #ffffff;
  border: var(--ui-border);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(21, 32, 51, 0.05);
  cursor: pointer;
  min-width: 0;
  padding: 10px;
  transition: border-color 120ms ease, opacity 120ms ease;
}

.summary-card.is-inactive {
  opacity: 0.45;
}

.summary-card:hover,
.summary-card:focus-visible {
  background-color: var(--ui-background-hover);
  border-color: var(--ui-border-color-hover);
  outline: none;
}

.summary-card.is-inactive:hover,
.summary-card.is-inactive:focus-visible {
  opacity: 0.9;
}

.summary-title {
  align-items: center;
  color: #475a73;
  display: flex;
  font-size: 0.82rem;
  font-weight: 800;
  gap: 4px;
  margin: 0 0 8px;
  min-width: 0;
}

.summary-title .device-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-values {
  display: grid;
  gap: 5px 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.summary-values span {
  color: #182942;
  font-size: 0.84rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.charts-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(var(--chart-rows, 2), minmax(0, 1fr));
  min-height: 0;
  overflow: hidden;
}

.app-footer {
  font-size: 10px;
  line-height: 1;
  text-align: center;
}

.app-footer a {
  color: #8b98aa;
  opacity: 0.7;
  text-decoration: none;
}

.app-footer a:hover,
.app-footer a:focus-visible {
  color: #53657d;
  opacity: 1;
  text-decoration: underline;
}

.charts-grid[data-count="1"] {
  grid-template-columns: 1fr;
}

.empty-charts {
  align-items: center;
  background: #ffffff;
  border: var(--ui-border);
  border-radius: 8px;
  color: #6d7d91;
  display: flex;
  font-weight: 750;
  grid-column: 1 / -1;
  justify-content: center;
}

.chart-card {
  background: #ffffff;
  border: var(--ui-border);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(21, 32, 51, 0.06);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.chart-header {
  align-items: center;
  border-bottom: 1px solid var(--ui-border-color);
  display: flex;
  gap: 10px;
  justify-content: space-between;
  min-height: 44px;
  padding: 8px 10px;
}

.chart-title {
  min-width: 0;
}

.chart-title h2 {
  font-size:18px;
  line-height: 1.1;
  margin: 0;
}

.chart-title p {
  color: #68788d;
  font-size: 0.76rem;
  margin: 3px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-actions {
  flex: 0 0 auto;
}

.chart-actions button {
  background: #eef3f8;
  border: var(--ui-border);
  border-radius: 7px;
  color: #25364f;
  font-size: 0.78rem;
  font-weight: 750;
  min-height: 30px;
  padding: 5px 9px;
}

.chart-wrap {
  min-height: 0;
  position: relative;
  padding: 0px 5px;
}

.chart-card.is-fullscreen .chart-wrap {
  height: auto;
}

canvas {
  display: block;
  height: 100%;
  width: 100%;
}

.tooltip {
  background: rgba(255, 255, 255, 0.98);
  border: var(--ui-border);
  border-radius: 8px;
  box-shadow: 0 14px 36px rgba(21, 32, 51, 0.14);
  color: #152033;
  display: none;
  font-size: 0.82rem;
  left: 0;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
  position: fixed;
  top: 0;
  z-index: 70;
}

.tooltip.is-visible {
  display: block;
}

.tooltip strong {
  display: block;
  padding: 9px 10px 6px;
}

.tooltip-row {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  padding: 4px 10px;
}

.tooltip-row:last-child {
  padding-bottom: 10px;
}

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

.host-modal[hidden] {
  display: none;
}

.host-modal {
  align-items: center;
  background: rgba(21, 32, 51, 0.48);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: fixed;
  z-index: 100;
}

.host-modal-dialog {
  background: #ffffff;
  border: var(--ui-border);
  border-radius: 8px;
  box-shadow: 0 26px 72px rgba(21, 32, 51, 0.3);
  max-width: min(920px, 100%);
  padding: 20px;
  position: relative;
  width: 100%;
}

.host-modal-close {
  align-items: center;
  background: #eef3f8;
  border: var(--ui-border);
  border-radius: 7px;
  color: #25364f;
  display: inline-flex;
  font-size: 1.25rem;
  font-weight: 750;
  height: 34px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  position: absolute;
  right: 14px;
  top: 14px;
  width: 34px;
}

.host-modal-close:hover,
.host-modal-close:focus-visible {
  background: #eef5ff;
  border-color: var(--ui-border-color-hover);
  color: #1f6fdb;
  outline: none;
}

.host-modal h2 {
  color: #152033;
  font-size: 1.2rem;
  line-height: 1.2;
  margin: 0 44px 18px 0;
  overflow-wrap: anywhere;
}

.host-modal-details {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0;
}

.host-info-card {
  background: #f9fbfd;
  border: var(--ui-border);
  border-radius: 7px;
  display: grid;
  gap: 8px;
  min-height: 92px;
  padding: 12px;
}

.host-modal-details dt {
  color: #68788d;
  font-size: 0.76rem;
  font-weight: 800;
  margin: 0;
  text-transform: uppercase;
}

.host-modal-details dd {
  color: #152033;
  font-size: 1.05rem;
  font-weight: 750;
  line-height: 1.2;
  margin: 0;
  overflow-wrap: anywhere;
}

.host-modal-details dd[data-host-modal-gpu-count],
.host-metric-number {
  font-size: 32px;
  line-height: 1;
}

.host-metric-unit {
  font-size: 1.05rem;
}

.host-metric-percent {
  color: #7d8ba0;
  font-size: 1.05rem;
}

@media (max-width: 1180px) {
  .topbar {
    flex-wrap: wrap;
  }

  .topbar-spacer {
    display: none;
  }

  .control-section {
    margin-left: auto;
  }
}

@media (min-width: 984px) {
  .summary {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    padding: 8px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    padding: 10px;
    position: static;
  }

  .brand h1 {
    font-size: 24px;
  }

  .brand,
  .dropdown,
  .dropdown-trigger,
  .host-info-trigger,
  .control-section {
    max-width: none;
    width: 100%;
  }

  .host-info-trigger {
    flex-basis: var(--topbar-control-height);
  }

  .host-control,
  .host-select-label,
  .gpu-selector,
  .gpu-trigger {
    max-width: none;
    min-width: 0;
    width: 100%;
  }

  .gpu-selector {
    flex-basis: auto;
  }

  .dropdown-panel,
  .gpu-panel,
  .time-panel,
  .refresh-panel {
    left: 0;
    max-width: none;
    right: auto;
    width: 100%;
  }

  .control-section {
    align-items: stretch;
    display: grid;
    gap: 6px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    height: auto;
    padding: 6px;
  }

  .control-input-label {
    height: var(--topbar-control-height);
    justify-content: center;
    width: 100%;
  }

  .dropdown-actions {
    flex-wrap: wrap;
  }

  .primary-action {
    border-radius: 7px;
    grid-column: 1 / -1;
    height: var(--topbar-control-height);
    min-height: var(--topbar-control-height);
    width: 100%;
  }

  .status-indicator {
    display: none;
  }

  .host-modal {
    align-items: flex-start;
    overflow: auto;
  }

  .host-modal-details {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .charts-grid {
    grid-template-rows: none;
    overflow: visible;
  }

  .chart-wrap {
    height: 240px;
  }
}

@media (max-width: 520px) {
  .host-modal-details {
    grid-template-columns: 1fr;
  }
}
