/*
 * Governance panels — Guardrails, Safety & Crisis, Acceptable Use, Retention,
 * Quotas, Memory, Engines, Token Usage, Service Health.
 *
 * Kept out of admin.html's inline block because these panels share one visual
 * vocabulary that the older panels do not use, and because a separate file can
 * be reasoned about as a whole. Everything below builds on the variables
 * admin.html already defines (--surface, --accent, --maroon, --font-head…) so
 * there is one palette, not two.
 *
 * The house style these follow: a tinted rule and a label before each group, a
 * gold left-edge on anything that states policy, Fraunces italic for titles,
 * DM Mono uppercase for labels and machine values, and nothing filled solid
 * except the one primary action per card.
 */

/* ── Requirement banner ────────────────────────────────────────────────
   Every governance panel opens with one of these. It is the answer to "which
   district requirement does this screen satisfy, and what is actually
   enforcing it" — the question the whole panel exists to answer. */
.gov-hero {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  background: linear-gradient(135deg, rgba(107, 18, 40, 0.35), rgba(36, 13, 19, 0.6));
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 22px;
}
.gov-hero-icon {
  width: 38px; height: 38px;
  flex-shrink: 0;
  border-radius: 10px;
  background: rgba(201, 162, 39, 0.12);
  border: 1px solid rgba(201, 162, 39, 0.28);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.05rem;
}
.gov-hero-body { flex: 1; min-width: 0; }
.gov-hero-req {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 5px;
}
.gov-hero h2 {
  font-family: var(--font-head);
  font-size: 1.15rem;
  font-weight: 600;
  font-style: italic;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
}
.gov-hero p {
  font-size: 0.84rem;
  line-height: 1.65;
  color: var(--muted);
  max-width: 76ch;
}
.gov-hero p + p { margin-top: 8px; }
.gov-hero code {
  font-family: var(--font-mono);
  font-size: 0.78em;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--accent2);
}

/* ── Layout helpers ──────────────────────────────────────────────────── */
.gov-grid { display: grid; gap: 18px; }
.gov-grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.gov-grid.three { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }

.gov-section-label {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 4px 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.gov-section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.gov-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.gov-actions .spacer { flex: 1; }

.gov-empty {
  text-align: center;
  padding: 34px 20px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.7;
}
.gov-empty .big { font-size: 1.7rem; display: block; margin-bottom: 10px; opacity: 0.6; }

.gov-note {
  font-size: 0.8rem;
  line-height: 1.7;
  color: var(--muted);
  border-left: 2px solid var(--border);
  padding-left: 12px;
  margin-top: 14px;
}
.gov-note strong { color: var(--text); font-weight: 600; }

/* ── Fields ──────────────────────────────────────────────────────────── */
.gov-field { margin-bottom: 16px; }
.gov-field:last-child { margin-bottom: 0; }
.gov-field > label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.gov-field .hint {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.6;
  margin-top: 6px;
}
.gov-input,
.gov-field input[type="text"],
.gov-field input[type="number"],
.gov-field input[type="email"],
.gov-field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 13px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.86rem;
  outline: none;
  transition: border-color 0.15s;
}
.gov-field textarea {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.7;
  resize: vertical;
  min-height: 120px;
}
.gov-input:focus,
.gov-field input:focus,
.gov-field textarea:focus { border-color: var(--accent); }
.gov-field input::placeholder,
.gov-field textarea::placeholder { color: rgba(158, 128, 112, 0.65); }

.gov-inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.gov-inline > .grow { flex: 1; min-width: 160px; }

/* ── Toggle switch ───────────────────────────────────────────────────── */
.switch-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.switch-row:last-child { border-bottom: none; }
.switch-row .switch-body { flex: 1; min-width: 0; }
.switch-row .switch-name { font-size: 0.875rem; font-weight: 600; }
.switch-row .switch-desc {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.6;
  margin-top: 3px;
}

.switch {
  position: relative;
  flex-shrink: 0;
  width: 40px; height: 22px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s;
  padding: 0;
  margin-top: 1px;
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.18s, background 0.18s;
}
.switch[aria-checked="true"] {
  background: linear-gradient(135deg, var(--maroon), var(--maroon2));
  border-color: rgba(201, 162, 39, 0.45);
}
.switch[aria-checked="true"]::after { transform: translateX(18px); background: var(--accent); }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch[disabled] { opacity: 0.4; cursor: not-allowed; }

