/* ─────────────────────────────────────────────────────────────────────────────
   Sales Lead Finder — Mobile-first stylesheet
   Color scheme: #1a3a5c (primary) · #2d6a9f (accent) · #f0f4f8 (background)

   Structure:
     1. Reset & base
     2. Shared utilities (buttons, fields, errors)
     3. Login page
     4. App page
     5. Report (mobile cards → desktop table)
     6. Loading overlay
   ───────────────────────────────────────────────────────────────────────────── */

/* ── 1. Reset & base ─────────────────────────────────────────────────────── */

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

/* Ensure [hidden] always wins over display rules set by class selectors */
[hidden] { display: none !important; }

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f4f8;
  color: #1a1a1a;
  min-height: 100dvh;
}

/* ── 2. Shared utilities ─────────────────────────────────────────────────── */

.btn-primary {
  display: block;
  width: 100%;
  padding: 0.875rem 1rem;      /* 14px top/bottom — keeps tap target ≥ 44px */
  background: #2d6a9f;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover:not(:disabled)  { background: #1a3a5c; }
.btn-primary:disabled              { opacity: 0.6; cursor: not-allowed; }

.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: 1rem;
}

.field label {
  font-size: 0.875rem;
  font-weight: 500;
  color: #444;
}

.field input {
  padding: 0.75rem 0.875rem;   /* keeps tap target ≥ 44px */
  border: 1.5px solid #c9d4e0;
  border-radius: 8px;
  font-size: 1rem;
  color: #1a1a1a;
  background: #fff;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

.field input:focus {
  outline: none;
  border-color: #2d6a9f;
}

.error-msg {
  color: #c0392b;
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
}

/* ── 3. Login page ───────────────────────────────────────────────────────── */

.page-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.10);
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 400px;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1a3a5c;
  text-align: center;
  margin-bottom: 1.75rem;
}

/* ── 4. App page ─────────────────────────────────────────────────────────── */

.page-app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.25rem;
  background: #1a3a5c;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header-title  { font-size: 1.125rem; font-weight: 700; }

.app-header-logout {
  color: rgba(255,255,255,0.8);
  font-size: 0.875rem;
  text-decoration: none;
}
.app-header-logout:hover { color: #fff; text-decoration: underline; }

/* Main content */
.app-main {
  flex: 1;
  padding: 1.25rem 1rem;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

/* Card container used by each section */
.app-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  padding: 1.5rem 1.25rem;
  margin-bottom: 1rem;
}

.app-card--center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  text-align: center;
  padding: 2.5rem 1.25rem;
}

/* GPS button — extra visual weight */
.btn-gps { font-size: 1.0625rem; padding: 1rem; }

/* "— or —" divider */
.or-divider {
  text-align: center;
  color: #888;
  font-size: 0.875rem;
  margin: 1rem 0;
}

