/* Local IBM Plex — latin+cyrillic subsets, one file per face (no unicode-range swap) */
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/plex-sans-400.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/plex-sans-500.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans Condensed";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/plex-condensed-600.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans Condensed";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/plex-condensed-700.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/plex-mono-500.woff2") format("woff2");
}

:root {
  --ink: #14100D;
  --paper: #F2EFEA;
  --card: #FFFFFF;
  --accent: #C1121F;
  --muted: #6E6660;
  --rule: #DDD7D0;
  --low: #3F6B4A;
  --mid: #A9761B;
  --high: #C1121F;
  --font-sans: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-cond: "IBM Plex Sans Condensed", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
}

a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden, .skip-link:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link:focus {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 100;
  background: var(--card);
  padding: 0.5rem 0.75rem;
}

.masthead {
  background: var(--ink);
  color: var(--paper);
  padding: 0.75rem 1.25rem;
  border-bottom: 3px solid var(--accent);
}
.masthead__inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.masthead__left {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.65rem 0.85rem;
  min-width: 0;
}
.masthead__brand {
  font-family: var(--font-cond);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: 0.01em;
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
}
.masthead__sep {
  display: inline-block;
  width: 1px;
  height: 1em;
  background: rgba(242, 239, 234, 0.35);
  align-self: center;
}
.masthead__org {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(242, 239, 234, 0.72);
  white-space: nowrap;
}
.masthead__admin {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: rgba(242, 239, 234, 0.6);
  flex-shrink: 0;
  text-decoration: none;
}
.masthead__admin:hover,
.masthead__admin:focus-visible {
  color: var(--paper);
}
.masthead__gear { display: block; }

.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.site-foot {
  border-top: 1px solid var(--rule);
  padding: 1rem 1.25rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.site-foot__inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}
.site-foot__hash {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.page-title {
  font-family: var(--font-cond);
  font-weight: 700;
  font-size: clamp(1.6rem, 2.5vw, 2rem);
  margin: 0 0 0.35rem;
  letter-spacing: -0.01em;
}
.page-lead { margin: 0; color: var(--muted); }
.page-intro { margin-bottom: 1.75rem; }
.section-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.75rem;
  font-weight: 500;
}

.crumb {
  display: flex;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
}
.crumb a { color: var(--muted); }

.empty-state {
  background: var(--card);
  border: 1px solid var(--rule);
  padding: 2rem 1.5rem;
  max-width: 36rem;
}

