/* IBVC Command Center v5 */
:root {
  --bg-primary: #0B090A; --bg-card: #161A1D; --bg-elevated: #1E2328; --bg-hover: #252A2F;
  --text-primary: #F5F3F4; --text-secondary: #B1A7A6; --text-muted: #6B6B6B;
  --accent-red: #A4161A; --accent-red-light: #E5383B; --accent-blue: #007BFF;
  --accent-green: #34C759; --accent-yellow: #FFD60A; --accent-orange: #FF9F0A;
  --border: #2A2A2A; --radius-sm: 8px; --radius-md: 12px; --radius-lg: 16px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font-sans); background: var(--bg-primary); color: var(--text-primary); line-height: 1.5; -webkit-font-smoothing: antialiased; }

.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; border-bottom: 1px solid var(--border); gap: 24px; }
.topbar-left { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 20px; font-weight: 700; letter-spacing: 2px; }
.logo-sub { font-size: 13px; font-weight: 500; color: var(--text-muted); letter-spacing: 0.5px; }
.logo-link { display: inline-flex; align-items: center; line-height: 0; }
.logo-img { width: 36px; height: 36px; display: block; object-fit: contain; }
.topbar-nav { display: flex; align-items: center; gap: 4px; flex: 1; }
.nav-link {
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
  text-decoration: none; padding: 6px 12px; border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--bg-elevated); color: var(--text-primary); }
.nav-link.active { background: var(--bg-elevated); color: var(--text-primary); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.beast-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); transition: background 0.3s; }
.beast-dot.online { background: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); }
.beast-dot.offline { background: var(--accent-red-light); box-shadow: 0 0 6px var(--accent-red-light); }
.beast-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.beast-status { font-size: 12px; color: var(--text-muted); }

.pulse-bar { display: flex; align-items: center; justify-content: center; padding: 14px 24px; background: var(--bg-card); border-bottom: 1px solid var(--border); }
.pulse-item { display: flex; align-items: center; gap: 8px; padding: 0 24px; }
.pulse-divider { width: 1px; height: 24px; background: var(--border); }
.pulse-icon { font-size: 16px; }
.pulse-label { font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.pulse-value { font-size: 18px; font-weight: 700; }
.pulse-delta { font-size: 12px; font-weight: 600; }
.pulse-delta.up { color: var(--accent-green); }
.pulse-delta.down { color: var(--accent-red-light); }
.pulse-delta.neutral { color: var(--text-muted); }

/* ── Pipelines: 3-column DB layout, status rows stacked, share-driven bars ── */
.pipelines { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; padding: 16px 24px; }
.pipeline {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pipeline-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.pipeline-name { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1.2px; }

/* Status row: label · 7d delta · right-anchored bar with count */
.stage-row { display: flex; align-items: center; gap: 8px; min-height: 30px; }
.stage-label {
  flex-shrink: 0; width: 84px;
  font-size: 11px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.4px;
  text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* 7-day percent delta — color tells you whether the change is good or bad in context.
   See app.js deltaTier() for the heat-aware logic. */
.stage-delta {
  flex-shrink: 0; width: 46px;
  font-family: var(--font-mono);
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.2px;
  text-align: right;
  color: var(--text-muted);
}
.stage-delta.good { color: var(--accent-green); }
.stage-delta.bad  { color: var(--accent-red-light); }
.stage-delta.neutral { color: var(--text-muted); opacity: 0.4; }
.stage-delta:empty { opacity: 0.25; }
.stage-track {
  flex: 1; position: relative; height: 26px;
  background: rgba(255,255,255,0.025);
  border-radius: 5px;
  overflow: hidden;
}
.stage-fill {
  position: absolute; right: 0; top: 0; bottom: 0;
  width: 0; min-width: 0;
  background: var(--text-muted);
  border-radius: 5px;
  transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1),
              background 0.4s, box-shadow 0.4s;
}
.stage-num {
  position: absolute;
  right: 8px;
  top: 50%; transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 13px; font-weight: 700;
  color: var(--text-primary);
  pointer-events: none;
  text-shadow: 0 0 4px rgba(0,0,0,0.5);
}

/* Share-based heat tiers (share = count / db_total). More share → louder. */
.stage-row.heat-empty .stage-fill { background: transparent; }
.stage-row.heat-empty .stage-label { opacity: 0.4; }
.stage-row.heat-empty .stage-num { color: var(--text-muted); font-weight: 500; }

.stage-row.heat-cool .stage-fill { background: linear-gradient(90deg, rgba(0,123,255,0.25), rgba(0,123,255,0.55)); }

.stage-row.heat-warm .stage-fill { background: linear-gradient(90deg, rgba(255,159,10,0.35), rgba(255,159,10,0.7)); }

.stage-row.heat-hot .stage-fill {
  background: linear-gradient(90deg, rgba(229,56,59,0.45), rgba(229,56,59,0.85));
  box-shadow: 0 0 10px rgba(229,56,59,0.25) inset, 0 0 14px rgba(229,56,59,0.18);
}
.stage-row.heat-hot .stage-label { color: var(--accent-red-light); }
.stage-row.heat-hot .stage-num { color: var(--text-primary); font-size: 14px; }

/* Extreme (>60% share) — pulse to demand attention */
.stage-row.heat-hot.heat-dominant .stage-fill {
  animation: bar-pulse 2.2s ease-in-out infinite;
}
@keyframes bar-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(229,56,59,0.25) inset, 0 0 14px rgba(229,56,59,0.20); }
  50%      { box-shadow: 0 0 10px rgba(229,56,59,0.25) inset, 0 0 22px rgba(229,56,59,0.55); }
}

