/* Configuration page.
 *
 * Loads on top of style.css and inherits every colour token from it, so the
 * two pages cannot drift apart and the theme toggle works on both without a
 * second palette to maintain. */

.cfg-body { padding-bottom: 4rem; }

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

.tabs {
  display: flex;
  gap: 2px;
  padding: 0 clamp(12px, 3vw, 28px);
  border-bottom: 1px solid var(--rule);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}
.tabs button {
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 12px 16px;
  font: inherit;
  font-size: 13px;
  color: var(--dim);
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease;
}
.tabs button:hover { color: var(--mid); }
.tabs button[aria-pressed="true"] {
  color: var(--text);
  border-bottom-color: var(--flow);
}

.cfg {
  padding: clamp(12px, 3vw, 28px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 1500px;
  margin: 0 auto;
}

.split {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
}

.sub-head { margin-top: 20px; }
.sub-head h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text); }

/* ------------------------------------------------------- policy list ----- */

.pol-list { display: flex; flex-direction: column; gap: 2px; }
.pol-item button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  background: none;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 4px;
  font: inherit;
  color: var(--mid);
  text-align: left;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.pol-item button:hover { background: var(--panel-2); color: var(--text); }
.pol-item[aria-current="true"] button {
  background: var(--panel-2);
  color: var(--text);
  border-left-color: var(--flow);
}
.pol-name { font-size: 13px; }
.pol-tags { display: flex; gap: 5px; flex-shrink: 0; }
.pol-mode, .pol-src {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 2px;
  border: 1px solid currentColor;
  color: var(--dim);
}
/* Enforce is the only stage that can affect a real person, so it is the only
   one that gets a colour. */
.pol-item[data-mode="enforce"] .pol-mode { color: var(--halt); background: var(--halt-soft); }
.pol-item[data-mode="shadow"]  .pol-mode { color: var(--watch); }
.pol-src { color: var(--iris); }

.templates { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--rule); }
.tmpl-list { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.tmpl-list button {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  background: none;
  border: 0;
  border-radius: 4px;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background .15s ease;
}
.tmpl-list button:hover { background: var(--panel-2); }
.tmpl-name { font-size: 12.5px; color: var(--text); }
.tmpl-note {
  font-size: 11px;
  color: var(--dim);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ----------------------------------------------------------- form bits --- */

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--dim);
}
.field-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; }
.field-narrow { min-width: 230px; }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  appearance: none;
  background: var(--sunk);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 7px 9px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  transition: border-color .15s ease;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--flow);
}
input:disabled, select:disabled, textarea:disabled { opacity: .5; cursor: not-allowed; }
select { cursor: pointer; }
.mini-select { padding: 5px 7px; font-size: 12px; }

.btn {
  appearance: none;
  background: var(--flow);
  color: var(--void);
  border: 0;
  border-radius: 4px;
  padding: 8px 16px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s ease;
}
.btn:hover { opacity: .88; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.ghost-btn.sm { padding: 3px 9px; font-size: 11.5px; }
.ghost-btn.danger { color: var(--halt); border-color: currentColor; }

.editor-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.save-state { font-size: 12px; color: var(--dim); }

/* --------------------------------------------------------- code editor --- */

/* A textarea over a highlighted <pre>. The two must agree on every metric
   that affects glyph position — font, size, line height, padding, tab size,
   letter spacing — or the coloured text drifts away from the caret as the
   policy grows. */
.code-editor {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  background: var(--sunk);
  border: 1px solid var(--rule);
  border-radius: 5px;
  overflow: hidden;
  margin-top: 6px;
}
.code-editor:focus-within { border-color: var(--flow); }

.gutter {
  display: flex;
  flex-direction: column;
  padding: 10px 8px 10px 10px;
  background: var(--panel);
  border-right: 1px solid var(--rule);
  overflow: hidden;
  user-select: none;
}
.gutter i {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  font-style: normal;
  color: var(--tick);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.code-stack { position: relative; min-height: 300px; }

.code-mirror,
#cedar {
  margin: 0;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  letter-spacing: 0;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  border: 0;
  border-radius: 0;
}
.code-mirror {
  position: absolute;
  inset: 0;
  pointer-events: none;
  color: var(--mid);
  overflow: hidden;
}
#cedar {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 300px;
  resize: vertical;
  background: transparent;
  /* Transparent ink over the mirror, with the caret painted back in. The
     alternative — hiding the textarea — loses the native caret, selection
     highlight and mobile keyboard, which are not worth reimplementing. */
  color: transparent;
  caret-color: var(--flow);
}
#cedar::selection { background: var(--flow-soft); }

.tk-keyword    { color: var(--iris); font-weight: 600; }
.tk-string     { color: var(--flow); }
.tk-entity     { color: var(--gold); }
.tk-annotation { color: var(--dim); font-style: italic; }
.tk-comment    { color: var(--tick); font-style: italic; }
.tk-number     { color: var(--watch); }

