/* Backloop dashboard. Dark, quiet, precise: Inter, mono eyebrows, hairlines, dot-matrix accents. */
:root {
  --bg: #000;
  --surface: #0a0c0e;
  --surface-2: #101316;
  --surface-3: #161a1e;
  --line: rgba(255, 255, 255, 0.075);
  --line-2: rgba(255, 255, 255, 0.13);
  --text: #f2f4f5;
  --text-2: #d3d9de;
  --muted: #88939b;
  --faint: #59636a;
  --accent: #bedcec;
  --accent-2: #9db8cc;
  --accent-soft: rgba(190, 220, 236, 0.1);
  --ok: #9ed9b0;
  --warn: #e8c585;
  --bad: #f0a3a3;
  --ok-soft: rgba(158, 217, 176, 0.1);
  --warn-soft: rgba(232, 197, 133, 0.1);
  --bad-soft: rgba(240, 163, 163, 0.1);
  --radius: 14px;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-variant-ligatures: none; }

.eyebrow {
  margin: 0;
  font: 500 10.5px/1.4 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-2);
}
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Dot-matrix type, the signature accent. */
.dot {
  color: var(--accent);
}
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .dot {
    background-image: radial-gradient(circle, var(--accent) 1px, transparent 1.45px);
    background-size: 3px 3px;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
}

/* ── top bar ──────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 28px;
  height: 60px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(12px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.02em;
}
.brand:hover { text-decoration: none; }
.brand svg {
  width: 26px;
  height: 26px;
  padding: 3px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.4;
  stroke-linecap: round;
}
.top-stats { display: flex; gap: 22px; }
.top-stat { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.top-stat b { font-weight: 500; font-size: 15px; font-variant-numeric: tabular-nums; }
.top-stat span { color: var(--muted); font-size: 12px; }
.integrations { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  font: 500 11px/1.5 var(--mono);
  color: var(--text-2);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.badge.on::before { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.badge.dry::before { background: var(--warn); }

.me { display: flex; align-items: center; gap: 10px; padding-left: 14px; margin-left: 4px; border-left: 1px solid var(--line); }
.me:empty { display: none; }
.me img, .me .initial { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line-2); object-fit: cover; }
.me .initial { display: grid; place-items: center; font-size: 12px; font-weight: 600; background: var(--surface-3); }
.me .who { display: grid; line-height: 1.2; }
.me .who b { font-weight: 500; font-size: 13px; }
.me .who em { font: normal 10px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.me form { margin: 0; }
.me .link-button { margin: 0; }
/* Viewers see everything and change nothing (the server enforces it too). */
.viewer [data-action], .viewer #recluster, .viewer .workaround-input, .viewer .note-input { display: none !important; }

/* ── layout ───────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: minmax(320px, 400px) 1fr;
  min-height: calc(100vh - 60px);
}
.sidebar {
  border-right: 1px solid var(--line);
  padding: 20px 14px 20px 20px;
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
}
.sidebar-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; padding-right: 6px; }
.filters { display: flex; gap: 4px; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.chip.active, .chip:hover { color: var(--text); border-color: var(--line-2); background: var(--surface-2); }

.cluster-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.cluster-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--surface) 0%, rgba(10, 12, 14, 0.4) 100%);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.cluster-card:hover { border-color: var(--line-2); }
.cluster-card.selected { border-color: rgba(190, 220, 236, 0.45); background: linear-gradient(180deg, var(--surface-2), var(--surface)); }
.cluster-card h3 { grid-column: 1; margin: 0; font-size: 14px; font-weight: 500; line-height: 1.35; letter-spacing: -0.01em; }
.cluster-card .meta { grid-column: 1 / -1; display: flex; gap: 12px; color: var(--muted); font-size: 12px; align-items: center; }
.cluster-card .meta b { color: var(--text-2); font-weight: 500; }
.cluster-card .top { grid-column: 1; display: flex; gap: 8px; align-items: center; }
.score {
  grid-column: 2;
  grid-row: 1 / 3;
  --p: 50;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font: 500 14px var(--sans);
  font-variant-numeric: tabular-nums;
  background:
    radial-gradient(closest-side, var(--surface) 80%, transparent 81% 100%),
    conic-gradient(var(--accent) calc(var(--p) * 1%), rgba(255, 255, 255, 0.08) 0);
}
.spark { display: inline-flex; gap: 2px; align-items: flex-end; height: 14px; margin-left: auto; }
.spark i { display: block; width: 3px; background: var(--accent-2); opacity: 0.8; border-radius: 1px; min-height: 1px; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: 500 10px/1.6 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.status::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.status.s-new { color: var(--accent); }
.status.s-issue_open, .status.s-investigating { color: var(--accent-2); }
.status.s-awaiting_approval { color: var(--warn); }
.status.s-pr_open, .status.s-resolved { color: var(--ok); }
.status.s-dismissed { color: var(--faint); }
.type { font: 500 10px/1.6 var(--mono); text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); }

.link-button { margin: 16px 0 0; background: none; border: 0; color: var(--muted); font-size: 12px; cursor: pointer; padding: 0; }
.link-button:hover { color: var(--text); }

/* ── detail ───────────────────────────────────────────────── */
.detail { padding: 32px 40px 80px; min-width: 0; max-width: 1180px; }
.detail-head { display: grid; gap: 12px; margin-bottom: 28px; }
.detail-head h1 {
  margin: 0;
  font-size: clamp(26px, 3vw, 36px);
  line-height: 1.12;
  font-weight: 500;
  letter-spacing: -0.035em;
  max-width: 900px;
}
.detail-head .summary { margin: 0; color: var(--text-2); font-size: 15px; max-width: 820px; }
.keywords { display: flex; gap: 6px; flex-wrap: wrap; }
.keywords span { padding: 2px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font: 12px var(--mono); }

