/* Diagnose/Snapshot-Viewer: uebernimmt die Inhaltsstruktur der Vorlage
   Dokumente/mvp_snapshot_viewer/index.html, eingebettet in die vorhandene
   Portal-Navigation und deren Farbtokens. */

:root {
  --diag-src-inv: #c026d3;
  --diag-src-0: #006c69;
  --diag-src-1: #7b5ea7;
  --diag-src-2: #b26a00;
  --diag-src-3: #0e7490;
  --diag-src-4: #b2473f;
  --diag-src-5: #187a54;
  --diag-src-6: #7c3aed;
  --diag-src-7: #586c70;
  --diag-src-8: #a21caf;
  --diag-src-9: #0f766e;
  --diag-heat-low: #b2473f;
  --diag-heat-mid: #d7e4e1;
  --diag-heat-high: #187a54;
  --diag-bit-both: #7c3aed;
}

:root[data-theme="dark"] {
  --diag-src-inv: #f0abfc;
  --diag-src-0: #83d8c6;
  --diag-src-1: #c9a7f5;
  --diag-src-2: #f4c773;
  --diag-src-3: #7dd3fc;
  --diag-src-4: #ffaaa1;
  --diag-src-5: #81d6a5;
  --diag-src-6: #d8b4fe;
  --diag-src-7: #a6b8b8;
  --diag-src-8: #f0abfc;
  --diag-src-9: #5eead4;
  --diag-heat-low: #ffaaa1;
  --diag-heat-mid: #344546;
  --diag-heat-high: #81d6a5;
  --diag-bit-both: #d8b4fe;
}

#view-diagnosis.diag-page {
  padding: 0 24px 22px;
  gap: 14px;
  overflow-anchor: none;
}

#view-diagnosis.diag-page > * {
  flex: 0 0 auto;
}

/* -------------------------------------------------------------------------
   Snapshot-Auswahl oben
   ------------------------------------------------------------------------- */

.diag-toolbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 0 5px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.diag-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 1 520px;
  min-width: 0;
}

.diag-picker .diag-select {
  flex: 1 1 340px;
  min-width: 0;
}

.diag-icon-btn {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  padding: 0 0 2px;
}

.diag-icon-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.diag-icon-btn:disabled {
  opacity: .4;
  cursor: default;
}

.diag-select {
  width: auto;
  height: 30px;
  min-height: 30px;
  margin: 0;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  min-width: 0;
}

.diag-count,
.diag-note {
  color: var(--text-mute);
  font-size: 12px;
  white-space: nowrap;
}

.diag-spacer { flex: 1 1 auto; }

.diag-device-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--text-mute);
  font-size: 12px;
  white-space: nowrap;
}

.diag-device-label .diag-select {
  width: 190px;
  min-width: 190px;
  max-width: 260px;
}

.diag-toolbar .btn-sm {
  height: 30px;
  min-height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
}

#diag-message {
  padding: 6px 2px;
  text-align: left;
  font-size: 13px;
}

#diag-message.error { color: var(--err); }

/* -------------------------------------------------------------------------
   Kopf, Badges und Metazeile
   ------------------------------------------------------------------------- */

.diag-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 2px;
}

.diag-heading-text { min-width: 0; }

.diag-subtitle {
  margin: 0;
  color: var(--text);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -.02em;
  line-height: 1.25;
}

.diag-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.diag-badge.ok { background: var(--ok-bg); color: var(--ok); }
.diag-badge.warn { background: var(--warn-bg); color: var(--warn); }
.diag-badge.neutral { background: var(--surface-2); color: var(--text-dim); }

.diag-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 24px;
  padding: 0 2px;
  color: var(--text-dim);
  font-size: 12.5px;
}

