@import url('https://rsms.me/inter/inter.css');

:root {
  --bg: #FAFBFC;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --border: #E2E8F0;
  --border-soft: #F1F5F9;
  --text: #0F172A;
  --text-2: #475569;
  --text-3: #64748B;
  --text-4: #94A3B8;
  --brand: #2563EB;
  --brand-hover: #1D4ED8;
  --crit: #DC2626;
  --crit-soft: #FEF2F2;
  --high: #EA580C;
  --high-soft: #FFF7ED;
  --med: #D97706;
  --med-soft: #FFFBEB;
  --safe: #059669;
  --safe-soft: #F0FDF4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-feature-settings: 'cv02','cv03','cv04','cv11','ss01';
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.tabular { font-variant-numeric: tabular-nums; }

a { color: inherit; text-decoration: none; }

button { font-family: inherit; }

/* ============ Top nav ============ */
.nav {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}
.nav-logo {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: linear-gradient(135deg, #38BDF8 0%, #1D4ED8 100%);
  display: flex; align-items: center; justify-content: center;
}
.nav-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.nav-tabs {
  display: flex;
  gap: 2px;
  margin-left: 28px;
}
.nav-tab {
  font-size: 13.5px;
  color: var(--text-2);
  padding: 18px 12px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.nav-tab:hover { color: var(--text); }
.nav-tab.active {
  color: var(--text);
  font-weight: 500;
  border-bottom-color: var(--brand);
}
.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
}
.nav-logout {
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
}
.nav-logout:hover {
  background: var(--surface-2);
  color: var(--text);
}
.nav-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #334155;
  color: white;
  font-size: 11px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============ Page container ============ */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 32px;
}
.page-wide { max-width: 1280px; }
.page-narrow { max-width: 940px; }

.page-header {
  padding-top: 36px;
  padding-bottom: 22px;
}
.crumbs {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 6px;
}
.crumbs a { color: var(--text-3); }
.crumbs a:hover { color: var(--text-2); }
.crumbs .sep {
  color: var(--text-4);
  margin: 0 6px;
}
.page-title {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0;
}
.page-subtitle {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 4px;
}

/* ============ Card / Section ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-width: 0; /* grid/flex items default to min-width:auto, which lets long
                   unbroken text (e.g. filenames) stretch the whole column
                   instead of the text ellipsizing within a fixed width */
}
.card-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-body { padding: 20px; }

