:root {
  --bg: #f6f7f6; --surface: #ffffff; --surface-2: #f0f2f0; --border: #dde1dd;
  --text: #1b1f1c; --muted: #5f6a62; --accent: #028b2f; --accent-ink: #ffffff; --accent-soft: #e3f3e8;
  --danger: #b3261e; --danger-soft: #fbe9e7; --warn: #8a5a00; --warn-soft: #fdf1d8;
  --info: #1f5fa8; --info-soft: #e5eefa; --ok: #1d7a3a; --ok-soft: #e1f2e6;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --radius: 8px; --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --t-MR: #7a3db8; --t-PR: #1f5fa8; --t-SYS: #0d7a73; --t-SUB: #5b6b12; --t-DES: #6b5a3e; --t-RSK: #b3261e; --t-TC: #9a4d00;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121513; --surface: #1a1e1b; --surface-2: #232824; --border: #323933;
    --text: #e6ebe7; --muted: #9aa69d; --accent: #3fbf67; --accent-ink: #07210f; --accent-soft: #173a22;
    --danger: #ff8a80; --danger-soft: #3d1c1a; --warn: #f3c060; --warn-soft: #3a2d10;
    --info: #8ab8f0; --info-soft: #182a40; --ok: #7fd89a; --ok-soft: #173a22;
    --shadow: none;
    --t-MR: #c49af0; --t-PR: #8ab8f0; --t-SYS: #6fd6cc; --t-SUB: #c3d36a; --t-DES: #d4bb93; --t-RSK: #ff8a80; --t-TC: #f0a860;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121513; --surface: #1a1e1b; --surface-2: #232824; --border: #323933;
  --text: #e6ebe7; --muted: #9aa69d; --accent: #3fbf67; --accent-ink: #07210f; --accent-soft: #173a22;
  --danger: #ff8a80; --danger-soft: #3d1c1a; --warn: #f3c060; --warn-soft: #3a2d10;
  --info: #8ab8f0; --info-soft: #182a40; --ok: #7fd89a; --ok-soft: #173a22; --shadow: none;
  --t-MR: #c49af0; --t-PR: #8ab8f0; --t-SYS: #6fd6cc; --t-SUB: #c3d36a; --t-DES: #d4bb93; --t-RSK: #ff8a80; --t-TC: #f0a860;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 16px 0 6px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.pad { padding: 24px; }
.mono { font-family: var(--mono); font-size: 12.5px; }

header#top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px;
  padding: 8px 20px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.logo { background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 2px 7px; font-size: 13px; letter-spacing: .03em; }
nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.who { display: flex; align-items: center; gap: 10px; }
#whoami { color: var(--muted); font-size: 13px; }

main { max-width: 1400px; margin: 0 auto; padding: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
@media (max-width: 900px) { .cols-2 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--accent); background: var(--accent);
  color: var(--accent-ink); border-radius: 6px; padding: 6px 12px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { filter: brightness(1.07); text-decoration: none; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); font-weight: 500; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.small { padding: 3px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
button.link.danger { color: var(--danger); }

input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; min-width: 0; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; min-height: 70px; resize: vertical; }
label.f { display: block; }
label.f > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 3px; }
label.f input, label.f select { width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
.table-wrap { overflow: auto; max-height: calc(100vh - 230px); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 10px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.type { font-family: var(--mono); font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px;
  border: 1px solid currentColor; white-space: nowrap; }
.type-MR { color: var(--t-MR); } .type-PR { color: var(--t-PR); } .type-SYS { color: var(--t-SYS); }
.type-SUB { color: var(--t-SUB); } .type-DES { color: var(--t-DES); } .type-RSK { color: var(--t-RSK); } .type-TC { color: var(--t-TC); }
.uid { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
.st-Draft { background: var(--surface-2); color: var(--muted); }
.st-In-review { background: var(--warn-soft); color: var(--warn); }
.st-Approved { background: var(--info-soft); color: var(--info); }
.st-Implemented { background: var(--accent-soft); color: var(--accent); }
.st-Verified { background: var(--ok-soft); color: var(--ok); }
.st-Rejected, .st-Obsolete { background: var(--danger-soft); color: var(--danger); text-decoration: line-through; }
.vv-passed, .res-Pass { background: var(--ok-soft); color: var(--ok); }
.vv-failed, .res-Fail { background: var(--danger-soft); color: var(--danger); }
.vv-open, .res-Blocked, .res-Not-run { background: var(--warn-soft); color: var(--warn); }
.vv-none { background: var(--surface-2); color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.kpi { padding: 12px 14px; }
.kpi .n { font-size: 26px; font-weight: 700; line-height: 1.1; }
.kpi .l { font-size: 12px; color: var(--muted); }
.bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--surface-2); margin-top: 8px; }
.bar > span { display: block; height: 100%; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.b-Draft { background: #a9b3ab; } .b-In-review { background: #e0a526; } .b-Approved { background: #3b7fd0; }
.b-Implemented { background: #43b36a; } .b-Verified { background: #1d7a3a; } .b-Rejected, .b-Obsolete { background: #d0645c; }

.gap { border-left: 3px solid var(--warn); padding: 8px 12px; background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0; }
.gap.bad { border-left-color: var(--danger); }
.gap.ok { border-left-color: var(--ok); }
.gap summary { cursor: pointer; font-weight: 600; }
.gap ul { margin: 6px 0 0; padding-left: 18px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 14px; padding: 3px 10px; cursor: pointer; font: inherit; font-size: 12.5px; color: var(--muted); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.detail-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
dl.fields { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 0; }
dl.fields dt { color: var(--muted); font-size: 12.5px; font-weight: 600; }
dl.fields dd { margin: 0; white-space: pre-wrap; }
.reqtext { font-size: 15px; white-space: pre-wrap; padding: 10px 12px; background: var(--surface-2); border-radius: 6px; margin: 8px 0 12px; }
.linkgroup { margin-bottom: 10px; }
.linkgroup .lt { font-size: 12px; color: var(--muted); font-weight: 600; }
.linkrow { display: flex; gap: 8px; align-items: baseline; padding: 3px 0; }
.linkrow .t { flex: 1; min-width: 0; }
.hist { font-size: 12.5px; border-left: 2px solid var(--border); padding: 2px 0 6px 10px; margin-left: 4px; }
.hist .meta { color: var(--muted); }
.diff del { color: var(--danger); } .diff ins { color: var(--ok); text-decoration: none; }
.comment { padding: 8px 10px; background: var(--surface-2); border-radius: 6px; margin-bottom: 6px; white-space: pre-wrap; }
.comment .meta { font-size: 12px; color: var(--muted); }

.tree ul { list-style: none; margin: 0; padding-left: 22px; border-left: 1px dashed var(--border); }
.tree > ul { padding-left: 0; border: 0; }
.tree li { margin: 3px 0; }
.tree .node { display: flex; gap: 8px; align-items: baseline; }
.tree button.tog { width: 18px; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0; font: inherit; }

.matrix { border-collapse: separate; border-spacing: 0; }
.matrix th.col { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; font-family: var(--mono); font-weight: 500; padding: 8px 4px; }
.matrix td.cell { text-align: center; width: 26px; padding: 3px; border-left: 1px solid var(--border); }
.matrix td.cell.x { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.matrix td.rowh, .matrix th.rowh { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 320px; }
.matrix tr.empty td.rowh { color: var(--danger); }

.login { max-width: 360px; margin: 10vh auto; }
.login .logo { font-size: 18px; }
.error { color: var(--danger); font-size: 13px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 16px; border-radius: 6px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
#toast.show { opacity: .95; }
#toast.err { background: var(--danger); color: #fff; }
.secret { font-family: var(--mono); background: var(--warn-soft); color: var(--warn); padding: 8px 10px; border-radius: 6px; }

@media (max-width: 640px) {
  main { padding: 12px; }
  header#top { padding: 8px 12px; gap: 8px; }
  dl.fields { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
