/* Threat Modelling Workbench — no remote fonts, no CDN, no network of any kind. */

:root {
  color-scheme: light dark;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f2f2ef;
  --border: #dfdfd8;
  --border-strong: #c4c4bb;
  --text: #1a1a17;
  --muted: #6b6b63;
  --accent: #2f5d50;
  --accent-soft: #e3ede9;
  --crit: #8b1a1a;
  --high: #b4531a;
  --med: #8a6d1a;
  --low: #4a6b4a;
  --warn: #a3651a;
  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --surface: #1e1e23;
    --surface-2: #26262c;
    --border: #33333b;
    --border-strong: #45454f;
    --text: #e8e8e3;
    --muted: #9a9a92;
    --accent: #6fae9b;
    --accent-soft: #22332e;
    --crit: #e06666;
    --high: #e0954f;
    --med: #d4c05a;
    --low: #7fae7f;
    --warn: #d9a04f;
  }
}

* { box-sizing: border-box; }

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

h1, h2, h3, h4, h5 { margin: 0 0 .4rem; line-height: 1.25; font-weight: 600; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
h4 { font-size: .9rem; }
h5 { font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-top: .8rem; }
p { margin: 0 0 .6rem; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: .86em; background: var(--surface-2); padding: .08rem .3rem; border-radius: 3px; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.warn-text { color: var(--warn); }

/* ------------------------------------------------------------------ head --- */

.app-head {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .7rem 1.2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.logo { font-size: 1.4rem; color: var(--accent); }
.brand-name { display: block; font-weight: 600; font-size: .95rem; }
.brand-sub { display: block; font-size: .8rem; color: var(--muted); max-width: 18rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.segmented { display: flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 2px; gap: 2px; }
.seg {
  border: 0; background: transparent; cursor: pointer; color: var(--muted);
  padding: .35rem .8rem; border-radius: 4px; text-align: left; font: inherit;
}
.seg:hover { color: var(--text); }
.seg.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg-label { display: block; font-size: .85rem; font-weight: 600; }
.seg-sub { display: block; font-size: .7rem; color: var(--muted); }

.head-actions { display: flex; align-items: center; gap: .4rem; margin-left: auto; }
.save-state { font-size: .78rem; color: var(--muted); }
.save-state.dirty { color: var(--warn); }

/* ---------------------------------------------------------------- layout --- */

.layout { display: grid; grid-template-columns: 15rem minmax(0, 1fr); align-items: start; }
.rail {
  position: sticky; top: 3.6rem; padding: 1rem .6rem; display: flex; flex-direction: column; gap: 2px;
  border-right: 1px solid var(--border); min-height: calc(100vh - 3.6rem);
}
.rail-item {
  display: flex; align-items: center; gap: .6rem; text-align: left;
  border: 0; background: transparent; cursor: pointer; color: var(--text);
  padding: .5rem .6rem; border-radius: var(--radius); font: inherit; width: 100%;
}
.rail-item:hover { background: var(--surface-2); }
.rail-item.active { background: var(--accent-soft); }
.rail-n {
  width: 1.35rem; height: 1.35rem; flex: none; display: grid; place-items: center;
  border-radius: 50%; background: var(--surface-2); font-size: .72rem; color: var(--muted);
}
.rail-item.active .rail-n { background: var(--accent); color: #fff; }
.rail-main { min-width: 0; flex: 1; }
.rail-label { display: block; font-size: .88rem; font-weight: 500; }
.rail-hint { display: block; font-size: .7rem; color: var(--muted); }

.main { padding: 1.2rem 1.5rem 5rem; min-width: 0; max-width: 68rem; }
.stage { display: flex; flex-direction: column; gap: 1.2rem; }

/* ---------------------------------------------------------------- panels --- */

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem;
  padding: .9rem 1.1rem; border-bottom: 1px solid var(--border);
}
.panel-head p { margin: .2rem 0 0; font-size: .84rem; max-width: 52rem; }
.panel > *:not(.panel-head) { padding: 1.1rem; }
.panel-actions { display: flex; gap: .4rem; flex: none; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.empty { color: var(--muted); font-style: italic; padding: 1rem 0; }

/* ---------------------------------------------------------------- inputs --- */

.field { display: block; margin: 0; }
.field-label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: .25rem; }
.field-hint { display: block; font-size: .76rem; color: var(--muted); margin-top: .25rem; }
.input {
  width: 100%; font: inherit; padding: .4rem .55rem;
  border: 1px solid var(--border-strong); border-radius: 4px;
  background: var(--surface); color: var(--text);
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.textarea { resize: vertical; line-height: 1.45; }
select.input { padding: .35rem .4rem; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: .8rem; }
.check { display: flex; align-items: flex-start; gap: .4rem; font-size: .84rem; cursor: pointer; }
.check input { margin-top: .2rem; flex: none; }
.flag-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: .4rem .9rem; }
.flagrow { display: flex; gap: 1.2rem; flex-wrap: wrap; }

.btn {
  font: inherit; font-size: .85rem; padding: .38rem .8rem; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 4px;
  background: var(--surface); color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { border-color: transparent; background: var(--surface-2); }
.btn.small { font-size: .78rem; padding: .25rem .55rem; }
.btn.icon { border-color: transparent; background: transparent; color: var(--muted); padding: .25rem .5rem; }
.btn.icon:hover { color: var(--text); background: var(--surface-2); }
.btn.danger:hover { color: var(--crit); border-color: var(--crit); }
.btn.active { background: var(--accent-soft); border-color: var(--accent); }

.linelist { display: flex; flex-direction: column; gap: .35rem; align-items: flex-start; }
.linelist-row { display: flex; gap: .4rem; align-items: center; width: 100%; }
.linelist-row .input { flex: 1; }
.seedrow { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; padding-top: .4rem; }

/* ----------------------------------------------------------------- cards --- */

.cards { display: flex; flex-direction: column; gap: .8rem; }
.card { border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem; background: var(--surface-2); display: flex; flex-direction: column; gap: .7rem; }
.card-head { display: flex; align-items: flex-start; gap: .6rem; }
.card-head .input { flex: 1; font-weight: 600; }
.card-head h3 { margin: 0; }
.card-actions { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
details > summary { cursor: pointer; font-size: .84rem; color: var(--muted); padding: .2rem 0; }
details[open] > summary { margin-bottom: .5rem; }
.detail h4 { margin-top: .6rem; }
.detail ul { margin: .2rem 0; padding-left: 1.1rem; }
.detail li { margin-bottom: .2rem; font-size: .88rem; }

/* ----------------------------------------------------------------- pills --- */

.pill {
  display: inline-block; font-size: .72rem; padding: .1rem .45rem; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  white-space: nowrap;
}
.chips { display: flex; flex-wrap: wrap; gap: .25rem; }
.pill.tag { background: transparent; }
.pill.stride { border-color: var(--accent); color: var(--accent); }
.pill.metric { font-family: var(--mono); }
.pill.warn { color: var(--warn); border-color: var(--warn); }
.pill.ok { color: var(--low); border-color: var(--low); }
.pill.count { min-width: 1.4rem; text-align: center; }
.pill.count.zero { opacity: .4; }
.pill.sev-critical, .pill.status-open { color: #fff; background: var(--crit); border-color: var(--crit); }
.pill.sev-high { color: #fff; background: var(--high); border-color: var(--high); }
.pill.sev-medium { color: #fff; background: var(--med); border-color: var(--med); }
.pill.sev-low { color: #fff; background: var(--low); border-color: var(--low); }
.pill.sev-none { opacity: .6; }

.chipset { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip {
  font: inherit; font-size: .76rem; padding: .2rem .55rem; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface); color: var(--muted);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ------------------------------------------------------------------ tabs --- */

.tabs { display: flex; gap: .3rem; flex-wrap: wrap; }
.tab { border-color: transparent; background: transparent; color: var(--muted); }
.tab.active { background: var(--surface); border-color: var(--border); color: var(--text); font-weight: 600; }

/* ------------------------------------------------------------ deployment --- */

.deploy-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; }
.deploy-cell { display: flex; flex-direction: column; gap: .4rem; }
.deploy-detail { font-size: .8rem; border-left: 2px solid var(--accent); padding-left: .6rem; }
.deploy-detail p { margin: 0 0 .3rem; }

/* --------------------------------------------------------------- threats --- */

.candidate .statement { font-size: .88rem; margin: .3rem 0 0; max-width: 54rem; }
.cand-score { display: flex; flex-direction: column; align-items: flex-end; gap: .25rem; flex: none; }
.pill.conf-low { opacity: .7; }

.statrow { display: flex; gap: .5rem; flex-wrap: wrap; }
.stat {
  display: flex; flex-direction: column; align-items: center; min-width: 4.5rem;
  padding: .5rem .8rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); font: inherit; color: inherit; cursor: default;
}
button.stat { cursor: pointer; }
button.stat.active { border-color: var(--accent); background: var(--accent-soft); }
.stat-n { font-size: 1.4rem; font-weight: 600; }
.stat-l { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.statrow.big .stat { min-width: 6rem; }
.stat.small .stat-n { font-size: 1.1rem; }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; }
.filters .input { max-width: 22rem; }

.threat-list { display: flex; flex-direction: column; gap: .3rem; }
.threat-row {
  display: flex; align-items: center; gap: .7rem; width: 100%; text-align: left;
  padding: .55rem .7rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); font: inherit; color: inherit; cursor: pointer;
}
.threat-row:hover { border-color: var(--accent); }
.threat-main { flex: 1; min-width: 0; }
.threat-title { display: block; font-weight: 500; font-size: .9rem; }
.threat-statement { display: block; font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.threat-meta { display: flex; gap: .3rem; flex: none; flex-wrap: wrap; justify-content: flex-end; }

/* ---------------------------------------------------------------- drawer --- */

.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40;
  display: flex; justify-content: flex-end;
}
.drawer {
  width: min(46rem, 100%); background: var(--surface); height: 100%;
  display: flex; flex-direction: column; border-left: 1px solid var(--border);
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .7rem 1rem; border-bottom: 1px solid var(--border); }
.drawer-head > div { display: flex; gap: .4rem; align-items: center; }
.drawer-body { overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .9rem; }
.drawer-section { border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem .9rem; }
.drawer-actions { padding-top: .5rem; border-top: 1px solid var(--border); }
.linked { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .3rem; }
.linked li { display: flex; align-items: center; gap: .4rem; font-size: .86rem; }
.rec-list { display: flex; flex-direction: column; gap: .4rem; }
.rec { display: flex; justify-content: space-between; align-items: flex-start; gap: .8rem; padding: .5rem .6rem; background: var(--surface-2); border-radius: 4px; }
.rec p { margin: .15rem 0 0; }
.linked-threats { display: flex; gap: .3rem; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------ calculator --- */

.calc { display: flex; flex-direction: column; gap: .8rem; }
.calc-block { border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem; background: var(--surface-2); }
.calc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; gap: .5rem; }
.calc-head h4 { margin: 0; }
.calc-head > div { display: flex; gap: .3rem; }
.scale { display: flex; gap: .2rem; }
.scale-btn {
  flex: 1; font: inherit; padding: .35rem 0; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 4px; background: var(--surface); color: var(--muted);
}
.scale-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: .6rem; }
.metric-cell { display: flex; flex-direction: column; gap: .2rem; }
.metric-name { font-size: .74rem; font-weight: 600; color: var(--muted); }
.metric-opts { display: flex; gap: .15rem; }
.opt {
  flex: 1; font: inherit; font-size: .72rem; padding: .22rem .1rem; cursor: pointer;
  border: 1px solid var(--border); border-radius: 3px; background: var(--surface); color: var(--muted);
}
.opt.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.vector { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: .7rem; font-size: .8rem; }
.env-block { margin-top: .8rem; padding-top: .8rem; border-top: 1px dashed var(--border-strong); }
.env-result { margin: .5rem 0 .3rem; font-size: .9rem; }
table.trace { width: 100%; border-collapse: collapse; font-size: .8rem; margin: .4rem 0; }
table.trace th, table.trace td { text-align: left; padding: .25rem .4rem; border-bottom: 1px solid var(--border); }
table.trace th { color: var(--muted); font-weight: 600; font-size: .74rem; }

.notice { border-left: 3px solid var(--warn); background: var(--surface-2); padding: .6rem .8rem; border-radius: 4px; font-size: .85rem; }
.notice.error { border-color: var(--crit); }
.notice.warn { border-color: var(--warn); margin-bottom: 1rem; }

/* -------------------------------------------------------------- mitigate --- */

.purpose-group { margin-bottom: 1.2rem; }
.purpose-head { display: flex; align-items: center; gap: .5rem; font-size: .88rem; color: var(--muted); margin-bottom: .5rem; }
.pill.purpose { border-color: var(--accent); color: var(--accent); }

/* ---------------------------------------------------------------- review --- */

.signals { display: flex; flex-direction: column; gap: .4rem; }
.signal { padding: .5rem .8rem; border-left: 3px solid var(--border-strong); background: var(--surface-2); border-radius: 4px; font-size: .88rem; }
.signal.sig-high { border-color: var(--crit); }
.signal.sig-medium { border-color: var(--warn); }
.signal.sig-low { border-color: var(--border-strong); }
.signal p { margin: .2rem 0 0; }
.stride-cov { display: grid; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr)); gap: .4rem; margin: .5rem 0; }
.cov-cell { display: flex; flex-direction: column; align-items: center; padding: .5rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); opacity: .5; }
.cov-cell.covered { opacity: 1; border-color: var(--accent); }
.cov-n { font-size: 1.2rem; font-weight: 600; }
.cov-l { font-size: .68rem; color: var(--muted); text-align: center; }
.export-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.code-preview { font-family: var(--mono); font-size: .76rem; white-space: pre-wrap; word-break: break-word; max-height: 60vh; overflow: auto; background: var(--surface-2); padding: .8rem; border-radius: 4px; }

/* ------------------------------------------------------------------ wiki --- */

.stage.wiki { display: grid; grid-template-columns: 15rem minmax(0, 1fr); gap: 2rem; align-items: start; }
.wiki-nav { position: sticky; top: 4.5rem; display: flex; flex-direction: column; gap: 1px; }
.wiki-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: .9rem 0 .3rem; }
.wiki-link { text-align: left; font: inherit; font-size: .85rem; padding: .3rem .5rem; border: 0; background: transparent; color: var(--text); cursor: pointer; border-radius: 4px; }
.wiki-link:hover { background: var(--surface-2); }
.wiki-link.active { background: var(--accent-soft); font-weight: 600; }
.wiki-body { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem 2rem; max-width: 46rem; }
.wiki-body h1 { font-size: 1.6rem; }
.wiki-body .lede { font-size: 1rem; color: var(--muted); margin-bottom: 1.2rem; }
.md h2 { margin-top: 1.8rem; font-size: 1.15rem; }
.md h3 { margin-top: 1.3rem; }
.md p, .md li { max-width: 42rem; }
.md ul, .md ol { padding-left: 1.3rem; }
.md li { margin-bottom: .3rem; }
.md blockquote { border-left: 3px solid var(--accent); margin: 1rem 0; padding: .1rem 0 .1rem 1rem; color: var(--muted); }
.md-table-wrap { overflow-x: auto; margin: 1rem 0; }
.md-table { border-collapse: collapse; width: 100%; font-size: .88rem; }
.md-table th, .md-table td { border: 1px solid var(--border); padding: .35rem .6rem; text-align: left; vertical-align: top; }
.md-table th { background: var(--surface-2); font-weight: 600; }

/* ----------------------------------------------------------- modal/toast --- */

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: grid; place-items: center; padding: 2rem; }
.modal { background: var(--surface); border-radius: var(--radius); width: min(46rem, 100%); max-height: 85vh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: .7rem 1rem; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-body { overflow-y: auto; padding: 1rem; }
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: .55rem 1rem; border-radius: 20px;
  font-size: .85rem; max-width: 32rem; text-align: center;
}

.questions .question-list { padding-left: 1.4rem; }
.questions li { margin-bottom: .3rem; font-size: .88rem; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .rail { position: static; flex-direction: row; overflow-x: auto; min-height: 0; border-right: 0; border-bottom: 1px solid var(--border); }
  .rail-item { flex: none; }
  .rail-hint { display: none; }
  .stage.wiki { grid-template-columns: 1fr; }
  .wiki-nav { position: static; }
  .head-actions { margin-left: 0; }
}
