/* NPU EMI integration panel */
.npu-emi-legend {
  display: flex;
  gap: 18px;
  padding: 8px 6px;
  font-size: 12px;
  opacity: 0.85;
  border-bottom: 1px solid #222;
  margin-bottom: 6px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-line {
  width: 18px;
  height: 2px;
  display: inline-block;
}

.legend-line.white {
  background: #ffffff;
}

.legend-line.purple {
  background: #a855f7;
}

.legend-box {
  width: 12px;
  height: 12px;
  display: inline-block;
  border-radius: 2px;
}

.legend-box.red {
  background: rgba(255, 0, 0, 0.6);
  border: 1px solid #ff0000;
}

.npu-emi-btn {
  background: #1f2937;
  border: 1px solid #374151;
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}

.npu-emi-btn:hover {
  background: #374151;
}
.npu-emi-marker-row {
  min-height: 44px;
  box-sizing: border-box;
  cursor: pointer;
  display: grid;
  grid-template-columns: 120px 1fr 100px;
  gap: 12px;
  align-items: center;
}

.npu-emi-marker-row:hover {
  background: rgba(96, 165, 250, 0.08);
}

.npu-emi-marker-row.fail {
  border-color: rgba(239, 68, 68, 0.8);
  background: rgba(239, 68, 68, 0.08);
}

.marker-left .freq {
  font-weight: 800;
  font-size: 13px;
}

.marker-left .sub {
  opacity: 0.75;
  font-size: 11px;
}

.marker-left .harmonic {
  color: #c084fc;
}

.marker-center .label {
  font-weight: 700;
}

.marker-center .note {
  opacity: 0.75;
  font-size: 11px;
}

.marker-right {
  text-align: right;
}

.marker-right .severity {
  font-weight: 900;
}

.marker-right .severity.fail {
  color: #ef4444;
}

.marker-right .severity.critical {
  color: #ef4444;
}

.marker-right .severity.high {
  color: #f97316;
}

.marker-right .severity.warning {
  color: #fbbf24;
}

.marker-right .severity.watch {
  color: #38bdf8;
}

.marker-right .margin {
  font-size: 12px;
}

.marker-right .margin-label {
  font-size: 10px;
  opacity: 0.65;
}
.npu-emi-marker-row {
  display: flex;
  justify-content: space-between;
  padding: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.marker-left .freq {
  font-size: 14px;
  font-weight: bold;
}

.marker-left .band {
  font-size: 11px;
  opacity: 0.6;
}

.marker-center .label {
  font-weight: 500;
}

.marker-center .note {
  font-size: 11px;
  opacity: 0.7;
}

.marker-right {
  text-align: right;
}

.severity {
  font-weight: bold;
}

.severity.watch { color: #38bdf8; }
.severity.warning { color: #fbbf24; }
.severity.high { color: #f97316; }
.severity.critical { color: #ef4444; }

.margin {
  font-size: 12px;
  opacity: 0.8;
}
#npuEmiPanel {
  margin: 10px 0 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(15,23,42,0.94), rgba(8,13,24,0.98));
  border: 1px solid rgba(96,165,250,0.22);
  color: #e5e7eb;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 10px 24px rgba(0,0,0,0.22);
}
#npuEmiPanel.npu-emi-anomaly {
  border-color: rgba(248,113,113,0.45);
  box-shadow: 0 0 0 1px rgba(248,113,113,0.12), 0 10px 24px rgba(0,0,0,0.25);
}
.npu-emi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.npu-emi-title {
  font-weight: 800;
  color: #f8fafc;
}
.npu-emi-subtitle {
  margin-top: 2px;
  font-size: 12px;
  color: #9fb2d8;
}
.npu-emi-pill {
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: rgba(148,163,184,0.16);
  color: #cbd5e1;
  border: 1px solid rgba(148,163,184,0.18);
}
.npu-emi-pill.ok {
  background: rgba(34,197,94,0.12);
  color: #86efac;
  border-color: rgba(34,197,94,0.28);
}
.npu-emi-pill.warn {
  background: rgba(239,68,68,0.14);
  color: #fecaca;
  border-color: rgba(239,68,68,0.34);
}
.npu-emi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}
.npu-emi-grid div {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  border: 1px solid rgba(255,255,255,0.055);
}
.npu-emi-grid span {
  display: block;
  font-size: 11px;
  color: #94a3b8;
  margin-bottom: 2px;
}
.npu-emi-grid b {
  color: #f8fafc;
  font-size: 13px;
}

.npu-emi-bars {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px 12px;
  margin-top: 12px;
}

.npu-emi-bars label {
  display: grid;
  grid-template-columns: 78px 1fr 48px;
  align-items: center;
  gap: 8px;
  color: #cbd5e1;
  font-size: 12px;
}

.npu-emi-bars meter {
  width: 100%;
  height: 10px;
}

.npu-emi-section-title {
  margin-top: 14px;
  margin-bottom: 8px;
  color: #e5e7eb;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.npu-emi-markers {
  display: grid;
  gap: 6px;
  height: calc((56px * 5) + (6px * 4));
  overflow-y: auto;
}

.npu-emi-marker-row {
  display: grid;
  grid-template-columns: 110px 1fr 54px 88px;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(15, 23, 42, 0.55);
  color: #dbeafe;
  font-size: 12px;
}

.npu-emi-marker-row.critical,
.npu-emi-marker-row.high {
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(127, 29, 29, 0.28);
}

.npu-emi-marker-row.warning {
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(113, 63, 18, 0.24);
}

.npu-emi-empty {
  color: #94a3b8;
  font-size: 12px;
  padding: 8px 0;
}


/* Fix NPU EMI label/marker text collisions and empty metric layout */
.npu-emi-marker-row,
.npu-emi-marker-row.source {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
}

.npu-emi-marker-row.source {
  display: grid;
  grid-template-columns: minmax(180px, 280px) minmax(0, 1fr) 90px;
  gap: 14px;
  align-items: center;
}

.npu-emi-marker-row .marker-left,
.npu-emi-marker-row .marker-center,
.npu-emi-marker-row .marker-right {
  min-width: 0;
}

.npu-emi-marker-row .freq,
.npu-emi-marker-row .label,
.npu-emi-marker-row .note,
.npu-emi-marker-row .sub {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.npu-emi-marker-row.source .marker-left .freq {
  white-space: normal;
  line-height: 1.2;
}

.npu-emi-bars label {
  min-width: 0;
}

.npu-emi-bars b {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 700px) {
  .npu-emi-marker-row.source {
    grid-template-columns: 1fr;
  }

  .npu-emi-marker-row.source .marker-right {
    text-align: left;
  }
}


/* ==========================================================================
   Per-frequency diagnosis: stable five-row viewport + top pagination
   ========================================================================== */
.npu-frequency-diagnosis {
  --npu-frequency-card-height: 202px;
  --npu-frequency-card-gap: 10px;
  width: 100%;
  box-sizing: border-box;
}

.npu-frequency-pagination {
  display: grid;
  grid-template-columns: auto minmax(150px, auto) 1fr auto;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  min-height: 42px;
  padding: 7px 9px;
  box-sizing: border-box;
  border: 1px solid rgba(125, 211, 252, 0.15);
  border-radius: 14px;
  background: rgba(3, 8, 18, 0.58);
}

.npu-frequency-pagination button {
  min-width: 72px;
  height: 30px;
  padding: 0 11px;
  border: 1px solid rgba(125, 211, 252, 0.22);
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.08);
  color: #dff7ff;
  font-size: 10px;
  font-weight: 900;
  cursor: pointer;
}

.npu-frequency-pagination button:hover:not(:disabled),
.npu-frequency-pagination button.active {
  border-color: rgba(34, 211, 238, 0.62);
  background: rgba(34, 211, 238, 0.18);
  color: #ffffff;
}

.npu-frequency-pagination button:disabled {
  cursor: default;
  opacity: 0.34;
}

.npu-frequency-page-status {
  display: grid;
  gap: 1px;
  min-width: 145px;
}

.npu-frequency-page-status b {
  color: #f8fafc;
  font-size: 11px;
}

.npu-frequency-page-status span {
  color: #8fa5bf;
  font-size: 9px;
}

.npu-frequency-page-buttons {
  display: flex;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.npu-frequency-page-buttons button {
  min-width: 30px;
  width: 30px;
  padding: 0;
}

.npu-frequency-diagnosis-list.npu-frequency-fixed-five {
  display: grid;
  grid-template-rows: repeat(5, var(--npu-frequency-card-height));
  gap: var(--npu-frequency-card-gap);
  height: calc(
    (5 * var(--npu-frequency-card-height)) +
    (4 * var(--npu-frequency-card-gap))
  );
  min-height: calc(
    (5 * var(--npu-frequency-card-height)) +
    (4 * var(--npu-frequency-card-gap))
  );
  max-height: calc(
    (5 * var(--npu-frequency-card-height)) +
    (4 * var(--npu-frequency-card-gap))
  );
  overflow: hidden;
  box-sizing: border-box;
  contain: layout paint;
}

.npu-frequency-fixed-five .npu-frequency-diagnosis-card {
  height: var(--npu-frequency-card-height);
  min-height: var(--npu-frequency-card-height);
  max-height: var(--npu-frequency-card-height);
  overflow: hidden;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.npu-frequency-fixed-five .npu-frequency-label-group {
  margin-top: 7px;
}

.npu-frequency-fixed-five .npu-frequency-label-group > div {
  max-height: 29px;
  overflow: hidden;
}

.npu-frequency-diagnosis-placeholder {
  pointer-events: none;
  cursor: default;
  border-style: dashed !important;
  border-color: rgba(125, 211, 252, 0.10) !important;
  background:
    linear-gradient(90deg, rgba(56,189,248,.025), rgba(255,255,255,.015)) !important;
  opacity: 0.46;
  justify-content: center !important;
  gap: 12px;
}

.npu-frequency-placeholder-line,
.npu-frequency-placeholder-block {
  display: block;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.10);
}

.npu-frequency-placeholder-line { height: 9px; }
.npu-frequency-placeholder-line.wide { width: 36%; }
.npu-frequency-placeholder-line.medium { width: 24%; }
.npu-frequency-placeholder-line.short { width: 18%; }
.npu-frequency-placeholder-block {
  width: 100%;
  height: 36px;
  border-radius: 10px;
}

@media (max-width: 760px) {
  .npu-frequency-diagnosis {
    --npu-frequency-card-height: 250px;
  }

  .npu-frequency-pagination {
    grid-template-columns: auto 1fr auto;
  }

  .npu-frequency-page-status {
    text-align: center;
  }

  .npu-frequency-page-buttons {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}


/* ==========================================================================
   Global AI classification: stable four-row viewport
   ========================================================================== */
.npu-global-ai-classification {
  --npu-global-row-height: 50px;
  --npu-global-row-gap: 2px;
  width: 100%;
  box-sizing: border-box;
  margin-top: 12px;
}

.npu-global-ai-list {
  display: grid;
  grid-template-rows: repeat(4, var(--npu-global-row-height));
  gap: var(--npu-global-row-gap);
  height: calc(
    (4 * var(--npu-global-row-height)) +
    (3 * var(--npu-global-row-gap))
  );
  min-height: calc(
    (4 * var(--npu-global-row-height)) +
    (3 * var(--npu-global-row-gap))
  );
  max-height: calc(
    (4 * var(--npu-global-row-height)) +
    (3 * var(--npu-global-row-gap))
  );
  overflow: hidden;
  box-sizing: border-box;
  contain: layout paint;
}

.npu-global-ai-row {
  height: var(--npu-global-row-height);
  min-height: var(--npu-global-row-height);
  max-height: var(--npu-global-row-height);
  display: grid;
  grid-template-columns: minmax(210px, 280px) 1fr 90px;
  align-items: center;
  gap: 14px;
  padding: 7px 10px;
  box-sizing: border-box;
  border: 1px solid rgba(125, 211, 252, 0.12);
  border-radius: 11px;
  background: rgba(15, 23, 42, 0.46);
  overflow: hidden;
  cursor: pointer;
}

.npu-global-ai-row:hover {
  border-color: rgba(56, 189, 248, 0.34);
  background: rgba(56, 189, 248, 0.07);
}

.npu-global-ai-left,
.npu-global-ai-center {
  min-width: 0;
  overflow: hidden;
}

.npu-global-ai-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #f8fafc;
  font-size: 13px;
  font-weight: 900;
}

.npu-global-ai-confidence {
  margin-top: 1px;
  color: #9fb3cc;
  font-size: 10px;
}

.npu-global-ai-kind {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #dbeafe;
  font-size: 11px;
  font-weight: 800;
}

.npu-global-ai-description {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
  color: #8fa5bf;
  font-size: 9px;
}

.npu-global-ai-right {
  text-align: right;
}

.npu-global-ai-severity {
  font-size: 11px;
  font-weight: 950;
}

.npu-global-ai-severity.high {
  color: #fb3b4b;
}

.npu-global-ai-severity.medium {
  color: #f59e0b;
}

.npu-global-ai-severity.low {
  color: #dbeafe;
}

.npu-global-ai-placeholder {
  pointer-events: none;
  cursor: default;
  opacity: 0.42;
  border-style: dashed;
  border-color: rgba(125, 211, 252, 0.10);
  background: linear-gradient(
    90deg,
    rgba(56, 189, 248, 0.025),
    rgba(255, 255, 255, 0.012)
  );
}

.npu-global-ai-placeholder-line {
  height: 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.10);
}

.npu-global-ai-placeholder-line.wide {
  width: 52%;
}

.npu-global-ai-placeholder-line.medium {
  width: 34%;
}

.npu-global-ai-placeholder-line.short {
  width: 48px;
  justify-self: end;
}

@media (max-width: 760px) {
  .npu-global-ai-classification {
    --npu-global-row-height: 62px;
  }

  .npu-global-ai-row {
    grid-template-columns: minmax(130px, 1fr) 1fr 62px;
    gap: 8px;
  }
}


/* ==========================================================================
   NPU summary metrics: stable two-row, twenty-slot viewport
   ========================================================================== */
.npu-emi-grid.npu-emi-grid-fixed {
  --npu-summary-row-height: 58px;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(2, var(--npu-summary-row-height));
  gap: 8px;
  height: calc((2 * var(--npu-summary-row-height)) + 8px);
  min-height: calc((2 * var(--npu-summary-row-height)) + 8px);
  max-height: calc((2 * var(--npu-summary-row-height)) + 8px);
  overflow: hidden;
  box-sizing: border-box;
  contain: layout paint;
}

.npu-emi-grid.npu-emi-grid-fixed .npu-emi-metric {
  min-width: 0;
  height: var(--npu-summary-row-height);
  min-height: var(--npu-summary-row-height);
  max-height: var(--npu-summary-row-height);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 8px 10px;
  box-sizing: border-box;
  overflow: hidden;
}

.npu-emi-grid.npu-emi-grid-fixed .npu-emi-metric span,
.npu-emi-grid.npu-emi-grid-fixed .npu-emi-metric b {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.npu-emi-grid.npu-emi-grid-fixed .npu-emi-metric b {
  line-height: 1.25;
}

.npu-emi-grid.npu-emi-grid-fixed .npu-emi-metric-placeholder {
  pointer-events: none;
  border-style: dashed;
  border-color: rgba(125, 211, 252, 0.08);
  background:
    linear-gradient(90deg, rgba(56,189,248,.02), rgba(255,255,255,.012));
  opacity: .42;
}

.npu-emi-grid.npu-emi-grid-fixed .npu-emi-metric-placeholder span,
.npu-emi-grid.npu-emi-grid-fixed .npu-emi-metric-placeholder b {
  border-radius: 999px;
  background: rgba(148,163,184,.10);
}

.npu-emi-grid.npu-emi-grid-fixed .npu-emi-metric-placeholder span {
  width: 48%;
  height: 7px;
  margin-bottom: 8px;
}

.npu-emi-grid.npu-emi-grid-fixed .npu-emi-metric-placeholder b {
  width: 72%;
  height: 11px;
}

@media (max-width: 1500px) {
  .npu-emi-grid.npu-emi-grid-fixed {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-template-rows: repeat(4, var(--npu-summary-row-height));
    height: calc((4 * var(--npu-summary-row-height)) + (3 * 8px));
    min-height: calc((4 * var(--npu-summary-row-height)) + (3 * 8px));
    max-height: calc((4 * var(--npu-summary-row-height)) + (3 * 8px));
  }
}

@media (max-width: 900px) {
  .npu-emi-grid.npu-emi-grid-fixed {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(10, var(--npu-summary-row-height));
    height: calc((10 * var(--npu-summary-row-height)) + (9 * 8px));
    min-height: calc((10 * var(--npu-summary-row-height)) + (9 * 8px));
    max-height: calc((10 * var(--npu-summary-row-height)) + (9 * 8px));
  }
}


/* ==========================================================================
   Final live-render scroll anchoring fix
   ========================================================================== */
#npuEmiPanel,
#npuEmiPanel *,
.npu-global-ai-classification,
.npu-frequency-diagnosis,
.npu-limits-threshold-summary {
  overflow-anchor: none !important;
}

#npuEmiPanel {
  contain: layout style;
}

/* Keep dynamic text changes from altering metric/card geometry. */
#npuEmiPanel b,
#npuEmiPanel strong,
#npuEmiPanel span,
#npuEmiPanel p,
#npuEmiPanel label,
#npuEmiPanel i,
#npuEmiPanel em {
  min-width: 0;
}

.npu-emi-grid-fixed,
.npu-global-ai-list,
.npu-frequency-fixed-five {
  content-visibility: visible;
}

/* Prevent late font wrapping from changing any fixed panel height. */
.npu-emi-grid-fixed .npu-emi-metric,
.npu-global-ai-row,
.npu-frequency-fixed-five .npu-frequency-diagnosis-card {
  overflow-wrap: normal;
  word-break: normal;
}


/* ==========================================================================
   Hard outer height + non-collapsing inference status
   ========================================================================== */
#npuEmiPanel {
  --npu-hard-panel-height: 1180px;
  position: relative !important;
  height: var(--npu-hard-panel-height) !important;
  min-height: var(--npu-hard-panel-height) !important;
  max-height: var(--npu-hard-panel-height) !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  box-sizing: border-box !important;
  scrollbar-gutter: stable both-edges;
  overscroll-behavior: contain;
  contain: size layout paint style;
}

