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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f5f5;
  color: #1a1a1a;
}

/* Login */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-box {
  background: #fff;
  padding: 48px;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  text-align: center;
  max-width: 400px;
  width: 90%;
}
.login-box h1 {
  font-size: 24px;
  margin-bottom: 8px;
}
.login-box p {
  color: #6b7280;
  font-size: 14px;
  margin-bottom: 24px;
}
.login-box input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
}
.login-box button {
  width: 100%;
  padding: 12px;
  background: #111;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.login-box button:hover {
  background: #333;
}
.login-error {
  color: #dc2626;
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}

/* App Layout */
.app {
  display: none;
}
.topbar {
  background: #111;
  color: #fff;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar h1 {
  font-size: 18px;
  font-weight: 600;
}
.topbar-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}
.topbar-actions button {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.topbar-actions button:hover {
  background: rgba(255, 255, 255, 0.25);
}
.topbar-actions .add-btn {
  background: #22c55e;
}
.topbar-actions .add-btn:hover {
  background: #16a34a;
}

/* Race Map */
.phase1-map-section {
  padding: 20px 24px 0;
  max-width: 1400px;
  margin: 0 auto;
}
.phase1-map-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.phase1-map-title {
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.phase1-map-count {
  font-size: 12px;
  color: #6b7280;
  background: #f3f4f6;
  padding: 2px 8px;
  border-radius: 12px;
}
#raceMap {
  height: 320px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* Pipeline Stats */
.pipeline {
  display: flex;
  gap: 8px;
  padding: 20px 24px 0;
  max-width: 1400px;
  margin: 0 auto;
  flex-wrap: wrap;
}
.pipeline-stat {
  background: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  text-align: center;
  flex: 1;
  min-width: 90px;
}
.pipeline-stat .label {
  font-size: 11px;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.pipeline-stat .value {
  font-size: 22px;
  font-weight: 700;
  margin-top: 2px;
}

/* Filters */
.filters {
  display: flex;
  gap: 12px;
  padding: 16px 24px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: center;
  flex-wrap: wrap;
}
.filters select {
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  cursor: pointer;
}
.result-count {
  font-size: 13px;
  color: #6b7280;
  margin-left: auto;
}

/* Table */
.table-container {
  padding: 0 24px 24px;
  max-width: 1400px;
  margin: 0 auto;
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
thead th {
  background: #f9fafb;
  padding: 12px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #e5e7eb;
  white-space: nowrap;
}
tbody td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}
tbody tr:hover {
  background: #f9fafb;
  cursor: pointer;
}
tbody tr:last-child td {
  border-bottom: none;
}

.venue-name {
  font-weight: 600;
}
.race-series {
  font-size: 12px;
  color: #6b7280;
}
.venue-website {
  font-size: 12px;
  color: #2563eb;
  text-decoration: none;
}
.venue-website:hover {
  text-decoration: underline;
}
.contact-title {
  font-size: 12px;
  color: #6b7280;
}
.contact-email {
  font-size: 12px;
  color: #2563eb;
  text-decoration: none;
}
.contact-email:hover {
  text-decoration: underline;
}
.contact-phone {
  font-size: 12px;
  color: #6b7280;
}
.race-date-cell {
  font-size: 13px;
  color: #374151;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  padding: 48px;
  color: #9ca3af;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.discovered {
  background: #f3f4f6;
  color: #6b7280;
}
.badge.enriched {
  background: #dbeafe;
  color: #1e40af;
}
.badge.draft_ready {
  background: #fef3c7;
  color: #92400e;
}
.badge.approved {
  background: #fce7f3;
  color: #9d174d;
}
.badge.sent {
  background: #d1fae5;
  color: #065f46;
}
.badge.replied {
  background: #ede9fe;
  color: #5b21b6;
}
.badge.meeting {
  background: #cffafe;
  color: #155e75;
}
.badge.closed {
  background: #22c55e;
  color: #fff;
}
.badge.not_interested {
  background: #fee2e2;
  color: #991b1b;
}
.badge.opened {
  background: #d1fae5;
  color: #065f46;
}
.badge.not-opened {
  background: #f3f4f6;
  color: #9ca3af;
}
.badge.clicked {
  background: #dbeafe;
  color: #1e40af;
}

/* Race type badges */
.badge.dh {
  background: #fee2e2;
  color: #991b1b;
}
.badge.enduro {
  background: #fef3c7;
  color: #92400e;
}
.badge.xc {
  background: #dbeafe;
  color: #1e40af;
}
.badge.youth_xc {
  background: #ede9fe;
  color: #5b21b6;
}
.badge.endurance {
  background: #d1fae5;
  color: #065f46;
}
.badge.festival {
  background: #fce7f3;
  color: #9d174d;
}

/* Region badges */
.badge.region-WA {
  background: #dbeafe;
  color: #1e40af;
}
.badge.region-OR {
  background: #d1fae5;
  color: #065f46;
}
.badge.region-ID {
  background: #fef3c7;
  color: #92400e;
}
.badge.region-MT {
  background: #f3f4f6;
  color: #374151;
}

/* Buttons */
.btn {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
}
.btn:hover {
  background: #f3f4f6;
}
.btn.advance {
  background: #111;
  color: #fff;
  border-color: #111;
}
.btn.advance:hover {
  background: #333;
}
.btn.danger {
  color: #dc2626;
  border-color: #fca5a5;
}
.btn.danger:hover {
  background: #fef2f2;
}
.btn.primary {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}
.btn.primary:hover {
  background: #1d4ed8;
}

.action-btns {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
}

/* Detail Panel */
.detail-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 200;
}
.detail-overlay.active {
  display: block;
}
.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 480px;
  max-width: 90vw;
  background: #fff;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.1);
  overflow-y: auto;
  padding: 32px;
}
.detail-panel h2 {
  font-size: 20px;
  margin-bottom: 24px;
}
.detail-panel .field-group {
  margin-bottom: 16px;
}
.detail-panel .field-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.detail-panel .field-group input,
.detail-panel .field-group select,
.detail-panel .field-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.detail-panel .field-group textarea {
  resize: vertical;
  min-height: 60px;
}
.detail-panel .detail-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}

/* Email Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 300;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active {
  display: flex;
}
.modal {
  background: #fff;
  border-radius: 16px;
  padding: 32px;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}
.modal.modal-wide {
  max-width: 640px;
}
.modal h2 {
  font-size: 18px;
  margin-bottom: 20px;
}
.modal label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  margin-bottom: 4px;
  margin-top: 12px;
}
.modal input,
.modal textarea,
.modal select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.modal textarea {
  resize: vertical;
  min-height: 60px;
}
.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  justify-content: flex-end;
}
.modal-actions .btn {
  padding: 10px 20px;
  font-size: 14px;
}

.email-history {
  display: none;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.email-history-pill {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: #f3f4f6;
  color: #374151;
  cursor: pointer;
  border: 1px solid #e5e7eb;
  white-space: nowrap;
}
.email-history-pill:hover {
  background: #e5e7eb;
}
.email-history-pill.active {
  background: #111;
  color: #fff;
  border-color: #111;
}

.email-status {
  margin-top: 12px;
  font-size: 13px;
  color: #6b7280;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #111;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 400;
  display: none;
}
.toast.error {
  background: #dc2626;
}
.toast.show {
  display: block;
}

/* Responsive */
@media (max-width: 768px) {
  .pipeline {
    flex-direction: column;
  }
  .filters {
    flex-direction: column;
  }
  .detail-panel {
    width: 100%;
  }
  .table-container {
    padding: 0 12px 12px;
  }
  .topbar {
    padding: 12px 16px;
  }
}