.section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  font-weight: 600;
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: background 100ms;
}
.btn:hover { background: var(--surface-2); }
.btn-primary {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
  padding: 9px 16px;
  font-weight: 500;
}
.btn-primary:hover { background: var(--brand-hover); }
.btn-ghost {
  border: none;
  background: transparent;
  color: var(--text-3);
  padding: 4px 8px;
  font-size: 12px;
}
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { color: var(--crit); border-color: var(--border); }
.btn-danger:hover { background: var(--crit-soft); border-color: #FECACA; }

/* ============ Forms ============ */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field-label {
  font-size: 12px; font-weight: 500; color: var(--text-2);
}
.field-hint { font-size: 11.5px; color: var(--text-4); }
.input, .select, .textarea {
  width: 100%;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  transition: border-color 100ms, box-shadow 100ms;
}
.input::placeholder, .textarea::placeholder { color: var(--text-4); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.textarea { resize: vertical; min-height: 64px; line-height: 1.5; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.field-error {
  border-color: var(--crit) !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.10) !important;
}

/* ============ Login ============ */
.login-page {
  min-height: calc(100vh - 56px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}
.login-card {
  width: 100%;
  max-width: 380px;
}
.login-form {
  display: flex;
  flex-direction: column;
}
.login-error {
  min-height: 18px;
  color: var(--crit);
  font-size: 12px;
  margin: -2px 0 10px;
}
.login-submit {
  justify-content: center;
}

/* Segmented radio (e.g. risk level) */
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segmented label {
  font-size: 12.5px; font-weight: 500; color: var(--text-3);
  padding: 8px 14px; cursor: pointer; background: var(--surface);
  border-right: 1px solid var(--border);
}
.segmented label:last-child { border-right: none; }
.segmented input { display: none; }
.segmented input:checked + span { color: var(--brand); }
.segmented label:has(input:checked) { background: #EFF6FF; color: var(--brand); }

/* Agent-initials editor chips */
.chip-input { display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; }
.chip-input:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.chip-tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 4px 6px 4px 8px; border-radius: 999px;
}
.chip-tag button { border: none; background: transparent; cursor: pointer; color: inherit; opacity: 0.6; font-size: 13px; line-height: 1; }
.chip-tag button:hover { opacity: 1; }
.chip-input input {
  border: none; outline: none; font-size: 13px; font-family: inherit;
  flex: 1; min-width: 70px; background: transparent; color: var(--text);
}

/* Suggested-agent rows: initials badge + name + one-line summary + remove */
.agent-cards { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.agent-cards:empty { display: none; }
.agent-card {
  display: flex; align-items: flex-start; gap: 10px;
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  background: var(--surface, #fff);
}
.agent-card .ac-badge {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.02em;
}
.agent-card .ac-body { flex: 1 1 auto; min-width: 0; }
.agent-card .ac-name { font-size: 13px; font-weight: 600; color: var(--text); }
.agent-card .ac-summary { font-size: 12px; color: var(--text-3); margin-top: 2px; line-height: 1.4; }
.agent-card .ac-summary.muted { font-style: italic; opacity: 0.8; }
.agent-card .ac-remove {
  flex: 0 0 auto; border: none; background: transparent; cursor: pointer;
  color: var(--text-3); font-size: 16px; line-height: 1; padding: 2px 5px; border-radius: 4px;
}
.agent-card .ac-remove:hover { color: var(--crit); background: rgba(0,0,0,0.04); }

/* ============ Badges / Pills ============ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 4px;
}
.badge-crit  { background: var(--crit-soft); color: #B91C1C; }
.badge-high  { background: var(--high-soft); color: #B45309; }
.badge-med   { background: var(--med-soft); color: #92400E; }
.badge-safe  { background: var(--safe-soft); color: #15803D; }
.badge-perm-read    { background: var(--safe-soft); color: #15803D; }
.badge-perm-write   { background: var(--med-soft); color: #92400E; }
.badge-perm-compute { background: #F5F3FF; color: #6D28D9; }

/* ============ Tool rows (agent modal) ============ */
.tool-row-view {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 100ms, background 100ms;
}
.tool-row-view:hover { border-color: var(--text-4); background: var(--surface-2); }
.tool-row-name { font-size: 13.5px; color: var(--text); }
.tool-row-remove {
  border: none; background: transparent; color: var(--text-4);
  font-size: 13px; line-height: 1; padding: 2px 4px; border-radius: 4px;
  opacity: 0; transition: opacity 100ms;
}
.tool-row-view:hover .tool-row-remove { opacity: 1; }
.tool-row-remove:hover { color: var(--crit); background: rgba(0,0,0,0.04); }
.tool-row-edit { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }

/* ============ SOP view (agent modal) ============ */
.sop-view {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-2);
}
.sop-view p { margin: 0 0 10px; }
.sop-view p:last-child { margin-bottom: 0; }
.sop-view ol { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }

.dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
}

/* ============ Agent initials avatar ============ */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-size: 10.5px;
  font-weight: 700;
  flex-shrink: 0;
}
.avatar-sm { width: 22px; height: 22px; font-size: 9.5px; }
.avatar-lg { width: 36px; height: 36px; font-size: 12px; }

/* ============ Tables ============ */
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-weight: 500; }

/* ============ Stat row ============ */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.stat {
  padding: 18px 20px;
  border-right: 1px solid var(--border);
}
.stat:last-child { border-right: none; }
.stat-value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat-label {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 4px;
}
.stat-value.crit { color: var(--crit); }
.stat-value.safe { color: var(--safe); }

/* ============ Workflow card grid (Screen 1) ============ */
.wf-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}
.wf-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  cursor: pointer;
  transition: box-shadow 150ms, border-color 150ms;
}
.wf-card:hover {
  box-shadow: 0 6px 20px -8px rgba(15,23,42,0.08);
  border-color: #CBD5E1;
}
.wf-card-domain {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  font-weight: 600;
}
.wf-card-name {
  font-size: 16px;
  font-weight: 600;
  margin-top: 8px;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.wf-card-sub {
  font-size: 12.5px;
  color: var(--text-3);
  margin-top: 6px;
  line-height: 1.45;
}
.wf-card-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}
.wf-card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-3);
}
.avatar-stack {
  display: flex;
  margin-right: 2px;
}
.avatar-stack .avatar {
  border: 2px solid var(--surface);
  margin-left: -6px;
}
.avatar-stack .avatar:first-child { margin-left: 0; }