.diag-meta-entry {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.diag-meta-key {
  color: var(--text-mute);
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.diag-meta-val { overflow-wrap: anywhere; }

/* -------------------------------------------------------------------------
   Gemeinsame Diagrammflaeche
   ------------------------------------------------------------------------- */

.diag-surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(25, 43, 45, .025);
  overflow: hidden;
}

:root[data-theme="dark"] .diag-surface {
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
}

.diag-surface-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.diag-chips {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.diag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
}

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

.diag-chip.active {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  color: var(--accent);
}

.diag-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.diag-chip-warn {
  display: inline-grid;
  place-items: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}

.diag-surface-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px 10px;
  min-width: 0;
}

.diag-surface-actions .btn[href] { text-decoration: none; }

/* -------------------------------------------------------------------------
   Chart-Raster
   ------------------------------------------------------------------------- */

.diag-charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--border);
}

.diag-chart-section {
  min-width: 0;
  background: var(--surface);
  padding: 14px 16px 10px;
}

.diag-chart-section.full { grid-column: 1 / -1; }

.diag-chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px 12px;
  flex-wrap: wrap;
  margin-bottom: 3px;
}

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

.diag-chart-title h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -.005em;
}

.diag-chart-unit {
  margin-left: 5px;
  color: var(--text-mute);
  font-weight: 500;
  font-size: 11px;
}

.diag-chart-head-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 4px 10px;
  min-width: 0;
}

.diag-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 3px 9px;
  color: var(--text-dim);
  font-size: 10.5px;
}

.diag-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.diag-legend-line {
  width: 16px;
  height: 2px;
  border-radius: 2px;
  background: var(--c);
  flex: 0 0 auto;
}

.diag-legend-line.dashed {
  height: 0;
  border-top: 2px dashed var(--c);
  background: none;
  border-radius: 0;
}

.diag-legend-band {
  width: 16px;
  height: 8px;
  border-top: 1px solid var(--c);
  border-bottom: 1px solid var(--c);
  background: color-mix(in srgb, var(--c) 20%, transparent);
  border-radius: 2px;
  flex: 0 0 auto;
}

.diag-legend-multi {
  width: 16px;
  height: 8px;
  border-radius: 2px;
  background: linear-gradient(90deg,
    var(--ok) 0 25%,
    var(--warn) 25% 50%,
    var(--err) 50% 75%,
    var(--diag-bit-both) 75% 100%);
  flex: 0 0 auto;
}

.diag-bit-key {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 3px 8px;
  color: var(--text-mute);
  font-size: 10px;
}

.diag-bit-key-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.diag-bit-key-item i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.diag-bit-key-item i.ok { background: var(--ok); }
.diag-bit-key-item i.warn { background: var(--warn); }
.diag-bit-key-item i.err { background: var(--err); }
.diag-bit-key-item i.both { background: var(--diag-bit-both); }

.diag-chart-body {
  width: 100%;
  min-width: 0;
  touch-action: pan-y;
}

.diag-chart-body .uplot {
  font-family: var(--sans);
}

.diag-chart-empty {
  min-height: 120px;
  display: grid;
  place-items: center;
  color: var(--text-mute);
  font-size: 12px;
  text-align: center;
  padding: 20px;
}

.diag-chart-note {
  color: var(--text-mute);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.diag-heat-tools {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.diag-heat-scale {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-mute);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.diag-heat-bar {
  width: 58px;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--diag-heat-low), var(--diag-heat-mid), var(--diag-heat-high));
}

.diag-select-sm {
  height: 28px;
  min-height: 28px;
  padding: 0 24px 0 7px;
  font-size: 11px;
  border-radius: 6px;
}

.diag-play {
  padding: 4px 9px;
  font-size: 11px;
  color: var(--accent);
  border-color: var(--border);
  background: var(--surface);
}

.diag-play:hover { background: var(--accent-soft); border-color: var(--accent); }

/* -------------------------------------------------------------------------
   DataDevice-Uebersicht
   ------------------------------------------------------------------------- */

