@import url("https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,300;0,400;0,500;0,700;1,400&family=Roboto+Condensed:wght@500;600;700&display=swap");

/* ==========================================================================
   COI Re-extraction — EvidentID brand
   Design tokens (cross-file contract). Light is the default; dark overrides
   via :root[data-theme="dark"]. Brand green (#2BB597) is the single accent.
   ========================================================================== */

:root,
:root[data-theme="light"] {
  --bg: #f2f4f6;
  --surface: #ffffff;
  --surface-2: #f2f4f6;
  --border: #dde3e8;
  --ink: #23313a;
  --muted: #788fa2;
  --accent: #2bb597;
  --accent-hover: #1f9c82;
  --accent-contrast: #ffffff;
  --danger: #f15b47;
  --danger-bg: #feefed;
  --warn: #feb649;
  --warn-bg: #fef9ec;
  --ok: #38b349;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(35, 49, 58, 0.06), 0 2px 8px rgba(35, 49, 58, 0.06);
  --shadow-lg: 0 8px 24px rgba(35, 49, 58, 0.12), 0 2px 6px rgba(35, 49, 58, 0.06);

  --font: "Roboto", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-head: "Roboto Condensed", "Roboto", system-ui, sans-serif;

  /* Internal helper tints (not part of the shared contract) */
  --accent-tint: rgba(43, 181, 151, 0.1);
  --accent-ring: rgba(43, 181, 151, 0.35);
  --hover: rgba(35, 49, 58, 0.04);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #1b262c;
  --surface: #23313a;
  --surface-2: #2d3f50;
  --border: #3a4a55;
  --ink: #eaecee;
  --muted: #9aabb9;
  --accent: #2bb597;
  --accent-hover: #60c7b1;
  --accent-contrast: #10201b;
  --danger: #f15b47;
  --danger-bg: #3a2723;
  --warn: #feb649;
  --warn-bg: #3a3220;
  --ok: #38b349;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.4);

  --accent-tint: rgba(43, 181, 151, 0.16);
  --accent-ring: rgba(96, 199, 177, 0.45);
  --hover: rgba(255, 255, 255, 0.05);
  color-scheme: dark;
}

/* ==========================================================================
   Base
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3 {
  font-family: var(--font-head);
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
  color: var(--ink);
}

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

code,
pre {
  font-family: "SFMono-Regular", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
}

/* Page shell — app.js/ui.js may or may not wrap in a container; be tolerant. */
.app,
main {
  max-width: 920px;
  margin-inline: auto;
}

main {
  padding: 1.5rem 1.25rem 4rem;
  display: block;
}

/* ==========================================================================
   Header
   ========================================================================== */

.app-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  max-width: 920px;
  margin: 0 auto;
  padding: 1.1rem 1.25rem;
}

.brand {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: 0.005em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0;
}

/* Brand accent tick before the title (used only when no logo is present) */
.brand::before {
  content: "";
  width: 0.55rem;
  height: 1.35rem;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent-hover));
  flex: none;
}

/* When the brand carries the Evident logo, drop the gradient tick. */
.brand--logo::before { display: none; }
.brand--btn.brand--logo { gap: 0.7rem; }

/* Evident wordmark logo. The source PNG has a solid white background, so it
   sits on a white "chip" that keeps it legible in BOTH themes. */
.brand-chip {
  display: inline-flex;
  align-items: center;
  background: #ffffff;
  border-radius: 6px;
  padding: 4px 7px;
  box-shadow: inset 0 0 0 1px rgba(35, 49, 58, 0.08);
}
.brand-chip img { display: block; height: 22px; width: auto; }
.brand-chip--lg { border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); }
.brand-chip--lg img { height: 34px; }

.brand__sep { width: 1px; height: 1.15rem; background: var(--border); flex: none; }
.brand__name {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: 0.005em;
  color: var(--ink);
}
.brand--btn:hover .brand__name { color: var(--accent); }

