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

:root {
  --bg: #f7f8fa;
  --sidebar: #111820;
  --sidebar-text: #8a9ab5;
  --card: #ffffff;
  --border: #eaedf2;
  --border-soft: #f1f3f7;
  --text: #111827;
  --text-2: #6b7280;
  --text-3: #adb5c2;
  --blue: #4f7df7;
  --blue-dark: #3b63d4;
  --blue-soft: #eef3ff;
  --green: #18b76b;
  --green-soft: #edfaf3;
  --red: #ef4444;
  --amber: #f59e0b;
  --amber-soft: #fffbeb;
  --purple: #8b5cf6;
  --purple-soft: #f5f3ff;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; height: 100vh; overflow: hidden }

::-webkit-scrollbar { width: 4px }
::-webkit-scrollbar-track { background: transparent }
::-webkit-scrollbar-thumb { background: #dde1e9; border-radius: 10px }

/* ── Sidebar ── */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-logo {
  height: 68px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 20px;
}
.sidebar-logo-title {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.sidebar-logo-sub {
  font-size: 11px;
  color: #3d5068;
  margin-top: 3px;
  font-weight: 400;
}

.sidebar-nav { flex: 1; padding: 14px 10px }
.nav-section { margin-bottom: 20px }
.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  color: #2c3e52;
  letter-spacing: .10em;
  text-transform: uppercase;
  padding: 0 10px;
  margin-bottom: 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--sidebar-text);
  font-size: 15px;
  font-weight: 500;
  transition: background .12s, color .12s;
  white-space: nowrap;
  text-decoration: none;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: #c8d4e4 }
.nav-item.active { background: rgba(79,125,247,.14); color: #7da8fa }
.nav-badge {
  margin-left: auto;
  background: rgba(79,125,247,.18);
  color: #7da8fa;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
}

.sidebar-footer {
  padding: 14px 20px;
  font-size: 11px;
  color: #2c3e52;
  display: flex;
  align-items: center;
  gap: 7px;
}


/* ── Footer bar ── */
.footer-bar {
  height: 30px;
  background: var(--sidebar);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 20px;
  flex-shrink: 0;
}
.footer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #2c3e52;
  font-family: 'DM Mono', monospace;
}
.footer-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2.5s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .35 } }
.footer-sep { width: 1px; height: 10px; background: rgba(255,255,255,.05) }

/* ── Layout ── */
.main-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0 }
.content-with-drawer { display: flex; height: 100%; overflow: hidden }
.content-main { flex: 1; overflow-y: auto; padding: 24px 28px }

/* ── KPI cards ── */
.kpi-grid { display: grid; gap: 12px; margin-bottom: 24px }
.kpi-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  border: 1px solid var(--border);
}
.kpi-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 10px;
}
.kpi-value { font-size: 26px; font-weight: 700; line-height: 1; color: var(--text) }
.kpi-change { font-size: 11px; margin-top: 7px; color: var(--green); font-weight: 500 }

/* ── Card ── */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
}

