:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #6b7684;
  --accent: #1a3a5c;
  --accent2: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --border: #e3e8ef;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Topbar ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
  background: linear-gradient(135deg, #1a3a5c, #2563eb);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.topbar h1 { font-size: 20px; font-weight: 700; letter-spacing: .3px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.btn-ghost {
  background: rgba(255,255,255,.15);
  color: #fff; border: none; border-radius: 8px;
  padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
}

/* Toggle vacíos */
.switch { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #e2e8f0; }
.switch input { display: none; }
.switch span {
  background: rgba(255,255,255,.2);
  border-radius: 20px; padding: 4px 12px; cursor: pointer;
  user-select: none; transition: background .2s;
}
.switch input:checked + span { background: var(--green); }

/* ── Contenedor / buscador ── */
.container { max-width: 640px; margin: 0 auto; padding: 14px 16px; }

.search-wrap { position: sticky; top: calc(60px + env(safe-area-inset-top)); z-index: 15; padding: 4px 0 8px; background: var(--bg); }

#search {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  outline: none;
}
#search:focus { border-color: var(--accent2); }

.hint { font-size: 12px; color: var(--muted); margin: 6px 2px 0; min-height: 16px; }

.status { padding: 12px; text-align: center; color: var(--muted); font-size: 14px; }

/* ── Resultados ── */
.results { list-style: none; margin-top: 6px; }
.results .empty { text-align: center; color: var(--muted); padding: 30px 0; font-size: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 10px;
}
.card .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card h3 { font-size: 16px; font-weight: 700; line-height: 1.25; }
.card h3 .conyuge { color: var(--muted); font-weight: 500; }

.card .meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.card .meta b { color: var(--ink); }

.badge {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 20px; white-space: nowrap;
}
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.np { background: #e2e8f0; color: #475569; }

.card .body { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }

/* Botones de acción */
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  flex: 1 1 auto; min-width: 0;
  padding: 11px 10px;
  border: none; border-radius: 10px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  text-decoration: none; color: #fff;
}
.btn:active { transform: scale(.98); }
.btn.call { background: var(--green); }
.btn.wa { background: #25d366; color: #063a17; }
.btn.vcf { background: var(--accent); }
.btn.share { background: var(--accent2); }
.btn.lbl { background: #eef1f6; color: var(--muted); }
.btn.edit { background: #eef1f6; color: var(--ink); }

/* ── Pie ── */
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 16px 0 8px; }

/* ── Dialogs / formulario ── */
dialog {
  border: none; border-radius: var(--radius);
  padding: 0; width: min(92vw, 440px);
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  color: var(--ink);
}
dialog::backdrop { background: rgba(0,0,0,.45); }

.edit-form { padding: 20px; }
.edit-form h2 { font-size: 18px; margin-bottom: 14px; }
.edit-form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.edit-form input, .edit-form textarea {
  display: block; width: 100%; margin-top: 4px;
  padding: 10px 12px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit;
}
.edit-actions { display: flex; gap: 10px; margin-top: 14px; }
.edit-actions button {
  flex: 1; padding: 12px; border: none; border-radius: 10px;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
#btnEditCancel, #btnLoginCancel, #btnLogClose { background: #eef1f6; color: var(--ink); }
#btnEditSave, #btnLoginSubmit { background: var(--accent2); color: #fff; }
.edit-msg { font-size: 13px; margin-top: 10px; }

.log-list { list-style: none; max-height: 50vh; overflow-y: auto; font-size: 13px; }
.log-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.log-list .t { color: var(--muted); font-size: 12px; }
.log-list .c { color: var(--red); text-decoration: line-through; }
.log-list .d { color: var(--green); }