/* Status is an overlay; it never replaces or collapses the full result panel. */
.npu-live-status-overlay {
  position: sticky;
  top: 0;
  z-index: 200;
  display: block;
  width: 100%;
  pointer-events: none;
}

.npu-live-status-card {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  box-sizing: border-box;
  border: 1px solid rgba(125, 211, 252, .30);
  border-radius: 14px;
  background: rgba(7, 16, 31, .96);
  box-shadow: 0 14px 36px rgba(0, 0, 0, .35);
  backdrop-filter: blur(12px);
}

.npu-live-status-card.error {
  border-color: rgba(248, 113, 113, .48);
}

.npu-status-active > :not(.npu-live-status-overlay) {
  opacity: .68;
}

/* First-run shell reserves the same full outer height before any NPU response. */
.npu-status-reserved-shell {
  position: absolute;
  inset: 82px 14px 14px;
  display: grid;
  grid-template-rows: 52px 126px 245px 230px 1fr;
  gap: 14px;
  pointer-events: none;
  overflow: hidden;
}

.npu-status-skeleton-header,
.npu-status-skeleton-grid,
.npu-status-skeleton-block {
  border: 1px dashed rgba(125, 211, 252, .10);
  border-radius: 16px;
  background:
    linear-gradient(90deg, rgba(56,189,248,.025), rgba(255,255,255,.012));
}

.npu-status-skeleton-grid {
  background:
    repeating-linear-gradient(
      90deg,
      rgba(56,189,248,.025) 0,
      rgba(56,189,248,.025) calc(10% - 4px),
      transparent calc(10% - 4px),
      transparent 10%
    );
}

.npu-status-skeleton-block.medium,
.npu-status-skeleton-block.small,
.npu-status-skeleton-block.large {
  width: 100%;
}

/* Preserve a stable height at responsive breakpoints too. */
@media (max-width: 1500px) {
  #npuEmiPanel {
    --npu-hard-panel-height: 1320px;
  }
}

@media (max-width: 900px) {
  #npuEmiPanel {
    --npu-hard-panel-height: 1500px;
  }
}