/* ── Table ── */
table { width: 100%; border-collapse: collapse; font-size: 13px }
thead th {
  padding: 10px 14px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  letter-spacing: .04em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  z-index: 1;
  cursor: pointer;
  user-select: none;
  transition: color .12s;
}
thead th:hover { color: var(--text-2) }
thead th.sorted { color: var(--blue) }
tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
  text-align: center;
}
tbody tr { transition: background .1s; cursor: pointer }
tbody tr:last-child td { border-bottom: none }
tbody tr:hover { background: #fafbfd }
tbody tr.selected { background: var(--blue-soft) }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .01em;
}
.badge-blue { background: #e8effd; color: #3058c7 }
.badge-green { background: var(--green-soft); color: #0e7b4a }
.badge-amber { background: var(--amber-soft); color: #9a6200 }
.badge-purple { background: var(--purple-soft); color: #6434c0 }
.badge-gray { background: var(--border-soft); color: #6b7280 }
.badge-red { background: #fef2f2; color: #b91c1c }

/* ── Filters ── */
.filters-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-select {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  outline: none;
  font-family: inherit;
  transition: border-color .15s;
}
.filter-select:hover { border-color: #c5ccd8 }
.filter-select:focus { border-color: #bfccf5 }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .15s;
}
.btn:hover { opacity: .88 }
.btn-primary { background: var(--blue); color: #fff }
.btn-sm { padding: 5px 11px; font-size: 12px }
.btn-ghost {
  background: transparent;
  color: var(--text-3);
  border: none;
  padding: 4px 8px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s, color .12s;
  font-family: inherit;
}
.btn-ghost:hover { background: var(--bg); color: var(--text-2) }

/* ── Drawer ── */
.drawer {
  width: 0;
  min-width: 0;
  background: var(--card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  transition: width .25s ease, min-width .25s ease;
}
.drawer.open {
  width: 400px;
  min-width: 400px;
}
.drawer-resize-handle {
  width: 1px;
  flex-shrink: 0;
  background: var(--border);
  cursor: ew-resize;
  position: relative;
  opacity: 0;
  transition: background .15s, opacity .25s ease;
}
/* widen hit area without visual change */
.drawer-resize-handle::before {
  content: '';
  position: absolute;
  left: -4px; right: -4px;
  top: 0; bottom: 0;
}
.drawer-resize-handle:hover { background: rgba(79,125,247,.5); }
/* show handle when drawer is open — toggled via JS */
.drawer-resize-handle.visible { opacity: 1; }
.ext-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-3);
  text-decoration: none;
  transition: color .15s;
  margin-top: 4px;
}
.ext-link-btn:hover { color: var(--text-2) }
.drawer-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.drawer-body { flex: 1; overflow-y: auto }

.info-section-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .1em;
  padding: 16px 20px 8px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 20px;
  border-bottom: 1px solid var(--border-soft);
}
.info-row:last-of-type { border-bottom: none }
.info-label { font-size: 13px; color: var(--text-3) }
.info-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  max-width: 60%;
  word-break: break-word;
}
.info-value.score { color: var(--green) }
.info-value.partner { color: var(--blue-dark) }
.info-value.not-found { color: var(--text-3); font-family: 'DM Mono', monospace; font-weight: 400 }
.info-value.mono { font-family: 'DM Mono', monospace; font-size: 11px }

.brief-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.75;
  margin: 0 20px 16px;
}
.evidence-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 0 20px 16px;
}

/* ── Score bars ── */
.score-bar-wrap { padding: 4px 20px 16px }
.score-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px }
.score-bar-label { font-size: 11px; color: var(--text-3); width: 104px; flex-shrink: 0 }
.score-bar-track {
  flex: 1;
  height: 5px;
  background: var(--border-soft);
  border-radius: 10px;
  overflow: hidden;
}
.score-bar-fill { height: 5px; border-radius: 10px; transition: width .35s ease }
.score-bar-pts {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  width: 24px;
  text-align: right;
  flex-shrink: 0;
  color: var(--text-2);
}
.score-bar-just {
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.5;
  margin: -2px 0 10px 114px;
}

/* ── Page ── */
.page-title { font-size: 20px; font-weight: 700; margin-bottom: 20px; color: var(--text) }

.status-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block }
.status-healthy { background: var(--green) }

/* ── Export modal ── */
.export-modal {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
  padding: 8px;
  z-index: 300;
  min-width: 180px;
}
.export-modal[hidden] { display: none; }
.export-modal-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 4px 8px 8px;
}
.export-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: background .1s;
  text-align: left;
}
.export-opt:hover { background: var(--bg) }
.export-opt-sub {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-3);
  margin-left: auto;
}

/* ── Date pills ── */
.date-pills {
  display: flex;
  gap: 2px;
  background: var(--border-soft);
  border-radius: 9px;
  padding: 3px;
}
.date-pill {
  padding: 5px 12px;
  border-radius: 7px;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  font-family: inherit;
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.date-pill:hover { color: var(--text) }
.date-pill.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.07) }

/* ── Filters button + panel ── */
.btn-filters {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  font-family: inherit;
  transition: border-color .15s, color .15s, background .15s;
}
.btn-filters:hover { border-color: #c5ccd8; color: var(--text) }
.btn-filters.active { border-color: var(--blue); color: var(--blue) }
.filters-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  min-width: 200px;
}
.filters-panel[hidden] { display: none; }

/* ── Custom Select ── */
.csel { position: relative; display: inline-flex; flex-direction: column; }

