:root {
  --bg: #f7f8fa;
  --bg-elev: #ffffff;
  --fg: #14171a;
  --fg-soft: #3a4047;
  --muted: #6a7480;
  --line: #e1e5ea;
  --line-strong: #cbd2da;
  --accent: #1f5eff;
  --accent-soft: #e6efff;
  --critical: #c20505;
  --high: #d96a00;
  --medium: #b58a00;
  --low: #1f7a32;
  --info: #4d586a;
  --chip-bg: #e9eef5;
  --chip-bg-hover: #dde4ee;
  --shadow: 0 1px 2px rgba(15, 22, 36, 0.04), 0 4px 12px rgba(15, 22, 36, 0.04);
  --radius: 8px;
  --bar: var(--accent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-elev: #161b22;
    --fg: #e6edf3;
    --fg-soft: #c9d1d9;
    --muted: #8b949e;
    --line: #2a3138;
    --line-strong: #3b424a;
    --accent: #6aa8ff;
    --accent-soft: #1f2c4a;
    --critical: #ff7370;
    --high: #ff9a40;
    --medium: #d4c14b;
    --low: #6fd17a;
    --info: #adb5bd;
    --chip-bg: #1d2530;
    --chip-bg-hover: #2a3340;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.25);
    --bar: var(--accent);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--chip-bg);
  padding: 1px 6px;
  border-radius: 4px;
}

/* ----------------------------- Header ----------------------------- */
.masthead {
  padding: 1.75rem 0 1.25rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
}
.title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}
.masthead h1 {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.subtitle {
  max-width: 72rem;
  color: var(--fg-soft);
  margin: 0.4rem 0 0;
  font-size: 0.95rem;
}
.links {
  margin: 0;
  font-size: 0.875rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.links a { color: var(--fg-soft); }
.links a:hover { color: var(--accent); }
.links code {
  background: transparent;
  border: 1px solid var(--line);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8em;
}

main.wrap { padding-top: 1.5rem; padding-bottom: 3rem; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: 2rem 0 0.75rem;
}
.section-head h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.005em;
}
.section-head .hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}
section.stats { margin-top: 0.5rem; }
section.stats + .section-head { margin-top: 2rem; }

/* ----------------------------- Stats hero ----------------------------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
  margin: 1.25rem 0 0.5rem;
}
.stat {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
}
.stat .num {
  display: block;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.stat .label {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.stat .sub {
  display: block;
  margin-top: 0.1rem;
  font-size: 0.78rem;
  color: var(--muted);
}

/* ----------------------------- Severity legend ----------------------------- */
.sev-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.1rem;
  margin: 0.1rem 0 0.25rem;
  padding: 0 0.15rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.sev-key {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.sev-key .dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: currentColor;
}

/* ----------------------------- Buttons ----------------------------- */
.btn-secondary {
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.btn-secondary:disabled { opacity: 0.5; cursor: default; }
.head-right {
  display: flex;
  align-items: center;
  gap: 0.6rem 1rem;
  flex-wrap: wrap;
}
.head-right .hint { margin: 0; }

/* ----------------------------- CTA row ----------------------------- */
.cta-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1.2rem;
  margin: 1rem 0 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}
.cta {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--accent);
  color: white;
  padding: 7px 14px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  white-space: nowrap;
}
.cta:hover { background: var(--fg); color: var(--bg-elev); text-decoration: none; }
.cta-hint { color: var(--fg-soft); font-size: 0.88rem; }

/* ----------------------------- Charts ----------------------------- */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 0.85rem;
}
.chart-card {
  margin: 0;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem 0.9rem;
  box-shadow: var(--shadow);
}
/* Default: wide charts span two columns on medium+ screens, full on small */
.chart-card.chart-wide { grid-column: span 2; }
@media (max-width: 760px) { .chart-card.chart-wide { grid-column: auto; } }
.chart-card figcaption {
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 0.4rem;
  color: var(--fg);
}
.chart {
  width: 100%;
  min-height: 140px;
  position: relative;
}
.chart svg { display: block; width: 100%; height: auto; }
.chart .bar { cursor: pointer; transition: opacity 0.12s; }
.chart .bar:hover { opacity: 0.78; }
.chart .axis-label,
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .value-label { fill: var(--muted); font-size: 11px; }
.chart .row-label { fill: var(--fg-soft); font-size: 12px; }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--fg);
  color: var(--bg-elev);
  padding: 6px 9px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -120%);
  transition: opacity 0.08s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  z-index: 10;
}
.chart-tooltip.visible { opacity: 1; }