.env-badge {
  font-family: var(--font-head);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  line-height: 1.4;
}

/* Optional env-derived accents if HTML sets data-env */
.env-badge[data-env="prod"] {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-bg);
}
.env-badge[data-env="int"] {
  color: var(--warn);
  border-color: var(--warn);
  background: var(--warn-bg);
}
.env-badge[data-env="dev"],
.env-badge[data-env="local"] {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-tint);
}

.theme-toggle {
  margin-left: auto;
  width: 2.4rem;
  height: 2.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.theme-toggle:hover {
  background: var(--hover);
  border-color: var(--muted);
}

.theme-toggle:active {
  transform: scale(0.94);
}

/* ==========================================================================
   Stepper — signature element: a connected Select -> Review -> Run rail
   ========================================================================== */

.stepper {
  display: flex;
  align-items: flex-start;
  gap: 0;
  max-width: 920px;
  margin: 0.25rem auto 1.6rem;
  padding: 0 1.25rem;
  counter-reset: step;
}

.step {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  text-align: center;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

/* the step number comes from the CSS counter on .step::before;
   hide the literal markup fallback so it isn't rendered twice */
.step__num { display: none; }

/* numbered marker */
.step::before {
  counter-increment: step;
  content: counter(step);
  z-index: 1;
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* connecting rail between markers */
.step::after {
  content: "";
  position: absolute;
  top: 1rem;
  left: -50%;
  width: 100%;
  height: 2px;
  background: var(--border);
  z-index: 0;
  transition: background 0.2s ease;
}

.step:first-child::after {
  display: none;
}

.step.is-active {
  color: var(--ink);
}

.step.is-active::before {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-tint);
  box-shadow: 0 0 0 4px var(--accent-tint);
}

.step.is-done {
  color: var(--ink);
}

.step.is-done::before {
  content: "\2713"; /* checkmark */
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.step.is-done::after {
  background: var(--accent);
}

/* ==========================================================================
   Cards / views
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.75rem;
}

.view {
  max-width: 920px;
  margin: 0 auto 1.25rem;
}

.view h2 {
  font-size: 1.15rem;
  margin-bottom: 1.1rem;
}

/* Field grouping helpers (used loosely by the layout) */
.field,
.form-row {
  margin-bottom: 1.4rem;
}

.field > label,
.field-label,
label.block {
  display: block;
  font-weight: 500;
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

/* ==========================================================================
   Combobox (relying-party search)
   ========================================================================== */

.combobox {
  position: relative;
}

.combobox__input {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 2.5rem 0.7rem 2.5rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  /* left-aligned search icon */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23788fa2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.8rem center;
  background-size: 18px 18px;
}

.combobox__input::placeholder {
  color: var(--muted);
}

.combobox__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* Spinner pinned to the right side of the input. Scoped to __control so a
   spinner rendered inside the results panel stays inline (not absolute).
   Center with margin (not transform) so the spin keyframe stays free.
   Larger + thicker + two full-accent arcs so the search is unmistakable. */
.combobox__control .spinner {
  position: absolute;
  right: 0.8rem;
  top: 50%;
  width: 1.4rem;
  height: 1.4rem;
  margin-top: -0.7rem;
  border-width: 3px;
  border-color: color-mix(in srgb, var(--accent) 22%, transparent);
  border-top-color: var(--accent);
  border-right-color: var(--accent);
  animation-duration: 0.6s;
}

/* "Searching…" status row shown in the results panel while a search runs. */
.combobox__loading {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.7rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.spinner--sm {
  width: 0.95rem;
  height: 0.95rem;
  border-width: 2px;
}

.combobox__panel {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  max-height: 320px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 0.35rem;
}

.combobox__option {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s ease;
}

.combobox__option:hover,
.combobox__option.is-active,
.combobox__option[aria-selected="true"] {
  background: var(--accent-tint);
}

.combobox__option-name {
  font-weight: 500;
  color: var(--ink);
  font-size: 0.92rem;
}

.combobox__option-dn {
  font-size: 0.76rem;
  color: var(--muted);
  word-break: break-all;
}

/* selected chip */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.4rem 0.5rem 0.4rem 0.85rem;
  background: var(--accent-tint);
  border: 1px solid var(--accent);
  color: var(--ink);
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 500;
  max-width: 100%;
}

.chip__remove {
  width: 1.3rem;
  height: 1.3rem;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
}

.chip__remove:hover {
  background: var(--accent-hover);
}

/* ==========================================================================
   Risk-profile checkbox list
   ========================================================================== */

.rp-list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.rp-list__filter {
  width: 100%;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--surface-2);
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 0.85rem;
}

.rp-list__filter::placeholder {
  color: var(--muted);
}

.rp-list__filter:focus {
  outline: none;
  box-shadow: inset 0 -2px 0 var(--accent);
}

.rp-list__all {
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 600;
}

.rp-list__options {
  max-height: 280px;
  overflow-y: auto;
}

/* one clickable row */
.rp-option {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.85rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s ease;
}

.rp-list__options .rp-option + .rp-option {
  border-top: 1px solid var(--border);
}

.rp-option:hover {
  background: var(--hover);
}

.rp-option__label {
  font-size: 0.92rem;
  color: var(--ink);
}

.rp-list__count {
  padding: 0.6rem 0.85rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.empty {
  padding: 1.5rem 0.85rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  font-style: italic;
}

/* ==========================================================================
   Custom checkboxes (risk-profile rows + table)
   ========================================================================== */

.rp-option__cb,
.data-table input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  border: 2px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  cursor: pointer;
  position: relative;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.rp-option__cb:checked,
.data-table input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.rp-option__cb:checked::after,
.data-table input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid var(--accent-contrast);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.rp-option__cb:indeterminate,
.data-table input[type="checkbox"]:indeterminate {
  background: var(--accent);
  border-color: var(--accent);
}

.rp-option__cb:indeterminate::after,
.data-table input[type="checkbox"]:indeterminate::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 6px;
  width: 9px;
  height: 2px;
  background: var(--accent-contrast);
}

.rp-option__cb:focus-visible,
.data-table input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font);
  font-weight: 500;
  font-size: 0.92rem;
  line-height: 1;
  padding: 0.7rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.08s ease, box-shadow 0.15s ease;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

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

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

.btn--ghost {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border);
}

.btn--ghost:hover {
  background: var(--hover);
  border-color: var(--muted);
}

.btn--danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn--danger:hover {
  background: color-mix(in srgb, var(--danger) 85%, #000);
  border-color: color-mix(in srgb, var(--danger) 85%, #000);
}

.btn--danger.is-loading::after {
  border-color: rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
}

.btn:disabled,
.btn.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* inline spinner for in-flight buttons (no extra markup needed) */
.btn.is-loading {
  cursor: progress;
  color: transparent !important;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 1.05rem;
  height: 1.05rem;
  border: 2px solid currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn--primary.is-loading::after {
  border-color: rgba(255, 255, 255, 0.4);
  border-top-color: var(--accent-contrast);
}

.btn--ghost.is-loading::after {
  border-color: var(--border);
  border-top-color: var(--accent);
}

/* ==========================================================================
   Review — data table
   ========================================================================== */

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: left;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table tbody td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  vertical-align: middle;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* zebra */
.data-table tbody tr:nth-child(even) {
  background: var(--surface-2);
}

.data-table tbody tr:hover {
  background: var(--accent-tint);
}

/* keep checkbox columns tight */
.data-table th:first-child,
.data-table td:first-child {
  width: 1px;
  white-space: nowrap;
}

/* Scroll wrapper so wide tables never break the layout */
.table-wrap,
.data-table-scroll,
.data-table__scroll {
  overflow-x: auto;
  border-radius: var(--radius);
}

/* ==========================================================================
   Badges
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.badge--ok {
  color: var(--ok);
  background: var(--accent-tint);
  border-color: color-mix(in srgb, var(--ok) 45%, transparent);
}

.badge--warn {
  color: #a6740b;
  background: var(--warn-bg);
  border-color: color-mix(in srgb, var(--warn) 55%, transparent);
}

:root[data-theme="dark"] .badge--warn {
  color: var(--warn);
}

.badge--danger {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: color-mix(in srgb, var(--danger) 55%, transparent);
}

/* running status badge with a pulsing dot */
.badge--running {
  color: var(--accent);
  background: var(--accent-tint);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.badge--running::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.3s ease-in-out infinite;
}

/* ==========================================================================
   Banner / errors
   ========================================================================== */

.banner {
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  font-size: 0.88rem;
  margin-bottom: 1.25rem;
  display: flex;
  gap: 0.6rem;
  line-height: 1.45;
}

.banner--warn {
  background: var(--warn-bg);
  border: 1px solid color-mix(in srgb, var(--warn) 55%, transparent);
  color: var(--ink);
}

.banner--warn::before {
  content: "\26A0"; /* warning sign */
  color: var(--warn);
  font-size: 1rem;
  line-height: 1.4;
  flex: none;
}

.banner--info {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--ink);
}

.banner--info::before {
  content: "\2139"; /* information source */
  color: var(--accent);
  font-size: 1rem;
  line-height: 1.4;
  flex: none;
}

.banner--danger {
  background: var(--danger-bg);
  border: 1px solid color-mix(in srgb, var(--danger) 55%, transparent);
  color: var(--ink);
}

.banner--danger::before {
  content: "\26A0"; /* warning sign */
  color: var(--danger);
  font-size: 1rem;
  line-height: 1.4;
  flex: none;
}

/* Multi-line banner content (heading + steps) */
.banner__body {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.banner__body strong {
  font-weight: 600;
}

.banner__list {
  margin: 0.15rem 0 0;
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0.75rem 0 0;
  min-height: 1.1em;
  white-space: pre-wrap;
}

.error:not(:empty) {
  background: var(--danger-bg);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
}

/* ==========================================================================
   Review actions
   ========================================================================== */

.review__actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.review__count {
  margin-left: auto;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
}

/* ==========================================================================
   Run view — terminal log (dark in BOTH themes)
   ========================================================================== */

.run__head,
.run-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

#job-id {
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
}

.log {
  background: #101a21;
  color: #d6e4e0;
  border: 1px solid #1f2d36;
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  font-size: 0.82rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
  max-height: 460px;
  margin: 0 0 1rem;
  box-shadow: inset 0 1px 8px rgba(0, 0, 0, 0.4);
}

.log::selection {
  background: rgba(43, 181, 151, 0.4);
}

/* ==========================================================================
   Utilities & state
   ========================================================================== */

.hidden {
  display: none !important;
}

.is-disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* Spinner (rotating). Works as a bare element with no children. */
.spinner {
  width: 1.15rem;
  height: 1.15rem;
  flex: none;
  border: 2px solid var(--accent-ring);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

/* Skeleton shimmer */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: 6px;
  color: transparent !important;
}

/* skeleton rows inside the risk-profile list */
.rp-list__options .skeleton {
  height: 1rem;
  margin: 0.85rem;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    transparent,
    color-mix(in srgb, var(--ink) 8%, transparent),
    transparent
  );
  animation: shimmer 1.4s ease-in-out infinite;
}

/* ==========================================================================
   Keyframes
   ========================================================================== */

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  100% {
    transform: translateX(100%);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.35;
    transform: scale(0.7);
  }
}

/* Opacity-only pulse for reduced-motion: keeps the spinner alive without
   any translate/scale motion. */
@keyframes rp-pulse-fade {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

/* ==========================================================================
   Accessibility — visible focus, reduced motion
   ========================================================================== */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* elements that manage their own focus ring shouldn't get the default too */
.btn:focus-visible,
.combobox__input:focus,
.rp-option__cb:focus-visible,
.data-table input[type="checkbox"]:focus-visible,
.theme-toggle:focus-visible {
  outline: none;
}

.theme-toggle:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-ring);
}

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

  .skeleton::after {
    display: none;
  }

  .spinner,
  .combobox .spinner,
  .btn.is-loading::after {
    animation: none;
    border-top-color: var(--accent);
  }

  /* Keep the RP search spinner alive with a gentle opacity-only pulse.
     The "Searching…" status row is the primary affordance here; this just
     reinforces it without any vestibular-triggering motion. */
  .combobox .spinner {
    animation: rp-pulse-fade 1.4s ease-in-out infinite !important;
  }

  .badge--running::before {
    animation: none;
    opacity: 0.85;
  }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 640px) {
  main {
    padding: 1rem 0.85rem 3rem;
  }

  .card {
    padding: 1.15rem;
    border-radius: var(--radius);
  }

  .app-header {
    padding: 0.9rem 0.85rem;
    gap: 0.6rem;
  }

  .brand {
    font-size: 1.1rem;
  }

  .stepper {
    padding: 0 0.85rem;
  }

  .step {
    font-size: 0.68rem;
    letter-spacing: 0.02em;
  }

  .review__actions {
    flex-wrap: wrap;
  }

  .review__count {
    width: 100%;
    margin-left: 0;
    order: -1;
    margin-bottom: 0.25rem;
  }

  .btn {
    flex: 1 1 auto;
  }

  .data-table {
    font-size: 0.82rem;
  }

  .hub-hero__title { font-size: 1.45rem; }
  .brand__name { font-size: 1.05rem; }
  .brand-chip img { height: 20px; }
}

