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

:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --wa: #25d366;
  --wa-dark: #1eba58;
  --tg: #0088cc;
  --tg-dark: #0070a8;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 16px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --shadow-md: 0 4px 20px rgba(0,0,0,.10);

  /* Touch targets mínimos iOS/Android */
  --touch: 52px;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  /* Evita zoom en inputs en iOS */
  font-size: 16px;
}

.hidden { display: none !important; }

/* ══════════════════════════════
   LOGIN
══════════════════════════════ */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  background: linear-gradient(160deg, #1e40af 0%, #3b82f6 60%, #60a5fa 100%);
}

.login-card {
  background: var(--surface);
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  padding: 2.25rem 1.5rem 2rem;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 76px;
  height: 76px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 50%;
  margin-bottom: 1.25rem;
}

.login-card h1 {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.02em;
  margin-bottom: .25rem;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: .95rem;
  margin-bottom: 2rem;
}

.field {
  text-align: left;
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: .4rem;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.field input {
  width: 100%;
  height: var(--touch);
  padding: 0 1rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;         /* >= 16px evita zoom en iOS */
  color: var(--text);
  background: #f8fafc;
  outline: none;
  -webkit-appearance: none;
  transition: border-color .18s, box-shadow .18s;
}

.field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37,99,235,.15);
  background: #fff;
}

.error-msg {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: .7rem 1rem;
  font-size: .9rem;
  margin-bottom: .75rem;
  text-align: left;
}

#loginBtn {
  width: 100%;
  height: var(--touch);
  margin-top: .5rem;
  background: var(--primary);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .18s;
  letter-spacing: .01em;
}

#loginBtn:active { background: var(--primary-dark); }
#loginBtn:disabled { opacity: .55; }


/* ══════════════════════════════
   DASHBOARD — TOPBAR
══════════════════════════════ */
.dashboard-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--primary);
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 2px 10px rgba(37,99,235,.35);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  height: 56px;
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 800;
  font-size: 1.1rem;
  color: #fff;
  letter-spacing: -.01em;
}

.logout-btn {
  background: rgba(255,255,255,.18);
  border: none;
  border-radius: 8px;
  padding: .45rem .9rem;
  font-size: .88rem;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s;
  height: 38px;
}

.logout-btn:active { background: rgba(255,255,255,.3); }


/* ══════════════════════════════
   SEARCH SECTION (sticky bajo topbar)
══════════════════════════════ */
.search-section {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 56px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}

.search-inner {
  max-width: 700px;
  margin: 0 auto;
  padding: .85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .65rem;
}

/* Tabs de tipo */
.search-type-tabs {
  display: flex;
  gap: .5rem;
}

.tab {
  flex: 1;
  height: 42px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: none;
  font-size: .92rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all .18s;
}

.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.tab:not(.active):active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* Input de búsqueda */
.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 1rem;
  color: var(--text-muted);
  pointer-events: none;
  flex-shrink: 0;
}

#searchInput {
  width: 100%;
  height: var(--touch);
  padding: 0 3rem 0 3rem;
  border: 2px solid var(--border);
  border-radius: 14px;
  font-size: 1rem;          /* >= 16px evita zoom iOS */
  color: var(--text);
  background: #f8fafc;
  outline: none;
  -webkit-appearance: none;
  transition: border-color .18s, box-shadow .18s;
}

#searchInput:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37,99,235,.15);
  background: #fff;
}

.clear-btn {
  position: absolute;
  right: .65rem;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--border);
  border: none;
  border-radius: 50%;
  color: var(--text-muted);
  font-size: .9rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s;
}

.clear-btn:active { background: #cbd5e1; }


/* ══════════════════════════════
   CONTENIDO PRINCIPAL
══════════════════════════════ */
.main {
  flex: 1;
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
  padding: 1rem 1rem 5rem;
}

.status-msg {
  font-size: .88rem;
  color: var(--text-muted);
  padding: .25rem .25rem .75rem;
}

.status-msg.error { color: #dc2626; }

/* ── Estado vacío ── */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
}

.empty-state svg { opacity: .25; margin-bottom: 1rem; }
.empty-state p { font-size: 1rem; }


/* ══════════════════════════════
   TARJETA DE CONTACTO
══════════════════════════════ */
.results-list {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.contact-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  /* Animación de entrada */
  animation: slideIn .2s ease both;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-header {
  display: flex;
  align-items: center;
  gap: .9rem;
  padding: 1rem 1rem .75rem;
}

.card-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  color: #fff;
  font-size: 1.3rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: -.02em;
}

.card-name-wrap { flex: 1; min-width: 0; }

.card-name {
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.25;
  /* Permitir wrap en nombres largos */
  overflow-wrap: break-word;
}

.card-colonia {
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: .1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Info de dirección y teléfono */
.card-body {
  padding: 0 1rem .85rem;
  display: flex;
  flex-direction: column;
  gap: .55rem;
}

.card-row {
  display: flex;
  align-items: baseline;
  gap: .5rem;
}

.card-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  min-width: 70px;
  flex-shrink: 0;
}

.card-value {
  font-size: .95rem;
  color: var(--text);
  overflow-wrap: break-word;
}

/* Separador */
.card-divider {
  height: 1px;
  background: var(--border);
  margin: 0;
}

/* Botones de acción — grandes y fáciles de tocar */
.card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.btn-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  height: var(--touch);   /* 52px — bien para dedos */
  font-size: .95rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: .01em;
  border: none;
  transition: filter .15s;
}

.btn-action:active { filter: brightness(.88); }

.btn-wa {
  background: var(--wa);
  color: #fff;
  border-right: 1px solid rgba(255,255,255,.2);
  border-radius: 0 0 0 var(--radius);
}

.btn-tg {
  background: var(--tg);
  color: #fff;
  border-radius: 0 0 var(--radius) 0;
}

.btn-action.disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: default;
  pointer-events: none;
}

/* ══════════════════════════════
   TABLET / DESKTOP
══════════════════════════════ */
@media (min-width: 600px) {
  .results-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
  }

  .contact-card {
    /* En grid, los botones siguen en la parte baja */
    display: flex;
    flex-direction: column;
  }

  .card-body { flex: 1; }
}

@media (min-width: 900px) {
  .results-list {
    grid-template-columns: repeat(3, 1fr);
  }
}