/* ----------------------------- Filters ----------------------------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.9rem;
  margin: 0.5rem 0 0.5rem;
  padding: 0.9rem 1rem;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.filter { display: flex; flex-direction: column; gap: 3px; }
.filter label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}
.filter input[type="search"],
.filter select {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 7px 9px;
  font: inherit;
  font-size: 0.9rem;
  min-width: 8.5rem;
}
.filter input[type="search"]:focus,
.filter select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.filter-search input[type="search"] { min-width: 18rem; }
.filter-toggle { justify-content: flex-end; padding-bottom: 0.3rem; }
.filter-toggle label {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--fg);
}
.filter-toggle input[type="checkbox"] {
  margin-right: 0.4rem;
  vertical-align: -2px;
  accent-color: var(--accent);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0 0.75rem;
  min-height: 1.5rem;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 3px 9px 3px 11px;
  background: var(--chip-bg);
  color: var(--fg-soft);
  border-radius: 999px;
  font-size: 0.82rem;
  border: 1px solid transparent;
}
.chip.chip-clear {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--muted);
  cursor: pointer;
}
.chip.chip-clear:hover { background: var(--chip-bg-hover); color: var(--fg); }
.chip .chip-key {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 0.15rem;
}
.chip button {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  margin-left: 2px;
}
.chip button:hover { color: var(--fg); }

/* ----------------------------- Table ----------------------------- */
.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  overflow-x: auto;
  box-shadow: var(--shadow);
}
.incidents {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.incidents th, .incidents td {
  text-align: left;
  vertical-align: top;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.incidents thead th {
  font-weight: 600;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line-strong);
  position: sticky;
  top: 0;
  z-index: 1;
}
.incidents tbody tr { cursor: pointer; }
.incidents tbody tr:hover { background: var(--accent-soft); }
.incidents tbody tr.expanded { background: var(--accent-soft); }
.incidents tbody tr.expanded td { border-bottom-color: transparent; }
.incidents td.date {
  white-space: nowrap;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  width: 6.5rem;
}
.incidents td.id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  white-space: nowrap;
}
.incidents td.id a { color: var(--fg); }
.incidents td.id a:hover { color: var(--accent); }
.incidents td.title-cell { line-height: 1.4; }
.incidents td.cves {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}
.incidents td.llm, .incidents td.asi {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.sev-badge {
  display: inline-block;
  min-width: 60px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: center;
  border: 1px solid currentColor;
}
.sev-Critical { color: var(--critical); }
.sev-High { color: var(--high); }
.sev-Medium { color: var(--medium); }
.sev-Low { color: var(--low); }
.sev-Info { color: var(--info); }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--fg); }
th.sortable .caret {
  display: inline-block;
  width: 0.7em;
  margin-left: 0.2em;
  opacity: 0.5;
}
th.sort-asc  .caret::after { content: "▲"; }
th.sort-desc .caret::after { content: "▼"; }
th.sort-asc, th.sort-desc { color: var(--fg); }
th.sort-asc .caret, th.sort-desc .caret { opacity: 1; }

/* Row expansion */
tr.detail td {
  padding: 0 10px 14px 10px;
  background: var(--accent-soft);
}
.detail-body {
  padding: 0.6rem 0.5rem 0.4rem;
  font-size: 0.9rem;
  color: var(--fg-soft);
  line-height: 1.55;
}
.detail-body p { margin: 0 0 0.5rem; }
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  margin-top: 0.3rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.detail-meta strong { color: var(--fg-soft); font-weight: 600; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.4rem; }
.detail-tags .tag {
  background: var(--chip-bg);
  color: var(--muted);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
}

/* ----------------------------- Pager ----------------------------- */
.pager {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.pager button {
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}
.pager button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.pager button:disabled { opacity: 0.4; cursor: default; }
.pager .pager-info {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

/* ----------------------------- Footer ----------------------------- */
footer {
  margin-top: 3rem;
  padding: 1.5rem 0 2rem;
  border-top: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--muted);
  font-size: 0.85rem;
}
footer .meta { margin-top: 0.4rem; }

/* ----------------------------- Shard pages ----------------------------- */
.shard-page main.shard-body {
  padding: 1.5rem 1.5rem 3rem;
  font-size: 0.95rem;
  color: var(--fg-soft);
}

.incident-anchor {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  margin: 0 0 1rem;
  box-shadow: var(--shadow);
  scroll-margin-top: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.incident-anchor.target {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow);
}
.incident-anchor h3 {
  margin: 0 0 0.3rem;
  font-size: 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.incident-anchor h3 + p strong {
  font-size: 1.05rem;
  color: var(--fg);
  font-weight: 600;
}
.incident-anchor em {
  color: var(--muted);
  font-size: 0.85rem;
  font-style: normal;
}
.incident-anchor p { margin: 0.4rem 0; line-height: 1.55; }
.incident-anchor ul {
  margin: 0.25rem 0 0.5rem;
  padding-left: 1.4rem;
}
.incident-anchor ul li { margin: 0.15rem 0; }
.incident-anchor a { word-break: break-word; }
.incident-anchor code {
  font-size: 0.82em;
  background: var(--chip-bg);
}

/* Make the inline metadata lines (Affected, Attack vector, OWASP, etc.)
 * read as a compact stack with bold labels but tighter spacing than the
 * default kramdown <br> behaviour gives. */
.incident-anchor p strong { color: var(--fg); }

.back-to-top {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  font-size: 1.2rem;
  font-weight: 700;
  text-decoration: none;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.18s, transform 0.18s;
  box-shadow: 0 4px 12px rgba(31, 94, 255, 0.4);
  z-index: 5;
}
.back-to-top.visible { opacity: 1; pointer-events: auto; transform: translateY(0); }
.back-to-top:hover { background: var(--fg); color: var(--bg-elev); text-decoration: none; }

/* ----------------------------- Mobile ----------------------------- */
@media (max-width: 720px) {
  .wrap { padding: 0 1rem; }
  .masthead h1 { font-size: 1.35rem; }
  .filter-search input[type="search"] { min-width: 100%; }
  .filter { flex: 1 1 calc(50% - 0.5rem); }
  .filter-toggle { flex-basis: 100%; }
  .chart-grid { grid-template-columns: 1fr; }
  .chart-card.chart-wide { grid-column: auto; }
  /* The horizontal-bar charts crowd the narrow viewport (long left-side
     labels eat most of the width). Hide the two least-essential ones on
     mobile so the page stays readable. They're still on desktop. */
  .chart-secondary { display: none; }
  .incidents { font-size: 0.85rem; }
  .incidents td.llm, .incidents td.asi { display: none; }
  .pager .pager-info { width: 100%; text-align: right; }
  .head-right { width: 100%; justify-content: space-between; }
}