/* Pipeline stepper. */
.pipeline { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 4px 0 28px; }
.step { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.step p { margin: 0; }
.step .n { font: 500 10px var(--mono); color: var(--faint); letter-spacing: 0.1em; }
.step .label { font-size: 13px; color: var(--muted); }
.step.done { border-color: rgba(190, 220, 236, 0.18); }
.step.done .label { color: var(--text-2); }
.step.done .n { color: var(--accent-2); }
.step.current { border-color: rgba(190, 220, 236, 0.55); background: var(--surface-2); box-shadow: inset 0 0 0 1px rgba(190, 220, 236, 0.08); }
.step.current .label { color: var(--text); }
.step.current .n { color: var(--accent); }

.grid-2 { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 16px; }
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 20px;
  min-width: 0;
}
.card + .card, .grid-2 + .card, .card + .grid-2 { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card h2 { margin: 0; font-size: 15px; font-weight: 500; letter-spacing: -0.01em; }

/* Impact. */
.impact { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border-radius: 10px; overflow: hidden; }
.impact div { background: var(--surface); padding: 14px 16px; }
.impact b { display: block; font-size: 28px; font-weight: 500; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.impact span { color: var(--muted); font-size: 12px; }
.bars { display: grid; gap: 10px; margin-top: 18px; }
.bar { display: grid; grid-template-columns: 150px 1fr 44px; gap: 12px; align-items: center; font-size: 12px; color: var(--muted); }
.bar .track { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.06); overflow: hidden; }
.bar .fill { height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); border-radius: 3px; }
.bar b { color: var(--text-2); font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; }

.gauge { display: grid; place-items: center; position: relative; }
.gauge svg { width: 190px; height: 190px; }
.gauge .value { position: absolute; text-align: center; }
.gauge .value b { display: block; font-size: 46px; font-weight: 500; letter-spacing: -0.04em; line-height: 1; }
.gauge .value span { color: var(--muted); font: 10px var(--mono); letter-spacing: 0.12em; text-transform: uppercase; }

.quotes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.quotes li { display: flex; gap: 12px; justify-content: space-between; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); }
.quotes li span { overflow-wrap: anywhere; }
.quotes li em { font-style: normal; color: var(--muted); font: 12px var(--mono); white-space: nowrap; }

