/* dashboard.css — PermitPulseOS contractor leads dashboard */
/* Shares color tokens with seacoast-nh-hvac.css: navy/red/gold palette */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

:root {
  --navy:     #1a2744;
  --navy-dk:  #111b33;
  --navy-lt:  #243256;
  --red:      #c0392b;
  --red-lt:   #e74c3c;
  --amber:    #f59e0b;
  --white:    #ffffff;
  --off-white:#f7f8fa;
  --gray:     #6b7280;
  --gray-lt:  #e5e7eb;
  --text:     #1f2937;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--off-white);
  min-height: 100vh;
}

/* ── Header ── */
.dash-header {
  background: var(--navy-dk);
  border-bottom: 3px solid var(--red);
  padding: 14px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  /* Smooth hide/show on scroll (mobile scroll-hide JS sets transform) */
  transition: transform 0.22s ease;
  will-change: transform;
}
.dash-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.dash-logo {
  font-size: 18px;
  font-weight: 800;
  color: var(--white);
  letter-spacing: -0.02em;
  text-decoration: none;
}
.dash-logo span { color: var(--amber); }
.dash-nav {
  display: flex;
  align-items: center;
  gap: 16px;
}
.dash-user-chip {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 13px;
  color: #cbd5e1;
  font-weight: 500;
}
.dash-logout {
  font-size: 13px;
  color: #94a3b8;
  text-decoration: none;
  padding: 5px 0;
}
.dash-logout:hover { color: #e2e8f0; }

/* ── Page Layout ── */
.dash-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* ── Stats Bar ── */
.dash-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-lt);
  border-radius: 8px;
  padding: 16px 20px;
  flex: 1;
  min-width: 140px;
}
.stat-card .stat-number {
  font-size: 28px;
  font-weight: 800;
  color: var(--navy);
  line-height: 1;
  margin-bottom: 4px;
}
.stat-card .stat-label {
  font-size: 12px;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.stat-card.stat-highlight .stat-number { color: var(--red); }

/* ── Section header ── */
.dash-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}
.dash-section-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
}
.dash-territory-badge {
  background: var(--navy);
  color: var(--white);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 12px;
  border-radius: 20px;
}

/* ── Leads Table ── */
.leads-table-wrap {
  background: var(--white);
  border: 1px solid var(--gray-lt);
  border-radius: 8px;
  overflow: hidden;
}
.leads-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.leads-table thead {
  background: var(--navy);
  color: var(--white);
}
.leads-table thead th {
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.leads-table thead th:first-child { padding-left: 20px; }
.leads-table tbody tr {
  border-bottom: 1px solid var(--gray-lt);
  cursor: pointer;
  transition: background 0.1s;
}
.leads-table tbody tr:last-child { border-bottom: none; }
.leads-table tbody tr:hover { background: #f0f4ff; }
.leads-table tbody td {
  padding: 12px 16px;
  vertical-align: middle;
}
.leads-table tbody td:first-child { padding-left: 20px; }

/* ── Table cell types ── */
.td-date    { color: var(--gray); white-space: nowrap; font-size: 12px; }
.td-address { font-weight: 600; color: var(--navy); max-width: 220px; }
.td-address small { display: block; font-weight: 400; color: var(--gray); font-size: 11px; }
.td-type    { font-size: 12px; color: var(--text); max-width: 160px; }
.td-val     { font-weight: 600; white-space: nowrap; }
.td-score   {}

/* ── Intent score badge ── */
.intent-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
}
.intent-high { background: #fef2f2; color: #b91c1c; }
.intent-med  { background: #fff7ed; color: #c2410c; }
.intent-low  { background: #f0fdf4; color: #15803d; }
.intent-none { background: var(--gray-lt); color: var(--gray); }

/* ── Status select ── */
.status-select {
  border: 1.5px solid var(--gray-lt);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 600;
  background: var(--white);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 22px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  transition: border-color 0.15s;
  min-width: 100px;
}
.status-select:focus { outline: none; border-color: var(--navy); }

.status-new       { color: #1e40af; border-color: #93c5fd; background-color: #eff6ff; }
.status-contacted { color: #c2410c; border-color: #fed7aa; background-color: #fff7ed; }
.status-won       { color: #15803d; border-color: #86efac; background-color: #f0fdf4; }
.status-dead      { color: var(--gray); border-color: var(--gray-lt); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}
.empty-state-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 8px;
}
.empty-state p {
  font-size: 14px;
  color: var(--gray);
  max-width: 400px;
  margin: 0 auto 24px;
  line-height: 1.6;
}
.empty-eta {
  display: inline-block;
  background: var(--navy);
  color: var(--white);
  font-size: 14px;
  font-weight: 600;
  padding: 12px 24px;
  border-radius: 8px;
}

/* ── Detail Drawer ── */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  backdrop-filter: blur(2px);
}
.drawer-overlay.open { display: block; }
.drawer {
  position: fixed;
  top: 0;
  right: -600px;
  width: min(560px, 100vw);
  height: 100%;
  background: var(--white);
  z-index: 201;
  overflow-y: auto;
  transition: right 0.25s ease;
  display: flex;
  flex-direction: column;
}
.drawer.open { right: 0; }
.drawer-header {
  background: var(--navy-dk);
  border-bottom: 3px solid var(--red);
  padding: 20px 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.drawer-header-content {}
.drawer-eyebrow {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--amber);
  margin-bottom: 6px;
}
.drawer-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--white);
  line-height: 1.3;
}
.drawer-close {
  background: rgba(255,255,255,0.1);
  border: none;
  color: #94a3b8;
  font-size: 20px;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
}
.drawer-close:hover { background: rgba(255,255,255,0.2); color: var(--white); }

.drawer-body {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
}

.drawer-section { margin-bottom: 24px; }
.drawer-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gray);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--gray-lt);
}
.drawer-field {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #f3f4f6;
  font-size: 13px;
}
.drawer-field:last-child { border-bottom: none; }
.drawer-field-label { color: var(--gray); font-weight: 500; flex-shrink: 0; }
.drawer-field-value { color: var(--text); font-weight: 600; text-align: right; word-break: break-word; }

