/* PatentScope TR — design tokens */
:root {
  /* warm off-white base */
  --bg: #faf8f4;
  --bg-panel: #ffffff;
  --bg-sunken: #f3efe7;
  --bg-hover: #f1ede4;

  /* text */
  --fg: #1a1a1f;
  --fg-muted: #6b6a6e;
  --fg-subtle: #97969a;

  /* borders */
  --border: #e6e1d6;
  --border-strong: #d4cdba;

  /* accents */
  --indigo: #2e2a8a;
  --indigo-soft: #ebe9fb;
  --indigo-ink: #1b1956;
  --amber: #b07a1a;
  --amber-soft: #f8eed4;
  --amber-bg: #fdf6e3;
  --green: #2c6a3d;
  --green-soft: #e0eede;
  --red: #993a2d;
  --red-soft: #f6e1dc;
  --blue: #1f5fa8;
  --blue-soft: #e3ecf8;

  /* type */
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', monospace;
  --font-serif: 'IBM Plex Serif', Georgia, serif;

  /* radius */
  --r-sm: 4px;
  --r: 6px;
  --r-md: 8px;
  --r-lg: 12px;

  /* shadow */
  --shadow-sm: 0 1px 2px rgba(20,15,5,0.04);
  --shadow: 0 1px 3px rgba(20,15,5,0.06), 0 1px 2px rgba(20,15,5,0.04);
  --shadow-lg: 0 8px 24px -8px rgba(20,15,5,0.12), 0 2px 6px rgba(20,15,5,0.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
  font-feature-settings: 'ss01', 'cv11';
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: inherit; }

/* App shell */
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  background: var(--bg);
}

/* ============ SIDEBAR ============ */
.sidebar {
  background: var(--bg-sunken);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
}
.sidebar-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}
.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: var(--r);
  background: var(--indigo);
  color: white;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.02em;
}
.brand-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
}
.brand-name .tr {
  color: var(--fg-muted);
  font-weight: 400;
  margin-left: 3px;
}
.icon-btn {
  width: 26px; height: 26px;
  border-radius: var(--r-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--fg-muted);
  display: grid; place-items: center;
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--fg); }

.sidebar-new {
  padding: 12px;
}
.btn-new {
  width: 100%;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  border-radius: var(--r);
  border: 1px solid var(--indigo);
  background: var(--indigo);
  color: white;
  font-weight: 500;
  font-size: 13px;
  transition: background 0.12s, transform 0.04s;
}
.btn-new:hover { background: var(--indigo-ink); }
.btn-new:active { transform: translateY(1px); }
.btn-new .kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.7;
  padding: 1px 5px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 3px;
}

.sidebar-section-label {
  padding: 14px 18px 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--fg-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 6px 12px;
}
.history-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border-radius: var(--r);
  border: 1px solid transparent;
  background: transparent;
  margin-bottom: 1px;
  position: relative;
  transition: background 0.1s;
  cursor: pointer;
}
.history-item:hover { background: var(--bg-hover); }
.history-item.active {
  background: var(--bg-panel);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}
.history-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
  line-height: 1.3;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--fg-subtle);
  font-family: var(--font-mono);
}
.history-meta .dot {
  width: 4px; height: 4px; border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
}
.history-actions {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  gap: 2px;
  background: linear-gradient(to right, transparent, var(--bg-hover) 20%);
  padding-left: 18px;
}
.history-item:hover .history-actions { display: flex; }
.history-item.active .history-actions {
  background: linear-gradient(to right, transparent, var(--bg-panel) 20%);
}
.history-actions .icon-btn {
  width: 22px; height: 22px;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--r);
}
.user-card:hover { background: var(--bg-hover); }
.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #c7a37d, #8b6645);
  color: white;
  display: grid; place-items: center;
  font-size: 12px;
  font-weight: 600;
}
.user-name { font-size: 13px; font-weight: 500; }
.user-org { font-size: 11px; color: var(--fg-muted); font-family: var(--font-mono); }