.csel-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  font-family: inherit;
  transition: border-color .15s, color .15s;
  white-space: nowrap;
  min-width: 120px;
  text-align: left;
}
.csel-trigger:hover { border-color: #c5ccd8; color: var(--text) }
.csel-trigger.open { border-color: #bfccf5; color: var(--text) }

.csel-arrow {
  width: 13px; height: 13px;
  margin-left: auto;
  flex-shrink: 0;
  color: var(--text-3);
  transition: transform .18s;
  pointer-events: none;
}
.csel-trigger.open .csel-arrow { transform: rotate(180deg) }

.csel-dropdown {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  min-width: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.07), 0 2px 6px rgba(0,0,0,.04);
  z-index: 200;
  padding: 4px;
  max-height: 240px;
  overflow-y: auto;
}

.csel-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  transition: background .1s;
  white-space: nowrap;
}
.csel-option:hover { background: var(--bg) }
.csel-option.csel-active { color: var(--blue); font-weight: 600 }
.csel-check {
  width: 12px; height: 12px;
  flex-shrink: 0;
  opacity: 0;
  color: var(--blue);
}
.csel-option.csel-active .csel-check { opacity: 1 }

/* ── Article Modal ── */
.amodal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.amodal-overlay[hidden] { display: none; }
.amodal-panel {
  background: var(--card);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
}
#article-modal-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.amodal-header {
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex-shrink: 0;
}
.amodal-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.amodal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}
.amodal-section-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .1em;
  margin: 4px 0 12px;
}
.amodal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-bottom: 4px;
}
.amodal-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-soft);
}
.amodal-grid .amodal-field:nth-last-child(-n+2) { border-bottom: none }
.amodal-label { font-size: 11px; color: var(--text-3) }
.amodal-val { font-size: 13px; font-weight: 600; color: var(--text) }

/* ── Article Feed ── */
.article-tabs-inline {
  display: flex;
  gap: 2px;
}
.article-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  font-family: inherit;
  transition: background .1s, color .1s;
}
.article-tab-btn span {
  font-size: 11px;
  background: var(--border-soft);
  color: var(--text-3);
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}
.article-tab-btn:hover { background: var(--bg); color: var(--text) }
.article-tab-btn.active { background: var(--blue-soft); color: var(--blue) }
.article-tab-btn.active span { background: var(--blue-soft); color: var(--blue) }

.article-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.article-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .12s, border-color .12s;
}
.article-tab span {
  font-size: 11px;
  background: var(--border-soft);
  color: var(--text-3);
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}
.article-tab:hover { color: var(--text) }
.article-tab.active { color: var(--text); border-bottom-color: var(--blue) }
.article-tab.active span { background: var(--blue-soft); color: var(--blue) }

.article-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.article-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: border-color .15s;
}
.article-card:hover { border-color: #c5ccd8 }

.article-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.article-status-pass {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--green);
}
.article-status-skip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
}
.article-meta-right {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
}
.article-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.article-skip-reason {
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.article-card-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
}
.article-attr {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}
.article-attr + .article-attr::before {
  content: '·';
  margin-right: 8px;
  color: var(--border);
}
.article-score {
  font-size: 12px;
  font-weight: 700;
  font-family: 'DM Mono', monospace;
}

/* ── Agent AI Page ── */
.agent-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}
.agent-sidebar {
  width: 260px;
  min-width: 260px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--card);
}
.agent-sidebar-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.agent-search-row { padding: 10px 12px 6px; flex-shrink: 0 }
.agent-search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color .15s;
}
.agent-search:focus { border-color: #bfccf5; background: var(--card) }
.agent-filter-row {
  display: flex;
  gap: 2px;
  padding: 4px 12px 8px;
  flex-shrink: 0;
}
.agent-filter-row .date-pill { padding: 4px 10px; font-size: 11px }
.agent-article-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
}
.agent-article-item {
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .1s;
  margin-bottom: 2px;
}
.agent-article-item:hover { background: var(--bg) }
.agent-article-item.active { background: var(--blue-soft) }

