/* Contraflow — control plane.
   Direction: calm technical console. Hairline dividers, restrained slate
   palette, one blue accent, IBM Plex Sans / Plex Mono, no card-in-card. */

:root {
  /* surfaces */
  --bg: #0c0e12;
  --surface: #111419;
  --surface-2: #161a21;
  --surface-3: #1c2129;
  --line: #262b34;
  --line-soft: #1b2028;

  /* ink */
  --ink: #e9edf3;
  --ink-muted: #9aa4b2;
  --ink-faint: #6c7686;

  /* accent + semantics */
  --accent: #8fb4fd;
  --accent-ink: #0a1524;
  --accent-soft: rgba(143, 180, 253, 0.12);
  --ok: #4ecb92;
  --ok-soft: rgba(78, 203, 146, 0.14);
  --warn: #e2a94a;
  --danger: #f2755f;
  --danger-soft: rgba(242, 117, 95, 0.14);

  --font: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;

  --t-xs: 0.6875rem;
  --t-sm: 0.8125rem;
  --t-md: 0.9375rem;
  --t-lg: 1.0625rem;
  --t-xl: 1.375rem;
  --t-2xl: 1.875rem;

  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2.25rem;
  --sp-7: 3.5rem;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  --sidebar: 232px;
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
  --ease: 140ms cubic-bezier(0.32, 0.72, 0, 1);
}

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

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--t-md)/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.015em; line-height: 1.2; }
p { margin: 0; }

a { color: var(--accent); text-underline-offset: 3px; }

.mono { font-family: var(--mono); font-variant-ligatures: none; }
.muted { color: var(--ink-faint); }
.num { font-variant-numeric: tabular-nums; }

:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--r-sm); }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

.kicker {
  font-family: var(--mono);
  font-size: var(--t-xs);
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* --- brand ------------------------------------------------------------ */

.brand {
  display: inline-flex; align-items: center; gap: var(--sp-3);
  color: var(--ink); text-decoration: none; font-weight: 500;
}
.brand-name {
  font-family: var(--mono);
  font-size: var(--t-sm);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.mark { width: 26px; height: 26px; display: block; flex: none; }

.pill {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-muted);
  font-family: var(--mono); font-size: var(--t-xs);
}
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-faint); flex: none; }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }

/* --- public landing --------------------------------------------------- */

.bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-4) clamp(1rem, 4vw, 2.25rem);
  border-bottom: 1px solid var(--line-soft);
}
.bar-nav { display: flex; align-items: center; gap: var(--sp-4); font-size: var(--t-sm); }

.link {
  color: var(--ink-muted); text-decoration: none;
  background: none; border: 0; padding: 0; font: inherit; cursor: pointer;
}
.link:hover { color: var(--ink); }

.wrap {
  width: min(920px, calc(100% - 2.5rem));
  margin: 0 auto;
  padding: clamp(2.5rem, 7vw, 5rem) 0 var(--sp-7);
  display: grid; gap: var(--sp-6);
}

.foot {
  display: flex; justify-content: space-between; align-items: center; gap: var(--sp-4);
  color: var(--ink-faint);
  font-size: var(--t-sm);
}
.foot .mono { font-size: var(--t-xs); letter-spacing: 0.04em; }

/* the public footer shares the landing column, not the full bleed */
body.page-public .foot {
  width: min(920px, calc(100% - 2.5rem));
  margin: 0 auto;
  padding: var(--sp-4) 0 var(--sp-6);
  border-top: 1px solid var(--line-soft);
}

.hero { display: grid; gap: var(--sp-4); }
.hero h1 {
  font-size: clamp(1.9rem, 5vw, 2.75rem);
  line-height: 1.12;
  max-width: 24ch;
  text-wrap: balance;
}
.lede { max-width: 60ch; color: var(--ink-muted); font-size: var(--t-lg); }
.meta { color: var(--ink-faint); font-size: var(--t-xs); letter-spacing: 0.04em; }

.h-sm { font-size: var(--t-md); font-weight: 600; color: var(--ink); }
.h-note { color: var(--ink-faint); font-size: var(--t-xs); letter-spacing: 0.04em; }
.panel-note { color: var(--ink-faint); font-size: var(--t-sm); }

section { display: grid; gap: var(--sp-4); }

.pipeline {
  display: grid; gap: 1px; margin: 0; padding: 0; list-style: none;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  overflow: hidden;
}
.step { display: grid; gap: 2px; padding: var(--sp-4); background: var(--surface); }
.step-n { font-family: var(--mono); font-size: var(--t-xs); color: var(--accent); }
.step-name { font-size: var(--t-md); font-weight: 600; }
.step-note { color: var(--ink-muted); font-size: var(--t-sm); line-height: 1.5; }

