:root {
  --bg: #faf8f5;
  --panel: #ffffff;
  --ink: #2b2926;
  --muted: #7a7468;
  --accent: #6b5b95;
  --accent-soft: #ece7f5;
  --line: #e6e1d8;
  --warn-bg: #fff4e5;
  --warn-border: #e8b34d;
  --crisis-bg: #fdecec;
  --crisis-border: #d9534f;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.topbar .brand { font-weight: 600; font-size: 1.1rem; }
.topbar .brand small { color: var(--muted); font-weight: 400; margin-left: 8px; }

.lang-toggle button {
  background: none;
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
}
.lang-toggle button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.profile-bar {
  max-width: 720px;
  margin: 10px auto 0;
  padding: 0 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.profile-list { display: flex; flex-wrap: wrap; gap: 6px; }
.profile-chip-wrap {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 20px;
  overflow: hidden;
}
.profile-chip-wrap.active { background: var(--accent); border-color: var(--accent); }
.profile-chip {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 5px 6px 5px 12px;
  font-size: 0.82rem;
  cursor: pointer;
  font-family: inherit;
}
.profile-chip-wrap.active .profile-chip { color: white; }
.profile-del {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 5px 10px 5px 4px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.55;
}
.profile-del:hover { opacity: 1; color: #e5484d; }
.profile-chip-wrap.active .profile-del { color: rgba(255, 255, 255, 0.85); opacity: 0.85; }
.profile-chip-wrap.active .profile-del:hover { color: #fff; opacity: 1; }
.profile-form { display: flex; gap: 6px; }
.profile-form input {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 0.82rem;
  font-family: inherit;
}
.profile-form button {
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 0.82rem;
  cursor: pointer;
  font-weight: 600;
}

.chat-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px 140px;
  min-height: calc(100vh - 60px);
}

.msg {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.msg.user {
  background: var(--accent);
  color: white;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  background: var(--panel);
  border: 1px solid var(--line);
  margin-right: auto;
  border-bottom-left-radius: 4px;
}
.msg.system-note {
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
  margin: 8px auto;
  max-width: 100%;
}

.msg.crisis {
  background: var(--crisis-bg);
  border: 1px solid var(--crisis-border);
}
.msg.level1-flag {
  border-left: 3px solid var(--warn-border);
}

.sources {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 6px;
}

.composer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 14px 16px;
}
.composer form {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: inherit;
}
.composer button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0 20px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}
.composer button:disabled { opacity: 0.5; cursor: default; }

.disclaimer {
  max-width: 720px;
  margin: 0 auto 10px;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}

/* ---- age gate ---- */
.age-gate-overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 41, 38, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}
.age-gate-box {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 28px 26px;
  max-width: 440px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.age-gate-box h2 { margin-top: 0; font-size: 1.15rem; }
.age-gate-box p { color: var(--ink); font-size: 0.9rem; line-height: 1.5; }
.age-gate-box p em { color: var(--muted); font-style: italic; }
.age-gate-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.age-gate-actions button {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}
#age-confirm { background: var(--accent); color: white; }
.age-deny { background: var(--bg); color: var(--muted); border: 1px solid var(--line) !important; }

/* ---- admin panel ---- */
.admin-wrap { max-width: 900px; margin: 0 auto; padding: 24px 16px 60px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h2 { margin-top: 0; font-size: 1rem; }
.provider-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.provider-row:last-child { border-bottom: none; }
.provider-row select { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); }
.badge { font-size: 0.72rem; padding: 2px 8px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.stat-grid { display: flex; gap: 16px; flex-wrap: wrap; }
.stat { flex: 1; min-width: 120px; background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; }
.stat .num { font-size: 1.4rem; font-weight: 700; color: var(--accent); }
.stat .label { font-size: 0.75rem; color: var(--muted); }
nav.tabs { max-width: 900px; margin: 0 auto; padding: 10px 16px 0; }
nav.tabs a { color: var(--muted); text-decoration: none; margin-right: 16px; font-size: 0.9rem; }
nav.tabs a.active { color: var(--accent); font-weight: 600; }

/* ---------- Autenticacion (login / registro / salir) ---------- */
.topbar-right { display: flex; align-items: center; gap: 12px; }
.auth-user { font-size: 0.8rem; color: var(--muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-btn { border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 20px; padding: 4px 14px; font-size: 0.8rem; cursor: pointer; }
.logout-btn:hover { color: var(--accent); border-color: var(--accent); }

.auth-box { min-width: 300px; max-width: 360px; }
.auth-tabs { display: flex; gap: 8px; justify-content: center; margin: 4px 0 16px; }
.auth-tabs button { border: none; background: transparent; color: var(--muted); font-size: 0.9rem; padding: 6px 10px; cursor: pointer; border-bottom: 2px solid transparent; }
.auth-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
#login-form, #register-form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.auth-box input[type="email"], .auth-box input[type="password"] { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 0.95rem; font-family: inherit; }
.auth-box form > button[type="submit"] { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 10px; font-size: 0.95rem; cursor: pointer; font-weight: 600; }
.auth-box form > button[type="submit"]:hover { filter: brightness(1.08); }
.auth-check { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--muted); }
.auth-check input { width: auto; }
.auth-error { background: var(--crisis-bg); color: var(--crisis-border); border: 1px solid var(--crisis-border); border-radius: 8px; padding: 8px 10px; font-size: 0.85rem; margin-bottom: 10px; }