.agent-chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
.agent-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
}
.agent-context-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.agent-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.agent-suggestions {
  display: flex;
  gap: 8px;
  padding: 0 20px 12px;
  flex-wrap: wrap;
}
.agent-suggestion {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  font-family: inherit;
  transition: border-color .12s, color .12s;
}
.agent-suggestion:hover { border-color: var(--blue); color: var(--blue) }
.agent-input-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px 18px;
  background: var(--bg);
  flex-shrink: 0;
}
.agent-input-pill {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 8px 0 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  transition: border-color .15s, box-shadow .15s;
}
.agent-input-pill:focus-within {
  border-color: #bfccf5;
  box-shadow: 0 1px 8px rgba(79,125,247,.12);
}
.agent-attach-btn {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: none;
  background: none;
  color: var(--text-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color .15s, background .15s;
}
.agent-attach-btn:hover { color: var(--text-2); background: var(--border-soft); }
.attach-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: 320px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.1);
  padding: 14px;
  z-index: 200;
}
.attach-panel[hidden] { display: none; }
.attach-textarea {
  width: 100%;
  height: 140px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  outline: none;
  resize: none;
  line-height: 1.5;
  transition: border-color .15s;
}
.attach-textarea:focus { border-color: #bfccf5; background: var(--card) }

/* ── AI Chat ── */
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 12px;
}
.chat-msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.chat-msg.user { flex-direction: row-reverse }
.chat-bubble {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
}
.chat-msg.user .chat-bubble {
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.ai .chat-bubble {
  background: var(--bg);
  color: var(--text);
  border-bottom-left-radius: 4px;
  padding: 0;
}
.chat-msg.ai .chat-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6b8fd4, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 12px;
  color: #fff;
}
.chat-msg.ai .chat-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  max-width: 80%;
}
.chat-msg.ai .chat-body .chat-bubble {
  max-width: 100%;
}
/* Header row: name above line, equal spacing around the line */
.chat-msg.ai .chat-header {
  display: flex;
  flex-direction: column;
  padding-left: 2px;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.chat-msg.ai .chat-sender {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  line-height: 1;
}
.chat-tool-notice {
  font-size: 11px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 0;
  font-style: italic;
}
.chat-input-row {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  padding: 0 6px 0 14px;
  transition: border-color .15s, background .15s;
}
.chat-input-row:focus-within {
  border-color: #bfccf5;
  background: var(--card);
}
.chat-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 11px 0;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  outline: none;
}
.chat-input::placeholder { color: var(--text-3) }
.chat-send-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: none;
  color: var(--text-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color .15s, background .15s;
}
.chat-send-btn:hover { color: var(--blue); background: var(--blue-soft); }
/* Thinking indicator — vertically aligned */
.chat-msg.ai.typing-msg {
  align-items: center;
}

/* Markdown in chat bubbles */
.chat-bubble h1,.chat-bubble h2,.chat-bubble h3 {
  font-weight: 700; margin: 10px 0 4px; line-height: 1.3;
}
.chat-bubble h1 { font-size: 15px }
.chat-bubble h2 { font-size: 14px }
.chat-bubble h3 { font-size: 13px; color: var(--text-2) }
.chat-bubble strong { font-weight: 700 }
.chat-bubble em { font-style: italic }
.chat-bubble ul, .chat-bubble ol { padding-left: 18px; margin: 6px 0 }
.chat-bubble li { margin: 3px 0 }
.chat-bubble p { margin: 6px 0 }
.chat-bubble p:first-child { margin-top: 0 }
.chat-bubble p:last-child { margin-bottom: 0 }
.chat-bubble code { background: var(--border-soft); border-radius: 4px; padding: 1px 5px; font-family: 'DM Mono', monospace; font-size: 11px }
.chat-bubble pre { background: var(--border-soft); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 8px 0 }
.chat-bubble pre code { background: none; padding: 0 }
.chat-bubble hr { border: none; border-top: 1px solid var(--border); margin: 10px 0 }
.chat-bubble a { color: var(--blue); text-decoration: underline }

.chat-typing {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  padding: 4px 2px;
}
.chat-typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-3);
  animation: chatdot 1.2s ease-in-out infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .2s }
.chat-typing span:nth-child(3) { animation-delay: .4s }
@keyframes chatdot { 0%,80%,100% { opacity:.2 } 40% { opacity:1 } }

/* ── HTMX ── */
.htmx-indicator { opacity: 0; transition: opacity 150ms ease }
.htmx-request .htmx-indicator { opacity: 1 }
.htmx-request.htmx-indicator { opacity: 1 }
