:root {
  color-scheme: dark;
  --primary: #2b7cd3;
  --primary-dark: #1f63b0;
  --navy: #0b2b4f;
  --bg: #0a1628;
  --card: #14253d;
  --field: #0e1d33;
  --text: #f1f5f9;
  --muted: #8fa3bf;
  --border: #243b5c;
  --gold: #d4af37;
  --green: #43a047;
  --danger: #ef5350;
  --radius: 14px;
  --nav-h: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
.hidden { display: none !important; }
#app { max-width: 620px; margin: 0 auto; min-height: 100vh; }

/* Encabezado */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--primary); color: #fff;
  padding: 14px 16px; font-size: 1.25rem; font-weight: 700;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar .logo { display: flex; align-items: center; gap: 8px; }
.topbar .logo img { height: 30px; width: 30px; border-radius: 8px; }
.topbar button.icon {
  background: rgba(255,255,255,.15); border: 0; color: #fff;
  border-radius: 10px; padding: 8px 10px; font-size: 1rem;
}

/* Formularios */
.form-wrap { padding: 32px 20px; max-width: 420px; margin: 0 auto; }
.form-wrap h1 { text-align: center; margin-bottom: 6px; }
.form-wrap p.sub { text-align: center; color: var(--muted); margin-top: 0; }
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
label { display: block; font-size: .85rem; font-weight: 600; margin: 12px 0 4px; }
input[type=text], input[type=password], input[type=email], input[type=tel], input[type=date], input[type=number], select, textarea {
  width: 100%; padding: 12px; font-size: 1rem;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-family: inherit; background: var(--field); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
textarea { min-height: 110px; resize: vertical; }
.btn {
  display: block; width: 100%; padding: 14px; margin-top: 16px;
  background: var(--primary); color: #fff; border: 0; border-radius: 12px;
  font-size: 1.05rem; font-weight: 700; cursor: pointer;
}
.btn:active { background: var(--primary-dark); }
.btn.secondary { background: #22344f; color: var(--text); }
.btn.danger { background: var(--danger); }
.link { text-align: center; margin-top: 14px; color: var(--muted); font-size: .95rem; }
.link a { color: var(--primary); font-weight: 600; }
.error { color: var(--danger); font-size: .9rem; margin-top: 8px; text-align: center; }

/* Historias */
.stories-bar {
  display: flex; gap: 12px; overflow-x: auto; padding: 14px 12px 6px;
  scrollbar-width: none;
}
.stories-bar::-webkit-scrollbar { display: none; }
.story-thumb {
  flex: 0 0 auto; width: 68px; text-align: center; cursor: pointer;
  border: 0; background: none; padding: 0;
}
.story-thumb .ring {
  width: 62px; height: 62px; border-radius: 50%;
  padding: 3px; background: conic-gradient(var(--primary), #a78bfa, var(--primary));
}
.story-thumb img {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover;
  border: 2.5px solid var(--card); display: block; background: #22344f;
}
.story-thumb .sname { font-size: .7rem; margin-top: 4px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 68px; }
.story-thumb.add .ring { background: var(--border); }

/* Publicaciones */
.post { background: var(--card); border-radius: var(--radius); margin: 12px; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.post-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: #22344f; flex: 0 0 auto; }
.post-head .who { flex: 1; min-width: 0; }
.post-head .who b { display: block; font-size: .95rem; }
.post-head .who small { color: var(--muted); font-size: .78rem; }
.post-head .del { background: none; border: 0; color: var(--muted); font-size: 1.1rem; }
.post-text { padding: 0 14px 12px; white-space: pre-wrap; word-wrap: break-word; }
.post-media img, .post-media video { width: 100%; max-height: 70vh; object-fit: contain; background: #000; display: block; }
.post-actions { display: flex; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--border); }
.post-actions button {
  flex: 1; background: none; border: 0; padding: 10px; font-size: .95rem;
  color: var(--muted); font-weight: 600; border-radius: 8px;
}
.post-actions button.liked { color: var(--danger); }
.post-actions button:active { background: var(--bg); }
.comments { padding: 0 14px 12px; }
.comment { display: flex; gap: 8px; margin: 8px 0; font-size: .9rem; }
.comment .avatar { width: 30px; height: 30px; }
.comment-form { display: flex; gap: 8px; margin-top: 8px; }
.comment-form input { flex: 1; padding: 10px; border: 1.5px solid var(--border); border-radius: 20px; font-size: .9rem; }
.comment-form button { background: var(--primary); color: #fff; border: 0; border-radius: 20px; padding: 0 16px; font-weight: 700; }

/* Navegación inferior */
#bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; align-items: stretch; justify-content: space-around;
}
#bottomnav button {
  flex: 1; background: none; border: 0; font-size: 1.4rem; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
#bottomnav button span { font-size: .68rem; }
#bottomnav button.active { color: var(--primary); }
#bottomnav button.fab {
  background: var(--primary); color: #fff; font-size: 1.8rem;
  width: 56px; height: 56px; border-radius: 50%; flex: 0 0 auto;
  align-self: center; box-shadow: 0 4px 12px rgba(79,70,229,.4);
}

/* Visor de historias */
#story-viewer {
  position: fixed; inset: 0; z-index: 50; background: #000;
  display: flex; flex-direction: column;
}
#story-viewer .s-top {
  display: flex; align-items: center; gap: 10px; padding: 14px; color: #fff;
  background: linear-gradient(rgba(0,0,0,.5), transparent); z-index: 2;
}
#story-viewer .s-top .avatar { width: 36px; height: 36px; }
#story-viewer .s-top .grow { flex: 1; }
#story-viewer .s-top button { background: rgba(255,255,255,.2); border: 0; color: #fff;
  border-radius: 8px; padding: 8px 12px; font-size: 1rem; }
