/* Design tokens live in tokens.css; this file styles components against
   the aliased variables (--fg, --bg, --muted, --line, --accent, --ok, --warn, --bad).
   Do NOT re-declare those aliases here — it would override the dark-mode
   overrides defined in tokens.css. */

* { box-sizing: border-box; }
body {
  font-family: var(--font-body);
  color: var(--fg);
  background: var(--bg);
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color-scheme: inherit;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.truncate { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { padding: 24px; max-width: 1200px; margin: 0 auto; }
footer { padding: 16px 24px; color: var(--muted); font-size: 12px; text-align: center; border-top: 1px solid var(--line); margin-top: 48px; }

h1 { font-size: 20px; margin: 0 0 8px 0; }
h2 { font-size: 16px; margin: 24px 0 12px 0; }

.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.agent-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px;
}
.agent-card header { display: flex; justify-content: space-between; align-items: baseline; }
.agent-card h2 { margin: 0; font-size: 16px; }
.agent-card .counts { margin: 12px 0 8px 0; }
.agent-card .counts .total { font-size: 28px; font-weight: 600; margin-right: 8px; }
.agent-card .counts .label { color: var(--muted); font-size: 12px; }
.agent-card .actions { list-style: none; padding: 0; margin: 8px 0 0 0; display: flex; flex-wrap: wrap; gap: 4px; }
.agent-card .actions li { font-size: 12px; background: var(--bg); padding: 2px 8px; border-radius: 12px; }
.agent-card .actions .action { color: var(--muted); margin-right: 4px; }

table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
th { background: var(--bg); font-weight: 600; color: var(--muted); }
tr:last-child td { border-bottom: none; }
tr:hover { background: var(--surface-sunken); }

.event-meta { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; background: var(--surface); padding: 16px; border: 1px solid var(--line); border-radius: 4px; }
.event-meta dt { color: var(--muted); font-size: 12px; }
.event-meta dd { margin: 0; }

pre.payload {
  background: #282c34;
  color: #f8f8f2;
  padding: 16px;
  border-radius: 4px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.5;
  max-height: 600px;
  font-family: var(--font-mono);
}

/* ── Proposal diff (unified) ─────────────────────────────── */

.diff-box {
  background: #1e2127;
  color: #d8d8d8;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  border-radius: 4px;
  padding: 8px 0;
  max-height: 640px;
  overflow: auto;
}
.diff-line {
  padding: 0 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-left: 3px solid transparent;
  min-height: 1.5em;
}
.diff-add  { background: #1c3a26; border-left-color: #4caf50; color: #b6e3c4; }
.diff-del  { background: #3a1c1c; border-left-color: #e57373; color: #f0b3b3; }
.diff-hunk { background: #2c2f36; color: #9aa9c2; padding-top: 4px; padding-bottom: 4px; margin: 6px 0; font-weight: 600; }
.diff-header { color: #888; }
.diff-ctx  { color: #c0c0c0; }

/* Side-by-side raw view (collapsed by default under a <details>) */
.diff-table { table-layout: fixed; width: 100%; border-collapse: collapse; }
.diff-table th, .diff-table td { vertical-align: top; width: 50%; padding: 4px; }
pre.diff-raw {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 400px;
  overflow-y: auto;
}

/* ── Controls page ───────────────────────────────────────── */
/* (.flash is now defined in shell.css with token-driven styling.) */

.control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.control-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px;
}

.control-card header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.control-card h2 { margin: 0; font-size: 16px; }

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }

.state {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 4px 8px;
  font-size: 13px;
  margin: 12px 0;
}
.state dt { color: var(--muted); }
.state dd { margin: 0; }

.control-row {
  display: flex;
  gap: 8px;
  margin: 12px 0 8px 0;
  flex-wrap: wrap;
}

.inline-form { margin: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  background: var(--surface-sunken);
  color: var(--fg);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary {
  background: var(--accent);
  color: var(--text-on-brand);
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); color: var(--text-on-brand); }
.btn-caution {
  background: var(--surface);
  color: var(--bad);
  border-color: var(--bad);
}
.btn-caution:hover { background: var(--bad); color: var(--text-on-brand); }
.btn-ghost {
  background: var(--surface);
  border-style: dashed;
}

.reprocess-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.reprocess-form input[type=text] {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--fg);
}
.reprocess-form input[type=text]:focus {
  outline: none;
  border-color: var(--accent);
}

.error {
  color: var(--bad);
  font-size: 13px;
  margin: 12px 0;
}

/* ── Spend page ──────────────────────────────────────────── */
.spend-headlines {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.spend-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.spend-card .label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.spend-card .total {
  font-size: 28px;
  font-weight: 600;
  color: var(--fg);
  font-feature-settings: "tnum";
}

/* ── Facts page ──────────────────────────────────────────── */
.fact-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  flex-wrap: wrap;
}
.filter-bar label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.filter-bar select {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--fg);
  min-width: 140px;
}
.tag {
  display: inline-block;
  background: var(--bg);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-family: -apple-system, sans-serif;
}
.fact-content {
  max-width: 480px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
}
.empty-state {
  text-align: center;
  padding: 48px 24px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 6px;
}
.empty-state p { margin: 8px 0; }
.empty-state code {
  background: var(--surface-sunken);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

/* ── Alerts editor ───────────────────────────────────────── */
.alert-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 20px;
  margin-bottom: 24px;
}
.alert-section-header { margin-bottom: 16px; }
.alert-section-header h2 { margin: 0; font-size: 18px; }
.alert-section-header p { margin: 4px 0 0 0; }
.alert-section-header code {
  background: var(--surface-sunken);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}

.rule-card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 14px;
  margin-bottom: 12px;
}
.rule-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.rule-form { margin: 0; }
.rule-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.rule-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px 16px;
  margin-bottom: 12px;
}
.rule-fields label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.rule-fields label.wide { grid-column: span 2; }
.rule-fields label.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  text-transform: none;
  letter-spacing: normal;
  font-size: 13px;
  color: var(--fg);
}
.rule-fields input[type=text],
.rule-fields input[type=number],
.rule-fields select,
.rule-fields textarea {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--fg);
}
.rule-fields input[type=text]:focus,
.rule-fields input[type=number]:focus,
.rule-fields select:focus,
.rule-fields textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.rule-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

