/* Aires-Marketeer operator console styles.
 *
 * Design tokens live here and only here (50-frontend.mdc): no hardcoded
 * colour values in components, no inline styles anywhere — the CSP has no
 * `unsafe-inline`.
 *
 * This is an operator tool used for hours at a time, so it favours data
 * density over whitespace. Contrast ratios meet WCAG 2.2 AA (4.5:1 for body
 * text, 3:1 for large text and UI boundaries).
 */

:root {
  /* Neutrals */
  --bg: #ffffff;
  --bg-sunken: #f4f5f7;
  --bg-raised: #ffffff;
  --border: #c9ced6;
  --border-strong: #8b94a3;

  /* Text — measured against --bg and --bg-sunken */
  --text: #16191f;
  --text-muted: #545c6b;
  --text-inverse: #ffffff;

  /* Accents */
  --accent: #1c4f8f;
  --accent-hover: #163f73;
  --accent-subtle: #e8effa;

  /* Status */
  --ok-bg: #e6f4ea;
  --ok-border: #1e7a3c;
  --ok-text: #14532a;
  --warn-bg: #fdf3e2;
  --warn-border: #9a6200;
  --warn-text: #6b4400;
  --error-bg: #fdeaea;
  --error-border: #a3231f;
  --error-text: #7a1a17;

  /* Spacing and type */
  --gap-xs: 0.25rem;
  --gap-sm: 0.5rem;
  --gap: 0.875rem;
  --gap-lg: 1.5rem;
  --radius: 4px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  --focus-ring: 3px solid #1c4f8f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --bg-sunken: #0e1116;
    --bg-raised: #1b1f26;
    --border: #333a45;
    --border-strong: #59626f;

    --text: #e8eaee;
    --text-muted: #a3abb8;
    --text-inverse: #0e1116;

    --accent: #7aa9e8;
    --accent-hover: #9cc0f0;
    --accent-subtle: #1c2a3d;

    --ok-bg: #12271a;
    --ok-border: #4caf6d;
    --ok-text: #a9dfba;
    --warn-bg: #2b2113;
    --warn-border: #d19a2b;
    --warn-text: #f0cd8e;
    --error-bg: #2c1615;
    --error-border: #e4706c;
    --error-text: #f3b3b1;

    --focus-ring: 3px solid #7aa9e8;
  }
}

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

body {
  margin: 0;
  background: var(--bg-sunken);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
}

/* Visible focus is never removed, only replaced (WCAG 2.4.7). */
:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

a {
  color: var(--accent);
}

h1 {
  font-size: 1.4rem;
  margin: 0 0 var(--gap-lg);
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 var(--gap-sm);
}

/* ── Application chrome ───────────────────────────────────────────────── */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: var(--gap-sm) var(--gap-lg);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}

.app-name {
  font-weight: 600;
  letter-spacing: 0.01em;
}

.app-user {
  display: flex;
  align-items: center;
  gap: var(--gap);
  font-size: 0.9rem;
}

