* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: #f5f6f8;
  color: #1f2430;
}

a {
  color: #2563eb;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px;
}

.back-link {
  display: inline-block;
  margin-bottom: 16px;
  color: #4b5563;
}

.topnav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1f2937;
  color: #fff;
  padding: 12px 24px;
}

.topnav-brand a {
  color: #fff;
  font-weight: bold;
  font-size: 1.1rem;
}

.topnav-links {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topnav-links a {
  color: #d1d5db;
}

.logout-form {
  margin: 0;
}

.logout-form button {
  background: none;
  border: 1px solid #6b7280;
  color: #d1d5db;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
}

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: #1f2937;
}

.login-card {
  background: #fff;
  padding: 32px;
  border-radius: 8px;
  width: 320px;
}

.login-card h1 {
  font-size: 1.2rem;
  margin-top: 0;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.btn, button, .btn-secondary {
  display: inline-block;
  background: #2563eb;
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
}

.btn:hover, button:hover {
  background: #1d4ed8;
  text-decoration: none;
}

.btn-secondary {
  background: #6b7280;
}

.btn-primary {
  background: #2563eb;
}

.btn.btn-opened, .btn.btn-opened:hover {
  background: #e5e7eb;
  color: #374151;
}

.btn-highlight {
  outline: 2px solid #1d4ed8;
  outline-offset: 1px;
  font-weight: 600;
}

button:disabled, button:disabled:hover, .btn-disabled {
  display: inline-block;
  background: #9ca3af;
  color: #f5f6f8;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: not-allowed;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  margin-bottom: 24px;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid #e5e7eb;
}

.data-table th {
  background: #f3f4f6;
  font-size: 0.85rem;
  text-transform: uppercase;
  color: #6b7280;
}

.stat-cards {
  display: flex;
  gap: 16px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}

.stat-card {
  background: #fff;
  border-radius: 8px;
  padding: 16px 24px;
  min-width: 140px;
  text-align: center;
}

a.stat-card {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s ease;
}

a.stat-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.stat-value {
  font-size: 2rem;
  font-weight: bold;
}

.stat-label {
  color: #6b7280;
  font-size: 0.85rem;
  text-transform: uppercase;
}

.search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}

.search-form input, .search-form select {
  padding: 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
}

.stacked-form {
  display: flex;
  flex-direction: column;
  max-width: 480px;
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 24px;
}

.stacked-form label {
  margin-top: 12px;
  margin-bottom: 4px;
  font-weight: 600;
  font-size: 0.9rem;
}

.stacked-form input, .stacked-form select, .stacked-form textarea {
  padding: 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-family: inherit;
}

.stacked-form button {
  margin-top: 16px;
  align-self: flex-start;
}

.inline-form {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.inline-form select {
  padding: 6px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  background: #fff;
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 16px;
}

.note-list {
  list-style: none;
  padding: 0;
}

.note-item {
  background: #fff;
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 8px;
}

.note-meta {
  color: #9ca3af;
  font-size: 0.8rem;
  margin-top: 4px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
  text-transform: capitalize;
}

.badge-open {
  background: #fee2e2;
  color: #991b1b;
}

.badge-in-progress {
  background: #fef3c7;
  color: #92400e;
}

.badge-resolved {
  background: #d1fae5;
  color: #065f46;
}

.badge-priority-low {
  background: #e5e7eb;
  color: #374151;
}

.badge-priority-medium {
  background: #dbeafe;
  color: #1e40af;
}

.badge-priority-high {
  background: #fecaca;
  color: #7f1d1d;
}

.inline-action {
  display: inline-block;
  margin: 0;
}

.error {
  color: #b91c1c;
  background: #fee2e2;
  padding: 8px 12px;
  border-radius: 4px;
}

.success {
  color: #065f46;
  background: #d1fae5;
  padding: 8px 12px;
  border-radius: 4px;
}

.notice-warn {
  color: #92400e;
  background: #fef3c7;
  padding: 8px 12px;
  border-radius: 4px;
}

.error-inline {
  color: #b91c1c;
  font-size: 0.8rem;
  margin-top: 4px;
}

.info {
  color: #1e40af;
  background: #dbeafe;
  padding: 8px 12px;
  border-radius: 4px;
}

.attachment-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
}