/* ==========================================================================
   Auth — Google login gate + header identity
   ========================================================================== */

/* Blocking gate: covers the viewport until the user signs in. The app
   (header, stepper, main) is hidden until <body> gains .authed. */
#login-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--bg);
  z-index: 50;
}

body.authed #login-gate {
  display: none;
}

body:not(.authed) .app-header,
body:not(.authed) .stepper,
body:not(.authed) .app-main {
  display: none;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.25rem 2rem;
  max-width: 24rem;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}
.login-brand__name {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 0.005em;
  color: var(--ink);
}

.login-card__sub {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
  margin: 0 0 1.5rem;
}

.g-signin {
  display: flex;
  justify-content: center;
  min-height: 44px;
}

.login-card .error {
  margin-top: 1rem;
}

/* Header right-side cluster: identity + sign-out + theme toggle. */
.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* The wrapper owns the right-alignment now; neutralise the toggle's own auto. */
.header-right .theme-toggle {
  margin-left: 0;
}

.user-email {
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Active-runs drawer --- */
.drawer { position: fixed; inset: 0; z-index: 100; }
.drawer.hidden { display: none; }
.drawer__backdrop {
  position: absolute; inset: 0;
  background: rgba(35, 49, 58, 0.45);
}
.drawer__panel {
  position: absolute; top: 0; right: 0; height: 100%;
  width: min(460px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  padding: 20px;
  overflow-y: auto;
}
.drawer__head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.drawer__title { font-family: var(--font-head); margin: 0; }
.jobs-list { display: flex; flex-direction: column; gap: 10px; }
.jobs-list__empty { color: var(--muted); }
.job-card {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "badge rp" "meta meta" "by by";
  gap: 4px 10px;
  width: 100%; text-align: left; cursor: pointer;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font: inherit; color: var(--ink);
}
.job-card:hover { background: var(--hover); border-color: var(--accent-ring); }
.job-card .badge { grid-area: badge; align-self: center; }
.job-card__rp { grid-area: rp; align-self: center; font-weight: 700; }
.job-card__by { grid-area: by; color: var(--muted); font-size: 0.9em; }
.job-card__meta { grid-area: meta; color: var(--muted); font-size: 0.9em; }

/* --- Confirm modal (type-to-confirm gate for irreversible executes) --- */
.modal { position: fixed; inset: 0; z-index: 110;
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal.hidden { display: none; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(35, 49, 58, 0.45); }
.modal__panel {
  position: relative;
  width: min(440px, 94vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 20px;
}
.modal__panel .banner { margin-bottom: 1rem; }
.modal__actions {
  display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px;
}
/* The phrase the user must type — made deliberately prominent and high-contrast
   so it's unmistakable which exact value to enter. */
#confirm-phrase {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.4;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 16%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 55%, transparent);
  border-radius: 6px;
  padding: 1px 8px;
  letter-spacing: 0.02em;
  text-transform: none;   /* show the true casing, not the label's uppercase */
  user-select: all;       /* one click selects the whole phrase to copy */
}
#confirm-modal .field__label { font-size: 0.95rem; }

/* --- Post-dry-run "execute for real" CTA --- */
.run-actions { margin-top: 4px; }
.run-execute {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  border-radius: var(--radius);
  background: var(--danger-bg);
}
.run-execute.hidden { display: none; }
.run-execute__note { margin: 0 0 12px; color: var(--ink); }

/* ==========================================================================
   Automation Hub — landing tiles + generic manifest form
   ========================================================================== */

/* Header brand rendered as a button (home / all automations) */
.brand--btn {
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  font: inherit;
}
.brand--btn:hover { color: var(--accent); }

.view__desc { color: var(--muted); margin: -4px 0 16px; }
.btn--back { margin-bottom: 12px; }

/* Hub landing hero */
.hub-hero { margin-bottom: 1.6rem; }
.hub-hero__title { font-size: 1.75rem; line-height: 1.15; }
.hub-hero__sub {
  color: var(--muted);
  font-size: 1rem;
  margin: 0.4rem 0 0;
  max-width: 46ch;
}
.hub-hero__meta {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-top: 1.1rem;
}
.hub-hero__meta::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.hub-hero__count {
  font-family: var(--font-head);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

/* Hub tiles */
.hub-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.hub-tiles__loading { color: var(--muted); }

/* Signature element: a status spine that encodes how dangerous the automation
   is — brand green for safe, danger-red for destructive ones. */
.tile {
  position: relative;
  display: block;
  overflow: hidden;
  text-align: left;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  font: inherit;
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: border-color 0.14s ease, box-shadow 0.14s ease, transform 0.14s ease;
}
.tile__spine {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--accent);
  transition: width 0.14s ease;
}
.tile--danger .tile__spine { background: var(--danger); }

.tile__body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px 18px 15px 22px;
}
.tile:hover {
  border-color: var(--accent-ring);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}
.tile--danger:hover {
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}
.tile:hover .tile__spine { width: 6px; }
.tile:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.tile--danger:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 40%, transparent);
}

.tile__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.tile__title {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.15rem;
  line-height: 1.2;
}
.tile__tag {
  flex: none;
  font-family: var(--font-head);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 700;
}
.tile__tag--danger {
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
}
.tile__desc {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tile__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.tile__kind {
  font-family: var(--font-head);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
}
.tile__open {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--accent);
}
.tile--danger .tile__open { color: var(--danger); }
.tile__arrow { transition: transform 0.14s ease; }
.tile:hover .tile__arrow { transform: translateX(3px); }

/* Generic manifest form */
.generic-form { display: flex; flex-direction: column; gap: 16px; margin-bottom: 8px; }
.gf-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
.gf-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.gf-textarea { resize: vertical; min-height: 88px; font-family: ui-monospace, monospace; }
.gf-help { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 4px; }
.gf-check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.gf-check input { width: 16px; height: 16px; accent-color: var(--accent); }
.req { color: var(--danger); }
