:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-soft: #f7f9fc;
  --text: #333;
  --muted: #6b7280;
  --border: #e6ebf2;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  --shadow-soft: 0 8px 24px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

.chart-legend-note {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 8px 0 12px;
  font-size: 12px;
  color: #5f6b7a;
}

.chart-legend-note strong {
  color: #374151;
}

.chart-legend-note span {
  display: inline-block;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  margin: 0;
  padding: 24px;
  background: var(--bg);
  color: var(--text);
}

h1 {
  margin: 0 0 10px;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  line-height: 1.15;
}

h3 {
  margin: 0 0 6px;
  font-size: 1rem;
  line-height: 1.3;
  color: #243245;
}

.page-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.top-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.doc-link-button {
  display: inline-block;
  padding: 10px 14px;
  border-radius: 8px;
  background: #4e79a7;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.doc-link-button:hover {
  background: #365b82;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

input {
  padding: 10px 12px;
  width: min(320px, 100%);
  border-radius: 8px;
  border: 1px solid #ccc;
  background: #fff;
}

button {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: #4e79a7;
  color: white;
  cursor: pointer;
  font-weight: 600;
}

button:hover {
  background: #365b82;
}

.controls-hint {
  color: #666;
  font-size: 14px;
  margin: 4px 0 18px;
}

.cards,
.grid {
  display: grid;
  gap: 20px;
  width: 100%;
  min-width: 0;
}

.cards {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
}

.grid {
  margin-top: 20px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cards > *,
.grid > * {
  min-width: 0;
}

.panel,
.metric-card {
  background: var(--panel);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(230, 235, 242, 0.9);
  min-width: 0;
  overflow: hidden;
}

.panel {
  position: relative;
}

.panel-wide {
  grid-column: 1 / -1;
}

.metric-card {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  text-align: center;
  min-height: 180px;
}

.metric-title {
  font-size: 13px;
  color: #666;
  line-height: 1.25;
  margin-bottom: 8px;
}

.metric-value {
  font-size: clamp(2rem, 3vw, 2.5rem);
  font-weight: 700;
  line-height: 1.05;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.metric-value-compact {
  font-size: clamp(1.25rem, 2vw, 1.8rem);
}

.card-desc {
  font-size: 12px;
  color: #777;
  margin-top: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: clamp(300px, 36vw, 420px);
  min-height: 300px;
  max-height: 420px;
  margin-top: 6px;
}

.chart-wrap.chart-wrap-tall {
  height: clamp(340px, 42vw, 520px);
  min-height: 340px;
  max-height: 520px;
}

.chart-wrap.chart-wrap-compact {
  height: clamp(260px, 30vw, 340px);
  min-height: 260px;
  max-height: 340px;
}

.panel canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.panel-header-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.summary-mini-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  width: min(100%, 460px);
  min-width: 0;
}

.summary-mini-card {
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  min-width: 0;
}

.mini-value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 6px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.mini-label {
  font-size: 18px;
  line-height: 1.2;
}

.fix-table-wrap {
  overflow-x: auto;
  width: 100%;
}

.fix-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 14px;
}

.fix-table th,
.fix-table td {
  text-align: left;
  padding: 8px 8px;
  border-top: 1px solid #edf1f6;
  vertical-align: top;
}

.fix-table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-top: none;
  padding-top: 20px;
}

.fix-table tbody tr {
  cursor: pointer;
}

.fix-table tbody tr:hover {
  background: #f8fbff;
}

.inventory-detail-copy {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.rank-pill,
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.rank-pill {
  background: #eef3f9;
  color: #355070;
}

.badge-critical {
  background: #fdeaea;
  color: #a33a3a;
}

.badge-serious {
  background: #fff0e2;
  color: #a35a1d;
}

.badge-moderate {
  background: #fff8dc;
  color: #8a6b00;
}

.badge-minor {
  background: #eaf2ff;
  color: #355c9a;
}

.badge-unknown {
  background: #eef2f7;
  color: #55606e;
}

.badge-systemic {
  background: #e9f7ef;
  color: #2f6b46;
}

.badge-local {
  background: #f1f3f5;
  color: #5c6773;
}

.priority-cell strong {
  display: block;
  margin-bottom: 6px;
}

.priority-bar {
  width: 100%;
  height: 8px;
  background: #edf1f6;
  border-radius: 999px;
  overflow: hidden;
}

.priority-fill {
  height: 100%;
  background: linear-gradient(90deg, #4e79a7 0%, #76b7b2 100%);
  border-radius: 999px;
}

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

.inventory-summary-note {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  border: 1px solid var(--border);
}

.inventory-ok {
  background: #eef8f2;
  color: #2f6b46;
}

.inventory-warn {
  background: #fff4ea;
  color: #9a5a18;
}

.inventory-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.inventory-metric-card {
  width: 100%;
}

.metric-stack {
  margin-top: 4px;
  line-height: 1.25;
}

.metric-stack-row {
  display: block;
  font-size: clamp(1.15rem, 1.8vw, 1.5rem);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.legacy-frames-card {
  text-align: center;
}

#frame_issues {
  display: block;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.15;
  margin-top: 8px;
}

#frame_pages {
  display: block;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  margin-top: 4px;
}

.legacy-frame-pages-list,
#frame_pages_list {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #edf1f6;
  text-align: left;
  font-size: 11px;
  line-height: 1.45;
  color: #5f6368;
  max-width: 100%;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.legacy-frames-card .metric-title {
  text-align: center;
}

#drilldown {
  margin-top: 30px;
}

@media (max-width: 900px) {
  body {
    padding: 18px;
  }

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

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

  .chart-wrap {
    height: clamp(260px, 44vw, 360px);
    min-height: 260px;
  }

  .chart-wrap.chart-wrap-tall {
    height: clamp(300px, 52vw, 440px);
    min-height: 300px;
  }

  .summary-mini-cards {
    width: 100%;
  }
}

@media (max-width: 640px) {
  body {
    padding: 14px;
  }

  .page-topbar {
    align-items: stretch;
  }

  .top-links {
    justify-content: flex-start;
  }

  .panel,
  .metric-card {
    padding: 16px;
    border-radius: 12px;
  }

  .cards,
  .grid {
    gap: 14px;
  }

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

  .chart-wrap {
    height: clamp(220px, 54vw, 300px);
    min-height: 220px;
  }

  .chart-wrap.chart-wrap-tall {
    height: clamp(260px, 64vw, 360px);
    min-height: 260px;
  }

  .fix-table {
    min-width: 640px;
  }

  #frame_pages_list {
    font-size: 10px;
  }

  #top5_pages_list {
    font-size: 11px;
    line-height: 1.45;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}