.attachment-item {
  background: #fff;
  padding: 8px;
  border-radius: 8px;
  text-align: center;
  width: 160px;
}

.attachment-thumb {
  width: 144px;
  height: 144px;
  object-fit: cover;
  border-radius: 4px;
  display: block;
}

.attachment-name {
  font-size: 0.8rem;
  color: #6b7280;
  margin: 6px 0;
  word-break: break-all;
}

.badge-new {
  background: #dbeafe;
  color: #1e40af;
}

.badge-sent {
  background: #d1fae5;
  color: #065f46;
}

.badge-sending {
  background: #fef3c7;
  color: #92400e;
}

.badge-discarded {
  background: #e5e7eb;
  color: #374151;
}

.badge-bounced {
  background: #fed7aa;
  color: #9a3412;
}

.badge-replied {
  background: #dbeafe;
  color: #1e40af;
}

.draft-preview {
  white-space: pre-wrap;
  background: #f9fafb;
  padding: 12px;
  border-radius: 6px;
  margin: 8px 0;
  font-size: 0.9rem;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.chip-btn {
  background: #6b7280;
  color: #fff;
  border: none;
  padding: 4px 10px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.8rem;
}

.chip-btn:hover {
  background: #4b5563;
}

.badge-ai-researched {
  background: #ede9fe;
  color: #5b21b6;
}

.badge-quick-match {
  background: #e5e7eb;
  color: #4b5563;
}

.badge-qa-unreviewed {
  background: #e5e7eb;
  color: #4b5563;
}

.badge-qa-passed {
  background: #d1fae5;
  color: #065f46;
}

.badge-qa-flagged {
  background: #fecaca;
  color: #7f1d1d;
}

.qa-notes {
  color: #7f1d1d;
  font-size: 0.8rem;
  margin-top: 4px;
  max-width: 220px;
}

.badge-confidence-found {
  background: #d1fae5;
  color: #065f46;
}

.badge-confidence-confirmed {
  background: #bbf7d0;
  color: #14532d;
}

.badge-confidence-guessed {
  background: #e5e7eb;
  color: #4b5563;
}

.badge-confidence-bounced {
  background: #fecaca;
  color: #7f1d1d;
}

.coverage-summary {
  background: #f9fafb;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
}

.stats-summary {
  margin-bottom: 24px;
}

.stats-summary h2 {
  font-size: 1rem;
  margin: 0 0 12px;
}

.stats-summary .stat-cards {
  margin-bottom: 0;
}

.coverage-summary h2 {
  font-size: 1rem;
  margin: 0 0 4px;
}

.badge-pending {
  background: #fef3c7;
  color: #92400e;
}

.badge-done {
  background: #d1fae5;
  color: #065f46;
}

.badge-exhausted {
  background: #e5e7eb;
  color: #374151;
}

.badge-verify-valid {
  background: #d1fae5;
  color: #065f46;
}

.badge-verify-invalid {
  background: #fecaca;
  color: #7f1d1d;
}

.badge-verify-unknown {
  background: #e5e7eb;
  color: #4b5563;
}

.domain-health-panel {
  background: #f9fafb;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
}

.domain-health-panel h2 {
  font-size: 1rem;
  margin: 0 0 8px;
}

.domain-health-checks {
  list-style: none;
  margin: 8px 0;
  padding: 0;
}

.domain-health-checks li {
  margin-bottom: 8px;
}

/* Leads page: tabs + two-line rows */
.container.leads-page {
  max-width: 1440px;
  padding: 24px 16px;
}

.tabs-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  border-bottom: 2px solid #e5e7eb;
  margin: 12px 0 8px;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab {
  display: inline-block;
  padding: 8px 14px;
  color: #4b5563;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
}

.tab:hover {
  text-decoration: none;
  color: #1f2430;
}

.tab.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
  font-weight: 600;
}

.tab-count {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #e5e7eb;
  color: #374151;
  font-size: 0.75rem;
  text-align: center;
  font-weight: 600;
}

.tab.active .tab-count {
  background: #dbeafe;
  color: #1e40af;
}

.tabs-right form {
  display: inline;
}

