:root {
  color-scheme: light dark;
  --bg: #f7f7f8;
  --card-bg: #ffffff;
  --border: #e0e0e3;
  --text: #1c1c1f;
  --muted: #6b6b70;
  --accent: #c05a32;
  --danger: #a3453a;
  --success: #5b7a4a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --card-bg: #1f2024;
    --border: #33343a;
    --text: #f0f0f2;
    --muted: #9a9aa2;
    --accent: #d9782e;
    --success: #7c9a5e;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 2rem;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.brand-logo {
  height: 96px;
  width: auto;
  display: block;
  margin-top: 1rem;
}

header h1 { margin-bottom: 0.25rem; }
.source { color: var(--muted); font-size: 0.9rem; margin-top: 0; }

.header-actions { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.refresh-count-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.refresh-count-input {
  width: 3.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 0.4rem 0.5rem;
  font-family: inherit;
  font-size: 0.9rem;
}

main {
  display: grid;
  gap: 1.5rem;
  max-width: 760px;
  margin: 1.5rem auto 0;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.card-header-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
}

.btn.skip-lead { border-color: var(--danger); color: var(--danger); }
.btn.skip-lead:hover { background: rgba(163,69,58,0.12); }

.card h2 { margin: 0 0 0.25rem; font-size: 1.15rem; }
.btn.copy-title {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  margin-left: 0.5rem;
  vertical-align: middle;
  font-weight: normal;
}
.meta { color: var(--muted); font-size: 0.85rem; margin: 0; }
.meta-extra { margin-top: 0.2rem; font-size: 0.8rem; opacity: 0.8; }

.status-badge {
  text-transform: uppercase;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.status-sent { background: rgba(31,138,76,0.15); color: var(--success); }
.status-skipped { background: rgba(192,57,43,0.15); color: var(--danger); }

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0.9rem 0 0.25rem;
}

.subject-input, .body-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 0.5rem 0.6rem;
  font-family: inherit;
  font-size: 0.9rem;
}

.body-input { resize: vertical; line-height: 1.4; }

.actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
}

.btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  text-decoration: none;
  display: inline-block;
  white-space: nowrap;
}

.btn.send { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.warm-toggle.active { background: rgba(192,57,43,0.15); border-color: var(--danger); color: var(--danger); }
.btn.undeliverable-toggle.active { background: rgba(107,107,112,0.15); border-color: var(--muted); color: var(--muted); }

.result { font-size: 0.8rem; color: var(--muted); min-height: 1.1em; margin: 0.5rem 0 0; }
.sent-note { color: var(--success); font-size: 0.85rem; align-self: center; }

.followups-section {
  max-width: 760px;
  margin: 2.5rem auto 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.followups-section h2 { font-size: 1.2rem; margin-bottom: 0.25rem; }
.section-note { color: var(--muted); font-size: 0.85rem; margin-top: 0; margin-bottom: 1rem; }
.followups-section .card { margin-bottom: 1.5rem; }

.errors {
  max-width: 760px;
  margin: 0 auto 1rem;
  color: var(--danger);
  font-size: 0.9rem;
}

.duplicates {
  max-width: 760px;
  margin: 0 auto 1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  max-width: 760px;
  margin: 0 auto 1.5rem;
}
.tab {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
}
.tab:hover { background: var(--border); }
.tab.active { color: var(--text); background: var(--card-bg); border: 1px solid var(--border); }
.logout-form { margin-left: auto; }
.tab.logout-btn { background: none; border: none; font: inherit; cursor: pointer; }

.card.removing {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.empty-note {
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
  padding: 2rem 0;
}

.history-main { max-width: 1000px; margin: 1.5rem auto 0; }
.history-table-wrap { overflow-x: auto; border-radius: 10px; }
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.history-table th, .history-table td {
  padding: 0.6rem 0.8rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.history-table td:last-child, .history-table th:last-child { white-space: normal; }
.history-table td:last-child .btn { margin: 0.15rem 0.3rem 0.15rem 0; }
.history-table th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; }
.history-table tr:last-child td { border-bottom: none; }
.nowrap { white-space: nowrap; }

/* Marks where one lead's thread ends and the next one's starts, so
   Outreach/Follow-up/Final Follow-up rows for the same home read as a
   group instead of blending into whichever lead sent nearest in time. */
.history-table tr.group-start td { border-top: 2px solid var(--accent); }

/* Keep the select checkbox and the row's action reachable without having
   to scroll a wide table all the way over - they stay pinned to either
   edge of the scroll area while the informational columns scroll under. */
.sticky-col-left, .sticky-col-right {
  position: sticky;
  background: var(--card-bg);
  z-index: 1;
}
.sticky-col-left { left: 0; box-shadow: 2px 0 4px -2px rgba(0,0,0,0.25); }
.sticky-col-right { right: 0; box-shadow: -2px 0 4px -2px rgba(0,0,0,0.25); }
.history-table th.sticky-col-left, .history-table th.sticky-col-right { background: var(--bg); }

.bulk-toolbar {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.7rem;
}
.bulk-toolbar .selected-count { color: var(--muted); font-size: 0.85rem; }
.btn.delete-selected-btn { border-color: var(--danger); color: var(--danger); }
.btn.delete-selected-btn:disabled { opacity: 0.4; }

.kind-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
}
.kind-outreach { background: rgba(47,111,235,0.15); color: var(--accent); }
.kind-followup { background: rgba(31,138,76,0.15); color: var(--success); }
.kind-finalfollowup { background: rgba(192,57,43,0.12); color: var(--danger); }

/* Proposal builder */
.builder-main { max-width: 900px; margin: 1.5rem auto 3rem; }
.back-link { color: var(--muted); font-size: 0.85rem; text-decoration: none; }
.back-link:hover { text-decoration: underline; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.9rem;
}
.field-grid label { margin-top: 0; }
.field { min-width: 0; }
.field input, .field textarea, .field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 0.5rem 0.6rem;
  font-family: inherit;
  font-size: 0.9rem;
}
.field textarea { resize: vertical; }
.reference-note { color: var(--muted); font-size: 0.85rem; }

.f-ai-summary {
  display: block;
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 0.5rem 0.6rem;
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
  overflow: hidden;
}

.section-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0.9rem 0;
}
.toggle-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.toggle-chip input { margin: 0; }

.optional-section {
  border-top: 1px solid var(--border);
  margin-top: 1.2rem;
  padding-top: 1rem;
}
.optional-section[hidden] { display: none; }
.optional-section h3 { margin: 0 0 0.6rem; font-size: 1rem; }

.comps-table-wrap { overflow-x: auto; margin-top: 0.5rem; }
.comps-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.comps-table th, .comps-table td { padding: 0.35rem; border-bottom: 1px solid var(--border); }
.comps-table th { color: var(--muted); font-weight: 600; text-align: left; font-size: 0.72rem; text-transform: uppercase; }
.comps-table input {
  width: 100%;
  min-width: 70px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  padding: 0.3rem 0.4rem;
  font-size: 0.82rem;
}
.comps-summary { color: var(--muted); font-size: 0.85rem; margin-top: 0.5rem; }

.next-steps-row { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; align-items: flex-start; }
.next-steps-row input { flex: 1; }

.photo-preview {
  max-width: 220px;
  border-radius: 8px;
  display: block;
  margin-top: 0.5rem;
  border: 1px solid var(--border);
}

.proposal-preview-frame {
  width: 100%;
  height: 1400px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-top: 1rem;
}

.builder-actions { display: flex; gap: 0.6rem; margin-top: 1.2rem; flex-wrap: wrap; }