.contact-card {
  background: #f0f4ff;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  padding: 14px 16px;
}
.contact-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 4px;
}
.contact-detail {
  font-size: 12px;
  color: var(--gray);
  margin-bottom: 2px;
}
.contact-detail a { color: var(--red); text-decoration: none; }
.contact-detail a:hover { text-decoration: underline; }

.no-contact {
  background: #fafafa;
  border: 1px dashed var(--gray-lt);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 13px;
  color: var(--gray);
  text-align: center;
}

/* ── Action buttons in drawer ── */
.drawer-actions {
  padding: 16px 24px 24px;
  border-top: 1px solid var(--gray-lt);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.btn-primary {
  background: var(--red);
  color: var(--white);
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--red-lt); }
.btn-primary:disabled { background: var(--gray); cursor: not-allowed; }
.btn-secondary {
  background: transparent;
  color: var(--navy);
  border: 1.5px solid var(--gray-lt);
  border-radius: 6px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s;
}
.btn-secondary:hover { border-color: var(--navy); }

/* ── Status action bar inside drawer ── */
.drawer-status-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: #fafbff;
  border-bottom: 1px solid var(--gray-lt);
  flex-shrink: 0;
}
.drawer-status-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray);
  flex-shrink: 0;
}
.drawer-status-select {
  flex: 1;
}
.status-saved-msg {
  font-size: 12px;
  color: #15803d;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.3s;
}
.status-saved-msg.visible { opacity: 1; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--navy);
  color: var(--white);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  z-index: 300;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red); }

/* ── Magic link page ── */
.magic-wrap {
  min-height: 100vh;
  background: var(--navy-dk);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.magic-card {
  background: var(--white);
  border-radius: 12px;
  overflow: hidden;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.magic-card-header {
  background: var(--navy);
  border-bottom: 3px solid var(--red);
  padding: 24px 28px;
}
.magic-card-brand {
  font-size: 13px;
  color: #8fa8c8;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
  margin-bottom: 6px;
}
.magic-card-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--white);
  line-height: 1.2;
}
.magic-card-body {
  padding: 28px;
}
.magic-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.magic-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--gray-lt);
  border-radius: 6px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 16px;
}
.magic-input:focus { border-color: var(--navy); }
.magic-submit {
  width: 100%;
  padding: 13px;
  background: var(--red);
  color: var(--white);
  border: none;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.magic-submit:hover { background: var(--red-lt); }
.magic-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 13px;
  color: #b91c1c;
  margin-bottom: 16px;
}
.magic-success {
  text-align: center;
  padding: 8px 0;
}
.magic-success-icon {
  font-size: 40px;
  margin-bottom: 12px;
}
.magic-success h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 8px;
}
.magic-success p {
  font-size: 13px;
  color: var(--gray);
  line-height: 1.6;
}
.magic-fine-print {
  padding: 16px 28px;
  border-top: 1px solid var(--gray-lt);
  font-size: 12px;
  color: var(--gray);
  text-align: center;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .leads-table { font-size: 12px; }
  .leads-table thead th,
  .leads-table tbody td { padding: 10px 10px; }
  .leads-table thead th:first-child,
  .leads-table tbody td:first-child { padding-left: 12px; }
  .dash-stats { gap: 10px; }
  .stat-card { padding: 12px 14px; min-width: 100px; }
  .stat-card .stat-number { font-size: 22px; }
  /* Hide less important columns on mobile */
  .col-type, .col-contractor { display: none; }
}