#story-viewer .s-media { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; }
#story-viewer img, #story-viewer video { max-width: 100%; max-height: 100%; object-fit: contain; }
#story-viewer .s-nav { display: flex; }
#story-viewer .s-nav button {
  flex: 1; background: rgba(255,255,255,.08); border: 0; color: #fff;
  padding: 18px; font-size: 1.3rem;
}

/* Perfil */
.profile-head { text-align: center; padding: 28px 16px 8px; }
.profile-head .avatar { width: 96px; height: 96px; margin: 0 auto; }
.profile-head h2 { margin: 10px 0 2px; }
.profile-head .uname { color: var(--muted); margin: 0 0 8px; }
.profile-head .bio { color: var(--text); margin: 0 0 8px; white-space: pre-wrap; }
.menu-list { margin: 12px; }
.menu-list button {
  display: block; width: 100%; text-align: left; background: var(--card);
  border: 0; border-bottom: 1px solid var(--border); padding: 16px; font-size: 1rem;
}
.menu-list button:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.menu-list button:last-child { border-bottom: 0; border-radius: 0 0 var(--radius) var(--radius); }

/* Admin */
.tabs { display: flex; gap: 8px; padding: 12px; }
.tabs button { flex: 1; padding: 10px; border: 0; border-radius: 10px; background: #22344f; color: var(--text); font-weight: 600; }
.tabs button.active { background: var(--primary); color: #fff; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.row .grow { flex: 1; min-width: 0; }
.row small { color: var(--muted); display: block; }
.chip { background: rgba(43,124,211,.18); color: #7fb3ec; border-radius: 20px; padding: 4px 10px; font-size: .75rem; font-weight: 700; }
.mini-btn { background: #22344f; color: var(--text); border: 0; border-radius: 8px; padding: 8px 12px; font-size: .85rem; font-weight: 600; }
.mini-btn.danger { background: rgba(239,83,80,.15); color: var(--danger); }

/* Varios */
#toast {
  position: fixed; bottom: calc(var(--nav-h) + 20px); left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff; padding: 12px 20px; border-radius: 24px;
  font-size: .9rem; z-index: 60; max-width: 90vw; text-align: center;
}
.preview img, .preview video { width: 100%; border-radius: 10px; margin-top: 10px; max-height: 40vh; object-fit: contain; background: #000; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.file-label {
  display: block; text-align: center; padding: 14px; margin-top: 12px;
  border: 2px dashed var(--border); border-radius: 12px; color: var(--muted); font-weight: 600;
}
input[type=file] { display: none; }
.loading { text-align: center; padding: 40px; color: var(--muted); }

/* Árbol genealógico */
.tree-wrap { position: relative; }
.tree-scroll { overflow: auto; background: var(--bg); border-radius: var(--radius); margin: 12px;
  border: 1px solid var(--border); max-height: 62vh; }
.tree-zoom { position: sticky; top: 0; display: flex; gap: 8px; padding: 10px; z-index: 5;
  background: rgba(10,22,40,.92); }
.tree-zoom button { background: var(--primary); color: #fff; border: 0; border-radius: 8px;
  padding: 8px 14px; font-size: 1rem; font-weight: 700; }
.tnode text { pointer-events: none; font-family: inherit; }
.unlinked { margin: 12px; }
.unlinked-grid { display: flex; flex-wrap: wrap; gap: 10px; padding: 4px 12px 16px; }
.unlinked-grid button {
  display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--border);
  border-radius: 24px; padding: 6px 14px 6px 6px; font-size: .9rem;
}
.unlinked-grid .avatar { width: 32px; height: 32px; }

/* ---------- Pantalla de acceso (login) ---------- */
.login-page { min-height: 100vh; background: var(--bg); padding-bottom: 24px; }
.login-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--navy); color: #fff;
  position: sticky; top: 0; z-index: 20;
}
.login-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.3rem; letter-spacing: .04em; }
.login-brand img { width: 38px; height: 38px; border-radius: 10px; }
.login-brand small { display: block; font-size: .68rem; font-weight: 400; opacity: .75; letter-spacing: .12em; }
.login-lang {
  background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 20px;
  padding: 8px 14px; font-size: .9rem; font-weight: 600; cursor: pointer;
}
.login-hero { position: relative; overflow: hidden; }
.login-hero img { width: 100%; height: 300px; object-fit: cover; display: block; }
.login-hero .hero-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center;
  padding: 24px; background: linear-gradient(90deg, rgba(10,30,60,.55) 0%, rgba(10,30,60,.15) 55%, transparent 100%);
  color: #fff;
}
.login-hero h1 { margin: 0; font-size: 2.6rem; letter-spacing: .06em; text-shadow: 0 2px 12px rgba(0,0,0,.45); }
.login-hero .slogan { margin: 6px 0; font-size: 1.25rem; font-weight: 700; line-height: 1.3; text-shadow: 0 1px 8px rgba(0,0,0,.45); }
.login-hero .desc { margin: 4px 0 0; font-size: .98rem; opacity: .95; max-width: 340px; text-shadow: 0 1px 6px rgba(0,0,0,.45); }
.login-card {
  background: #fff; color: #1f2937; border-radius: 22px; margin: -34px 16px 0;
  padding: 26px 22px; position: relative; z-index: 5;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
}
.login-card h2 { margin: 0; font-size: 1.7rem; text-align: center; }
.login-card .sub { text-align: center; color: #6b7280; margin: 6px 0 18px; }
.login-field { position: relative; margin-bottom: 12px; }
.login-field .fi { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-size: 1.15rem; opacity: .55; }
.login-field input {
  width: 100%; padding: 15px 44px 15px 46px; font-size: 1rem; color: #1f2937;
  border: 1.5px solid #e5e7eb; border-radius: 14px; background: #f9fafb;
}
.login-field input:focus { outline: none; border-color: var(--primary); background: #fff; }
.login-field .toggle-pass {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: 0; font-size: 1.2rem; padding: 8px; cursor: pointer; opacity: .6;
}
.btn-login {
  width: 100%; padding: 16px; margin-top: 6px; border: 0; border-radius: 14px;
  background: var(--navy); color: #fff; font-size: 1.1rem; font-weight: 700; cursor: pointer;
}
.btn-login:active { background: var(--primary-dark); }
.btn-login:disabled { opacity: .6; }
.login-options { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; font-size: .9rem; }
.login-options label { display: flex; align-items: center; gap: 8px; color: #4b5563; cursor: pointer; }
.login-options input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); }
.login-options a { color: var(--primary); font-weight: 600; text-decoration: none; }
.login-error { color: var(--danger); font-size: .9rem; margin-top: 10px; text-align: center; min-height: 1.2em; }
.register-card {
  display: flex; align-items: center; gap: 14px; margin: 14px 16px 0; padding: 18px;
  background: rgba(43,124,211,.12); border: 1.5px solid rgba(43,124,211,.35); border-radius: 18px;
  color: var(--text); cursor: pointer; width: calc(100% - 32px); text-align: left; font: inherit;
}
.register-card .rc-icon { font-size: 2rem; }
.register-card small { color: var(--muted); font-weight: 700; letter-spacing: .08em; font-size: .72rem; }
.register-card b { display: block; font-size: 1.25rem; margin: 2px 0; }
.register-card p { margin: 0; color: var(--muted); font-size: .92rem; }
.register-card .rc-go { margin-left: auto; font-size: 1.6rem; color: var(--primary); }
.trust-badges { display: flex; gap: 8px; margin: 20px 16px 0; }
.trust-badges div {
  flex: 1; text-align: center; font-size: .78rem; color: var(--muted); line-height: 1.35;
}
.trust-badges .tb-icon {
  width: 52px; height: 52px; margin: 0 auto 6px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
}
.login-version { text-align: center; color: var(--muted); font-size: .75rem; margin-top: 18px; opacity: .6; }
@media (min-width: 720px) {
  .login-hero img { height: 380px; }
  .login-hero h1 { font-size: 3.4rem; }
  .login-card { max-width: 480px; margin-left: auto; margin-right: auto; }
  .register-card { max-width: 480px; margin-left: auto; margin-right: auto; }
  .trust-badges { max-width: 520px; margin-left: auto; margin-right: auto; }
}

/* Hoja inferior (sheet) */
#sheet { position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center; }
.sheet-body { background: var(--card); border-radius: 20px 20px 0 0; padding: 20px; width: 100%;
  max-width: 620px; padding-bottom: calc(24px + env(safe-area-inset-bottom));
  max-height: 92vh; max-height: 92dvh; overflow-y: auto; }
.sheet-body .who { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.sheet-body .who .avatar { width: 56px; height: 56px; }