/* Pipelines horizontal-scroll at ≤ 1024px is handled in agents.css responsive block. */
@media (max-width: 980px) {
  .stage-label { width: 96px; }
}

.panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.panel-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.panel-header h2 { font-size: 15px; font-weight: 600; letter-spacing: 0.3px; }

/* ── Collapsible sections ── */
/* Any element with [data-collapse] becomes a clickable header that toggles its
   parent into .collapsed. The whole header is the affordance — no visible
   chevron, just a cursor hint on hover. */
[data-collapse] {
  cursor: pointer;
  user-select: none;
  position: relative;
}

/* Panel-style sections — hide anything that isn't the header */
.panel.collapsed > .panel-header { border-bottom-color: transparent; }
.panel.collapsed > .panel-body,
.panel.collapsed > .agent-cards,
.panel.collapsed > .auto-section,
.panel.collapsed > .event-feed { display: none; }

/* Pipeline cards: hide all status rows when collapsed */
.pipeline.collapsed > .stage-row { display: none; }
.pipeline.collapsed { padding-bottom: 14px; }

/* Per-agent-card collapse: hide everything except the hero */
.agent-card.collapsed > .feat-grid,
.agent-card.collapsed > .agent-progress { display: none; }
.agent-card.collapsed { padding-bottom: 14px; }
.agent-card > .agent-hero { cursor: pointer; user-select: none; }
.panel-count { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.panel-body { padding: 0; max-height: 480px; overflow-y: auto; }
.panel-loading { padding: 32px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* Bottom fade on list-style panels (Event Log, Automations & Connectors,
   Case Pipeline, Property Pipeline) — long scrollable lists dissolve into
   the card edge instead of cutting off abruptly. `:has(.panel-body)`
   automatically skips card-style panels (e.g. Agents) which don't use it. */
.panel:has(.panel-body) { position: relative; }
.panel:has(.panel-body)::after {
  content: "";
  position: absolute;
  left: 0; right: 4px;       /* leave 4px gutter for the panel-body scrollbar */
  bottom: 0;
  height: 44px;
  background: linear-gradient(to top, var(--bg-card) 30%, transparent);
  pointer-events: none;
}

.deals-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; padding: 0 24px 16px; }
.deal-group { border-bottom: 1px solid var(--border); }
.deal-group:last-child { border-bottom: none; }
.deal-group-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; background: var(--bg-elevated); }
.deal-group-name { font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.deal-group-count { font-size: 11px; color: var(--text-muted); }
a.deal-card { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; border-bottom: 1px solid rgba(42,42,42,0.5); cursor: pointer; transition: background 0.15s; text-decoration: none; color: inherit; }
a.deal-card:hover { background: var(--bg-hover); }
a.deal-card:last-child { border-bottom: none; }
.deal-info { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.deal-name { font-size: 14px; font-weight: 600; }
.deal-meta { font-size: 12px; color: var(--text-muted); }
.deal-touch { font-size: 12px; font-weight: 600; white-space: nowrap; padding: 2px 8px; border-radius: var(--radius-sm); }
.deal-touch.stale { color: var(--accent-red-light); background: rgba(164,22,26,0.15); }
.deal-touch.warm { color: var(--accent-orange); background: rgba(255,159,10,0.15); }
.deal-touch.fresh { color: var(--accent-green); background: rgba(52,199,89,0.15); }

.bottom-grid { display: grid; grid-template-columns: 1fr; gap: 16px; padding: 0 24px 24px; }

/* === Tracers stats inside the auto-history drawer ========================== */
/* Renders on top of the historic runs ONLY when the Tracers row is expanded. */
.tracers-drawer-stats { padding: 12px 14px; margin: 0 0 8px; border-radius: 6px; background: rgba(255,255,255,0.04); border: 1px solid var(--border, #2a2a2a); font-size: 12px; }
.tracers-drawer-loading { color: var(--text-muted); font-style: italic; }
.tracers-drawer-error { color: var(--accent-red-light, #ff9999); }
.tracers-drawer-stats .tdrawer-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.tracers-drawer-stats .tdrawer-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.tracers-drawer-stats .tdrawer-status { font-size: 11px; font-style: italic; }
.tracers-drawer-stats .tdrawer-numbers { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; margin-bottom: 8px; color: var(--text, #e5e5e5); }
.tracers-drawer-stats .tdrawer-numbers b { font-weight: 700; font-size: 14px; }
.tracers-drawer-stats .tdrawer-sep { color: var(--text-muted); }
.tracers-drawer-stats .tdrawer-bar { height: 6px; background: rgba(255,255,255,0.06); border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
.tracers-drawer-stats .tdrawer-bar-fill { height: 100%; border-radius: 3px; transition: width 0.4s ease; }
.tracers-drawer-stats .tdrawer-projection { font-size: 11px; color: var(--text-muted); }
.tracers-drawer-stats .tdrawer-projection b { color: var(--text, #e5e5e5); font-weight: 700; }
.tracers-drawer-stats .tdrawer-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; padding-top: 6px; border-top: 1px dashed rgba(255,255,255,0.06); }
.tracers-drawer-stats .tdrawer-age { font-size: 10px; color: var(--text-muted); font-style: italic; }
.tracers-drawer-stats .tdrawer-refresh { font-size: 10px; padding: 2px 8px; border-radius: 4px; background: rgba(255,255,255,0.06); color: var(--text, #e5e5e5); border: 1px solid var(--border, #2a2a2a); cursor: pointer; transition: background 0.15s ease; }
.tracers-drawer-stats .tdrawer-refresh:hover { background: rgba(255,255,255,0.12); }

/* Pipelines section: small refresh affordance as a full-width header row. */
/* Spans all 3 grid columns so it never overlaps a card.                    */
.pipelines-meta {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: -8px;  /* tighten the gap to the cards below */
}
.pipelines-age { font-style: italic; }
.pipelines-refresh { font-size: 12px; line-height: 1; padding: 2px 6px; border-radius: 4px; background: rgba(255,255,255,0.04); color: var(--text-muted); border: 1px solid var(--border, #2a2a2a); cursor: pointer; transition: all 0.15s ease; }
.pipelines-refresh:hover { background: rgba(255,255,255,0.12); color: var(--text, #e5e5e5); }
.tracers-drawer-green  .tdrawer-bar-fill { background: var(--accent-green,  #34c759); }
.tracers-drawer-green  .tdrawer-status   { color:      var(--accent-green,  #34c759); }
.tracers-drawer-yellow .tdrawer-bar-fill { background: var(--accent-yellow, #ffcc00); }
.tracers-drawer-yellow .tdrawer-status   { color:      var(--accent-yellow, #ffcc00); }
.tracers-drawer-red    .tdrawer-bar-fill { background: var(--accent-red,    #ff453a); }
.tracers-drawer-red    .tdrawer-status   { color:      var(--accent-red,    #ff453a); }

.auto-section { border-bottom: 1px solid var(--border); }
.auto-section:last-child { border-bottom: none; }
.auto-section-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; padding: 14px 20px 8px; }
.auto-row-wrap { border-bottom: 1px solid rgba(42,42,42,0.5); }
.auto-row-wrap:last-child { border-bottom: none; }
.auto-row { display: flex; align-items: center; gap: 12px; padding: 10px 20px; cursor: pointer; transition: background 0.12s; }
.auto-row:hover { background: rgba(255,255,255,0.02); }
.auto-row:focus { outline: none; background: rgba(255,255,255,0.03); }
.auto-row.is-open { background: rgba(255,255,255,0.03); }

/* Inline history drawer below each auto-row */
.auto-history { padding: 6px 20px 14px 50px; background: rgba(0,0,0,0.18); display: flex; flex-direction: column; gap: 4px; position: relative; }
/* `display: flex` above overrides the user-agent stylesheet's
   `[hidden] { display: none }` — must re-establish it explicitly. */
.auto-history[hidden] { display: none; }
.auto-history-loading, .auto-history-empty { font-size: 12px; color: var(--text-muted); padding: 6px 0; }
.auto-history-close {
  position: absolute; top: 4px; right: 8px;
  background: transparent; border: none; color: var(--text-muted);
  font-size: 18px; line-height: 1; cursor: pointer; padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.auto-history-close:hover { color: var(--accent-red-light); background: rgba(255,255,255,0.05); }
.auto-history-row {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  font-size: 12px;
  color: var(--text-secondary);
}
.auto-history-time { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 11px; }
.auto-history-name { font-weight: 500; color: var(--text-primary); }
.auto-history-detail { grid-column: 2 / span 2; color: var(--text-muted); font-size: 11px; }
.auto-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.auto-name { font-size: 13px; font-weight: 600; }
.auto-schedule { font-size: 10px; font-weight: 500; color: var(--text-muted); }
.schedule-auto { color: var(--accent-green); }
.schedule-manual { color: var(--accent-blue); }
.auto-last { font-size: 11px; color: var(--text-muted); white-space: nowrap; min-width: 70px; text-align: right; }
.btn-trigger { font-family: var(--font-sans); font-size: 11px; font-weight: 600; padding: 5px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-elevated); color: var(--text-primary); cursor: pointer; transition: all 0.15s; white-space: nowrap; }
.btn-trigger:hover { background: var(--accent-blue); border-color: var(--accent-blue); }
.btn-trigger:active { transform: scale(0.97); }
.btn-trigger.running { background: var(--accent-blue); border-color: var(--accent-blue); opacity: 0.7; pointer-events: none; }
/* Multi-DB target selector — sits between .auto-last and the ▶ Run button on
   automations that can be scoped to REGISTRY / CASE / PROPERTY (PRC, Heir,
   Additional Search, Auto Tracers). */
.auto-db-select {
  font-family: var(--font-sans); font-size: 11px; font-weight: 600;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23B1A7A6' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 22px;
}
.auto-db-select:hover { color: var(--text-primary); border-color: var(--accent-blue); }
.auto-db-select:focus { outline: none; border-color: var(--accent-blue); }

/* PRC v6: Status select + County free-text input — visually consistent with
   .auto-db-select. Both sit between the DB select and the ▶ Run button. */
.auto-status-select {
  font-family: var(--font-sans); font-size: 11px; font-weight: 600;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23B1A7A6' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 22px;
}
.auto-status-select:hover { color: var(--text-primary); border-color: var(--accent-blue); }
.auto-status-select:focus { outline: none; border-color: var(--accent-blue); }
.auto-county-input {
  font-family: var(--font-sans); font-size: 11px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  width: 120px;
}
.auto-county-input:hover { border-color: var(--accent-blue); }
.auto-county-input:focus { outline: none; border-color: var(--accent-blue); color: var(--text-primary); }
.auto-county-input::placeholder { color: var(--text-muted); }

/* Agent CARD per-agent controls — frosted-glass dropdowns/inputs that sit
   on top of the banner image. Semi-transparent dark background + backdrop
   blur gives the "darkened blurry" look. Container-based selector covers
   ALL select/input inside .agent-banner-actions in one rule so they're
   guaranteed identical height + style regardless of element type. */
.agent-banner-actions select,
.agent-banner-actions input[type="text"] {
  box-sizing: border-box;
  height: 26px;
  font-family: var(--font-sans); font-size: 11px; font-weight: 600;
  padding: 0 8px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text-secondary);
  width: 120px;
}
.agent-banner-actions select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23B1A7A6' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 22px;
  width: auto; min-width: 110px;
}
.agent-banner-actions select:hover,
.agent-banner-actions input[type="text"]:hover { color: var(--text-primary); border-color: var(--accent-blue); }
.agent-banner-actions select:focus,
.agent-banner-actions input[type="text"]:focus { outline: none; border-color: var(--accent-blue); color: var(--text-primary); }
.agent-banner-actions input[type="text"]::placeholder { color: var(--text-muted); }
.agent-banner-actions select option { background: var(--bg-card); color: var(--text-primary); }

/* Run + Stop buttons inside agent banner — same 26px height so they align with
   the filter pills above. Without this they inherit browser-default button
   sizing which is taller. */
.agent-banner-actions .btn-agent-run,
.agent-banner-actions .btn-agent-stop {
  box-sizing: border-box;
  height: 26px;
  padding: 0 10px;
  font-family: var(--font-sans); font-size: 11px; font-weight: 600;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text-primary);
  cursor: pointer;
}
.agent-banner-actions .btn-agent-run:hover,
.agent-banner-actions .btn-agent-stop:hover { border-color: var(--accent-blue); }
.agent-banner-actions .btn-agent-run:disabled { opacity: 0.5; cursor: not-allowed; }

/* Filter pills are wrapped in .agent-filters which collapses to width:0 by
   default. Clicking the gear button (.btn-agent-filters) flips
   data-filters-open to "true" and the wrapper expands inline. */
.agent-filters {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  max-width: 0;
  opacity: 0;
  pointer-events: none;
  transition: max-width 0.25s ease, opacity 0.2s ease;
}
.agent-filters[data-filters-open="true"] {
  max-width: 600px;  /* enough room for 3-4 pills */
  opacity: 1;
  pointer-events: auto;
  margin-right: 6px;
}
/* Gear toggle — square 26px button matching Run/Stop. */
.agent-banner-actions .btn-agent-filters {
  box-sizing: border-box;
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 12px;
  line-height: 1;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.agent-banner-actions .btn-agent-filters:hover { border-color: var(--accent-blue); }

/* Graceful-stop button (⏹) sits to the right of ▶ Run. Smaller + muted —
   it's a recovery action, not an everyday one. */
.btn-stop {
  font-family: var(--font-sans); font-size: 11px; font-weight: 700;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  margin-left: 4px;
}
.btn-stop:hover { color: var(--accent-red-light); border-color: var(--accent-red-light); }
.btn-stop.pending { opacity: 0.7; pointer-events: none; }

.connector-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; border-bottom: 1px solid rgba(42,42,42,0.5); font-size: 13px; }
.connector-row:last-child { border-bottom: none; }
.connector-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.connector-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.connector-dot.green { background: var(--accent-green); }
.connector-dot.yellow { background: var(--accent-yellow); }
.connector-dot.red { background: var(--accent-red-light); }
.connector-last { font-size: 12px; color: var(--text-muted); }

.event-feed { padding: 0; }
/* Each event row is a 3-column grid: [time] [name] [status]. The optional
   detail line drops into the name column on a second row so it always aligns
   under the event name regardless of the time column's actual width.

       column 1 (time)    column 2 (name + detail)        column 3 (status)
       ──────────────     ──────────────────────────      ────────────────
       4:09 PM            Health Check                    ✅ done
                          🟢 LIVE — May 24, 04:09 PM …   ←  detail line  */
.event-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  column-gap: 12px;
  row-gap: 4px;
  align-items: baseline;
  padding: 9px 20px;
  border-bottom: 1px solid rgba(42,42,42,0.5);
  font-size: 12px;
}
.event-row:last-child { border-bottom: none; }
.event-time {
  grid-column: 1;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
}
.event-name {
  grid-column: 2;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden;
  /* Soft fade on the right edge so long names don't visually crash into the
     ✅ status badge. Replaces hard text-overflow: ellipsis with a gradient
     mask — both Chromium and Safari support `mask-image` unprefixed. */
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 64px), transparent);
          mask-image: linear-gradient(to right, #000 calc(100% - 64px), transparent);
}
.event-status-badge {
  grid-column: 3;
  font-size: 11px; font-weight: 500; white-space: nowrap;
}
.event-row-detail {
  grid-column: 2 / 4;            /* span name + status columns on the second row */
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.4;
  overflow: hidden;
  white-space: nowrap;
  /* Longer fade than .event-name — detail strings are subprocess stdout tails
     and tend to be much longer / less meaningful at the end. */
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 96px), transparent);
          mask-image: linear-gradient(to right, #000 calc(100% - 96px), transparent);
}
/* Event Log links (e.g. "View ↗" → Notion): gray, a touch stronger than the muted
   detail text so it reads as a link, but quieter than the blue accent. */
.event-link { color: var(--text-secondary); text-decoration: underline; text-decoration-color: var(--text-muted); text-underline-offset: 2px; transition: color 0.15s ease, text-decoration-color 0.15s ease; }
.event-link:hover { color: var(--text-primary); text-decoration-color: var(--text-secondary); }
.event-status-badge.written   { color: var(--accent-green); }
.event-status-badge.duplicate { color: var(--text-muted); }
.event-status-badge.failed    { color: var(--accent-red-light); }
.event-status-badge.running   { color: var(--accent-blue); }

@media (max-width: 720px) {
  .event-row { padding: 8px 14px; column-gap: 8px; grid-template-columns: 48px 1fr auto; }
}

.panel-body::-webkit-scrollbar { width: 4px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Responsive grid + horizontal-scroll rules consolidated in agents.css
   (loaded after styles.css). See the RESPONSIVE section there. */

@media (prefers-color-scheme: light) {
  :root { --bg-primary:#F5F5F7;--bg-card:#FFF;--bg-elevated:#F0F0F2;--bg-hover:#E8E8ED;--text-primary:#1D1D1F;--text-secondary:#6E6E73;--text-muted:#AEAEB2;--accent-red:#A4161A;--accent-red-light:#D70015;--accent-blue:#0071E3;--accent-green:#248A3D;--accent-yellow:#B25000;--accent-orange:#C93400;--border:#D2D2D7;--shadow:0 1px 3px rgba(0,0,0,0.08); }
  .topbar,.pulse-bar { background:var(--bg-card);border-bottom-color:var(--border); }
  .panel,.stat-card { box-shadow:var(--shadow);border-color:var(--border); }
}
[data-theme="light"] { --bg-primary:#F5F5F7;--bg-card:#FFF;--bg-elevated:#F0F0F2;--bg-hover:#E8E8ED;--text-primary:#1D1D1F;--text-secondary:#6E6E73;--text-muted:#AEAEB2;--accent-red:#A4161A;--accent-red-light:#D70015;--accent-blue:#0071E3;--accent-green:#248A3D;--accent-yellow:#B25000;--accent-orange:#C93400;--border:#D2D2D7;--shadow:0 1px 3px rgba(0,0,0,0.08); }
[data-theme="light"] .topbar,[data-theme="light"] .pulse-bar { background:var(--bg-card);border-bottom-color:var(--border); }
[data-theme="light"] .panel,[data-theme="light"] .stat-card { box-shadow:var(--shadow);border-color:var(--border); }
.event-status-badge.running { color: var(--accent-blue); }

/* ============================================================================
   Floating chat widget — mirrors the Telegram conversation.
   FAB at bottom-right; click expands into a 360×520 panel with messages + composer.
   Polling lives in chat.js.
   ============================================================================ */
#chat-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  font-family: var(--font-sans);
}
.chat-fab {
  position: relative;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent-blue);
  color: #fff;
  border: 0;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0,0,0,0.45), 0 2px 4px rgba(0,0,0,0.3);
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.chat-fab:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0,0,0,0.55); }
.chat-fab:active { transform: translateY(0); }
.chat-fab-icon { display: inline-flex; }
.chat-fab-icon svg { width: 24px; height: 24px; }

.chat-panel {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: min(520px, calc(100vh - 120px));
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-panel[hidden] { display: none; }
.chat-header {
  display: flex; align-items: baseline; gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.chat-title { font-weight: 700; font-size: 14px; color: var(--text-primary); }
.chat-subtitle { font-size: 11px; color: var(--text-muted); flex: 1; }
.chat-close {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.chat-close:hover { color: var(--text-primary); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-card);
}
.chat-msg { display: flex; }
.chat-msg-in  { justify-content: flex-start; }   /* agent / bot messages on the left */
.chat-msg-out { justify-content: flex-end;   }   /* user messages on the right */
.chat-bubble {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--bg-elevated);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-primary);
}
.chat-msg-out .chat-bubble {
  background: var(--accent-blue);
  color: #fff;
}
.chat-msg-out .chat-bubble a { color: #cfe5ff; }
.chat-body {
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-body a { color: var(--accent-blue); text-decoration: none; }
.chat-body a:hover { text-decoration: underline; }
.chat-meta {
  display: flex; justify-content: space-between; gap: 8px;
  margin-top: 4px;
  font-size: 10px;
  opacity: 0.65;
}
.chat-source { text-transform: uppercase; letter-spacing: 0.3px; }
.chat-time { font-family: var(--font-mono); }

.chat-composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}
.chat-input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text-primary);
  resize: none;
  outline: none;
  line-height: 1.4;
  max-height: 120px;
}
.chat-input:focus { border-color: var(--accent-blue); }
.chat-send {
  background: var(--accent-blue);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  font-family: var(--font-sans);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.chat-send:hover { opacity: 0.92; }
.chat-send:active { opacity: 0.8; }

@media (max-width: 520px) {
  #chat-widget { right: 12px; bottom: 12px; }
  .chat-panel { right: 0; width: calc(100vw - 24px); }
}

/* ── Toasts (Run-button undo, etc.) ─────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--bg-card); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px 14px 14px;
  display: flex; align-items: center; gap: 14px;
  min-width: 280px; max-width: 360px;
  font-size: 13px; line-height: 1.4;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  animation: toast-in 220ms ease-out;
  position: relative; overflow: hidden;
}
.toast.toast-out { opacity: 0; transform: translateY(8px); transition: opacity 220ms, transform 220ms; }
.toast-text { flex: 1; color: var(--text-primary); }
.toast-undo {
  background: transparent; color: var(--accent-blue); border: 0;
  cursor: pointer; font-weight: 600; font-size: 13px;
  padding: 4px 6px; border-radius: 6px;
}
.toast-undo:hover { background: var(--bg-elevated); }
.toast-progress {
  position: absolute; left: 0; bottom: 0; height: 2px;
  background: var(--accent-blue);
  transform-origin: left center;
  transform: scaleX(1);
}
.toast.is-running .toast-progress { background: var(--accent-green); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (max-width: 520px) {
  #toast-container { right: 12px; bottom: 12px; left: 12px; align-items: stretch; }
  .toast { min-width: 0; }
}

/* Pending state for trigger buttons during the undo window */
.btn-trigger.pending { opacity: 0.7; cursor: default; }