/* ============ MAIN ============ */
.main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  display: flex;
  align-items: center;
  padding: 12px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--fg-muted);
}
.crumb .crumb-sep { color: var(--fg-subtle); }
.crumb .crumb-current { color: var(--fg); font-weight: 500; }

.topbar-spacer { flex: 1; }

.token-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 8px;
  background: var(--amber-bg);
  border: 1px solid var(--amber-soft);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--amber);
  font-weight: 500;
}
.token-pill .coin {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--amber);
  display: grid; place-items: center;
  color: white;
  font-size: 9px;
  font-weight: 700;
}
.token-pill .top-up {
  margin-left: 4px;
  color: var(--amber);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn-ghost {
  padding: 6px 10px;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  font-size: 12px;
  color: var(--fg);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-ghost:hover { background: var(--bg-hover); }
.btn-primary {
  padding: 8px 14px;
  background: var(--indigo);
  border: 1px solid var(--indigo);
  border-radius: var(--r);
  color: white;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn-primary:hover { background: var(--indigo-ink); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.content {
  padding: 28px 28px 60px;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
}

/* ============ NEW SEARCH FORM ============ */
.page-header {
  margin-bottom: 28px;
}
.page-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--indigo);
  margin-bottom: 8px;
}
.page-title {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0 0 8px;
  color: var(--fg);
}
.page-sub {
  color: var(--fg-muted);
  font-size: 14px;
  max-width: 640px;
}

.form-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}
.form-row label {
  font-size: 12px;
  font-weight: 500;
  color: var(--fg);
}
.form-row .hint {
  font-size: 11px;
  color: var(--fg-muted);
  margin-top: -2px;
}
.field-input, .field-textarea {
  border: 1px solid var(--border-strong);
  background: var(--bg);
  border-radius: var(--r);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--fg);
  resize: vertical;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.field-textarea { font-family: var(--font-sans); line-height: 1.5; min-height: 110px; }
.field-input:focus, .field-textarea:focus {
  outline: none;
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px var(--indigo-soft);
}

.keywords-input {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  border-radius: var(--r);
  padding: 6px;
  min-height: 38px;
  align-items: center;
}
.keyword-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 9px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--fg);
}
.keyword-chip .x {
  width: 16px; height: 16px;
  display: grid; place-items: center;
  border-radius: 3px;
  color: var(--fg-muted);
}
.keyword-chip .x:hover { background: var(--border); color: var(--fg); cursor: pointer; }
.keywords-input input {
  border: none;
  outline: none;
  background: transparent;
  flex: 1;
  min-width: 100px;
  padding: 4px 6px;
  font-size: 12px;
}

.form-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 14px;
  background: var(--bg-sunken);
  border-radius: var(--r);
  margin-bottom: 18px;
}
.opt-block { font-size: 12px; }
.opt-block .opt-label { color: var(--fg-muted); margin-bottom: 4px; }
.opt-block .opt-value { font-weight: 500; }
.opt-block .opt-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-top: 6px;
}
.cost-readout {
  font-size: 12px;
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  gap: 10px;
}
.cost-readout strong { color: var(--fg); font-family: var(--font-mono); font-weight: 600; }
.cost-readout .bar {
  width: 1px; height: 16px; background: var(--border);
}

/* ============ WORKFLOW ============ */
.run-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}
@media (max-width: 1100px) {
  .run-grid { grid-template-columns: 1fr; }
}

.workflow-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.workflow-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.run-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 999px;
}
.run-status-pill.running {
  background: var(--blue-soft);
  color: var(--blue);
}
.run-status-pill.done {
  background: var(--green-soft);
  color: var(--green);
}
.run-status-pill .live-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}
.workflow-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
}
.workflow-title .run-id {
  font-family: var(--font-mono);
  color: var(--fg-subtle);
  font-weight: 400;
  margin-left: 8px;
  font-size: 12px;
}

.workflow-canvas {
  padding: 28px 24px;
  background:
    radial-gradient(circle at 1px 1px, var(--border) 0.5px, transparent 1px);
  background-size: 18px 18px;
  background-color: var(--bg);
  position: relative;
}

.flow {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  position: relative;
}