.validation {
  margin: 8px 0 0;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.45;
  min-height: 1.2em;
  color: var(--dim);
  white-space: pre-wrap;
}
.validation[data-state="ok"]  { color: var(--flow); }
.validation[data-state="bad"] { color: var(--halt); }

/* ------------------------------------------------------------ backtest --- */

.backtest {
  margin-top: 14px;
  padding: 14px;
  background: var(--panel-2);
  border: 1px solid var(--rule);
  border-radius: 5px;
}
.bt-verdict { margin: 0 0 12px; font-size: 13px; color: var(--text); line-height: 1.45; }
.bt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.bt-stat { display: flex; flex-direction: column; gap: 2px; }
.bt-num {
  font-family: var(--mono);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.bt-stat[data-tone="halt"]  .bt-num { color: var(--halt); }
.bt-stat[data-tone="watch"] .bt-num { color: var(--watch); }
.bt-label {
  font-size: 10.5px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--dim);
}
.bt-break { margin-bottom: 10px; }
.bt-break ul { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; }
.bt-break li {
  display: flex;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--mid);
}
.bt-break b { color: var(--text); font-variant-numeric: tabular-nums; }
.bt-note {
  margin: 10px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
  font-size: 11px;
  line-height: 1.5;
  color: var(--dim);
}

/* ---------------------------------------------------------- cheatsheet --- */

.cheatsheet { margin-top: 16px; border-top: 1px solid var(--rule); padding-top: 12px; }
.cheatsheet summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--mid);
  list-style: none;
}
.cheatsheet summary::-webkit-details-marker { display: none; }
.cheatsheet summary::before { content: '▸ '; color: var(--dim); }
.cheatsheet[open] summary::before { content: '▾ '; }
.cheat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-top: 12px;
}
.cheat-grid code {
  display: block;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--gold);
  padding: 1px 0;
  word-break: break-all;
}
.cheat-note {
  margin-top: 12px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--dim);
}
.cheat-note code { color: var(--iris); font-family: var(--mono); }

/* ------------------------------------------------------------ settings --- */

.settings { display: flex; flex-direction: column; gap: 16px; }
#setting-groups { display: flex; flex-direction: column; gap: 16px; }

.setting {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(160px, 280px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 11px 0;
  border-top: 1px solid var(--rule);
}
.setting:first-of-type { border-top: 0; }
@media (max-width: 820px) {
  .setting { grid-template-columns: 1fr; gap: 5px; }
}
.setting-label { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.setting-label label { font-size: 13px; color: var(--text); }
.setting[data-readonly="1"] .setting-label label { color: var(--mid); }
.pill {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .07em;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 2px;
  border: 1px solid var(--rule);
  color: var(--dim);
}
.setting-help {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--dim);
  margin: 0;
}
.setting-reason { color: var(--watch); }

.sticky-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  background: linear-gradient(to top, var(--void) 55%, transparent);
}

.runtime-panel { margin-top: 4px; }
.runtime {
  display: grid;
  grid-template-columns: minmax(140px, 220px) minmax(0, 1fr);
  gap: 6px 14px;
}
.runtime dt {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--dim);
}
.runtime dd {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12.5px;
  color: var(--text);
}
.runtime dd .setting-reason { font-size: 11px; }

/* ------------------------------------------------------------ analysis --- */

.intel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}
.intel-cell { display: flex; flex-direction: column; gap: 3px; }
.intel-val {
  margin: 0;
  font-family: var(--mono);
  font-size: 18px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.intel-note { margin: 0; font-size: 11px; line-height: 1.45; color: var(--dim); }

.note-line { margin: 6px 0 10px; font-size: 11.5px; color: var(--watch); }

.spend { width: 100%; border-collapse: collapse; font-size: 12px; }
.spend th, .spend td {
  text-align: right;
  padding: 6px 8px;
  border-bottom: 1px solid var(--rule);
  font-variant-numeric: tabular-nums;
}
.spend th:first-child, .spend td:first-child { text-align: left; font-family: var(--mono); }
.spend th {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 400;
}
.spend td { color: var(--mid); }

/* ----------------------------------------------------------- setup guide -- */

.lede {
  max-width: 62ch;
  margin: 0 0 4px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--mid);
}

.guides {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 16px;
}
@media (max-width: 900px) { .guides { grid-template-columns: 1fr; } }

.guide {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--tick);
  border-radius: 4px;
  padding: var(--pad);
}
/* Status is the first thing read, so it is carried by the card's own edge
   rather than by a badge someone has to find. */
.guide[data-status="active"]   { border-left-color: var(--flow); }
.guide[data-status="partial"]  { border-left-color: var(--watch); }
.guide[data-status="inactive"] { border-left-color: var(--tick); }