.tabs-right .btn-secondary {
  padding: 3px 8px;
  font-size: 0.75rem;
}

.tabs-right {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  font-size: 0.85rem;
  color: #4b5563;
  white-space: nowrap;
}

.sent-today.cap-reached {
  color: #b91c1c;
  font-weight: 600;
}

.health-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.health-green { background: #10b981; }
.health-yellow { background: #f59e0b; }
.health-red { background: #ef4444; }
.health-grey { background: #9ca3af; }

.page-details {
  margin-bottom: 12px;
}

.page-details summary {
  cursor: pointer;
}

.table-scroll {
  overflow-x: auto;
  max-width: 100%;
}

.leads-table {
  table-layout: auto;
}

.leads-table th, .leads-table td {
  white-space: nowrap;
  vertical-align: top;
  padding: 8px 9px;
}

.leads-table .line {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.5;
}

.leads-table .line.note-meta {
  margin-top: 0;
}

.leads-table .cell-contact {
  min-width: 260px;
  max-width: 300px;
}

.leads-table .cell-company {
  min-width: 200px;
  max-width: 260px;
}

.leads-table .cell-subject {
  min-width: 150px;
  max-width: 240px;
}

.leads-table .cell-status {
  min-width: 150px;
}

.leads-table .cell-date {
  min-width: 150px;
}

.leads-table .cell-actions {
  min-width: 240px;
}

.leads-table .badge {
  white-space: nowrap;
  line-height: 1.3;
}

.action-line {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 6px;
  line-height: 1.5;
  min-height: 30px;
}

.action-line .send-controls {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.send-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
}

.send-links {
  font-size: 0.8rem;
  white-space: nowrap;
  line-height: 1.5;
}

.send-links .note-meta {
  margin-top: 0;
}

.action-line .btn-primary, .action-line .btn-secondary, .action-line button, .action-line .btn-disabled {
  padding: 5px 12px;
  font-size: 0.85rem;
}

.action-line .btn.btn-opened {
  padding: 5px 12px;
  font-size: 0.85rem;
}

.action-line .error-inline {
  flex-basis: 100%;
  margin-top: 0;
}

.leads-table .line.fold-confidence {
  display: none;
}

.text-link {
  font-size: 0.85rem;
}

/* QA pill: collapsed one-liner; notes open in a floating box */
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: nowrap;
}

.pill-passed { background: #d1fae5; color: #065f46; }
.pill-flagged { background: #fecaca; color: #7f1d1d; }
.pill-unreviewed { background: #e5e7eb; color: #4b5563; }
.pill-optout { background: #fecaca; color: #7f1d1d; font-weight: 600; }
.pill-followup { background: #e0e7ff; color: #3730a3; }

.optout-details {
  display: inline-block;
}

.optout-details summary {
  list-style: none;
  cursor: pointer;
}

.optout-details summary::-webkit-details-marker {
  display: none;
}

.optout-box {
  margin: 4px 0;
  padding: 6px 8px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 4px;
  font-size: 0.8rem;
  color: #7f1d1d;
  max-width: 440px;
  white-space: normal;
}

.qa-pill {
  display: inline-block;
  position: relative;
}

.qa-pill summary {
  list-style: none;
  cursor: pointer;
}

.qa-pill summary::-webkit-details-marker {
  display: none;
}

.qa-pill summary::after {
  content: ' \25BE';
  font-size: 0.7rem;
}

.qa-notes-box {
  position: absolute;
  left: 0;
  top: 100%;
  z-index: 30;
  width: 440px;
  max-height: 320px;
  overflow: auto;
  margin-top: 4px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  white-space: pre-wrap;
  font-size: 0.8rem;
  color: #1f2430;
  text-align: left;
}

/* Kebab menu: rare per-row actions */
.kebab {
  display: inline-block;
  position: relative;
}

.kebab summary {
  list-style: none;
}

.kebab summary::-webkit-details-marker {
  display: none;
}

.kebab-btn {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1.2;
  user-select: none;
}

.kebab-btn:hover, .kebab[open] .kebab-btn {
  background: #f3f4f6;
}

.kebab-menu {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 30;
  min-width: 220px;
  margin-top: 4px;
  padding: 6px 0;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  text-align: left;
}

.kebab-item {
  padding: 4px 12px 8px;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 4px;
}

.kebab-item .note-input {
  width: 100%;
  font-size: 0.85rem;
  padding: 4px 6px;
}

.kebab-form {
  display: block;
  margin: 0;
}

.kebab-action, .kebab-action:hover {
  display: block;
  width: 100%;
  padding: 7px 12px;
  background: none;
  color: #1f2430;
  border: none;
  border-radius: 0;
  text-align: left;
  font-size: 0.85rem;
  cursor: pointer;
}

.kebab-action:hover {
  background: #f3f4f6;
}

a.kebab-action {
  text-decoration: none;
  box-sizing: border-box;
}

.kebab-action:disabled, .kebab-action:disabled:hover {
  display: block;
  background: none;
  color: #9ca3af;
  padding: 7px 12px;
  cursor: not-allowed;
}

.kebab-menu .btn-highlight {
  outline: none;
  font-weight: 600;
  color: #1d4ed8;
}

/* Draft preview row: hidden until "View draft"; the <details> inside stays the source of truth */
.draft-row {
  display: none;
}

.draft-row.open {
  display: table-row;
}

.draft-row td {
  white-space: normal;
  background: #f9fafb;
}

.draft-details summary {
  cursor: pointer;
}

.draft-row .draft-preview {
  max-width: 900px;
}

/* Narrow screens (1024): fold Confidence into Status, fixed column widths, no table scroll */
@media (max-width: 1100px) {
  .leads-table {
    table-layout: fixed;
    width: 100%;
  }

  .leads-table th, .leads-table td {
    padding: 8px 6px;
  }

  .leads-table .th-confidence, .leads-table .cell-confidence {
    display: none;
  }

  .leads-table .line.fold-confidence {
    display: block;
  }

  .leads-table .badge {
    font-size: 0.72rem;
    padding: 0 6px;
    line-height: 1.25;
  }

  .leads-table .cell-status .line {
    line-height: 1.2;
    padding: 1px 0;
  }

  .leads-table .th-status, .leads-table .cell-status { width: 152px; min-width: 0; }
  .leads-table .th-qa, .leads-table .cell-qa { width: 78px; }
  .leads-table .th-contact, .leads-table .cell-contact { width: 200px; min-width: 200px; max-width: 200px; }
  .leads-table .th-company, .leads-table .cell-company { width: 170px; min-width: 170px; max-width: 170px; }
  .leads-table .th-subject, .leads-table .cell-subject { width: auto; min-width: 0; max-width: none; }
  .leads-table .th-actions, .leads-table .cell-actions { width: 246px; min-width: 246px; }

  .leads-table.sent-layout .th-date, .leads-table.sent-layout .cell-date { width: 205px; min-width: 0; }
  .leads-table.sent-layout .th-to { width: 200px; }
  .leads-table.sent-layout .th-subject { width: auto; }
  .leads-table.sent-layout .th-actions, .leads-table.sent-layout .cell-actions { width: 330px; min-width: 330px; }

  .company-location {
    display: none;
  }

  .action-line .btn-primary, .action-line .btn-secondary, .action-line button, .action-line .btn-disabled, .action-line .btn.btn-opened {
    padding: 5px 9px;
    font-size: 0.8rem;
  }

  .send-buttons {
    flex-wrap: wrap;
  }

  .send-links {
    font-size: 0.75rem;
  }
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.9rem;
}

.badge-note-internal {
  background: #e5e7eb;
  color: #374151;
  margin-left: 8px;
}

.badge-note-visible {
  background: #dbeafe;
  color: #1e40af;
  margin-left: 8px;
}

.invite-link {
  display: inline-block;
  margin-top: 6px;
  word-break: break-all;
  font-size: 0.85rem;
}

.portal-aux-link {
  margin-top: 16px;
  font-size: 0.9rem;
}

.maintenance-table input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.maintenance-note {
  width: 100%;
  padding: 6px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
}

.maint-mark {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
}

.maint-yes {
  background: #d1fae5;
  color: #065f46;
}

.maint-no {
  background: #e5e7eb;
  color: #6b7280;
}