.caps {
  display: grid; gap: var(--sp-5); margin: 0; padding: 0; list-style: none;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.cap { display: grid; gap: var(--sp-2); align-content: start; }
.cap h3 { font-size: var(--t-md); }
.cap p { color: var(--ink-muted); font-size: var(--t-sm); line-height: 1.6; }

/* --- gate ------------------------------------------------------------- */

body.page-gate {
  display: grid; place-content: center; padding: var(--sp-5);
  background:
    radial-gradient(900px 480px at 50% -12%, #131b27 0%, transparent 72%),
    var(--bg);
}
.gate {
  width: min(360px, 100%);
  display: grid; gap: var(--sp-6);
  padding: var(--sp-6) var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: 0 30px 80px -40px #000;
}
.gate-head { display: grid; gap: var(--sp-4); justify-items: start; }
.gate-head h1 { font-size: var(--t-xl); }
.gate-form { display: grid; gap: var(--sp-3); }

label {
  font-family: var(--mono);
  font-size: var(--t-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

input[type="password"],
input[type="text"],
input[type="url"],
input[type="number"],
select {
  width: 100%;
  padding: 0.6rem 0.7rem;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font: 400 var(--t-sm)/1.4 var(--mono);
  transition: border-color var(--ease), box-shadow var(--ease);
}
input::placeholder { color: #5c6675; }
input:hover, select:hover { border-color: #333a45; }
input:focus-visible, select:focus-visible {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select { cursor: pointer; appearance: none; background-image: none; }

/* --- buttons ---------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 0.55rem 0.95rem;
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  font: 600 var(--t-sm)/1.2 var(--font);
  cursor: pointer;
  transition: background var(--ease), opacity var(--ease);
}
.btn:hover { background: #a8c6ff; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { box-shadow: var(--focus-ring); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.4rem 0.7rem;
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font: 500 var(--t-xs)/1.2 var(--mono);
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: color var(--ease), border-color var(--ease), background var(--ease);
}
.btn-ghost:hover { color: var(--ink); border-color: #3a424f; background: var(--surface-2); }
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-ghost.is-busy { color: var(--accent); border-color: rgba(143, 180, 253, 0.45); }
.btn-danger { color: #f0907d; }
.btn-danger:hover { color: #ffb0a1; border-color: rgba(242, 117, 95, 0.45); background: var(--danger-soft); }

.btn-danger-solid {
  background: var(--danger);
  color: #200d09;
}
.btn-danger-solid:hover { background: #ff9078; }

.confirm-body { color: var(--ink-muted); font-size: var(--t-sm); }

.inline { display: inline; margin: 0; }

.alert {
  margin: 0;
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--t-sm);
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--r-sm);
  border: 1px solid rgba(242, 117, 95, 0.28);
}
.alert-empty { min-height: 0; padding: 0; background: none; border: 0; }
.help { color: var(--ink-faint); font-size: var(--t-sm); }

/* --- app shell -------------------------------------------------------- */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100dvh;
}

.sidebar {
  display: flex; flex-direction: column; gap: var(--sp-6);
  padding: var(--sp-5) var(--sp-4);
  background: var(--surface);
  border-right: 1px solid var(--line-soft);
  position: sticky; top: 0; height: 100dvh;
}

.side-top { display: flex; align-items: center; }

.side-nav { display: flex; flex-direction: column; gap: 2px; }

.side-link {
  display: block;
  padding: 0.5rem var(--sp-3);
  color: var(--ink-muted);
  text-decoration: none;
  border-radius: var(--r-sm);
  font-size: var(--t-sm);
  font-weight: 500;
  border-left: 2px solid transparent;
  transition: background var(--ease), color var(--ease);
}
.side-link:hover { background: var(--surface-2); color: var(--ink); }
.side-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-left-color: var(--accent);
}

.side-foot { margin-top: auto; padding-top: var(--sp-4); border-top: 1px solid var(--line-soft); }

.side-signout {
  background: none; border: 0; padding: var(--sp-2) var(--sp-3);
  color: var(--ink-faint); font: 500 var(--t-sm)/1.2 var(--font);
  text-align: left; width: 100%; border-radius: var(--r-sm); cursor: pointer;
  transition: color var(--ease), background var(--ease);
}
.side-signout:hover { color: var(--danger); background: var(--danger-soft); }

.app-main { display: flex; flex-direction: column; min-height: 100dvh; min-width: 0; }

.console-main {
  flex: 1;
  width: 100%;
  max-width: 1120px;
  padding: clamp(1.25rem, 3.5vw, 2.5rem);
  display: grid; gap: var(--sp-5); align-content: start;
}

.console-foot {
  padding: var(--sp-4) clamp(1.25rem, 3.5vw, 2.5rem);
  border-top: 1px solid var(--line-soft);
}

.console-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  flex-wrap: wrap; gap: var(--sp-4);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--line-soft);
}
.console-head h1 { font-size: var(--t-2xl); margin-top: 2px; }
.head-meta { color: var(--ink-faint); font-size: var(--t-xs); letter-spacing: 0.04em; }
.head-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

/* --- panels ----------------------------------------------------------- */

.panel { display: grid; gap: var(--sp-3); }
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--sp-3);
}

.stats {
  display: grid; gap: 1px;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  overflow: hidden;
}
.stat { display: grid; gap: 3px; align-content: start; padding: var(--sp-3) var(--sp-4); background: var(--surface); }
.stat-label {
  font-family: var(--mono); font-size: var(--t-xs);
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint);
}
.stat-value { font-size: var(--t-lg); font-weight: 500; }
.stat-note { color: var(--ink-faint); font-size: var(--t-xs); }

