/* ═══════════════════════════════════════════════════════════════
   HPA Admin Dashboard — CSS
   Design system: Navy #0B2545 | Gold #AD9569 | Cream #F8F6F2
═══════════════════════════════════════════════════════════════ */

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

:root {
  --navy: #0B2545;
  --navy-light: #1a3a65;
  --gold: #AD9569;
  --gold-light: #c8b08a;
  --cream: #F8F6F2;
  --cream-dark: #EDE9E2;
  --white: #ffffff;
  --green: #15803d;
  --green-light: #dcfce7;
  --red: #b91c1c;
  --red-light: #fee2e2;
  --amber: #b45309;
  --amber-light: #fef3c7;
  --gray: #6b7280;
  --gray-light: #f3f4f6;
  --border: #d1c9bc;
  --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.18);
  --radius: 6px;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-serif: 'Playfair Display', Georgia, serif;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--navy);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}

/* ─── Buttons ─────────────────────────────────────────────────────── */

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--gold);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--gold-light); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  background: transparent;
  color: var(--white);
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:hover { background: rgba(255,255,255,0.12); }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  background: transparent;
  color: var(--navy);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-ghost:hover { background: var(--cream-dark); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: rgba(255,255,255,0.8);
  border: none;
  padding: 6px;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 0.15s;
}
.btn-icon:hover { background: rgba(255,255,255,0.12); color: white; }

.btn-sm { padding: 6px 12px; font-size: 12px; }

.btn-link {
  background: none;
  border: none;
  color: var(--gold);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
  text-decoration: none;
}
.btn-link:hover { background: var(--cream-dark); }

/* ─── Form elements ──────────────────────────────────────────────── */

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  font-family: var(--font-sans);
  color: var(--navy);
  background: var(--white);
  transition: border-color 0.15s;
}
.form-input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(173,149,105,0.15); }

.filter-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray);
  margin-bottom: 4px;
}
.filter-select, .filter-input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font-sans);
  color: var(--navy);
  background: var(--white);
  cursor: pointer;
}
.filter-select:focus, .filter-input:focus { outline: none; border-color: var(--gold); }

/* ─── LOGIN SCREEN ───────────────────────────────────────────────── */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, #1a3a65 100%);
  padding: 20px;
}

.login-card {
  background: var(--white);
  border-radius: 12px;
  padding: 48px 44px 44px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.login-title {
  font-family: var(--font-serif);
  font-size: 22px;
  color: var(--navy);
  margin-bottom: 6px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--gray);
  margin-bottom: 32px;
}

.login-form { text-align: left; }
.login-form .form-label { margin-bottom: 8px; }
.login-form .btn-primary { width: 100%; justify-content: center; margin-top: 20px; padding: 12px; }

.login-error {
  background: var(--red-light);
  color: var(--red);
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-top: 12px;
}

/* ─── HEADER ─────────────────────────────────────────────────────── */

.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--navy);
  color: var(--white);
  padding: 0 24px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.dash-header-left { display: flex; align-items: center; gap: 10px; }

.dash-logo-mark {
  font-size: 18px;
  color: var(--gold);
}

.dash-title {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 600;
  color: var(--white);
}

.dash-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.quick-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: rgba(255,255,255,0.8);
}

.stat-item { white-space: nowrap; }
.stat-alert { color: var(--gold-light); font-weight: 600; }
.stat-divider { opacity: 0.3; }

/* ─── FILTER BAR ─────────────────────────────────────────────────── */

.filter-bar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.filter-group { display: flex; flex-direction: column; }
.filter-select, .filter-input { min-width: 130px; }
.filter-actions { display: flex; gap: 8px; align-items: center; padding-top: 18px; }

/* ─── MAIN CONTENT ───────────────────────────────────────────────── */

.dash-main {
  padding: 20px 24px;
  max-width: 1400px;
  margin: 0 auto;
}

/* ─── LOADING / EMPTY ────────────────────────────────────────────── */

.loading-state, .empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 24px;
  color: var(--gray);
  font-size: 14px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── TABLE ──────────────────────────────────────────────────────── */

.table-wrapper {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.leads-table {
  width: 100%;
  border-collapse: collapse;
}

.leads-table thead tr {
  background: var(--navy);
  color: var(--white);
}

.leads-table th {
  padding: 11px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  user-select: none;
}

.leads-table th.sortable { cursor: pointer; }
.leads-table th.sortable:hover { background: var(--navy-light); }
.sort-arrow { opacity: 0.5; margin-left: 4px; }
.sort-arrow.active { opacity: 1; color: var(--gold); }

.leads-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--cream-dark);
  vertical-align: top;
  font-size: 13px;
}

.leads-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}
.leads-table tbody tr:last-child td { border-bottom: none; }
.leads-table tbody tr:hover { background: var(--cream); }