.role-badge {
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.app-body {
  display: flex;
  flex: 1;
  align-items: flex-start;
}

.app-nav {
  flex: 0 0 15rem;
  padding: var(--gap) 0;
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  min-height: calc(100vh - 3rem);
}

.app-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-link {
  display: block;
  padding: 0.35rem var(--gap-lg);
  color: var(--text);
  text-decoration: none;
}

.nav-link:hover {
  background: var(--accent-subtle);
}

.nav-link[aria-current="page"] {
  background: var(--accent-subtle);
  border-left: 3px solid var(--accent);
  padding-left: calc(var(--gap-lg) - 3px);
  font-weight: 600;
}

.nav-pending {
  color: var(--text-muted);
}

/* ── Setup wizard entry point ──────────────────────────────────────────────
 *
 * Below the nav list and separated from it, rather than sorted into it. The
 * wizard explains the other sixteen routes, so listing it as a seventeenth
 * peer would bury the one page a half-configured deployment needs.
 *
 * Deliberately not pinned to the viewport bottom. The sidebar sizes to its
 * content — `.app-body` sets `align-items: flex-start` — so on a long page
 * like the wizard itself, pinning would put this thousands of pixels below
 * the fold. Last in the list, with a rule above it, is the bottom of the menu
 * in the sense that matters.
 */
.app-nav-footer {
  padding: var(--gap) var(--gap-lg) 0;
  border-top: 1px solid var(--border);
}

.nav-setup {
  display: block;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  text-align: center;
  text-decoration: none;
  font-weight: 600;
}

.nav-setup:hover {
  background: var(--accent-subtle);
}

.nav-setup[aria-current="page"] {
  background: var(--accent);
  color: var(--bg-raised);
}

/* ── The wizard itself ────────────────────────────────────────────────── */

.setup-intro {
  max-width: 60ch;
}

.setup-summary {
  margin: var(--gap-lg) 0;
  padding: var(--gap);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.setup-posture {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  margin: var(--gap) 0;
  padding: 0;
}

.posture {
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.posture-yes {
  background: var(--ok-bg);
  border: 1px solid var(--ok-border);
  color: var(--ok-text);
}

.posture-no {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
}

.setup-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--gap);
}

.setup-step {
  padding: var(--gap);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  /* The state is carried by a left edge and by the text label in the header,
   * never by colour alone — the four states have to be distinguishable
   * without it. */
  border-left-width: 4px;
  border-radius: 4px;
}

.setup-done {
  border-left-color: var(--ok-border);
}

.setup-todo {
  border-left-color: var(--accent);
}

.setup-attention {
  border-left-color: var(--warn-border);
}

.setup-optional {
  border-left-color: var(--border);
}

.setup-head {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.setup-head h3 {
  margin: 0;
  flex: 1;
  font-size: 1rem;
}

.setup-number {
  flex: 0 0 1.5rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.setup-state {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.setup-done .setup-state {
  color: var(--ok-text);
}

.setup-attention .setup-state {
  color: var(--warn-text);
}

.setup-why {
  max-width: 68ch;
  margin: 0.5rem 0 0.35rem;
}

.setup-detail {
  margin: 0 0 0.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.setup-link {
  font-weight: 600;
}

.setup-note {
  margin-top: var(--gap-lg);
  padding: var(--gap);
  border: 1px solid var(--border);
  border-radius: 4px;
  max-width: 68ch;
}

.setup-note h2 {
  margin-top: 0;
  font-size: 1rem;
}

/* ── The discussion under a thread (§9.2) ─────────────────────────────────
 *
 * Open by default. It is collapsible because a long thread should not push
 * the draft off the screen — §9.2 wants the whole item on one screen at
 * 1440x900 — but collapsed by default would make the context easy to skip,
 * and the reviewer is being asked to approve a reply the model wrote *with*
 * this context.
 */
.thread-comments {
  margin: var(--gap) 0;
  padding: var(--gap-xs) var(--gap);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  /* Scrolls inside itself rather than growing the item. */
  max-height: 18rem;
  overflow-y: auto;
}

.thread-comments summary {
  cursor: pointer;
  font-weight: 600;
  padding: var(--gap-xs) 0;
}

.thread-comments ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.thread-comment {
  padding: var(--gap-xs) 0;
  border-top: 1px solid var(--border);
}

.thread-comment p {
  margin: 0.15rem 0;
}

.comment-meta {
  font-size: 0.85rem;
  font-weight: 600;
}

.app-main {
  flex: 1;
  padding: var(--gap-lg);
  max-width: 60rem;
}

/* ── Cards and banners ────────────────────────────────────────────────── */

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap-lg);
  margin-bottom: var(--gap-lg);
}

.card-warn {
  border-left: 4px solid var(--warn-border);
}

.banner {
  padding: var(--gap-sm) var(--gap);
  border-radius: var(--radius);
  border: 1px solid;
  margin: 0 0 var(--gap);
}

.banner-error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}

.banner-ok {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok-text);
}

.banner-warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-text);
}

.muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.pill {
  display: inline-block;
  margin-left: var(--gap-sm);
  padding: 0.05rem 0.4rem;
  border-radius: var(--radius);
  font-size: 0.75rem;
  text-transform: uppercase;
}

.pill-warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
}

/* ── Forms ────────────────────────────────────────────────────────────── */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  align-items: flex-start;
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--gap-xs);
  width: 100%;
  max-width: 34rem;
}

label,
.label-like {
  font-weight: 600;
  font-size: 0.9rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
  font: inherit;
  padding: 0.4rem 0.5rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  width: 100%;
}

textarea {
  resize: vertical;
}

.field .muted {
  margin: 0;
}

.fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
  width: 100%;
  max-width: 34rem;
}

.fieldset legend {
  font-weight: 600;
  padding: 0 var(--gap-xs);
}

.checks {
  list-style: none;
  margin: var(--gap-sm) 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap-xs);
}

.check {
  display: flex;
  align-items: baseline;
  gap: var(--gap-sm);
  font-weight: 400;
}

/* The universal floor renders locked: it is policy, not a choice. */
.check-locked {
  color: var(--text-muted);
}

.btn {
  font: inherit;
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-inverse);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-quiet {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
  padding: 0.2rem 0.4rem;
}

.inline-form {
  display: inline;
}

/* ── Tables ───────────────────────────────────────────────────────────── */

.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data th,
.data td {
  text-align: left;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data thead th {
  border-bottom: 2px solid var(--border-strong);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.data .numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.detail {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--gap-xs) var(--gap);
  margin: 0 0 var(--gap);
  font-size: 0.9rem;
}

.detail dt {
  font-weight: 600;
  color: var(--text-muted);
}

.detail dd {
  margin: 0;
}

/* ── Authentication screens ───────────────────────────────────────────── */

.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gap-lg);
}

.auth-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap-lg);
  width: 100%;
  max-width: 26rem;
}

.auth-card h1 {
  font-size: 1.2rem;
  margin: var(--gap-xs) 0 var(--gap-lg);
}

.auth-card .btn-primary {
  align-self: stretch;
  text-align: center;
}

.secret {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  padding: 0.3rem 0.5rem;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  word-break: break-all;
}

.recovery-codes {
  list-style: none;
  margin: var(--gap) 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap-xs);
  font-family: var(--font-mono);
}

/* Visually hidden but available to assistive technology. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Assessment display (/threads) ───────────────────────────────────── */

.score {
  display: inline-block;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}

.rationale {
  margin: var(--gap-xs) 0 0;
  max-width: 34rem;
}

.reasons {
  list-style: none;
  margin: var(--gap-xs) 0 0;
  padding: 0;
  font-size: 0.85rem;
  color: var(--warn-text);
}

.reasons li::before {
  content: "— ";
}

/* ── Review queue (§9.2) ───────────────────────────────────────────────
 *
 * The layout target is one item fully visible at 1440×900 with no page
 * scroll: thread, score, rationale, findings and editor all readable at
 * once. Long content (a thread body, a heavily annotated draft) scrolls
 * inside its own pane rather than pushing the actions off-screen, because
 * an action a reviewer has to hunt for is an action they stop taking.
 */

.queue-count {
  margin-bottom: var(--gap);
}

.queue-count kbd {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 var(--gap-xs);
  background: var(--bg-sunken);
  color: var(--text);
}

.review-queue {
  display: flex;
  flex-direction: column;
  gap: var(--gap-lg);
}

.review-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  padding: var(--gap);
}

.review-item:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

.review-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--gap-sm);
  padding-bottom: var(--gap-sm);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--gap);
}

.review-position {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.review-campaign {
  font-weight: 600;
}

.review-cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--gap-lg);
  align-items: start;
}

@media (max-width: 1100px) {
  .review-cols {
    grid-template-columns: minmax(0, 1fr);
  }
}

.thread-title {
  font-size: 1.05rem;
  margin: 0 0 var(--gap-xs);
}