/* ── Mobile-first permit feed cards (≤ 640px) ── */
@media (max-width: 640px) {
  .dash-container { padding: 12px 12px; }

  /* Header compact */
  .dash-header { padding: 10px 0; }
  .dash-header-inner { padding: 0 12px; gap: 8px; }
  .dash-logo { font-size: 16px; }
  .dash-user-chip { display: none; } /* save space on narrow viewports */
  .dash-nav { gap: 10px; }
  .dash-logout { font-size: 12px; }

  /* Stats — 2-up grid on mobile */
  .dash-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 14px;
  }
  .stat-card { min-width: unset; padding: 10px 12px; }
  .stat-card .stat-number { font-size: 24px; }
  .stat-card .stat-label { font-size: 10px; }

  /* ── Sticky filter bar ── */
  .app-filter-bar-sticky {
    position: sticky;
    top: 56px; /* below sticky header */
    z-index: 90;
    background: #f7f8fa;
    border-bottom: 1px solid #e2e8f0;
    padding: 8px 12px;
    margin: 0 -12px 12px;
  }

  /* ── Permit card layout (replaces table on mobile) ── */
  .permit-cards { display: flex; flex-direction: column; gap: 10px; }
  .permit-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px 14px 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
  }
  .permit-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
  }
  .permit-card-address {
    font-weight: 700;
    font-size: 0.95rem;
    color: #0f172a;
    line-height: 1.25;
    flex: 1;
  }
  .permit-card-address a { color: #0f172a; text-decoration: none; }
  .permit-card-address a:hover { color: #c0392b; }
  .permit-card-value {
    font-weight: 800;
    font-size: 1rem;
    color: #1e293b;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .permit-card-badges { margin-bottom: 6px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
  .permit-card-meta {
    font-size: 0.78rem;
    color: #64748b;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 8px;
  }
  .permit-card-contractor {
    font-size: 0.82rem;
    color: #475569;
    font-weight: 500;
  }
  .permit-card-detail {
    /* expandable secondary info — hidden by default */
    display: none;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #f1f5f9;
    font-size: 0.8rem;
    color: #64748b;
  }
  .permit-card-detail.open { display: block; }
  .permit-card-toggle {
    background: none;
    border: none;
    font-size: 0.78rem;
    color: #94a3b8;
    cursor: pointer;
    padding: 0;
    margin-top: 4px;
    text-decoration: underline;
  }

  /* Call/text CTAs on permit card */
  .permit-card-actions { display: flex; gap: 8px; margin-top: 10px; }
  .btn-call, .btn-sms {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    cursor: pointer;
  }
  .btn-call { background: #166534; color: #fff; }
  .btn-sms  { background: #0369a1; color: #fff; }
  .btn-call:hover { background: #14532d; }
  .btn-sms:hover  { background: #075985; }

  /* Full-width contact reveal CTA on mobile */
  .contact-reveal-mobile {
    display: block;
    width: 100%;
    padding: 13px;
    background: #c0392b;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    margin-top: 10px;
    cursor: pointer;
  }

  /* Mobile filter bar horizontal scroll strip */
  .mobile-filter-strip {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .mobile-filter-strip::-webkit-scrollbar { display: none; }
  .mobile-filter-chip {
    flex-shrink: 0;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    white-space: nowrap;
  }
  .mobile-filter-chip.active {
    background: #c0392b;
    border-color: #c0392b;
    color: #fff;
  }

  /* Bottom sheet overlay for service filter */
  .bottom-sheet-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 400;
  }
  .bottom-sheet-overlay.open { display: block; }
  .bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-radius: 18px 18px 0 0;
    padding: 16px 16px 32px;
    z-index: 401;
    max-height: 70vh;
    overflow-y: auto;
  }
  .bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 0 auto 16px;
  }
  .bottom-sheet-title {
    font-size: 1rem;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 14px;
    text-align: center;
  }
  .bottom-sheet-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 4px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.9rem;
    color: #1e293b;
    cursor: pointer;
  }
  .bottom-sheet-item:last-child { border-bottom: none; }
  .bottom-sheet-item input[type="checkbox"] { width: 18px; height: 18px; accent-color: #c0392b; }
  .bottom-sheet-apply {
    width: 100%;
    padding: 13px;
    background: #c0392b;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 700;
    margin-top: 14px;
    cursor: pointer;
  }

  /* Email-this-view button (replaces Export CSV on mobile) */
  .email-view-btn {
    display: block;
    width: 100%;
    padding: 11px;
    background: #0f2a44;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    margin-top: 10px;
  }

  /* Hide desktop table on mobile, show cards */
  .permit-table-desktop { display: none !important; }
  .permit-cards-mobile  { display: flex !important; }

  /* Toast positioning — bottom so thumb can reach */
  .toast { bottom: 80px; right: 12px; left: 12px; text-align: center; }
}

/* ── Freshness badge (shared by dashboard + territory pages) ──────────────── */
.freshness-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid;
  background: #fff;
  white-space: nowrap;
}
.fresh-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  animation: fresh-pulse 2.5s ease-in-out infinite;
}
@keyframes fresh-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}