.risk-dots {
  display: flex;
  gap: 3px;
}
.risk-dots .dot { width: 6px; height: 6px; background: #E2E8F0; }
.risk-dots .dot.on-high { background: var(--crit); }
.risk-dots .dot.on-med  { background: var(--med); }
.risk-dots .dot.on-low  { background: var(--safe); }

/* ============ Agent row ============ */
.agent-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 16px;
  align-items: center;
  padding: 16px 20px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-soft);
}
.agent-row:last-child { border-bottom: none; }
.agent-row:hover { background: var(--surface-2); }
.agent-row-main { min-width: 0; }
.agent-row-name { font-size: 14px; font-weight: 600; }
.agent-row-sop {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agent-row-meta { font-size: 11.5px; color: var(--text-3); text-align: right; line-height: 1.4; }
.agent-row-meta .light { color: var(--text-4); }
.agent-row-cta { color: var(--brand); font-size: 12.5px; font-weight: 500; }

/* ============ Modal ============ */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.45);
  backdrop-filter: blur(2px);
  z-index: 50;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 640px;
  max-height: 82vh;
  overflow-y: auto;
  box-shadow: 0 24px 48px -12px rgba(15,23,42,0.25);
}
.modal-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-body { padding: 20px 22px; }
.modal-footer {
  padding: 12px 22px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ============ Simulate block ============ */
.sim-block {
  display: grid;
  grid-template-columns: 1.1fr 1.2fr;
  gap: 32px;
  align-items: end;
}
.sim-divider {
  border-top: 1px solid var(--border);
  margin: 18px 0 16px;
}
.count-preset {
  min-width: 32px;
  height: 32px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  flex: none;
}
.count-preset:hover { background: var(--surface-2); }
.count-preset.active {
  border-color: var(--brand);
  color: var(--brand);
}
.count-sep {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 0 10px;
  flex: none;
}
.count-step-btn {
  width: 26px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-3);
  cursor: pointer;
  line-height: 1;
  flex: none;
}
.count-step-btn:hover { background: var(--surface-2); color: var(--text); }
.count-step-value {
  min-width: 28px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  box-sizing: border-box;
  padding: 0 4px;
  flex: none;
}
.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.mode-toggle-btn {
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-3);
  background: var(--surface-2);
  border: none;
  cursor: pointer;
}
.mode-toggle-btn.active {
  background: var(--surface);
  color: var(--text);
}
.mode-toggle-btn + .mode-toggle-btn {
  border-left: 1px solid var(--border);
}
.sim-section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  font-weight: 600;
  margin-bottom: 8px;
  display: block;
}
.tax-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
  box-sizing: border-box;
}
.tax-pill:hover { background: var(--surface-2); }

.trace-history-list { overflow: hidden; }

.inputs-scroll {
  height: 190px;
  min-width: 0;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--text-4) transparent;
}
.inputs-scroll.expanded {
  height: 340px;
}
.inputs-scroll::-webkit-scrollbar { width: 6px; }
.inputs-scroll::-webkit-scrollbar-track { background: transparent; }
.inputs-scroll::-webkit-scrollbar-thumb {
  background: var(--text-4);
  border-radius: 3px;
}