/* Cards */
.sheet-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}
.sheet-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--rule);
  padding: 1rem 1.1rem 1.15rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease;
}
.sheet-card:hover { border-color: var(--ink); }
.sheet-card__title {
  font-family: var(--font-cond);
  font-weight: 600;
  font-size: 1.05rem;
  margin: 0 0 0.5rem;
}
.sheet-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.dist { margin-top: 0.15rem; }
.dist-bar {
  display: flex;
  height: 8px;
  width: 100%;
  background: var(--rule);
  overflow: hidden;
}
.dist-bar__seg { display: block; min-width: 2px; }
.dist-bar__seg--high { background: var(--high); }
.dist-bar__seg--mid { background: var(--mid); }
.dist-bar__seg--low { background: var(--low); }
.dist-bar__seg--none { background: #b8b2aa; }
.dist-caption {
  margin: 0.4rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}

/* Matrix */
.matrix-block { margin-bottom: 2rem; }
.matrix {
  display: grid;
  grid-template-columns: auto minmax(0, 250px);
  grid-template-rows: auto auto;
  gap: 0.4rem 0.55rem;
  max-width: 310px;
}
.matrix__axis {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.matrix__axis--y {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  align-self: center;
}
.matrix__axis--x {
  grid-column: 2;
  text-align: center;
}
.matrix__grid {
  display: grid;
  grid-template-columns: 4.5rem repeat(3, minmax(0, 72px));
  grid-template-rows: auto repeat(3, minmax(0, 72px));
  gap: 3px;
  width: max-content;
  max-width: 250px;
}
.matrix__xlabels, .matrix__ylabel {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  line-height: 1.15;
  color: var(--muted);
  text-align: center;
}
.matrix__xlabels {
  grid-column: 2 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 72px));
  gap: 3px;
}
.matrix__ylabel {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.25rem;
  text-align: right;
}
.matrix__row { display: contents; }
.matrix__cell {
  width: 72px;
  height: 72px;
  max-width: 72px;
  max-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid color-mix(in srgb, var(--tone, var(--rule)) 22%, var(--rule));
  padding: 0;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 1.15rem;
  cursor: default;
  background: color-mix(in srgb, var(--tone) calc(var(--fill, 0.04) * 100%), #ffffff);
}
.matrix__cell--high { --tone: var(--high); }
.matrix__cell--mid { --tone: var(--mid); }
.matrix__cell--low { --tone: var(--low); }
.matrix__cell--dark { color: var(--ink); }
.matrix__cell--ink { color: #fff; }
.matrix__cell--empty .matrix__count { color: var(--muted); }
.matrix--interactive .matrix__cell { cursor: pointer; }
.matrix__cell[aria-pressed="true"] {
  box-shadow: inset 0 0 0 3px var(--ink);
}
.matrix-note {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  margin-bottom: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--rule);
}
.toolbar__search input {
  font: inherit;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--rule);
  background: var(--card);
  min-width: 14rem;
}
.toolbar__tags {
  border: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.tag-toggle {
  display: inline-flex;
  cursor: pointer;
}
.tag-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.tag-toggle span {
  font-size: 0.8rem;
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink);
}
.tag-toggle input:checked + span {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}
.tag-toggle input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.toolbar__count { margin: 0; color: var(--muted); font-size: 0.85rem; }
.toolbar__reset {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Table */
.table-wrap {
  overflow-x: hidden;
  width: 100%;
}
.risk-table {
  width: 100%;
  max-width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  background: var(--card);
  font-size: 0.9rem;
  position: relative;
}
.risk-table col[data-role="num"] { width: 3%; }
.risk-table col[data-role="area"] { width: 14%; }
.risk-table col[data-role="owner"] { width: 11%; }
.risk-table col[data-role="description"] { width: 38%; }
.risk-table col[data-role="tags"] { width: 12%; }
.risk-table col[data-role="level"] { width: 8%; }
.risk-table col[data-role="text"] { width: 10%; }
.risk-table th.risk-table__expand,
.risk-table td.risk-table__expand,
.risk-table col.risk-table__expand-col { display: none; }
.risk-table th {
  font-family: var(--font-cond);
  font-weight: 600;
  font-size: 0.8rem;
  text-align: left;
  padding: 0.45rem 0.4rem;
  border-bottom: 2px solid var(--ink);
  vertical-align: bottom;
  white-space: normal;
  overflow: visible;
  line-height: 1.2;
}
.risk-table th[data-role="level"] {
  white-space: nowrap;
  overflow: visible;
}
.risk-table td {
  padding: 0.45rem 0.45rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
  overflow: hidden;
}
.risk-row {
  position: relative;
  cursor: pointer;
}
.risk-row.is-hidden { display: none; }
.risk-details[open] .risk-panel {
  position: absolute;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 3;
  background: var(--card);
  border: 1px solid var(--rule);
  padding: 1rem 1.1rem;
  margin-top: 0.5rem;
  max-width: none;
  box-shadow: 0 6px 18px rgba(20, 16, 13, 0.08);
}

.risk-num {
  font-family: var(--font-mono);
  font-weight: 500;
}
.risk-area { display: flex; flex-direction: column; gap: 0.1rem; }
.risk-area__path {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.25;
}
.risk-area__title { font-weight: 500; }
.risk-owner {
  display: block;
  font-size: 0.85rem;
  line-height: 1.3;
}
.risk-owner__more {
  color: var(--muted);
  white-space: nowrap;
}
.risk-desc-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  min-width: 0;
}
.risk-desc {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: none;
}
.risk-text {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: none;
}
.risk-tags { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.pill {
  font-size: 0.72rem;
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--rule);
  background: var(--paper);
}