.diag-device-overview {
  padding: 10px 16px 11px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.diag-overview-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.diag-overview-title {
  font-size: 12px;
  font-weight: 650;
}

.diag-overview-hint {
  color: var(--text-mute);
  font-size: 10.5px;
}

.diag-overview-scroll {
  overflow-x: auto;
  scrollbar-width: thin;
}

.diag-device-overview table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.diag-device-overview th {
  padding: 3px 10px 4px 0;
  color: var(--text-mute);
  font-size: 9.5px;
  font-weight: 650;
  letter-spacing: .05em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.diag-device-overview td {
  padding: 4px 10px 4px 0;
  border-top: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}

.diag-device-overview tbody tr {
  cursor: pointer;
}

.diag-device-overview tbody tr:hover td,
.diag-device-overview tbody tr:focus-visible td {
  background: var(--surface-2);
}

.diag-device-overview tbody tr.is-selected td {
  background: var(--accent-soft);
}

.diag-device-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  vertical-align: middle;
  font-weight: 600;
  line-height: 1;
}

.diag-overview-count {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.diag-overview-note {
  color: var(--warn);
  font-weight: 700;
}

.diag-badge.err {
  background: var(--err-bg);
  color: var(--err);
}

/* -------------------------------------------------------------------------
   Klickbare Legende und Umschalter
   ------------------------------------------------------------------------- */

button.diag-legend-item {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

button.diag-legend-item:hover { color: var(--text); }

button.diag-legend-item.is-hidden {
  opacity: .42;
  text-decoration: line-through;
}

.diag-seg {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.diag-seg button {
  padding: 3px 7px;
  border: 0;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 10.5px;
  cursor: pointer;
}

.diag-seg button + button { border-left: 1px solid var(--border); }
.diag-seg button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* -------------------------------------------------------------------------
   Schwebendes Tooltip
   ------------------------------------------------------------------------- */

.diag-tooltip {
  position: fixed;
  z-index: 120;
  display: none;
  max-width: 280px;
  padding: 7px 9px;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 6px 22px rgba(25, 43, 45, .16);
  font-size: 11px;
  line-height: 1.35;
  pointer-events: none;
}

:root[data-theme="dark"] .diag-tooltip {
  box-shadow: 0 6px 22px rgba(0, 0, 0, .4);
}

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

.diag-tip-title {
  margin-bottom: 3px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.diag-tip-note {
  margin-top: 2px;
  color: var(--text-dim);
  white-space: normal;
}

.diag-tip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.diag-tip-swatch {
  flex: 0 0 auto;
  width: 12px;
  height: 2px;
  border-radius: 2px;
  background: var(--c);
}

.diag-tip-swatch.dashed {
  height: 0;
  border-top: 2px dashed var(--c);
  border-radius: 0;
  background: none;
}

.diag-tip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diag-tip-value {
  margin-left: auto;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}


.diag-chart-body svg {
  display: block;
  width: 100%;
  height: auto;
  font-family: inherit;
  overflow: visible;
}

.diag-chart-body svg:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

/* -------------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------------- */

@media (max-width: 1100px) {
  #view-diagnosis.diag-page { padding-inline: 18px; }
}

@media (max-width: 900px) {
  .diag-charts { grid-template-columns: 1fr; }
  .diag-chart-section.full { grid-column: auto; }
}

@media (max-width: 860px) {
  #view-diagnosis.diag-page { padding: 0 14px 18px; }
}

@media (max-width: 680px) {
  .diag-toolbar { gap: 8px; }
  .diag-picker { flex: 1 1 100%; }
  .diag-picker .diag-select { flex: 1 1 auto; }
  .diag-device-label { flex: 1 1 auto; }
  .diag-device-label .diag-select { max-width: none; width: 100%; }
  .diag-heading { flex-direction: column; align-items: flex-start; gap: 8px; }
  .diag-subtitle { font-size: 19px; }
  .diag-surface-head { padding: 9px 12px; }
  .diag-surface-actions { justify-content: flex-start; }
  .diag-device-overview { padding: 9px 12px 10px; }
  .diag-chart-section { padding: 12px 12px 8px; }
  .diag-chart-head { flex-direction: column; gap: 4px; }
  .diag-chart-head-right { justify-content: flex-start; }
  .diag-legend { justify-content: flex-start; }
}