/* Toggle switch */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.toggle input { display: none; }
.toggle-track {
  display: inline-block;
  width: 38px;
  height: 20px;
  background: var(--border-strong);
  border-radius: 10px;
  position: relative;
  transition: background 0.15s;
}
.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--surface);
  border-radius: 50%;
  transition: transform 0.15s;
}
.toggle input:checked + .toggle-track {
  background: var(--ok);
}
.toggle input:checked + .toggle-track::after {
  transform: translateX(18px);
}

.rule-overrides { margin-top: 16px; }
.rule-overrides h3 {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 8px 0;
}

.add-override {
  margin: 12px 0;
  font-size: 13px;
}
.add-override summary {
  cursor: pointer;
  color: var(--accent);
  padding: 6px 0;
}
.add-override summary:hover { text-decoration: underline; }
.inline-new {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  padding: 12px;
  background: var(--bg);
  border-radius: 4px;
  margin-top: 8px;
  align-items: end;
}

.activity-heading {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 24px 0 8px 0;
}
.activity-log { font-size: 12px; }
.activity-log td { padding: 5px 10px; }

/* Dry-run conditions panel on controls + cos pages */
.dry-run-conditions {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border-left: 3px solid var(--warn);
  border-radius: 4px;
  font-size: 13px;
}
.dry-run-conditions summary {
  cursor: pointer;
  padding: 2px 0;
  user-select: none;
}
.dry-run-conditions summary:hover { color: var(--link); }
.dry-run-conditions > p { margin: 8px 0; }
.filter-block {
  margin: 8px 0 6px 0;
  padding: 6px 0;
  border-top: 1px dashed var(--border);
}
.filter-label { font-size: 12px; margin-bottom: 4px; }
.filter-values {
  margin: 4px 0 4px 18px;
  padding: 0;
  font-size: 12px;
}
.filter-values li { padding: 1px 0; }

/* Dry-run semantics callout on /ops/cos */
.cos-dry-run-semantics {
  margin: 12px 0 20px 0;
  padding: 10px 14px;
  background: var(--bg);
  border-left: 3px solid var(--link);
  border-radius: 4px;
  font-size: 13px;
}
.cos-dry-run-semantics h3 { margin: 0 0 6px 0; font-size: 14px; }
.cos-dry-run-semantics ul { margin: 6px 0 0 18px; padding: 0; }
.cos-dry-run-semantics li { margin-bottom: 4px; }

/* Legacy .topbar nav-dropdown rules removed in the cleanup pass —
   they were replaced by the rail + utility bar in Phase 1.4 and no
   template references them anymore. */