.risk-level {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}
.risk-level__label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.risk-level__bar {
  display: block;
  height: 3px;
  width: 40px;
  max-width: 100%;
  background: var(--rule);
}
.risk-level--low .risk-level__bar { background: var(--low); }
.risk-level--mid .risk-level__bar { background: var(--mid); }
.risk-level--high .risk-level__bar { background: var(--high); }
.risk-level--none .risk-level__bar { background: transparent; }

.risk-details {
  position: static;
  width: 100%;
}
.risk-expand {
  cursor: pointer;
  list-style: none;
  display: inline;
  font-size: 0.8rem;
  line-height: 1.3;
  color: var(--accent);
  text-decoration: none;
}
.risk-expand::-webkit-details-marker { display: none; }
.risk-expand:hover,
.risk-expand:focus-visible {
  text-decoration: underline;
}
.risk-expand__clamp { display: none; }
.risk-expand__short { display: inline; }
.risk-expand__close { display: none; }
.risk-details.is-clamped .risk-expand__clamp { display: inline; }
.risk-details.is-clamped .risk-expand__short { display: none; }
.risk-details[open] .risk-expand__clamp,
.risk-details[open] .risk-expand__short { display: none; }
.risk-details[open] .risk-expand__close { display: inline; }

.risk-panel {
  margin-top: 0.75rem;
  padding: 0.85rem 0 0.25rem;
  border-top: 1px dashed var(--rule);
  max-width: none;
  cursor: default;
}
.risk-panel__block + .risk-panel__block { margin-top: 1rem; }
.risk-panel__title {
  font-family: var(--font-cond);
  font-weight: 600;
  font-size: 0.95rem;
  margin: 0 0 0.35rem;
}
.risk-panel__text { margin: 0; white-space: pre-wrap; }
.risk-measures {
  margin: 0;
  padding-left: 1.2rem;
}
.risk-measures li { margin-bottom: 0.35rem; }
.muted { color: var(--muted); }

/* Mobile cards */
@media (max-width: 900px) {
  .risk-table thead { display: none; }
  .risk-table, .risk-table tbody, .risk-table tr, .risk-table td {
    display: block;
    width: 100%;
  }
  .risk-row {
    background: var(--card);
    border: 1px solid var(--rule);
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.65rem;
  }
  .risk-table td {
    border: 0;
    padding: 0.35rem 0;
  }
  .risk-table td::before {
    content: attr(data-label);
    display: block;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.15rem;
  }
  .risk-table__expand::before { content: none; }
  .risk-desc, .risk-text {
    max-width: none;
    -webkit-line-clamp: unset;
    display: block;
  }
  .risk-owner { font-size: 0.9rem; }
  .risk-row { cursor: default; }
  .toolbar__search input { min-width: 0; width: 100%; }
  .table-wrap { overflow-x: visible; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

@media print {
  @page { size: A4 portrait; margin: 12mm; }
  body { background: #fff; color: #000; font-size: 10pt; }
  .masthead, .site-foot, .toolbar, .matrix-block, .crumb, .no-print, .skip-link {
    display: none !important;
  }
  .main { max-width: none; padding: 0; }
  .risk-table { background: #fff; }
  .risk-table th, .risk-table td { border-color: #999; }
  .risk-row { break-inside: avoid; page-break-inside: avoid; }
  .risk-details summary { display: none; }
  .risk-details > *:not(summary) { display: block !important; }
  .risk-details .risk-panel {
    display: block !important;
    position: static !important;
    box-shadow: none !important;
    border-color: #999;
    max-width: none;
  }
  .risk-level__bar { display: none !important; }
  .risk-level__label::after {
    content: " — " attr(data-print-level);
  }
  .risk-desc, .risk-text {
    display: block;
    -webkit-line-clamp: unset;
    overflow: visible;
  }
  .matrix__cell, .pill, .dist-bar__seg {
    background: #fff !important;
    color: #000 !important;
    border: 1px solid #999 !important;
    box-shadow: none !important;
  }
  a { color: inherit; text-decoration: none; }
}