/* Status-based row styling */
.leads-table tbody tr.status-new {
  background: #fffbf4;
  border-left: 3px solid var(--gold);
}
.leads-table tbody tr.status-new:hover { background: #fff7e8; }
.leads-table tbody tr.status-contacted { border-left: 3px solid var(--navy); }
.leads-table tbody tr.status-consultation_booked { border-left: 3px solid var(--green); }
.leads-table tbody tr.status-retained { border-left: 3px solid #7c3aed; }
.leads-table tbody tr.status-closed { border-left: 3px solid var(--gray); opacity: 0.75; }

/* Column widths */
.col-date  { width: 120px; }
.col-source { width: 100px; }
.col-name  { width: 140px; }
.col-phone { width: 120px; }
.col-summary { min-width: 200px; max-width: 320px; }
.col-score { width: 60px; text-align: center; }
.col-status { width: 130px; }
.col-action { width: 70px; text-align: right; }

.summary-cell {
  max-width: 320px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  color: var(--gray);
  font-size: 12px;
}

/* Source badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-screener { background: #ede9fe; color: #5b21b6; }
.badge-contact  { background: #dbeafe; color: #1d4ed8; }
.badge-widget   { background: #dcfce7; color: var(--green); }

/* Status badges */
.status-badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.status-badge.new { background: var(--amber-light); color: var(--amber); }
.status-badge.contacted { background: #dbeafe; color: #1d4ed8; }
.status-badge.consultation_booked { background: var(--green-light); color: var(--green); }
.status-badge.retained { background: #ede9fe; color: #5b21b6; }
.status-badge.closed { background: var(--gray-light); color: var(--gray); }

/* Score */
.score-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 12px;
}
.score-high { background: var(--green-light); color: var(--green); }
.score-mid  { background: var(--amber-light); color: var(--amber); }
.score-low  { background: var(--gray-light); color: var(--gray); }

/* ─── MOBILE CARDS ───────────────────────────────────────────────── */

.cards-wrapper {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lead-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s;
}
.lead-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.lead-card.status-new { border-left: 4px solid var(--gold); }
.lead-card.status-contacted { border-left: 4px solid var(--navy); }
.lead-card.status-consultation_booked { border-left: 4px solid var(--green); }
.lead-card.status-closed { opacity: 0.75; }

.lead-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}
.lead-card-name { font-weight: 600; font-size: 14px; }
.lead-card-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.lead-card-summary { font-size: 12px; color: var(--gray); line-height: 1.4; }
.lead-card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.lead-card-date { font-size: 11px; color: var(--gray); }

/* ─── PAGINATION ─────────────────────────────────────────────────── */

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 16px 0 4px;
}

.page-btn {
  min-width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--navy);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.page-btn:hover { border-color: var(--gold); color: var(--gold); }
.page-btn.active { background: var(--navy); color: var(--white); border-color: var(--navy); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.page-info { font-size: 13px; color: var(--gray); padding: 0 8px; }

/* ─── MODAL ──────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11,37,69,0.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-card {
  background: var(--white);
  border-radius: 10px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--gray);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--gray-light); color: var(--navy); }

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-family: var(--font-serif);
  font-size: 20px;
  color: var(--navy);
  margin-bottom: 4px;
}

.modal-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 12px;
  color: var(--gray);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.modal-actions-left { display: flex; gap: 8px; flex-wrap: wrap; }
.modal-actions-right { display: flex; gap: 8px; }

/* Modal body sections */
.detail-section { margin-bottom: 20px; }
.detail-section:last-child { margin-bottom: 0; }
.detail-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--gold);
  margin-bottom: 10px;
  border-bottom: 1px solid var(--cream-dark);
  padding-bottom: 4px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 20px;
}

.detail-item label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray);
  margin-bottom: 2px;
}
.detail-item span, .detail-item p {
  font-size: 13px;
  color: var(--navy);
  word-break: break-word;
}

.q-list { list-style: none; }
.q-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--cream-dark);
  font-size: 13px;
}
.q-list li:last-child { border-bottom: none; }
.q-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: block;
  margin-bottom: 2px;
}

.modal-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--navy);
  background: var(--white);
}
.modal-select:focus { outline: none; border-color: var(--gold); }

.modal-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--navy);
  resize: vertical;
  min-height: 90px;
}
.modal-textarea:focus { outline: none; border-color: var(--gold); }

.read-only-note {
  font-size: 11px;
  color: var(--gray);
  font-style: italic;
  margin-top: 4px;
}

/* ─── TOAST ──────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  background: var(--navy);
  color: var(--white);
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  max-width: 320px;
  line-height: 1.4;
}
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }

/* ─── RESPONSIVE ─────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .dash-header { padding: 0 14px; }
  .dash-title { font-size: 15px; }
  .quick-stats { display: none; }

  .filter-bar { padding: 10px 14px; }
  .filters-row { gap: 8px; }
  .filter-select, .filter-input { min-width: 0; flex: 1; }

  .dash-main { padding: 12px 14px; }

  .table-wrapper { display: none !important; }
  .cards-wrapper { display: flex !important; }

  .modal-card { max-height: 95vh; }
  .modal-body { padding: 14px 16px; }
  .modal-header { padding: 14px 16px 12px; }
  .modal-footer { padding: 12px 16px; flex-wrap: wrap; }
  .detail-grid { grid-template-columns: 1fr; }

  .toast { bottom: 16px; right: 16px; left: 16px; max-width: none; }
}

@media (min-width: 769px) {
  .cards-wrapper { display: none !important; }
  .table-wrapper { display: block !important; }
}

/* ─── Auto-refresh pulse ─────────────────────────────────────────── */
@keyframes newrow {
  0%   { background: rgba(173,149,105,0.2); }
  100% { background: transparent; }
}
.new-row-highlight { animation: newrow 2s ease-out; }
