:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --ok-bg: #dcfce7;
  --wa: #16a34a;
  --wa-hover: #15803d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 18px 48px;
}

.header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.header h1 {
  margin: 0 0 4px;
  font-size: 1.5rem;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.grid-top {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
}

@media (max-width: 900px) {
  .grid-top {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.card-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
  color: var(--text);
}

textarea:focus,
input:focus,
select:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25);
  border-color: var(--primary);
}

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.hint {
  font-size: 0.82rem;
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 560px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--muted);
}

.field input,
.field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  background: #fff;
}

.field-full {
  margin-top: 12px;
}

.field-span-2 {
  grid-column: span 2;
}

@media (max-width: 560px) {
  .field-span-2 {
    grid-column: span 1;
  }
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.label-row label {
  margin-bottom: 0;
}

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.stat {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
}

.stat span {
  font-size: 1rem;
  margin-right: 4px;
}

.stat-warn {
  background: var(--warn-bg);
  border-color: #fde68a;
  color: #92400e;
}

.stat-ok {
  background: var(--ok-bg);
  border-color: #bbf7d0;
  color: #166534;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #e2e8f0;
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: #cbd5e1;
}

.btn-wa {
  background: var(--wa);
  color: #fff;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.btn-wa:hover {
  background: var(--wa-hover);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 6px;
}

.badge {
  background: #e2e8f0;
  color: var(--text);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-no {
  background: var(--warn-bg);
  color: #92400e;
}

.badge-yes {
  background: var(--ok-bg);
  color: #166534;
}

.results-header {
  flex-wrap: wrap;
  gap: 10px;
}

.results-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.filter-pills {
  display: inline-flex;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.pill-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.pill-btn:hover {
  color: var(--text);
}

.pill-btn.active {
  background: var(--primary);
  color: #ffffff;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th,
td {
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:hover {
  background: #f8fafc;
}

th {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.biz-col {
  max-width: 260px;
}

.biz-name {
  font-weight: 700;
  color: var(--text);
}

.biz-cat {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 3px;
}

.biz-addr {
  font-size: 0.78rem;
  color: #475569;
  margin-top: 6px;
  margin-bottom: 5px;
  line-height: 1.35;
}

.phone-col {
  white-space: nowrap;
}

.phone-value {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.btn-xs {
  padding: 4px 8px;
  font-size: 0.75rem;
}

.web-col {
  min-width: 120px;
}

.msg-box {
  width: 100%;
  min-width: 340px;
  min-height: 112px;
  font-size: 0.85rem;
  line-height: 1.5;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #ffffff;
}

.action-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 115px;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 32px 16px;
}

.web-toggle {
  cursor: pointer;
  border: none;
  font-family: inherit;
}

.web-url {
  display: block;
  font-size: 0.78rem;
  color: var(--primary);
  margin-top: 6px;
  word-break: break-all;
  text-decoration: none;
}

.web-url:hover,
.web-find-link:hover {
  text-decoration: underline;
}

.web-find-link {
  display: inline-block;
  font-size: 0.76rem;
  color: var(--primary);
  margin-top: 6px;
  text-decoration: none;
  font-weight: 600;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.86rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 999;
}

.toast.show {
  opacity: 1;
}

/* Mobile Optimization */
@media (max-width: 768px) {
  .container {
    padding: 14px 12px 36px;
  }

  .header {
    align-items: flex-start;
  }

  .header h1 {
    font-size: 1.25rem;
  }

  .subtitle {
    font-size: 0.88rem;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .btn {
    flex: 1;
    text-align: center;
  }

  .card {
    padding: 14px;
  }

  /* Prevent iOS/Android auto-zoom on input focus */
  textarea,
  .field input,
  .field select {
    font-size: 16px;
  }

  .input-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .input-footer .btn {
    width: 100%;
    padding: 11px 14px;
  }

  .stats-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .stat {
    text-align: center;
    padding: 8px 6px;
    font-size: 0.82rem;
  }

  .results-controls {
    width: 100%;
    justify-content: space-between;
  }

  .filter-pills {
    flex: 1;
    justify-content: space-between;
  }

  .pill-btn {
    flex: 1;
    text-align: center;
    padding: 6px 6px;
    font-size: 0.78rem;
  }

  /* Convert table rows into clean mobile cards */
  .table-wrap {
    overflow-x: visible;
  }

  #resultsTable,
  #resultsTable tbody,
  #resultsTable tr,
  #resultsTable td {
    display: block;
    width: 100%;
  }

  #resultsTable thead {
    display: none;
  }

  #resultsTable tbody tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 12px;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  }

  #resultsTable tbody tr:hover {
    background: #ffffff;
  }

  #resultsTable td {
    border-bottom: none;
    padding: 5px 0;
  }

  #resultsTable td:first-child {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--muted);
    padding-top: 0;
  }

  #resultsTable td:first-child::before {
    content: "#";
  }

  .biz-col {
    max-width: 100%;
  }

  .phone-col {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 0 !important;
    border-top: 1px dashed var(--border) !important;
    border-bottom: 1px dashed var(--border) !important;
    margin: 4px 0;
  }

  .phone-value {
    margin-bottom: 0;
  }

  .msg-box {
    min-width: 0;
    width: 100%;
    min-height: 105px;
    font-size: 0.9rem;
  }

  .action-stack {
    flex-direction: row;
    min-width: 0;
    margin-top: 4px;
  }

  .action-stack .btn {
    flex: 1;
    padding: 10px 12px;
    font-size: 0.88rem;
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 14px;
    text-align: center;
  }
}