.flow-stage {
  display: grid;
  gap: 14px;
  align-items: start;
  position: relative;
}
.flow-stage.parallel {
  grid-template-columns: 1fr 1fr;
}
.flow-connector {
  height: 24px;
  width: 100%;
  display: flex;
  align-items: stretch;
  justify-content: center;
  position: relative;
}
.flow-connector .line {
  width: 1.5px;
  background: var(--border-strong);
  height: 100%;
}
.flow-connector.split::before,
.flow-connector.split::after {
  content: '';
  position: absolute;
  top: 12px;
  height: calc(100% - 12px);
  width: calc(25% + 0.75px);
  border-top: 1.5px solid var(--border-strong);
}
.flow-connector.split::before {
  left: 25%;
  border-left: 1.5px solid var(--border-strong);
  border-top-left-radius: 8px;
}
.flow-connector.split::after {
  right: 25%;
  border-right: 1.5px solid var(--border-strong);
  border-top-right-radius: 8px;
}
.flow-connector.split .line {
  position: absolute;
  top: 0;
  height: 12px;
}
.flow-connector.merge::before,
.flow-connector.merge::after {
  content: '';
  position: absolute;
  bottom: 12px;
  height: calc(100% - 12px);
  width: calc(25% + 0.75px);
  border-bottom: 1.5px solid var(--border-strong);
}
.flow-connector.merge::before {
  left: 25%;
  border-left: 1.5px solid var(--border-strong);
  border-bottom-left-radius: 8px;
}
.flow-connector.merge::after {
  right: 25%;
  border-right: 1.5px solid var(--border-strong);
  border-bottom-right-radius: 8px;
}
.flow-connector.merge .line {
  position: absolute;
  bottom: 0;
  height: 12px;
}

/* Active connector */
.flow-connector.active .line,
.flow-connector.active.split::before,
.flow-connector.active.split::after,
.flow-connector.active.merge::before,
.flow-connector.active.merge::after {
  border-color: var(--indigo);
  background: var(--indigo);
}
.flow-connector.active .line { background: var(--indigo); }

/* AGENT NODE */
.agent-node {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
  position: relative;
}
.agent-node.running {
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px var(--indigo-soft), var(--shadow-sm);
}
.agent-node.done {
  border-color: var(--border);
  background: var(--bg-panel);
}
.agent-node.done .agent-icon {
  background: var(--green-soft);
  color: var(--green);
}
.agent-node.running .agent-icon {
  background: var(--indigo-soft);
  color: var(--indigo);
}
.agent-node.pending {
  background: var(--bg-panel);
  opacity: 0.55;
}
.agent-icon {
  width: 32px; height: 32px;
  border-radius: var(--r);
  background: var(--bg-sunken);
  color: var(--fg-muted);
  display: grid; place-items: center;
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
}
.agent-body { flex: 1; min-width: 0; }
.agent-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.agent-name {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
}
.agent-handle {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
}
.agent-status {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.agent-status .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--fg-subtle);
}
.agent-node.running .agent-status .dot {
  background: var(--indigo);
  animation: pulse 1.4s infinite;
}
.agent-node.done .agent-status .dot { background: var(--green); }
.agent-node.running .agent-status { color: var(--indigo); }
.agent-node.done .agent-status { color: var(--green); }
.agent-desc {
  font-size: 12px;
  color: var(--fg-muted);
  margin-top: 3px;
  line-height: 1.45;
}
.agent-trace {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  display: flex;
  gap: 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
}
.agent-trace .kv strong { color: var(--fg); font-weight: 500; }

/* ============ LIVE LOG (right rail) ============ */
.run-rail {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 78px;
}
.rail-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.rail-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
}
.rail-head .meta { color: var(--fg-muted); font-weight: 400; font-family: var(--font-mono); font-size: 11px; }

