:root {
  /* Light theme — default */
  --bg: #f7f5f1;
  --panel: #ffffff;
  --panel-2: #f0ece5;
  --line: #d9d3c7;
  --text: #1a1815;
  --muted: #6b665d;
  --dim: #9a948a;
  --gold: #a07f1a;
  --gold-soft: rgba(160, 127, 26, 0.12);
  --warm: #8a8275;
  --cool: #6b7480;
  --green: #5a7d4e;
  --blue: #4a6885;
  --red: #a04d44;
  --input-bg: #ffffff;
  --row-hover: #efeae0;
  --conv-bg: #f0ece5;
  --bubble-bg: #ffffff;
  --composer-bg: #efeae0;
  --btn-disabled: #e6e0d3;
  --tag-bg: #efeae0;
  --on-gold: #ffffff;
  --gold-line: rgba(160, 127, 26, 0.45);
  --gold-line-soft: rgba(160, 127, 26, 0.30);
  --blue-bubble-bg: rgba(74, 104, 133, 0.10);
  --blue-bubble-line: rgba(74, 104, 133, 0.30);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --bg: #0d0d0d;
  --panel: #141413;
  --panel-2: #1a1917;
  --line: #2a2926;
  --text: #e8e6e3;
  --muted: #928d84;
  --dim: #5f5b53;
  --gold: #d4af37;
  --gold-soft: rgba(212, 175, 55, 0.16);
  --warm: #a99f90;
  --cool: #7f8890;
  --green: #87a878;
  --blue: #7b9bb7;
  --red: #b76e65;
  --input-bg: #10100f;
  --row-hover: #151411;
  --conv-bg: #111110;
  --bubble-bg: #1b1a18;
  --composer-bg: #0d0d0d;
  --btn-disabled: #171614;
  --tag-bg: #191815;
  --on-gold: #0d0d0d;
  --gold-line: rgba(212, 175, 55, 0.55);
  --gold-line-soft: rgba(212, 175, 55, 0.28);
  --blue-bubble-bg: rgba(123, 155, 183, 0.14);
  --blue-bubble-line: rgba(123, 155, 183, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-width: 0;
}

.inbox {
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-height: 0;
}

.brand,
.topline,
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.brand {
  padding: 28px 26px 24px;
}

.eyebrow {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  margin: 0 0 8px;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4 {
  font-family: var(--mono);
  font-weight: 500;
  line-height: 1.1;
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 18px;
}

h4 {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 12px;
  text-transform: uppercase;
}

.live-dot {
  background: var(--gold);
  border-radius: 999px;
  box-shadow: 0 0 24px rgba(212, 175, 55, 0.45);
  height: 9px;
  margin-top: 5px;
  width: 9px;
}

.filters {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 18px 18px 16px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 10px;
}

.filter-row.tight {
  margin-bottom: 8px;
}

.chip,
.btn,
.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
}

.chip {
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 9px;
  text-transform: uppercase;
}

.chip.active,
.chip:hover,
.btn:hover,
.icon-btn:hover {
  border-color: var(--gold-line);
  color: var(--text);
}

.search {
  display: grid;
  gap: 7px;
  margin-top: 14px;
}

.search span,
.modal label span {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
}

.search input,
.modal select,
.modal textarea {
  background: var(--input-bg);
  border: 1px solid var(--line);
  color: var(--text);
  outline: 0;
  padding: 11px 12px;
  width: 100%;
}

.search input:focus,
.modal select:focus,
.modal textarea:focus {
  border-color: var(--gold);
}

.lead-list {
  min-height: 0;
  overflow: auto;
  padding: 10px;
}

.lead-row {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  cursor: pointer;
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 10px;
  padding: 13px 10px;
  text-align: left;
  width: 100%;
}

.lead-row:hover,
.lead-row.active {
  background: var(--row-hover);
  border-color: var(--line);
}

.lead-row.active {
  border-left-color: var(--gold);
}

.lead-main {
  display: grid;
  gap: 3px;
}

.lead-main strong {
  font-size: 14px;
  font-weight: 500;
}

.lead-main small,
.identity span,
.composer small {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.lead-meta {
  align-items: flex-end;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tier-dot {
  border-radius: 999px;
  height: 8px;
  width: 8px;
}

.tier-A {
  background: var(--gold);
}

.tier-B {
  background: var(--warm);
}

.tier-C {
  background: var(--cool);
}

.large-tier {
  align-items: center;
  border-radius: 999px;
  color: var(--on-gold);
  display: inline-flex;
  font-family: var(--mono);
  height: 42px;
  justify-content: center;
  width: 42px;
}

.source,
.status,
.geo,
.mini,
.ping,
.owner,
.thread-state {
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  padding: 4px 7px;
  text-transform: uppercase;
  white-space: nowrap;
}

.source-form_plus_wa,
.source-wa_inbound {
  color: var(--gold);
}

.status.handoff_pending,
.status.booked_showroom {
  border-color: rgba(212, 175, 55, 0.45);
  color: var(--gold);
}

.status.with_human,
.status.qualified {
  color: var(--green);
}

.status.lost {
  color: var(--red);
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.topline {
  border-bottom: 1px solid var(--line);
  padding: 28px 30px 22px;
}

.top-metrics {
  display: flex;
  gap: 10px;
}

.top-metrics span {
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  padding: 9px 11px;
}

.top-metrics b {
  color: var(--text);
  font-weight: 500;
}

.dashboard-strip {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 14px 30px;
  background: var(--surface, transparent);
}

.dash-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.dash-tile {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  padding: 8px 12px;
  min-width: 110px;
}

.dash-tile .dash-label {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.dash-tile b {
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  margin-top: 2px;
}

.dash-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.dash-actions .btn[data-state="loading"] {
  opacity: 0.6;
  cursor: progress;
}

.tier-explain {
  border: 1px dashed var(--line);
  padding: 8px 11px;
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.tier-explain b {
  color: var(--text);
}

.detail-grid {
  display: grid;
  gap: 1px;
  grid-template-columns: minmax(240px, 300px) minmax(360px, 1fr) minmax(280px, 340px);
  min-height: 0;
  min-width: 0;
}

.panel {
  background: var(--panel);
  min-height: 0;
  overflow: auto;
  padding: 24px;
}

.conversation {
  background: var(--conv-bg);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  padding-bottom: 0;
}

.identity {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 7px;
  margin: 20px 0;
  padding-bottom: 18px;
}

.section {
  border-bottom: 1px solid var(--line);
  padding: 18px 0;
}

.section:last-child {
  border-bottom: 0;
}

.kv {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(96px, 0.75fr) 1fr;
  margin-bottom: 11px;
}

.kv span {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 11px;
}

.kv strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 400;
  overflow-wrap: anywhere;
}

.status-block {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  padding: 24px 4px 24px;
}

.bubble-wrap {
  max-width: 76%;
}

.bubble-wrap.user {
  align-self: flex-end;
}

.bubble-wrap.bot,
.bubble-wrap.jeff,
.bubble-wrap.yayo {
  align-self: flex-start;
}

.sender {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 10px;
  margin: 0 0 5px 2px;
  text-transform: uppercase;
}

.sender span {
  color: var(--muted);
  margin-left: 7px;
}

.bubble {
  background: var(--bubble-bg);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  padding: 12px 14px;
  white-space: pre-wrap;
}

.user .bubble {
  background: var(--gold-soft);
  border-color: var(--gold-line-soft);
}

.jeff .bubble,
.yayo .bubble {
  background: var(--blue-bubble-bg);
  border-color: var(--blue-bubble-line);
}

.composer {
  align-items: center;
  background: var(--composer-bg);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  margin: 0 -24px;
  padding: 15px 24px;
}

.composer span {
  color: var(--text);
  display: block;
  font-family: var(--mono);
  font-size: 13px;
  margin-bottom: 3px;
}

.composer button:disabled {
  background: var(--btn-disabled);
  border: 1px solid var(--line);
  color: var(--dim);
  padding: 9px 14px;
}

.extracted .kv strong:empty,
.kv strong {
  min-width: 0;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 18px 0;
}

.tags span {
  background: var(--tag-bg);
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 8px;
}

.round-robin {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  margin: 0 0 16px;
}

.round-robin b {
  color: var(--gold);
  font-weight: 500;
}

.button-grid {
  display: grid;
  gap: 9px;
  grid-template-columns: 1fr 1fr;
}

.btn {
  min-height: 38px;
  padding: 9px 11px;
}

.btn.primary {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--on-gold);
  grid-column: 1 / -1;
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  color: var(--red);
}

.ping.sent {
  color: var(--green);
}

.ping.pending {
  color: var(--gold);
}

.empty {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  padding: 28px 12px;
}

.thread-empty {
  align-self: center;
  border: 1px solid var(--line);
  margin-top: 80px;
}

.modal-backdrop {
  align-items: center;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  inset: 0;
  justify-content: center;
  position: fixed;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.4);
  width: 480px;
}

.modal .panel-head,
.modal-body,
.modal-actions {
  padding: 20px;
}

.modal .panel-head,
.modal-actions {
  border-bottom: 1px solid var(--line);
}

.modal-actions {
  border-bottom: 0;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal-body {
  display: grid;
  gap: 16px;
}

.modal label {
  display: grid;
  gap: 8px;
}

.modal textarea {
  line-height: 1.4;
  resize: vertical;
}

.toggle {
  align-items: center;
  display: flex !important;
  gap: 10px !important;
  grid-template-columns: auto 1fr;
}

.toggle input {
  accent-color: var(--gold);
  width: auto;
}

.icon-btn {
  height: 30px;
  width: 30px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.drawer-toggle {
  display: none;
  flex: 0 0 auto;
}

.drawer-backdrop {
  display: none;
}

.brand-actions {
  align-items: center;
  display: flex;
  gap: 12px;
}

.theme-toggle {
  align-items: center;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  font-family: var(--mono);
  font-size: 10px;
  gap: 6px;
  letter-spacing: 0.04em;
  padding: 5px 9px;
  text-transform: uppercase;
}

.theme-toggle:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.theme-toggle-icon {
  font-size: 12px;
  line-height: 1;
}

/* ─── v0.2 Round A additions ─────────────────────────────────────────────── */

.link-pill {
  align-items: center;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  display: inline-flex;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  padding: 5px 9px;
  text-decoration: none;
  text-transform: uppercase;
}
.link-pill:hover { border-color: var(--gold); color: var(--gold); }

.view-toggle {
  display: inline-flex;
  gap: 6px;
}
.view-toggle .chip {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  text-transform: uppercase;
}
.view-toggle .chip.active {
  background: var(--gold-soft);
  border-color: var(--gold);
  color: var(--gold);
}

/* Stale indicator */
.stale-dot {
  background: var(--red);
  border-radius: 50%;
  display: inline-block;
  height: 8px;
  margin-left: 6px;
  vertical-align: middle;
  width: 8px;
}
.lead-row.stale .lead-main strong::after {
  content: " •";
  color: var(--red);
  font-weight: 700;
}

/* Tier dots */
.tier-dot { display:inline-block; width:10px; height:10px; border-radius:50%; }
.tier-A { background: var(--red); }
.tier-B { background: var(--gold); }
.tier-C { background: var(--cool); }
.tier-badge {
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  cursor: pointer;
  display: inline-flex;
  font-family: var(--mono);
  font-size: 10px;
  gap: 6px;
  padding: 3px 8px;
  text-transform: uppercase;
}
.tier-badge.locked { border-color: var(--gold); color: var(--gold); }

/* Side stack for actions/notes/activity */
.side-stack {
  display: grid;
  gap: 18px;
  grid-template-rows: auto auto auto;
  overflow-y: auto;
}
.panel-inner {
  background: var(--panel);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px;
}
.panel-inner h4 {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  margin: 0 0 10px;
  text-transform: uppercase;
  color: var(--muted);
}
.panel-inner .panel-head {
  margin-bottom: 12px;
  padding: 0;
}

/* Collapsible */
.collapsible-toggle {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  padding: 0;
  text-transform: uppercase;
}
.collapsible-body[hidden] { display: none; }

.ai-context {
  gap: 12px;
}
.ai-context-status {
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.35;
  padding: 9px 10px;
}
.ai-context-status.ok { color: var(--text); border-left-color: var(--gold); }
.ai-context-status.warn { color: var(--muted); border-left-color: #d6a85a; }
.ai-context-grid {
  display: grid;
  gap: 14px;
  margin-top: 12px;
}
.ai-context-grid section {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.ai-context-grid strong {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
  text-transform: uppercase;
}
.ai-context-item {
  display: grid;
  gap: 3px;
  padding: 6px 0;
}
.ai-context-item span { font-size: 12px; }
.ai-context-item small,
.empty-mini {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  margin: 0;
}
.console-link {
  color: var(--gold);
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  margin-top: 8px;
  text-decoration: none;
}

/* Notes panel */
.notes textarea {
  background: var(--input-bg);
  border: 1px solid var(--line);
  color: var(--text);
  min-height: 80px;
  padding: 10px;
  resize: vertical;
  width: 100%;
}
.notes-meta {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 10px;
  margin-top: 6px;
}
.notes-save {
  align-self: flex-end;
  margin-top: 8px;
}

/* Activity log */
.activity-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
}
.activity-entry {
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.45;
  padding: 8px 0;
}
.activity-entry:last-child { border-bottom: 0; }
.activity-entry .actor {
  color: var(--gold);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
}
.activity-entry .at {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 10px;
  margin-left: 8px;
}

/* Template picker */
.composer { display: grid; gap: 8px; }
.composer-meta { display: flex; flex-direction: column; gap: 2px; }
.composer-templates { display: flex; gap: 8px; }
.template-picker {
  display: inline-grid;
  gap: 4px;
  flex: 1;
}
.template-picker select {
  background: var(--input-bg);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 6px 8px;
}
.template-picker span {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Kanban */
.kanban-view {
  overflow-x: auto;
  padding: 18px;
}
.kanban-board {
  display: grid;
  gap: 12px;
  grid-auto-columns: 260px;
  grid-auto-flow: column;
  min-width: 100%;
}
.kanban-col {
  background: var(--panel);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 160px);
}
.kanban-col[data-drag-over="true"] {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px var(--gold-line-soft);
}
.kanban-col-head {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
}
.kanban-col-head h4 {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  margin: 0;
  text-transform: uppercase;
}
.kanban-col-head .count {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}
.kanban-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding: 10px 12px;
}
.kanban-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  cursor: grab;
  display: grid;
  font-size: 12px;
  gap: 4px;
  padding: 10px;
}
.kanban-card:active { cursor: grabbing; }
.kanban-card[data-dragging="true"] { opacity: 0.4; }
.kanban-card.stale { border-left: 3px solid var(--red); }
.kanban-card .row1 {
  align-items: center;
  display: flex;
  gap: 6px;
  justify-content: space-between;
}
.kanban-card .name { font-weight: 600; }
.kanban-card .phone { color: var(--dim); font-family: var(--mono); font-size: 11px; }
.kanban-card .meta {
  color: var(--muted);
  display: flex;
  font-size: 11px;
  gap: 8px;
  justify-content: space-between;
}
.kanban-card .owner {
  align-items: center;
  background: var(--gold-soft);
  border-radius: 50%;
  color: var(--gold);
  display: inline-flex;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  height: 22px;
  justify-content: center;
  text-transform: uppercase;
  width: 22px;
}

/* RR hint */
#rrHint { color: var(--gold); font-family: var(--mono); font-size: 10px; }
.rr-suggested {
  background: var(--gold-soft) !important;
  border-color: var(--gold) !important;
  color: var(--gold) !important;
}

/* ─── Round B: Hermes badge + Send greeting result ──────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  line-height: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge.hermes {
  background: rgba(120, 90, 200, 0.12);
  color: #6e4fc0;
  border: 1px solid rgba(120, 90, 200, 0.25);
}
.send-greeting-result {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted, #777);
  min-height: 14px;
}
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ─── Round B+: composer textarea, composed preview, Jeffery panel ─────── */

/* Manual reply textarea — used by operator to send WA messages. Auto-grows
   on input via JS handler; CSS just enforces the bounds. */
#composerInput {
  background: var(--input-bg);
  border: 1px solid var(--line);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.45;
  padding: 10px 12px;
  width: 100%;
  min-height: 120px;
  max-height: 50vh;
  overflow-y: auto;
  resize: vertical;
  box-sizing: border-box;
}
#composerInput:disabled { opacity: 0.5; }
.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}
.composer-hint {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

/* Composed greeting preview — sits at the top of the actions panel. */
.composed-greeting-panel {
  border: 1px solid var(--line);
  background: var(--panel-2, var(--panel));
  padding: 10px 12px;
  margin-bottom: 14px;
  display: grid;
  gap: 8px;
}
.composed-greeting-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: var(--mono);
  color: var(--muted);
}
.composed-version {
  color: var(--dim);
  font-size: 10px;
}
.composed-preview {
  display: grid;
  gap: 6px;
  background: var(--bubble-bg);
  padding: 10px;
  border: 1px dashed var(--line);
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  max-height: 280px;
  overflow-y: auto;
}
.composed-bubble {
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.composed-sep {
  text-align: center;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 10px;
}
.composed-preview-loading,
.composed-preview-error {
  color: var(--muted);
  font-style: italic;
  font-size: 12px;
}
.composed-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Outbound colour coding by sent_via — distinguish CRM vs Hermes vs inbound. */
.bubble-wrap.via-hermes_jeffery .bubble {
  border-left: 3px solid #6e4fc0;
}
.bubble-wrap.via-crm_bot_manual .bubble {
  border-left: 3px solid var(--gold, #c89c4e);
}
.bubble-wrap.via-inbound .bubble {
  /* neutral — inherit defaults */
}

/* "How Jeffery replied" panel — collapsible, distinct accent. */
.jeffery-panel { margin: 8px 0; }
.jeffery-panel[hidden] { display: none; }
.jeffery-details {
  border: 1px solid var(--line);
  border-left: 3px solid #6e4fc0;
  background: var(--panel-2, var(--panel));
  padding: 6px 10px;
}
.jeffery-details > summary {
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 4px 0;
}
.jeffery-count {
  background: rgba(120, 90, 200, 0.18);
  color: #6e4fc0;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  margin-left: 6px;
}
.jeffery-list { display: grid; gap: 8px; margin-top: 8px; }
.jeffery-entry {
  border: 1px solid var(--line);
  background: var(--bubble-bg);
  padding: 8px 10px;
  border-left: 2px solid #6e4fc0;
}
.jeffery-meta {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-family: var(--mono);
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
}
.jeffery-chip {
  background: rgba(120, 90, 200, 0.12);
  color: #6e4fc0;
  padding: 1px 5px;
  border-radius: 3px;
}
.jeffery-body {
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
}

/* ─── 2026-05-18: VelaOps unified thread + greet rollout ───────────────────── */

/* Badge palette (client-side computed lead status). */
.badge.not-contacted {
  background: rgba(120, 120, 120, 0.10);
  color: var(--muted);
  border: 1px solid rgba(120, 120, 120, 0.25);
}
.badge.drafted {
  background: rgba(220, 200, 80, 0.16);
  color: #b9962a;
  border: 1px solid rgba(220, 200, 80, 0.45);
}
.badge.greeted {
  background: rgba(200, 156, 78, 0.18);
  color: var(--gold, #c89c4e);
  border: 1px solid var(--gold, #c89c4e);
}
.badge.jeffery-replied {
  background: rgba(120, 90, 200, 0.15);
  color: #6e4fc0;
  border: 1px solid rgba(120, 90, 200, 0.4);
}
.badge.in-hermes {
  background: rgba(120, 90, 200, 0.12);
  color: #6e4fc0;
  border: 1px solid rgba(120, 90, 200, 0.25);
}

/* Yellow draft card — only shows when lead.draft_greeting is truthy. */
.draft-card {
  border: 1px solid rgba(220, 200, 80, 0.55);
  background: rgba(255, 245, 200, 0.20);
  padding: 12px;
  margin: 0 0 12px;
  display: grid;
  gap: 10px;
}
.draft-card-head { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: #b9962a; }
.draft-body {
  background: var(--bg);
  border: 1px dashed rgba(220, 200, 80, 0.55);
  padding: 10px;
  margin: 0;
  font: inherit;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  max-height: 260px;
  overflow-y: auto;
}
.draft-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Single "Send greeting" row above composer / action grid. */
.send-greeting-row { margin: 0 0 10px; }
.send-greeting-row .btn { width: 100%; }

/* Thread source banner — tells operator whether VelaOps is wired. */
.thread-source-note {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 10px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
}
.thread-source-note.warn {
  border-color: rgba(220, 200, 80, 0.55);
  color: #b9962a;
  background: rgba(255, 245, 200, 0.15);
}
.thread-source-note.ok {
  color: var(--muted);
  background: var(--panel-2, var(--panel));
}

/* Sender chip — replaces the old plaintext sender label in unified thread. */
.sender-chip {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  border-radius: 3px;
  margin-right: 6px;
}
.sender-chip.chip-customer { background: rgba(120,120,120,0.12); color: var(--muted); }
.sender-chip.chip-human    { background: rgba(120, 90, 200, 0.18); color: #6e4fc0; }
.sender-chip.chip-ai       { background: rgba(200, 156, 78, 0.18); color: var(--gold, #c89c4e); }
.sender-chip.chip-ai-draft { background: rgba(220, 220, 220, 0.20); color: var(--muted); font-style: italic; }
.sender-chip.chip-system   { background: transparent; color: var(--dim); }

/* Hermes thread bubble accents per senderType. */
.bubble-wrap.hermes-msg .bubble { padding: 8px 10px; }
.bubble-wrap.hermes-customer .bubble {
  background: var(--bubble-bg, var(--panel-2, var(--panel)));
  border: 1px solid var(--line);
}
.bubble-wrap.hermes-human .bubble {
  background: rgba(120, 90, 200, 0.06);
  border: 1px solid rgba(120, 90, 200, 0.25);
  border-left: 4px solid #6e4fc0;
}
.bubble-wrap.hermes-ai .bubble {
  background: rgba(200, 156, 78, 0.06);
  border: 1px solid rgba(200, 156, 78, 0.30);
  border-left: 4px solid var(--gold, #c89c4e);
}
.bubble-wrap.hermes-ai_draft .bubble {
  background: transparent;
  border: 1px dashed var(--line);
  font-style: italic;
  color: var(--muted);
}
.bubble-wrap.hermes-system {
  text-align: center;
  margin: 6px 0;
}
.bubble-wrap.hermes-system .bubble {
  display: inline-block;
  background: transparent;
  border: 0;
  color: var(--dim);
  font-size: 11px;
}

.delivery { font-family: var(--mono); font-size: 10px; margin-left: 6px; color: var(--dim); }
.delivery.ok { color: var(--gold, #c89c4e); }
.delivery.fail { color: #d05050; }

/* Toast stack (lower-right, stacking). */
.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: grid;
  gap: 8px;
  z-index: 9999;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.3);
  transition: opacity 0.3s, transform 0.3s;
  max-width: 360px;
}
.toast-ok    { border-color: var(--gold, #c89c4e); }
.toast-warn  { border-color: rgba(220, 200, 80, 0.55); color: #b9962a; }
.toast-error { border-color: #d05050; color: #d05050; }
.toast-out   { opacity: 0; transform: translateY(8px); }

/* iPad / tablet — use an off-canvas lead drawer so the detail CRM gets the full screen. */
@media (max-width: 1100px) {
  body {
    overflow: hidden;
  }
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .workspace {
    min-width: 0;
  }
  .drawer-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .inbox {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(390px, 86vw);
    max-width: 390px;
    z-index: 80;
    background: var(--panel);
    border-right: 1px solid var(--line);
    box-shadow: 20px 0 60px rgba(0, 0, 0, 0.22);
    transform: translateX(-102%);
    transition: transform 180ms ease;
  }
  body.lead-drawer-open .inbox {
    transform: translateX(0);
  }
  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 70;
    border: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.36);
  }
  .drawer-backdrop[hidden] {
    display: none;
  }
  .brand { padding: 20px 18px 18px; }
  .filters { padding: 14px 12px; }
  .lead-row { padding: 13px 12px; }
  .topline {
    padding: calc(18px + env(safe-area-inset-top, 0px)) 22px 16px;
    gap: 12px;
  }
  .dashboard-strip {
    padding: 12px 22px;
  }
  .detail-grid {
    grid-template-columns: minmax(220px, 260px) minmax(340px, 1fr) minmax(240px, 280px);
  }
  .panel { padding: 18px; }
  .composer {
    margin: 0 -18px;
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .bubble-wrap { max-width: 86%; }
}

/* Mobile / portrait tablets — stack the lead detail columns; lead list remains drawer. */
@media (max-width: 820px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 1fr;
  }
  .inbox { border-bottom: 0; }
  .detail-grid { grid-template-columns: 1fr; }
  .conversation { min-height: 55vh; }
  .dash-row, .topline, .status-block { align-items: flex-start; flex-direction: column; }
  .dash-actions { flex-wrap: wrap; }
}

/* Mobile — keep the composer / preview comfortable instead of collapsing. */
@media (max-width: 720px) {
  #composerInput { min-height: 120px; max-height: 60vh; }
  .composed-preview { max-height: 220px; }
  .composed-actions { flex-direction: column; }
  .composed-actions .btn { width: 100%; }
}

/* Send-greeting / draft / reply confirmation modal — stacked bubble preview. */
.modal-header-line {
  margin: 0 0 12px 0;
  font-size: 13px;
  color: var(--muted, #888);
  line-height: 1.4;
}
.modal-bubble-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
}
.modal-bubble {
  background: var(--bubble-bg, #f4f4f5);
  border: 1px solid var(--border, #e4e4e7);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.modal-bubble.empty { color: var(--muted, #888); font-style: italic; }

/* Phase E — Compose reply panel (replaces Send greeting when conv exists). */
.compose-reply-row {
  margin: 12px 0;
  padding: 12px;
  border: 1px dashed var(--border, #e4e4e7);
  border-radius: 10px;
  background: var(--bg-soft, rgba(0,0,0,0.02));
}
.compose-reply-row .panel-head { margin: 0 0 6px 0; }
.compose-reply-row .hint {
  font-size: 12px;
  color: var(--muted, #888);
  margin: 0 0 10px 0;
  line-height: 1.4;
}

/* S0 — Build SHA footer pill */
.build-pill {
  position: fixed;
  right: 10px;
  bottom: 8px;
  z-index: 50;
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted, #888);
  background: rgba(0,0,0,0.04);
  border: 1px solid var(--line, rgba(0,0,0,0.08));
  border-radius: 999px;
  padding: 3px 9px;
  pointer-events: auto;
  user-select: text;
  opacity: 0.75;
}
.build-pill:hover { opacity: 1; }
[data-theme="dark"] .build-pill { background: rgba(255,255,255,0.04); }

/* S1.A — Inbound media inside thread bubbles */
.thread-media {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}
.thread-media:first-child { margin-top: 0; }
.thread-media-img {
  display: block;
  max-width: 320px;
  max-height: 320px;
  width: auto;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
  cursor: zoom-in;
  background: rgba(0,0,0,0.03);
  object-fit: cover;
}
.thread-media-audio {
  width: 100%;
  max-width: 320px;
  display: block;
}
.thread-media-video {
  display: block;
  max-width: 320px;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.thread-media-meta {
  font-size: 11px;
  color: var(--muted);
}
.thread-media-doc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  background: rgba(0,0,0,0.03);
  max-width: 320px;
}
[data-theme="dark"] .thread-media-doc { background: rgba(255,255,255,0.04); }
.thread-media-doc:hover { background: rgba(0,0,0,0.06); }
.thread-media-error {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  background: rgba(0,0,0,0.02);
}

/* Lightbox for click-to-enlarge */
.media-lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
}
.media-lightbox[hidden] { display: none; }
.media-lightbox-img {
  max-width: 95vw;
  max-height: 92vh;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.media-lightbox-close {
  position: absolute;
  top: 12px;
  right: 18px;
  font-size: 28px;
  line-height: 1;
  color: #fff;
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 4px 10px;
}

/* S1.C — Optimistic / pending send bubble */
.bubble-wrap.pending .bubble {
  background: rgba(0,0,0,0.04);
  border-style: dashed;
  color: var(--muted);
  font-style: italic;
}
[data-theme="dark"] .bubble-wrap.pending .bubble {
  background: rgba(255,255,255,0.04);
}
.bubble-wrap.pending .pending-spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: pending-spin 0.9s linear infinite;
  vertical-align: -1px;
}
.bubble-wrap.pending.failed .bubble {
  border-color: #c0392b;
  color: #c0392b;
  background: rgba(192, 57, 43, 0.06);
  font-style: normal;
}
@keyframes pending-spin {
  to { transform: rotate(360deg); }
}

/* S2 — Composer media upload */
.composer-input-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
}
.composer-input-row textarea {
  flex: 1;
  min-width: 0;
}
.composer-attach-btn {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--composer-bg, transparent);
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
}
.composer-attach-btn:hover { color: var(--text); border-color: var(--text); }
.composer-attach-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.composer-drop-overlay {
  position: absolute;
  inset: 0;
  border: 2px dashed var(--gold-line-soft, #c89b3c);
  border-radius: 8px;
  background: rgba(200, 155, 60, 0.08);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
}

.composer-attachments {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 8px;
  padding: 6px 2px 8px;
  margin-bottom: 4px;
}
.attach-tile {
  position: relative;
  flex: 0 0 auto;
  width: 88px;
  height: 88px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0,0,0,0.03);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
}
[data-theme="dark"] .attach-tile { background: rgba(255,255,255,0.04); }
.attach-tile img.attach-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.attach-tile .attach-icon {
  font-size: 28px;
  line-height: 1;
}
.attach-tile .attach-meta {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 10px;
  padding: 2px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-tile .attach-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 0;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.attach-tile .attach-progress {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
}
.attach-tile.uploaded .attach-progress { display: none; }
.attach-tile.failed { border-color: #c0392b; }
.attach-tile.failed .attach-progress {
  background: rgba(192, 57, 43, 0.78);
  flex-direction: column;
  gap: 3px;
}
.attach-tile .attach-retry {
  border: 1px solid #fff;
  background: transparent;
  color: #fff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  cursor: pointer;
}

/* S1.D — Toast action buttons */
.toast-actions {
  display: inline-flex;
  gap: 6px;
  margin-left: 10px;
}
.toast-actions button {
  font: inherit;
  font-size: 11px;
  background: rgba(255,255,255,0.18);
  color: inherit;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
}
.toast-actions button:hover { background: rgba(255,255,255,0.28); }

/* Login screen */
.login-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 10%, rgba(212,175,55,.20), transparent 34rem),
    linear-gradient(135deg, #fffaf0 0%, #f3eadb 46%, #e8ddc9 100%);
  color: #241b13;
}
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(440px, 100%);
  border: 1px solid rgba(36,27,19,.12);
  border-radius: 28px;
  background: rgba(255,250,240,.82);
  box-shadow: 0 24px 80px rgba(36,27,19,.14);
  padding: 34px;
}
.login-card h1 { margin: 6px 0 8px; font-size: clamp(36px, 8vw, 58px); letter-spacing: -.06em; }
.login-copy { margin: 0 0 24px; color: rgba(36,27,19,.64); line-height: 1.5; }
.login-form { display: grid; gap: 16px; }
.login-form label { display: grid; gap: 8px; font-weight: 700; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; }
.login-form input {
  width: 100%;
  border: 1px solid rgba(36,27,19,.16);
  border-radius: 16px;
  background: rgba(255,255,255,.72);
  color: #241b13;
  font: inherit;
  padding: 14px 15px;
  outline: none;
}
.login-form input:focus { border-color: #b78b2e; box-shadow: 0 0 0 4px rgba(212,175,55,.18); }
.login-form .btn { width: 100%; justify-content: center; min-height: 48px; }
.login-form .btn:disabled { opacity: .6; cursor: wait; }
.login-error { margin: 0; color: #a43422; font-weight: 700; font-size: 13px; }
