:root {
  color: #1d2939;
  background: #f8fafc;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; line-height: 1.5; }
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #17324d;
  color: #fff;
  padding: 1rem 2rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
header .demo-banner {
  flex: 1 0 100%;
  margin: -1rem -2rem 0.25rem;
  width: calc(100% + 4rem);
  border-bottom: 1px solid #e6d59a;
}
header > a { font-size: 1.15rem; font-weight: 700; }
a { color: #175c8c; text-decoration: none; }
header a { color: #fff; }
nav { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
nav a.active { text-decoration: underline; font-weight: 700; }
nav form { margin: 0; }
nav button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.45);
  color: #fff;
  padding: 0.35rem 0.7rem;
  border-radius: 4px;
  font: inherit;
  cursor: pointer;
}
main { max-width: 1100px; margin: 2rem auto; padding: 0 1.25rem; }
h1, h2 { color: #17324d; }
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.cta-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
a.button, .button {
  display: inline-block;
  background: #176b87;
  color: #fff;
  padding: 0.55rem 0.9rem;
  border-radius: 4px;
  font-weight: 650;
  border: 0;
}
a.button.secondary { background: #4a6274; }
form { display: grid; gap: 0.8rem; max-width: 650px; }
form.filters {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  max-width: none;
  align-items: end;
}
label { display: grid; gap: 0.25rem; font-weight: 600; }
input, select, textarea, button {
  font: inherit;
  padding: 0.55rem;
  border: 1px solid #b8c4ce;
  border-radius: 4px;
}
button {
  background: #176b87;
  color: #fff;
  border: 0;
  cursor: pointer;
  font-weight: 650;
}
button:disabled { background: #9aa7b0; cursor: not-allowed; }
button.danger { background: #a31b1b; }

.table-wrap { width: 100%; overflow-x: auto; }
table.data-table {
  border-collapse: collapse;
  width: 100%;
  background: #fff;
  table-layout: fixed;
  border: 1px solid #d9e1e7;
  border-radius: 6px;
  overflow: hidden;
}
table.data-table th,
table.data-table td {
  padding: 0.75rem 0.85rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid #d9e1e7;
  word-break: break-word;
}
table.data-table thead th {
  background: #eef3f6;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: #3d4f5f;
}
table.data-table tbody tr:last-child td { border-bottom: 0; }
table.data-table tbody tr:hover { background: #f0f6fa; }
.col-company { width: 20%; }
.col-suburb { width: 12%; }
.col-status { width: 11%; }
.col-offer { width: 14%; }
.col-contact { width: 24%; }
.col-when { width: 16%; }
.col-type { width: 12%; }
.col-summary { width: 40%; }
.contact-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
}
.contact-stack a { display: inline-block; }
.contact-links { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; }
.summary-cell { font-size: 0.92rem; }
.live-hint { color: #176b87; font-weight: 600; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1rem;
}
.cards article, .card-link article {
  background: #fff;
  border: 1px solid #d9e1e7;
  padding: 1rem;
  border-radius: 6px;
  transition: border-color 0.15s;
}
.card-link { color: inherit; }
.card-link:hover article { border-color: #176b87; }
.cards span { display: block; font-size: 1.8rem; font-weight: 700; }
.badge {
  display: inline-block;
  background: #e8eef2;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.85rem;
}
.badge.status-succeeded { background: #d8f3e0; }
.badge.status-failed { background: #f8d7da; }
.badge.status-running, .badge.status-queued { background: #fff3cd; }
.banner { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1rem; }
.banner.success { background: #d8f3e0; color: #0f5132; }
.banner.error, .error { color: #a31b1b; }
.banner.warn { background: #fff3cd; color: #664d03; }
.empty-state {
  padding: 1.25rem;
  background: #fff;
  border: 1px dashed #b8c4ce;
  border-radius: 6px;
}
.login { display: grid; place-items: center; min-height: 100vh; }
.login main {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid #d9e1e7;
  border-radius: 8px;
  padding: 2rem;
}
code { background: #e8eef2; padding: 0.15rem 0.3rem; }
.hint { color: #5b6b79; font-size: 0.9rem; }
.webhook-box {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #e8eef2;
  max-width: 720px;
}
.webhook-box h2 { margin: 0 0 0.5rem; font-size: 1rem; }
.copy-row {
  display: grid;
  gap: 0.35rem;
  margin: 0.85rem 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: #3d4f5f;
}
.copy-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
}
.copy-controls input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  font-weight: 400;
  color: #1d2939;
  background: #f4f7f9;
}
.copy-controls button {
  white-space: nowrap;
  padding: 0.45rem 0.75rem;
}
.team-section { margin-top: 2rem; max-width: 900px; }
.team-section h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.invite-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: end;
  max-width: 520px;
  margin: 1rem 0;
}
.temp-password-box {
  background: #fff8f3;
  border: 1px solid #e8a06a;
  border-radius: 6px;
  padding: 0.85rem 1rem;
  margin: 0.75rem 0 1rem;
  max-width: 520px;
}
.temp-password-box p { margin: 0 0 0.5rem; }
.team-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.team-actions form { display: inline; max-width: none; margin: 0; }
.ok { color: #1b7a3d; }
.warn { color: #9a6700; }
.demo-banner {
  margin: 0;
  padding: 0.55rem 1rem;
  background: #fff3cd;
  color: #664d03;
  border-bottom: 1px solid #e6d59a;
  font-size: 0.92rem;
  text-align: center;
}
.action-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.draft {
  background: #fff;
  border: 1px solid #d9e1e7;
  padding: 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}
.rich-editor {
  border: 1px solid #d9e1e7;
  border-radius: 8px;
  overflow: visible;
  position: relative;
  background: #fff;
}
.editor-tabs {
  display: flex;
  gap: 0;
  background: #eef3f6;
  border-bottom: 1px solid #d9e1e7;
  border-radius: 8px 8px 0 0;
  overflow: hidden;
}
.editor-tabs .tab {
  background: transparent;
  color: #3d4f5f;
  border: 0;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  padding: 0.55rem 1rem;
  font-weight: 600;
}
.editor-tabs .tab.active {
  background: #fff;
  color: #17324d;
  border-bottom-color: #176b87;
}
.quill-wrap { background: #fff; border-radius: 0 0 8px 8px; overflow: visible; }
.quill-wrap .ql-toolbar.ql-snow {
  border: 0;
  border-bottom: 1px solid #d9e1e7;
}
.quill-wrap .ql-container.ql-snow {
  border: 0;
  overflow: visible !important;
  min-height: 12rem;
  font-size: 1rem;
  position: relative;
}
.quill-wrap .ql-editor {
  min-height: 12rem;
  max-height: 22rem;
  overflow-y: auto;
  padding-bottom: 1rem;
}
/* Hide Quill snow link tooltip — we use prompt-based link edit instead (no clipping). */
.quill-wrap .ql-tooltip {
  display: none !important;
}
.email-preview {
  width: 100%;
  min-height: 220px;
  border: 0;
  border-top: 1px solid #d9e1e7;
  background: #fff;
}
.template-edit .draft-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}
.templates-table .template-subject {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 28rem;
}
.template-edit form { max-width: 720px; }
.prompt-body {
  width: 100%;
  max-width: 720px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.45;
  resize: vertical;
  white-space: pre-wrap;
}
.reset-prompt { margin-top: 1.25rem; }
.sms-preview {
  background: #fff;
  border: 1px solid #d9e1e7;
  border-radius: 6px;
  padding: 0.75rem 1rem;
}
.sms-preview h2 { margin: 0 0 0.5rem; font-size: 1rem; }
.sms-preview-body {
  margin: 0;
  white-space: pre-wrap;
  font-family: system-ui, sans-serif;
  font-size: 0.95rem;
  line-height: 1.4;
}
.timeline { list-style: none; padding: 0; }
.timeline li { padding: 0.75rem 0; border-bottom: 1px solid #e8eef2; }
.danger-zone {
  border: 1px solid #f5c2c7;
  background: #fff5f5;
  padding: 1rem;
  border-radius: 6px;
  margin-top: 2rem;
}
.settings-dl {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  gap: 0.4rem 1rem;
}
.settings-dl dd.ok,
.settings-dl .ok { color: #1b7a3d; }
.settings-dl dd.warn,
.settings-dl .warn { color: #9a6700; }
.nav-with-badge { position: relative; }
.nav-badge {
  display: inline-block;
  min-width: 1.25rem;
  padding: 0.05rem 0.35rem;
  margin-left: 0.25rem;
  border-radius: 999px;
  background: #c45c26;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.2;
  vertical-align: text-top;
}
.badge-unread {
  background: #fde8d8;
  color: #8a3b12;
  font-weight: 700;
}
.card-unread { border-color: #e8a06a; background: #fff8f3; }
/* Must beat `.timeline li { padding: … 0 }` — negative margins + overflow clip text. */
.timeline li.timeline-unread {
  background: #fff8f3;
  margin: 0;
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
  border-left: 3px solid #e8a06a;
}
.read-toggle {
  margin-top: 0.75rem;
  display: inline;
  max-width: none;
}
button.btn-read-toggle {
  background: #fff;
  color: #17324d;
  border: 1px solid #c5d0d8;
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 650;
  border-radius: 4px;
  cursor: pointer;
}
button.btn-read-toggle:hover {
  background: #eef3f6;
  border-color: #176b87;
  color: #176b87;
}
@media (max-width: 600px) {
  header { padding: 1rem; align-items: flex-start; }
  nav { flex-wrap: wrap; }
  main { margin: 1rem auto; }
  table.data-table { font-size: 0.9rem; table-layout: auto; }
  .settings-dl { grid-template-columns: 1fr; }
}

/* —— Lead detail workspace —— */
.lead-workspace {
  max-width: 1180px;
  margin-top: 1.25rem;
}
.crumb {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: #5b6b79;
  margin-bottom: 0.75rem;
}
.crumb a { font-weight: 600; }
.lead-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid #d9e1e7;
  border-radius: 8px;
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}
.lead-title-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}
.lead-title-row h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.2;
}
.lead-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0;
  margin: 0.4rem 0 0.55rem;
  color: #5b6b79;
  font-size: 0.92rem;
}
.lead-meta > span:not(:empty)::after {
  content: "·";
  margin: 0 0.55rem;
  color: #b8c4ce;
}
.lead-meta > span:last-child:not(:empty)::after { content: none; }
.lead-actions form { display: inline; max-width: none; }
.lead-actions button.secondary,
button.secondary {
  background: #4a6274;
}
button.ghost {
  background: transparent;
  color: #a31b1b;
  border: 1px solid #f5c2c7;
}
button.ghost:hover { background: #fff5f5; }

.lead-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 1rem;
  align-items: start;
}
.lead-col {
  display: grid;
  gap: 1rem;
  overflow: visible;
  min-width: 0;
}
.panel {
  background: #fff;
  border: 1px solid #d9e1e7;
  border-radius: 8px;
  padding: 0.9rem 1rem 1rem;
  overflow: visible;
}
.panel-muted { background: #f4f7f9; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.panel-head h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.01em;
}
.panel-save { padding: 0.4rem 0.85rem; font-size: 0.9rem; }

.lead-form {
  display: block;
  max-width: none;
  gap: 0;
}
.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem 0.75rem;
}
.field-grid .span-2 { grid-column: 1 / -1; }
.field-grid label { font-size: 0.85rem; font-weight: 600; color: #3d4f5f; }
.field-grid input,
.field-grid select,
.field-grid textarea {
  padding: 0.45rem 0.55rem;
  font-weight: 400;
  color: #1d2939;
}
.field-grid textarea[name="notes"] {
  min-height: 9rem;
  line-height: 1.45;
  resize: vertical;
  overflow-y: hidden; /* height grows with content; user can still drag-resize */
  box-sizing: border-box;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: start;
  max-width: none;
}
.inline-form textarea { min-height: 2.6rem; }
.consent-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #d9e1e7;
}
.consent-row form { display: inline; max-width: none; }
.consent-unsub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}
.consent-unsub .consent-row {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.draft-create {
  display: grid;
  grid-template-columns: 7.5rem 1fr auto;
  gap: 0.5rem;
  align-items: end;
  max-width: none;
  margin-bottom: 0.85rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid #e8eef2;
}
.draft-create .grow { min-width: 0; }
.draft-create label { font-size: 0.85rem; color: #3d4f5f; }
.empty-inline {
  margin: 0;
  padding: 0.65rem 0;
  color: #5b6b79;
  font-size: 0.92rem;
}

.draft { padding: 0.85rem; margin-bottom: 0.75rem; overflow: visible; }
.draft:last-child { margin-bottom: 0; }
.draft-head h3 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
  color: #17324d;
}
.draft-edit, .draft-send {
  max-width: none;
  gap: 0.55rem;
}
.draft-footer {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.75rem;
  padding: 0.75rem 0 0.35rem;
  border-top: 1px solid #e8eef2;
}
.draft-footer .draft-send {
  margin: 0;
  gap: 0.45rem;
}
.draft-footer .check-label {
  margin: 0 0 0.15rem;
  padding-bottom: 0.15rem;
}
.draft-footer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.draft-footer-actions button {
  width: 100%;
  margin: 0;
}
.follow-up-row {
  display: grid;
  grid-template-columns: 1.4fr 0.7fr 0.7fr;
  gap: 0.4rem;
}
.follow-up-row select { min-width: 0; }
.check-label {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  font-weight: 500;
  font-size: 0.88rem;
  color: #5b6b79;
}
.check-label input { width: auto; margin-top: 0.2rem; }

.timeline { margin: 0; max-height: 28rem; overflow-y: auto; }
.timeline li {
  padding: 0.55rem 0;
  border-bottom: 1px solid #e8eef2;
}
.timeline li:last-child { border-bottom: 0; }
.timeline-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
}
.timeline-meta time { color: #5b6b79; font-weight: 500; }
.timeline-body {
  margin-top: 0.2rem;
  font-size: 0.9rem;
  color: #3d4f5f;
}
.timeline-body-plain { white-space: pre-wrap; }
.timeline-email p { margin: 0 0 0.4rem; }
.timeline-email p:last-child { margin-bottom: 0; }
.timeline-inbound .email-meta {
  font-size: 0.82rem;
  color: #5b6b79;
  margin-bottom: 0.45rem;
  line-height: 1.35;
}
.timeline-inbound .email-reply {
  color: #1f2d3a;
  line-height: 1.45;
  margin-bottom: 0.5rem;
}
.timeline-inbound .email-quote {
  margin-top: 0.35rem;
  margin-bottom: 0.85rem;
  border-left: 3px solid #d5dee6;
  padding-left: 0.65rem;
  padding-bottom: 0.15rem;
}
.timeline-inbound .email-quote summary {
  cursor: pointer;
  color: #5b6b79;
  font-size: 0.82rem;
  font-weight: 600;
  list-style: none;
}
.timeline-inbound .email-quote summary::-webkit-details-marker { display: none; }
.timeline-inbound .email-quote summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 0.12s ease;
}
.timeline-inbound .email-quote[open] summary::before { transform: rotate(90deg); }
.timeline-inbound .email-quote-body {
  margin-top: 0.35rem;
  margin-bottom: 0.25rem;
  font-size: 0.82rem;
  color: #6a7a88;
  line-height: 1.4;
  max-height: 12rem;
  overflow: auto;
}

.badge.status-new { background: #e8eef2; }
.badge.status-queued { background: #fff3cd; }
.badge.status-researched { background: #d6eaf8; }
.badge.status-emailed { background: #d4edda; }
.badge.status-sms_sent { background: #d4edda; }
.badge.status-replied { background: #c3e6cb; }
.badge.status-meeting { background: #b8daff; }
.badge.status-quoted { background: #b8daff; }
.badge.status-won { background: #d8f3e0; }
.badge.status-lost { background: #f8d7da; }
.badge.status-unsubscribed { background: #e2e3e5; }

@media (max-width: 900px) {
  .lead-layout { grid-template-columns: 1fr; }
  .draft-create { grid-template-columns: 1fr 1fr; }
  .draft-create button { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .field-grid { grid-template-columns: 1fr; }
  .field-grid .span-2 { grid-column: auto; }
  .inline-form { grid-template-columns: 1fr; }
  .draft-create { grid-template-columns: 1fr; }
  .draft-footer-actions { grid-template-columns: 1fr; }
}