.token-meter {
  padding: 16px;
}
.token-balance-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.token-num {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.01em;
}
.token-num .delta {
  font-size: 13px;
  color: var(--red);
  margin-left: 6px;
  font-weight: 500;
}
.token-label {
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.token-cost-line {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 14px;
  font-size: 11px;
  color: var(--fg-muted);
  font-family: var(--font-mono);
}
.token-segments {
  display: flex;
  gap: 3px;
  margin-bottom: 6px;
}
.token-segments .seg {
  flex: 1;
  height: 6px;
  background: var(--amber-soft);
  border-radius: 2px;
}
.token-segments .seg.spent { background: var(--amber); }
.token-segments .seg.upcoming {
  background: repeating-linear-gradient(45deg, var(--amber-soft) 0 4px, transparent 4px 8px);
  border: 1px dashed var(--amber);
}
.token-foot-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--fg-muted);
}

.log-list {
  max-height: 320px;
  overflow-y: auto;
  padding: 8px 0;
}
.log-entry {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 8px;
  padding: 5px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
}
.log-entry .ts { color: var(--fg-subtle); }
.log-entry .msg { color: var(--fg); }
.log-entry .msg .tag {
  display: inline-block;
  font-size: 10px;
  padding: 0 4px;
  background: var(--bg-sunken);
  border-radius: 3px;
  color: var(--fg-muted);
  margin-right: 4px;
}
.log-entry.warn .msg { color: var(--amber); }
.log-entry.ok .msg { color: var(--green); }

/* ============ RESULTS ============ */
.results-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 24px;
  align-items: start;
}
@media (max-width: 1100px) {
  .results-grid { grid-template-columns: 1fr; }
}

.section-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.section-title .count {
  font-family: var(--font-mono);
  color: var(--fg-muted);
  font-weight: 400;
}

.report-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}
.report-eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--indigo);
  margin-bottom: 8px;
}
.report-title {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0 0 18px;
  line-height: 1.25;
}
.verdict-block {
  background: var(--amber-bg);
  border: 1px solid var(--amber-soft);
  border-left: 3px solid var(--amber);
  padding: 12px 14px;
  border-radius: var(--r);
  margin-bottom: 18px;
  font-size: 13px;
  line-height: 1.55;
}
.verdict-block strong { font-weight: 600; }
.report-body p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--fg);
  margin: 0 0 14px;
}
.report-body p:last-child { margin-bottom: 0; }
.report-body .num {
  font-family: var(--font-mono);
  font-weight: 500;
}
.report-foot {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--fg-muted);
}
.report-foot .actions { display: flex; gap: 8px; }

/* candidates */
.candidates-list { display: flex; flex-direction: column; gap: 10px; }
.candidate-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: start;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.candidate-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.candidate-rank {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
  padding-top: 2px;
}
.candidate-body { min-width: 0; }
.candidate-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 3px;
}
.source-chip.google {
  background: var(--blue-soft);
  color: var(--blue);
}
.source-chip.turk {
  background: #f8e8e3;
  color: var(--red);
}
.source-chip.espacenet {
  background: #e8f0e6;
  color: var(--green);
}
.record-type-chip {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 3px;
  text-transform: uppercase;
  border: 1px solid var(--border);
}
.record-type-chip.patent {
  background: transparent;
  color: var(--fg-muted);
  border-color: var(--border-strong);
}
.record-type-chip.utility_model {
  background: #fdf4e6;
  color: var(--amber);
  border-color: #f0d9a8;
}
.cand-id {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
}
.cand-date {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
  margin-left: auto;
}
.candidate-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--fg);
  margin: 2px 0 6px;
  text-wrap: pretty;
}
.candidate-abs {
  font-size: 12.5px;
  color: var(--fg-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.cand-tags {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.match-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-muted);
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 3px;
}
.match-tag.hit {
  border-color: var(--indigo-soft);
  background: var(--indigo-soft);
  color: var(--indigo);
}
.candidate-score {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  font-family: var(--font-mono);
}
.score-num {
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
}
.score-bar {
  width: 64px;
  height: 4px;
  background: var(--bg-sunken);
  border-radius: 2px;
  overflow: hidden;
}
.score-bar > div {
  height: 100%;
  background: var(--indigo);
  border-radius: 2px;
}
.candidate-score .lbl {
  font-size: 10px;
  color: var(--fg-subtle);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: var(--font-sans);
}

/* right rail on results */
.input-recap {
  padding: 14px 16px;
  font-size: 12px;
  line-height: 1.5;
}
.input-recap dl { margin: 0; display: grid; grid-template-columns: 88px 1fr; row-gap: 7px; column-gap: 12px; }
.input-recap dt { color: var(--fg-muted); font-family: var(--font-mono); font-size: 11px; }
.input-recap dd { margin: 0; color: var(--fg); }
.input-recap .kw-row { display: flex; flex-wrap: wrap; gap: 4px; }
.input-recap .kw {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-sunken);
  border-radius: 3px;
  padding: 1px 6px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
}
.stat-cell {
  background: var(--bg-panel);
  padding: 12px 14px;
}
.stat-cell .stat-label {
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.stat-cell .stat-val {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--fg);
}
.stat-cell .stat-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-subtle);
}