.inputs-toggle {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border-soft);
  font-size: 12px;
  font-weight: 500;
  color: var(--brand);
  cursor: pointer;
}
.inputs-toggle:hover { text-decoration: underline; }
.trace-history-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px 96px 84px;
  align-items: center;
  gap: 14px;
  padding: 9px 18px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-soft);
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.trace-history-head span:nth-child(n+2) { text-align: right; }
.trace-history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px 96px 84px;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 11px 18px;
  border-bottom: 1px solid var(--border-soft);
}
.trace-history-row:last-child { border-bottom: none; }
.trace-history-row:hover { background: var(--surface-2); }
.trace-history-main { min-width: 0; }
.trace-history-title-line {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.trace-history-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--safe);
  flex: 0 0 auto;
}
.trace-history-seq {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  flex: 0 0 auto;
}
.trace-history-critical { background: var(--crit); }
.trace-history-high { background: var(--high); }
.trace-history-medium { background: var(--med); }
.trace-history-clean { background: var(--safe); }
.trace-history-title {
  display: block;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.trace-history-meta {
  font-size: 11.5px;
  color: var(--text-3);
  margin-top: 4px;
  margin-left: 18px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.trace-history-risk {
  text-align: right;
  font-size: 11.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.trace-history-risk-count {
  display: block;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.1;
}
.trace-history-cta {
  color: var(--brand);
  font-size: 12.5px;
  font-weight: 500;
  text-align: right;
}
.trace-history-empty {
  padding: 18px;
  color: var(--text-3);
  font-size: 12.5px;
}

@media (max-width: 760px) {
  .trace-history-head { display: none; }
  .trace-history-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
    min-height: 0;
  }
  .trace-history-risk { text-align: left; margin-left: 18px; }
  .trace-history-row .badge { justify-self: end; }
  .trace-history-cta { grid-column: 2; }
}

/* ============ Dot canvas ============ */
.config-dot {
  cursor: pointer;
  transition: stroke-width 120ms, transform 120ms;
  transform-box: fill-box;
  transform-origin: center;
}
.config-dot:hover {
  transform: scale(1.15);
}
.config-dot:hover circle {
  stroke: var(--text);
  stroke-width: 1.8;
}
.config-dot.selected {
  stroke: var(--brand);
  stroke-width: 2;
}
.config-dot.selected circle {
  stroke: var(--brand);
  stroke-width: 2;
}
.density-bin {
  transition: opacity 120ms, transform 120ms;
  transform-box: fill-box;
  transform-origin: center;
}
.density-bin:hover {
  transform: scaleY(1.05);
}
.density-bin:hover rect {
  stroke: var(--text);
  stroke-width: 1.4;
}
.topology-panel {
  margin: 0 0 16px;
  padding: 10px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: var(--surface-2);
}
.topology-svg {
  width: 100%;
  height: 86px;
  display: block;
}
.topology-legend {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
  color: var(--text-3);
  font-size: 10px;
  line-height: 1.25;
}
.real-marker {
  pointer-events: none;
}

/* ============ Failure list rows ============ */
.failure-item { border-bottom: 1px solid var(--border-soft); }
.failure-item:last-child { border-bottom: none; }
.failure-row {
  display: grid;
  grid-template-columns: auto 1fr auto 220px auto auto;
  gap: 14px;
  align-items: center;
  width: 100%;
  padding: 12px 20px;
  cursor: pointer;
  /* button reset (rows are <button> so the whole aggregate row expands in place) */
  background: none;
  border: none;
  font: inherit;
  color: inherit;
  text-align: left;
}
.failure-row:hover { background: var(--surface-2); }
.failure-row-name { font-size: 13px; font-weight: 500; color: var(--text); }
.failure-ice { font-family: ui-monospace, monospace; color: var(--text-4); margin-right: 8px; font-size: 11.5px; }
.failure-row-count { font-size: 12.5px; font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; }
.failure-row-tag { font-size: 11.5px; color: var(--text-2); }
.failure-row-sev {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: right;
  width: 64px;
}
.failure-chevron { color: var(--text-3); transition: transform 0.15s ease; }
.failure-item.open .failure-chevron { transform: rotate(180deg); }
.sev-crit { color: #B91C1C; }
.sev-high { color: #B45309; }
.sev-med  { color: #92400E; }

/* expanded description of an aggregate failure (what the risk means) */
.failure-detail { padding: 2px 20px 16px 46px; }
.failure-detail[hidden] { display: none; }
.failure-detail-cat { font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; }
.failure-detail-line { font-size: 12.5px; color: var(--text-2); line-height: 1.5; margin-top: 7px; }
.failure-detail-k { font-weight: 600; color: var(--text); margin-right: 6px; }

/* ============ Trace step ============ */
.step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 0 0 18px;
}
.step:last-child { padding-bottom: 0; }
.step-icon {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.step-icon.ok   { background: #D1FAE5; color: #047857; }
.step-icon.skip { background: #FEE2E2; color: #B91C1C; }
.step-icon.warn { background: #FEF3C7; color: #92400E; }
.step-row {
  flex: 1;
  min-width: 0;
}
.step-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.step-name {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}
.step-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex: 0 0 auto;
}
.step-time {
  font-size: 10.5px;
  color: var(--text-4);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.step-chip {
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.step-chip.ok { background: #D1FAE5; color: #047857; }
.step-chip.warn { background: #FEF3C7; color: #92400E; }
.step-chip.danger { background: #FEE2E2; color: #B91C1C; }
.step-detail {
  font-size: 12.5px;
  color: var(--text-2);
  margin-top: 6px;
  line-height: 1.55;
}
.step-detail-rich {
  margin-top: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: var(--surface-2);
}
.step-detail-rich p {
  margin: 7px 0 0;
}
.step-detail-rich p:first-child { margin-top: 0; }
.step-detail-rich code {
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 1px 5px;
  background: #fff;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11.5px;
}
.step-detail-rich strong {
  color: var(--text);
  font-weight: 650;
}
.step-detail-collapsible {
  margin-top: 10px;
}
.step-detail-collapsible summary {
  cursor: pointer;
  color: var(--brand);
  font-size: 12.5px;
  font-weight: 650;
}
.step-detail-collapsible .step-detail,
.step-detail-collapsible .step-detail-rich {
  margin-top: 8px;
}
.trace-md-heading,
.trace-md-heading-sub {
  margin-top: 10px;
  color: var(--text);
  font-weight: 700;
}
.trace-md-heading:first-child,
.trace-md-heading-sub:first-child { margin-top: 0; }
.trace-md-heading {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
}
.trace-md-heading-sub {
  font-size: 12.5px;
}
.trace-md-list {
  margin: 8px 0 0 18px;
  padding: 0;
}
.trace-md-list li {
  margin-top: 6px;
  padding-left: 3px;
}
.trace-actor-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 9.5px;
  font-weight: 700;
  flex: 0 0 auto;
}
.trace-actor-badge.system {
  background: #F1F5F9;
  color: #94A3B8;
  font-size: 9px;
  font-weight: 600;
}
.step-skipped {
  margin-left: -8px;
  padding: 10px 12px;
  background: #FEF2F2;
  border: 1px solid #FECACA;
  border-radius: 8px;
}
.actor-tag {
  display: inline;
  font-weight: 600;
  font-size: 11px;
  margin-right: 6px;
  letter-spacing: 0.04em;
}

/* ============ Risk review rows (Screen 4) ============ */
.risk-review-row {
  display: grid;
  grid-template-columns: 4px minmax(0, 1fr) auto;
  gap: 18px;
  align-items: start;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-soft);
}
.risk-review-row:last-child { border-bottom: none; }
.risk-review-row:hover { background: var(--surface-2); }
.risk-review-marker {
  width: 4px;
  height: 100%;
  min-height: 58px;
  border-radius: 999px;
  background: var(--med);
}
.risk-sev-critical .risk-review-marker { background: var(--crit); }
.risk-sev-high .risk-review-marker { background: var(--high); }
.risk-sev-medium .risk-review-marker { background: var(--med); }
.risk-sev-clean .risk-review-marker { background: var(--safe); }
.risk-review-main { min-width: 0; }
.risk-review-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 7px;
  font-size: 11.5px;
  color: var(--text-2);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.risk-code-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 1px 6px;
  background: #fff;
  color: var(--text-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11.5px;
  letter-spacing: 0;
}
.risk-review-title {
  font-size: 15.5px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
}
.risk-review-evidence {
  max-width: 1120px;
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.5;
  color: #526179;
}
.risk-review-details {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-3);
}
.risk-review-details summary {
  display: inline-flex;
  cursor: pointer;
  color: var(--brand);
  font-weight: 650;
}
.risk-review-details div {
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: #fff;
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.55;
}
.risk-agent-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 21px;
  margin: 0 2px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 800;
  line-height: 1;
  vertical-align: 1px;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
}
.risk-annotate {
  align-self: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 650;
  line-height: 1;
  padding: 9px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.risk-annotate:hover {
  border-color: #CBD5E1;
  background: var(--surface-2);
}

@media (max-width: 760px) {
  .risk-review-row {
    grid-template-columns: 4px minmax(0, 1fr);
    gap: 12px;
    padding: 14px 16px;
  }
  .risk-annotate {
    grid-column: 2;
    justify-self: start;
    margin-top: 2px;
  }
}

/* ============ Sidebar (Screen 4) ============ */
.sidebar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}
.sidebar-kv {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  padding: 4px 0;
}
.sidebar-kv .k { color: var(--text-3); }
.sidebar-kv .v { color: var(--text); text-align: right; max-width: 60%; }

/* ============ Utility ============ */
.flex { display: flex; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.items-baseline { align-items: baseline; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-5 { gap: 20px; }
.gap-6 { gap: 24px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-5 { margin-top: 20px; }
.mt-6 { margin-top: 24px; }
.mt-8 { margin-top: 32px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.w-full { width: 100%; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-tiny { font-size: 11px; }
.text-3 { color: var(--text-3); }
.text-4 { color: var(--text-4); }
.text-crit { color: var(--crit); }
.text-safe { color: var(--safe); }
.text-brand { color: var(--brand); }
.cursor-pointer { cursor: pointer; }

/* ============ Analyze / chat (Screen 5) ============ */
.analyze-grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  margin-top: 24px;
  align-items: start;
}
.chat {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 230px);
  min-height: 480px;
}
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 4px 2px 8px;
}
.chat-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 8px;
}
.chat-empty-title { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.chat-empty-sub { font-size: 13px; color: var(--text-3); margin-top: 6px; line-height: 1.5; max-width: 520px; }

.msg {
  display: flex;
  gap: 12px;
  margin-bottom: 22px;
  align-items: flex-start;
}
.msg-avatar {
  width: 26px; height: 26px;
  border-radius: 7px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 700;
}
.msg-avatar.ice {
  background: linear-gradient(135deg, #38BDF8 0%, #1D4ED8 100%);
}
.msg-avatar.user {
  background: #334155; color: white;
}
.msg-body { flex: 1; min-width: 0; padding-top: 2px; }
.msg-role { font-size: 11px; font-weight: 600; color: var(--text-3); margin-bottom: 4px; letter-spacing: 0.02em; }
.msg-text { font-size: 13.5px; color: var(--text); line-height: 1.6; }
.msg-text p { margin: 0 0 10px; }
.msg-text p:last-child { margin-bottom: 0; }
.msg-text ul, .msg-text ol { margin: 4px 0 10px; padding-left: 20px; }
.msg-text li { margin-bottom: 4px; line-height: 1.55; }
.msg-text strong { font-weight: 600; }
.msg-text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  padding: 1px 5px;
}
.msg-user .msg-text { color: var(--text-2); }

.risk-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  font-weight: 600;
  color: #B91C1C;
  background: var(--crit-soft);
  border-radius: 4px;
  padding: 1px 5px;
  white-space: nowrap;
}

.typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 0; }
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-4);
  animation: typing 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.chip-row { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; max-width: 560px; }
.chip {
  text-align: left;
  font-size: 13px;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 13px;
  cursor: pointer;
  transition: border-color 120ms, background 120ms;
  line-height: 1.4;
}
.chip:hover { border-color: #CBD5E1; background: var(--surface-2); color: var(--text); }

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 10px 10px 10px 14px;
  margin-top: 14px;
}
.chat-input-bar:focus-within { border-color: #94A3B8; }
.chat-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
  background: transparent;
  max-height: 140px;
  padding: 4px 0;
}
.chat-input::placeholder { color: var(--text-4); }
.chat-send {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--brand);
  color: white;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 100ms;
}
.chat-send:hover { background: var(--brand-hover); }
.chat-send:disabled { background: #CBD5E1; cursor: default; }

/* context rail */
.ctx-card { padding: 16px 16px 8px; }
.ctx-trace {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  margin: 0 -8px;
  border-radius: 7px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text-2);
}
.ctx-trace:hover { background: var(--surface-2); }
.ctx-trace-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.ctx-trace-main { flex: 1; min-width: 0; }
.ctx-trace-title {
  font-size: 12.5px; font-weight: 500; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ctx-trace-meta { font-size: 11px; color: var(--text-3); margin-top: 1px; font-variant-numeric: tabular-nums; }
.ctx-trace.focused {
  background: #EFF6FF;
  box-shadow: inset 2px 0 0 var(--brand);
}
.ctx-trace.focused:hover { background: #E0EDFF; }
.ctx-focus-tag {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--brand);
  background: #DBEAFE;
  border-radius: 3px;
  padding: 1px 4px;
  margin-left: 6px;
  vertical-align: 1px;
}

.annotation-modal { width: 560px; }
.annotation-evidence {
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.5;
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: var(--surface-2);
}
.annotation-done {
  color: var(--safe);
  border-color: #BBF7D0;
  background: var(--safe-soft);
}
.annotation-done:hover {
  border-color: #86EFAC;
  background: #DCFCE7;
}