.thread-meta {
  margin: 0 0 var(--gap-sm);
  font-size: 0.85rem;
}

/* Attacker-controlled text. Bounded height so a wall of forum text cannot
 * push the draft and its actions out of view. */
.thread-body {
  max-height: 15rem;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-sunken);
  padding: var(--gap-sm);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.thread-body p {
  margin: 0;
}

.assessment {
  margin-top: var(--gap);
}

.assessment h3 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 var(--gap-xs);
}

.review-draft h3 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 var(--gap-xs);
}

.draft-annotated {
  max-height: 12rem;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-sunken);
  padding: var(--gap-sm);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin-bottom: var(--gap);
}

/* A guard finding, marked on the words that caused it. Underline as well as
 * colour: colour alone is not a distinction (WCAG 1.4.1). */
.guard {
  background: var(--warn-bg);
  color: var(--warn-text);
  text-decoration: underline wavy var(--warn-border);
  text-underline-offset: 2px;
  border-radius: 2px;
  padding: 0 1px;
}

.guard-identity_claim,
.guard-disclosure_missing,
.guard-prompt_leak {
  background: var(--error-bg);
  color: var(--error-text);
  text-decoration-color: var(--error-border);
  font-weight: 600;
}

/* The disclosure sentence, distinguished wherever it appears. */
.disclosure-span {
  background: var(--accent-subtle);
  border-bottom: 2px solid var(--accent);
  padding: 0 1px;
}

.draft-editor {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.45;
  width: 100%;
}

/* An edited draft looks different from an untouched one, so a reviewer
 * scrolling back can tell which they have already worked on. */
.draft-editor.edited {
  border-color: var(--accent);
}

.word-count {
  margin: var(--gap-xs) 0 0;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.word-count.over {
  color: var(--warn-text);
  background: var(--warn-bg);
  border-left: 3px solid var(--warn-border);
  padding: var(--gap-xs) var(--gap-sm);
  font-weight: 600;
}

.disclosure-note {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--bg-sunken);
  padding: var(--gap-sm);
  margin: var(--gap-sm) 0;
}

.disclosure-note p {
  margin: var(--gap-xs) 0 0;
  font-size: 0.85rem;
}

.draft-form,
.reject-form {
  margin: 0;
}

.reject-form {
  margin-top: var(--gap);
  padding-top: var(--gap-sm);
  border-top: 1px solid var(--border);
}

.claims-block {
  margin: var(--gap) 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap-sm);
}

.claims-block > summary {
  cursor: pointer;
  font-weight: 600;
}

.claim {
  border-top: 1px solid var(--border);
  padding: var(--gap-xs) 0;
}

.claim:first-of-type {
  border-top: 0;
}

.claim > summary {
  cursor: pointer;
}

.claim p {
  margin: var(--gap-xs) 0 0;
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: reduce) {
  .review-queue {
    scroll-behavior: auto;
  }
}

/* A numbered list of preconditions, as on /accounts. Denser than a default
   <ol> and with the leading label carrying the weight. */
.detail-list {
  margin: var(--gap-sm) 0 0;
  padding-left: 1.25rem;
}

.detail-list li {
  margin-bottom: var(--gap-sm);
}

/* Audit-log state payloads. Monospace and bounded: these are JSON blobs that
   can carry a whole forum post, and an unbounded <pre> would make one row
   taller than the screen. */
.audit-json {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.4;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap-sm);
  margin: var(--gap-xs) 0 var(--gap-sm);
  max-height: 18rem;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Install page: hashes and shell commands. Both are things an operator copies,
   so they get monospace, selectable text, and enough contrast to read a hex
   digest character by character. */
.hash {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  word-break: break-all;
  background: var(--bg-sunken);
  padding: var(--gap-xs) var(--gap-sm);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: inline-block;
}

.cmd {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.5;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: var(--gap-sm);
  margin: var(--gap-sm) 0;
  overflow-x: auto;
  white-space: pre;
  user-select: all;
}