/* Text-only toggle button */
.btn-link {
  background: none;
  border: none;
  color: #2d6a9f;
  font-size: 0.9375rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  display: block;
  margin-bottom: 1rem;
}
.btn-link:hover { color: #1a3a5c; }

/* Manual section */
#manual-section { margin-top: 0.75rem; }

/* Subtle note shown after GPS failure */
.location-note {
  font-size: 0.875rem;
  color: #555;
  background: #fff8e1;
  border-left: 3px solid #f0a500;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  margin-bottom: 0.875rem;
}

/* Block-level error (used in error section) */
.error-msg--block { margin-bottom: 1rem; }

/* Generic app link */
.app-link {
  display: block;
  color: #2d6a9f;
  font-size: 0.875rem;
  text-decoration: none;
  margin-bottom: 1rem;
}
.app-link:hover { text-decoration: underline; }

/* Confirmed location display */
.confirmed-location {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  margin-bottom: 1rem;
  padding: 0.875rem 1rem;
  background: #eaf4ec;
  border-radius: 8px;
}

.confirmed-check {
  color: #27ae60;
  font-size: 1.25rem;
  line-height: 1.3;
  flex-shrink: 0;
}

.confirmed-text {
  color: #1a1a1a;
  font-size: 0.9375rem;
  word-break: break-word;
  line-height: 1.4;
}

/* Generate button — extra visual weight */
.btn-generate { font-size: 1.0625rem; padding: 1rem; }

/* Secondary button (download, new report) */
.btn-secondary {
  padding: 0.75rem 1rem;
  background: #fff;
  color: #2d6a9f;
  border: 1.5px solid #2d6a9f;
  border-radius: 8px;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-secondary:hover { background: #2d6a9f; color: #fff; }

/* Report action bar */
.report-actions {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.report-actions .btn-secondary { flex: 1; }

/* Loading spinner — basic; animation added in Step 5.2 */
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #c9d4e0;
  border-top-color: #2d6a9f;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  color: #555;
  font-size: 0.9375rem;
}

@media (min-width: 768px) {
  .app-main { max-width: 1100px; padding: 1.5rem 2rem; }
}

/* ── 5. Report ───────────────────────────────────────────────────────────── */

/* Outer wrapper — card shell around the whole report */
.report-wrap {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  overflow: hidden;
}

/* Report header */
.report-header {
  padding: 1rem 1.25rem 0.875rem;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
}

.report-title {
  font-size: 1.0625rem;
  font-weight: 700;
  color: #1a3a5c;
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.report-meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.8125rem;
  color: #555;
}

/* Filter bar — sticky below the app header on mobile */
.report-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  position: sticky;
  top: 49px;          /* height of .app-header */
  z-index: 9;
}

.rpt-filter-input {
  flex: 1 1 160px;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid #c9d4e0;
  border-radius: 6px;
  font-size: 0.875rem;
  background: #fff;
  -webkit-appearance: none;
}
.rpt-filter-input:focus { outline: none; border-color: #2d6a9f; }

.rpt-filter-select {
  flex: 1 1 130px;
  padding: 0.5rem 0.5rem;
  border: 1.5px solid #c9d4e0;
  border-radius: 6px;
  font-size: 0.875rem;
  background: #fff;
  cursor: pointer;
}

/* Results count */
.results-count {
  padding: 0.5rem 1.25rem;
  font-size: 0.8125rem;
  color: #666;
  background: #fff;
}

/* No results message */
.no-results {
  text-align: center;
  padding: 2.5rem 1rem;
  color: #888;
  font-size: 0.9375rem;
}

/* ── Distance badges ──────────────────────────────────────────────────────── */

.dist-badge {
  display: inline-block;
  padding: 0.2em 0.55em;
  border-radius: 12px;
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-green  { background: #d4edda; color: #155724; }
.badge-yellow { background: #fff3cd; color: #856404; }
.badge-red    { background: #fde8e8; color: #721c24; }

/* ── Stars & rating ───────────────────────────────────────────────────────── */

.stars        { color: #f0a500; letter-spacing: 0.04em; }
.rating-count { color: #999; font-size: 0.8125rem; }

/* ── Flag button ──────────────────────────────────────────────────────────── */

.flag-btn {
  background: none;
  border: 1px solid #ddd;
  border-radius: 4px;
  color: #999;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.2em 0.5em;
  line-height: 1.4;
}
.flag-btn:hover { background: #f5f5f5; color: #666; }

/* ── Mobile: card layout (default) ───────────────────────────────────────── */

.report-cards { padding: 0.5rem; }

.company-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.625rem;
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.375rem;
}

.card-name {
  font-weight: 700;
  font-size: 1rem;
  color: #1a3a5c;
  line-height: 1.3;
}

.card-address,
.card-contact { font-size: 0.875rem; color: #555; margin-bottom: 0.2rem; }

.card-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.625rem;
}

.card-phone {
  font-size: 1rem;
  font-weight: 700;
  color: #2d6a9f;
  text-decoration: none;
  white-space: nowrap;
}
.card-phone:hover { text-decoration: underline; }

.card-website {
  display: inline-block;
  margin-top: 0.375rem;
  font-size: 0.8125rem;
  color: #2d6a9f;
  text-decoration: none;
}
.card-website:hover { text-decoration: underline; }

/* Table hidden on mobile */
.report-table-wrap { display: none; }

/* ── Desktop: table layout ── ≥ 768px ────────────────────────────────────── */

@media (min-width: 768px) {
  /* Swap: hide cards, show table */
  .report-cards      { display: none; }
  .report-table-wrap { display: block; overflow-x: auto; }

  .report-title { font-size: 1.25rem; }

  .report-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
  }

  .report-table thead th {
    background: #1a3a5c;
    color: #fff;
    padding: 0.75rem 0.875rem;
    text-align: left;
    white-space: nowrap;
    font-weight: 600;
  }

  .report-table td {
    padding: 0.625rem 0.875rem;
    border-bottom: 1px solid #e2e8f0;
    vertical-align: top;
    line-height: 1.4;
  }

  /* Alternating row colors */
  .report-table tbody tr:nth-child(even) td { background: #f8fafc; }
  .report-table tbody tr:hover td          { background: #e8f0f8; transition: background 0.1s; }

  .report-table a { color: #2d6a9f; text-decoration: none; }
  .report-table a:hover { text-decoration: underline; }

  /* Column widths */
  .col-num     { width: 2.5rem; color: #999; text-align: right; }
  .col-name    { min-width: 160px; font-weight: 600; color: #1a3a5c; }
  .col-address { min-width: 180px; color: #555; font-size: 0.8125rem; }
  .col-contact { min-width: 120px; color: #555; font-size: 0.8125rem; }
  .col-phone   { white-space: nowrap; }
  .col-rating  { white-space: nowrap; }
  .col-dist    { white-space: nowrap; text-align: center; }
  .col-website { font-size: 0.8125rem; }
  .col-flag    { width: 4rem; text-align: center; }
}

/* ── Report footer / disclaimer ───────────────────────────────────────────── */

.report-footer {
  padding: 1rem 1.25rem;
  font-size: 0.8125rem;
  color: #888;
  border-top: 1px solid #e2e8f0;
  line-height: 1.7;
  background: #fafafa;
}

/* ── 6. Loading overlay ──────────────────────────────────────────────────── */

/* Full-viewport overlay — overrides the .app-card base styles when visible */
#section-loading:not([hidden]) {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  background: rgba(240, 244, 248, 0.94);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 50;
  /* reset app-card box styles */
  border-radius: 0;
  box-shadow: none;
  padding: 2rem;
}