/* --- tables ----------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  background: var(--surface);
}

.table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }

.table th, .table td {
  padding: 0.65rem var(--sp-4);
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--line-soft);
}

.table thead th {
  font-family: var(--mono); font-size: var(--t-xs); font-weight: 500;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint);
  background: var(--surface-2);
  white-space: nowrap;
}

.table tbody th { font-weight: 400; }
.table tbody tr:last-child th,
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #141821; }
.table tbody tr.is-testing { background: rgba(143, 180, 253, 0.05); }

.table .empty td {
  color: var(--ink-faint);
  font-size: var(--t-sm);
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
}

.cell-primary { font-weight: 500; color: var(--ink); }
.cell-primary.mono { font-size: var(--t-sm); }
.cell-secondary { color: var(--ink-faint); font-size: var(--t-xs); margin-top: 2px; }
.cell-secondary.mono { font-size: var(--t-xs); }
.cell-wrap { max-width: 34ch; overflow-wrap: anywhere; white-space: normal; }
.cell-error { color: #d98b7c; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40ch; }
.cell-error:empty { display: none; }

.table td.num { white-space: nowrap; }
.unit { color: var(--ink-faint); font-size: var(--t-xs); }

.actions-cell { white-space: nowrap; }
.actions-cell > * + * { margin-left: var(--sp-2); }

/* --- status chips ----------------------------------------------------- */

.status-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--mono); font-size: var(--t-xs); letter-spacing: 0.02em;
  color: var(--ink-faint);
  background: var(--surface-2);
  white-space: nowrap;
}
.status-chip .dot { width: 5px; height: 5px; background: var(--ink-faint); }
.status-ok { color: var(--ok); border-color: rgba(78, 203, 146, 0.32); background: var(--ok-soft); }
.status-ok .dot { background: var(--ok); }
.status-err { color: var(--danger); border-color: rgba(242, 117, 95, 0.32); background: var(--danger-soft); }
.status-err .dot { background: var(--danger); }
.status-idle { color: var(--ink-faint); }
.status-pending { color: var(--accent); border-color: rgba(143, 180, 253, 0.32); background: var(--accent-soft); }
.status-pending .dot { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.35; } }

/* --- forms ------------------------------------------------------------ */

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-4);
}
.field { display: grid; gap: var(--sp-2); align-content: start; }
.field-wide { grid-column: 1 / -1; }

/* --- modal ------------------------------------------------------------ */

.modal {
  padding: 0; border: 0; background: transparent;
  max-width: min(520px, calc(100vw - 2rem));
  width: 100%;
  color: var(--ink);
}
.modal::backdrop { background: rgba(6, 8, 12, 0.72); backdrop-filter: blur(3px); }

.modal-card {
  display: grid; gap: var(--sp-5);
  padding: var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: 0 40px 90px -50px #000;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); }
.modal-head h2 { font-size: var(--t-lg); margin-top: 2px; }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); }

/* --- responsive ------------------------------------------------------- */

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    position: static; height: auto;
    flex-direction: row; align-items: center; gap: var(--sp-4);
    padding: var(--sp-3) var(--sp-4);
    border-right: 0; border-bottom: 1px solid var(--line-soft);
    overflow-x: auto;
  }
  .side-top { flex: none; }
  .side-nav { flex-direction: row; gap: var(--sp-1); }
  .side-link { border-left: 0; border-bottom: 2px solid transparent; border-radius: var(--r-sm); white-space: nowrap; }
  .side-link.active { border-left: 0; border-bottom-color: var(--accent); }
  .side-foot { margin: 0 0 0 auto; padding: 0; border: 0; }
  .side-signout { width: auto; padding: var(--sp-2); white-space: nowrap; }
  .brand-name { display: none; }
  .side-link { white-space: nowrap; }
}

@media (max-width: 700px) {
  .console-head h1 { font-size: var(--t-xl); }
  .field-grid { grid-template-columns: 1fr; }
  .table th, .table td { padding: 0.6rem var(--sp-3); }
  .cell-wrap { max-width: none; }

  /* drop the least useful column per table instead of forcing a scroll */
  .table-providers th:nth-child(2),
  .table-providers td:nth-child(2) { display: none; }

  .table-models th:nth-child(2),
  .table-models td:nth-child(2) { display: none; }

  #log th:nth-child(2), #log td:nth-child(2),
  #log th:nth-child(5), #log td:nth-child(5) { display: none; }
}

@media (max-width: 480px) {
  .actions-cell > * + * { margin-left: 0; }
  .actions-cell { display: grid; gap: var(--sp-2); }
  .actions-cell .btn-ghost { width: 100%; }
  .modal-card { padding: var(--sp-4); }

  /* keep the sidebar header on one row: tighten gaps and type */
  .sidebar { gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); }
  .side-link { padding: var(--sp-2); font-size: var(--t-xs); }
  .side-signout { font-size: var(--t-xs); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