.guide-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.guide-head h2 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text); }
.guide-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--tick);
  flex-shrink: 0;
}
.guide[data-status="active"]  .guide-dot { background: var(--flow); }
.guide[data-status="partial"] .guide-dot { background: var(--watch); }
.guide-status {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--dim);
}
.guide[data-status="active"]  .guide-status { color: var(--flow); }
.guide[data-status="partial"] .guide-status { color: var(--watch); }

.guide-note {
  margin: 6px 0 0;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--mid);
}

.guide-why { margin: 12px 0 0; }
.guide-why p { margin: 0 0 7px; font-size: 12.5px; line-height: 1.6; color: var(--mid); }
.guide-without { color: var(--dim) !important; }

.guide-steps {
  margin: 14px 0 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.guide-steps li { font-size: 12.5px; line-height: 1.55; color: var(--mid); }
.guide-steps li::marker { color: var(--dim); font-family: var(--mono); font-size: 11px; }
.guide-steps p { margin: 0; }

.guide-code { position: relative; margin-top: 7px; }
.guide-code pre {
  margin: 0;
  padding: 9px 11px;
  padding-right: 60px;
  background: var(--sunk);
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow-x: auto;
}
.guide-code code {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  color: var(--flow);
  white-space: pre;
}
.copy-mini {
  position: absolute;
  top: 6px; right: 6px;
  appearance: none;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 2px 7px;
  font: inherit;
  font-size: 10px;
  color: var(--dim);
  cursor: pointer;
}
.copy-mini:hover { color: var(--text); border-color: var(--tick); }

.guide-link {
  display: inline-block;
  margin-top: 7px;
  font-size: 11.5px;
  color: var(--iris);
  text-decoration: none;
}
.guide-link:hover { text-decoration: underline; }

.guide-notes { margin-top: 14px; border-top: 1px solid var(--rule); padding-top: 10px; }
.guide-notes summary {
  cursor: pointer;
  font-size: 11.5px;
  color: var(--dim);
  list-style: none;
}
.guide-notes summary::-webkit-details-marker { display: none; }
.guide-notes summary::before { content: '▸ '; }
.guide-notes[open] summary::before { content: '▾ '; }
.guide-notes ul { margin: 9px 0 0; padding-left: 17px; display: flex; flex-direction: column; gap: 7px; }
.guide-notes li { font-size: 11.5px; line-height: 1.55; color: var(--dim); }

/* ------------------------------------------------------------ forwarding -- */

.fwd-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}
.fwd-card {
  padding: 12px 14px;
  background: var(--panel-2);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--flow);
  border-radius: 4px;
}
.fwd-card[data-state="open"]   { border-left-color: var(--halt); }
.fwd-card[data-state="silent"] { border-left-color: var(--watch); }

.fwd-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fwd-name { font-family: var(--mono); font-size: 13px; color: var(--text); }
.fwd-flag {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--halt);
  border: 1px solid currentColor;
  border-radius: 2px;
  padding: 1px 5px;
}
.fwd-silent { margin: 8px 0 0; font-size: 11.5px; line-height: 1.5; color: var(--watch); }

.fwd-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(78px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.fwd-stat { display: flex; flex-direction: column; gap: 1px; }
.fwd-num {
  font-family: var(--mono);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.fwd-stat[data-tone="halt"]  .fwd-num { color: var(--halt); }
.fwd-stat[data-tone="watch"] .fwd-num { color: var(--watch); }
.fwd-label {
  font-size: 9.5px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--dim);
}

.fwd-disagree {
  margin: 10px 0 0;
  padding-top: 9px;
  border-top: 1px dashed var(--rule);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--mid);
}
.fwd-reason {
  margin: 5px 0 0;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --------------------------------------------------------------- digest -- */

.digest-preview {
  margin: 10px 0 0;
  padding: 14px 16px;
  background: var(--sunk);
  border: 1px solid var(--rule);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--mid);
  white-space: pre-wrap;
  max-height: 380px;
  overflow-y: auto;
}
.digest-preview::first-line { color: var(--text); font-weight: 600; }

.eyebrow-mini {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--dim);
  margin-right: 7px;
}

/* ------------------------------------------------------------ directory --- */

.scim-status { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.scim-status[data-tone="ok"]   { color: var(--flow); }
.scim-status[data-tone="warn"] { color: var(--watch); }
.scim-status[data-tone="bad"]  { color: var(--halt); }
#scim-log { width: 100%; table-layout: fixed; }
#scim-log th, #scim-log td { text-align: left; }
/* The call column carries the information; the other three are fixed so a
   long path never squeezes them and every row stays scannable. */
#scim-log th:nth-child(1), #scim-log td:nth-child(1) { width: 8.5em; }
#scim-log th:nth-child(3), #scim-log td:nth-child(3) { width: 5em; }
#scim-log th:nth-child(4), #scim-log td:nth-child(4) { width: 5.5em; }
#scim-log .mono {
  font-family: var(--mono);
  font-size: calc(11px * var(--u));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