/* ============ HISTORY (dashboard) ============ */
.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}
.kpi-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
}
.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
  margin-bottom: 5px;
}
.kpi-val {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.kpi-val.amber { color: var(--amber); }
.kpi-sub {
  font-size: 11px;
  color: var(--fg-subtle);
  margin-top: 3px;
  font-family: var(--font-mono);
}

.runs-table {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.runs-table-head, .runs-table-row {
  display: grid;
  grid-template-columns: 1fr 110px 90px 100px 110px 40px;
  gap: 14px;
  padding: 11px 18px;
  align-items: center;
  font-size: 12px;
}
.runs-table-head {
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
  font-weight: 500;
}
.runs-table-row {
  border-bottom: 1px solid var(--border);
}
.runs-table-row:last-child { border-bottom: none; }
.runs-table-row:hover { background: var(--bg); }
.run-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.run-name .sub {
  font-size: 11px;
  color: var(--fg-muted);
  font-weight: 400;
  margin-top: 2px;
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tag-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 3px;
}
.tag-status.done { background: var(--green-soft); color: var(--green); }
.tag-status.running { background: var(--blue-soft); color: var(--blue); }
.tag-status.draft { background: var(--bg-sunken); color: var(--fg-muted); }
.cell-mono { font-family: var(--font-mono); color: var(--fg-muted); font-size: 12px; }

.row-actions { position: relative; }
.menu-btn { width: 24px; height: 24px; border-radius: 4px; border: 1px solid transparent; background: transparent; color: var(--fg-muted); display: grid; place-items: center; }
.menu-btn:hover { background: var(--bg-sunken); }

/* layout helpers */
.stack { display: flex; flex-direction: column; gap: 24px; }
.row { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }
.hr { height: 1px; background: var(--border); margin: 0; border: 0; }

/* dropdown menu (very simple) */
.menu {
  position: absolute;
  right: 0;
  top: 28px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  min-width: 180px;
  z-index: 50;
}
.menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: transparent;
  border: none;
  text-align: left;
  padding: 7px 9px;
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--fg);
}
.menu button:hover { background: var(--bg-sunken); }
.menu button.danger { color: var(--red); }
.menu .sep { height: 1px; background: var(--border); margin: 4px 0; }

/* empty state inside agent body */
.live-out {
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--bg-sunken);
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.spinner {
  width: 10px; height: 10px;
  border: 2px solid var(--indigo-soft);
  border-top-color: var(--indigo);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.live-out.done { color: var(--green); background: var(--green-soft); }
.live-out.done .spinner { display: none; }

.heading-divider {
  display: flex; align-items: center; gap: 12px; margin: 22px 0 14px;
}
.heading-divider .label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-muted); font-weight: 500;
}
.heading-divider .line { flex: 1; height: 1px; background: var(--border); }

/* tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 4px;
  margin-bottom: 18px;
}
.tab {
  background: transparent;
  border: none;
  padding: 9px 14px;
  font-size: 13px;
  color: var(--fg-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  position: relative;
}
.tab.active { color: var(--fg); border-bottom-color: var(--indigo); font-weight: 500; }
.tab .badge {
  font-family: var(--font-mono);
  background: var(--bg-sunken);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--fg-muted);
}
.tab.active .badge { background: var(--indigo-soft); color: var(--indigo); }