/* ── Segmented control ───────────────────────────────────────────────── */
.seg {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.18);
}
.seg button {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 5px 13px;
  border-radius: 16px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.seg button:hover { color: var(--text); background: rgba(201, 162, 39, 0.1); }
.seg button[aria-pressed="true"] {
  background: linear-gradient(135deg, var(--maroon), var(--maroon2));
  color: var(--text);
}

/* ── Chips ───────────────────────────────────────────────────────────── */
.chip-set { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.14s;
}
.chip:hover { border-color: rgba(201, 162, 39, 0.4); color: var(--text); }
.chip[aria-pressed="true"] {
  background: rgba(201, 162, 39, 0.13);
  border-color: rgba(201, 162, 39, 0.4);
  color: var(--accent);
}
.chip.static { cursor: default; }
.chip.static:hover { border-color: var(--border); color: var(--muted); }

/* ── Meter (quota fill, retention fill) ──────────────────────────────── */
.meter { margin-bottom: 16px; }
.meter:last-child { margin-bottom: 0; }
.meter-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 7px;
}
.meter-name { font-size: 0.85rem; font-weight: 600; }
.meter-scope {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.meter-value { font-family: var(--font-mono); font-size: 0.76rem; color: var(--muted); }
.meter-track {
  height: 7px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--maroon2), var(--accent));
  transition: width 0.45s ease;
}
.meter.is-warning .meter-fill { background: linear-gradient(90deg, #a8700f, var(--warning)); }
.meter.is-exceeded .meter-fill { background: linear-gradient(90deg, #8f1f1a, var(--danger)); }
.meter-foot { font-size: 0.75rem; color: var(--muted); margin-top: 6px; }

/* ── Prompt viewer ───────────────────────────────────────────────────── */
.prompt-view {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  line-height: 1.75;
  color: rgba(245, 237, 232, 0.82);
  white-space: pre-wrap;
  max-height: 260px;
  overflow-y: auto;
}
.prompt-view::-webkit-scrollbar { width: 4px; }
.prompt-view::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

details.gov-disclose { margin-top: 12px; }
details.gov-disclose > summary {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  list-style: none;
  padding: 6px 0;
}
details.gov-disclose > summary::-webkit-details-marker { display: none; }
details.gov-disclose > summary::before { content: '▸ '; color: var(--accent); }
details.gov-disclose[open] > summary::before { content: '▾ '; }
details.gov-disclose > summary:hover { color: var(--accent); }

/* ── Preset cards ────────────────────────────────────────────────────── */
.preset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  background: rgba(0, 0, 0, 0.16);
  display: flex;
  flex-direction: column;
}
.preset.is-applied { border-color: rgba(63, 185, 80, 0.32); }
.preset.is-drifted { border-color: rgba(232, 188, 58, 0.32); }
.preset-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.preset-name {
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 600;
  font-style: italic;
}
.preset-summary { font-size: 0.8rem; color: var(--muted); line-height: 1.65; flex: 1; }
.preset-checks { margin: 14px 0 0; }
.preset-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.79rem;
  padding: 4px 0;
  color: var(--muted);
}
.preset-check .mark { width: 14px; text-align: center; flex-shrink: 0; }
.preset-check.on { color: rgba(245, 237, 232, 0.85); }
.preset-check.on .mark { color: var(--success); }
.preset-check.off .mark { color: var(--danger); }

/* ── Crisis queue ────────────────────────────────────────────────────── */
.queue-item {
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
  background: rgba(0, 0, 0, 0.16);
}
.queue-item.is-crisis { border-left-color: var(--danger); background: rgba(248, 81, 73, 0.05); }
.queue-item.is-reviewed { opacity: 0.55; border-left-color: var(--success); }
.queue-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.queue-who { font-family: var(--font-mono); font-size: 0.78rem; color: var(--accent); }
.queue-when { font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); }
.queue-reason { font-size: 0.82rem; line-height: 1.6; color: rgba(245, 237, 232, 0.85); }
.queue-prompt {
  margin-top: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.8rem;
  line-height: 1.65;
  color: var(--muted);
  white-space: pre-wrap;
  max-height: 150px;
  overflow-y: auto;
}
.queue-foot { display: flex; gap: 8px; align-items: center; margin-top: 10px; }

/* ── Health rows ─────────────────────────────────────────────────────── */
.health-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.health-row:last-child { border-bottom: none; }
.health-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--muted);
}
.health-dot.up { background: var(--success); box-shadow: 0 0 0 3px rgba(63, 185, 80, 0.14); }
.health-dot.down { background: var(--danger); box-shadow: 0 0 0 3px rgba(248, 81, 73, 0.16); animation: pulse 1.4s infinite; }
.health-dot.checking { background: var(--warning); animation: pulse 1s infinite; }
.health-body { flex: 1; min-width: 0; }
.health-name { font-size: 0.875rem; font-weight: 600; }
.health-detail { font-size: 0.76rem; color: var(--muted); margin-top: 2px; }
.health-meta { font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); text-align: right; flex-shrink: 0; }

/* ── Markdown preview (EULA, crisis response) ────────────────────────── */
.gov-md { font-size: 0.86rem; line-height: 1.75; color: rgba(245, 237, 232, 0.86); }
.gov-md h2 {
  font-family: var(--font-head);
  font-size: 1.05rem;
  font-style: italic;
  font-weight: 600;
  color: var(--text);
  margin: 20px 0 8px;
}
.gov-md h2:first-child { margin-top: 0; }
.gov-md h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  margin: 16px 0 6px;
}
.gov-md h4 {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 14px 0 6px;
}
.gov-md p { margin-bottom: 10px; }
.gov-md ul { margin: 0 0 10px 20px; }
.gov-md li { margin-bottom: 4px; }
.gov-md strong { color: var(--text); font-weight: 700; }
.gov-md hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.gov-md table { width: 100%; border-collapse: collapse; margin-bottom: 12px; font-size: 0.83rem; }
.gov-md th, .gov-md td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.gov-md th { font-family: var(--font-mono); font-size: 0.68rem; text-transform: uppercase; color: var(--muted); }
.gov-md code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--accent2);
}

/* ── Toast ───────────────────────────────────────────────────────────── */
.gov-toast {
  position: fixed;
  right: 24px; bottom: 24px;
  z-index: 10000;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 13px 18px;
  font-size: 0.84rem;
  line-height: 1.6;
  color: var(--text);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}
.gov-toast.is-shown { opacity: 1; transform: translateY(0); }
.gov-toast.is-error { border-left-color: var(--danger); }
.gov-toast.is-ok { border-left-color: var(--success); }

/* ── Busy state ──────────────────────────────────────────────────────── */
.gov-busy { pointer-events: none; opacity: 0.55; }

@media (max-width: 700px) {
  .gov-hero { flex-direction: column; gap: 12px; }
  .gov-grid.two, .gov-grid.three { grid-template-columns: 1fr; }
}