/* Actions. */
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--text);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.button:hover { background: var(--surface-3); text-decoration: none; }
.button.primary { background: var(--text); color: #0b0d0f; border-color: var(--text); }
.button.primary:hover { background: #fff; }
.button.approve { background: var(--ok); color: #07140c; border-color: var(--ok); }
.button.danger { color: var(--bad); border-color: rgba(240, 163, 163, 0.3); }
.button.ghost { border-color: transparent; color: var(--muted); }
.button:disabled { opacity: 0.4; cursor: not-allowed; }
.button .arrow { font-family: var(--sans); opacity: 0.7; }

.note-input, .workaround-input {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid var(--line-2);
  background: var(--bg);
}
.callout {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
}
.callout.warn { border-color: rgba(232, 197, 133, 0.25); background: var(--warn-soft); }
.callout.ok { border-color: rgba(158, 217, 176, 0.25); background: var(--ok-soft); }
.callout.bad { border-color: rgba(240, 163, 163, 0.25); background: var(--bad-soft); }

/* Investigation. */
.log, .diff, .testout {
  margin: 0;
  max-height: 360px;
  overflow: auto;
  padding: 14px;
  border-radius: 10px;
  background: #050607;
  border: 1px solid var(--line);
  font: 12px/1.6 var(--mono);
  color: var(--text-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.diff { white-space: pre; max-height: 520px; }
.diff span { display: block; min-height: 1.6em; padding: 0 6px; }
.diff .add { color: var(--ok); background: rgba(158, 217, 176, 0.07); }
.diff .del { color: var(--bad); background: rgba(240, 163, 163, 0.07); }
.diff .hunk { color: var(--accent-2); margin-top: 4px; }
.diff .file { color: var(--text); font-weight: 500; margin-top: 14px; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.diff .file:first-child { margin-top: 0; }
.markdown { color: var(--text-2); }
.markdown h1, .markdown h2, .markdown h3 { font-size: 13px; font-weight: 500; margin: 16px 0 6px; color: var(--text); }
.markdown h1:first-child, .markdown h2:first-child, .markdown h3:first-child { margin-top: 0; }
.markdown p { margin: 6px 0; }
.markdown ul { margin: 6px 0; padding-left: 18px; }
.markdown code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.markdown pre { background: #050607; padding: 12px; border-radius: 8px; overflow: auto; }
.markdown blockquote { margin: 8px 0; padding-left: 12px; border-left: 2px solid var(--line-2); color: var(--muted); }
.markdown table { border-collapse: collapse; font-size: 12px; }
.markdown td, .markdown th { border: 1px solid var(--line); padding: 4px 8px; }
.pill { display: inline-flex; gap: 6px; align-items: center; padding: 2px 9px; border-radius: 999px; font: 500 11px var(--mono); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.run { background: var(--accent-soft); color: var(--accent); }
.pill.run::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }

/* Records & events. */
table.records { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.records th { text-align: left; font: 500 10px var(--mono); text-transform: uppercase; letter-spacing: 0.1em; color: var(--faint); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.records td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; color: var(--text-2); }
.records td.goal { color: var(--text); max-width: 340px; }
.records td .msg { color: var(--muted); display: block; margin-top: 2px; }
.records .outcome { font: 11px var(--mono); }
.outcome.blocked { color: var(--bad); }
.outcome.degraded { color: var(--warn); }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.events li { display: grid; grid-template-columns: 110px 1fr; gap: 12px; font-size: 13px; color: var(--text-2); }
.events time { color: var(--faint); font: 11px var(--mono); padding-top: 2px; }

.empty { display: grid; place-items: center; min-height: 60vh; text-align: center; color: var(--muted); }
.empty h1 { color: var(--text); font-weight: 500; letter-spacing: -0.03em; font-size: 34px; margin: 12px 0; }
.empty pre { text-align: left; background: var(--surface); border: 1px solid var(--line); padding: 16px 18px; border-radius: 12px; color: var(--text-2); font-size: 12.5px; }

/* Dialog + toast. */
dialog {
  width: min(820px, calc(100vw - 32px));
  border: 1px solid var(--line-2);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 24px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(4px); }
dialog form { display: grid; gap: 14px; }
dialog label { display: grid; gap: 6px; font-size: 13px; color: var(--text-2); }
dialog label .muted { display: inline; }
dialog input, dialog textarea { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--bg); }
dialog textarea { font: 12.5px/1.55 var(--mono); resize: vertical; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translate(-50%, 20px);
  opacity: 0;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--surface-3);
  border: 1px solid var(--line-2);
  transition: all 0.2s;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(240, 163, 163, 0.4); color: var(--bad); }

@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
  .pipeline { grid-template-columns: repeat(3, 1fr); }
  .top-stats { display: none; }
}
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 16px; }
  .detail { padding: 24px 16px 60px; }
  .impact { grid-template-columns: repeat(2, 1fr); }
  .integrations { display: none; }
  .bar { grid-template-columns: 110px 1fr 40px; }
}
