:root {
  --bg: #f6f5fb;
  --card: #ffffff;
  --text: #1b1a23;
  --muted: #5c596c;
  --line: #e7e5f0;
  --field: #f3f2f8;
  --accent: #5140c9;
  --accent-soft: #ece9ff;
  --brand: var(--accent);
  --danger: #962438;
  --danger-soft: #fde8ec;
  --ok: #215c3c;
  --ok-soft: #e2f6ec;
  --warn: #674400;
  --warn-soft: #fdf2dc;
  --shadow: 0 1px 2px rgb(30 25 60 / 0.08);
  --radius: 12px;
  --font: system-ui, "Segoe UI", sans-serif;
  --font-title: var(--font);
  --card-padding: 16px;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
/* Oscuro: la clase la pone js/theme.js (según el teléfono o lo que elija cada uno). */
:root.dark {
  --bg: #0f0f14;
  --card: #18181f;
  --text: #eeedf3;
  --muted: #aaa7ba;
  --line: #272733;
  --field: #20202a;
  --accent: #b0a6ff;
  --accent-soft: #262245;
  --danger: #ff6b81;
  --danger-soft: #3a1d24;
  --ok: #46d08f;
  --ok-soft: #173126;
  --warn: #f0b552;
  --warn-soft: #362a14;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.25);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text); font-family: var(--font); }
h1, h2, .brand { font-family: var(--font-title); }
h1 { font-size: 1.5rem; letter-spacing: -0.02em; margin: 0 0 4px; }
h2 { font-size: 1.05rem; letter-spacing: -0.01em; margin: 0 0 12px; }
p { margin: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }

.icon {
  width: 1.15em; height: 1.15em; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* --- Marca --- */
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 750; font-size: 1.2rem; letter-spacing: -0.02em; }
.brand-mark { position: relative; display: inline-block; flex: none; width: 30px; height: 30px; border-radius: calc(var(--radius) * 0.45); background: var(--accent); }
.brand-mark::before, .brand-mark::after { content: ''; position: absolute; width: 42%; height: 42%; border-radius: 50%; background: var(--card); }
.brand-mark::before { left: 18%; top: 24%; }
.brand-mark::after { left: 40%; top: 36%; opacity: 0.6; }

/* --- Encabezado --- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.top nav { display: flex; align-items: center; gap: 4px; }
.navlink {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 36px; min-height: 36px; padding: 4px 8px;
  --button-bg: var(--bg);
  --button-text: var(--muted);
  text-decoration: none; font-weight: 600; font-size: 0.92rem;
}
.navlink.active { --button-bg: var(--accent-soft); --button-text: var(--accent); --button-border: var(--accent); }
.navlink.me { padding: 2px; }

main { max-width: 620px; margin: 0 auto; padding: 16px 14px 48px; }
.page-title { margin: 8px 4px 16px; }

/* --- Tarjetas --- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--card-padding); margin-bottom: 16px; box-shadow: var(--shadow); }
.card.highlight { border-color: var(--accent); }
.fade-in { animation: fade-in 0.15s ease-out both; }
@keyframes fade-in { from { opacity: 0; } }

/* --- Avatares (iniciales con color fijo por usuario) --- */
.avatar {
  --size: 40px;
  width: var(--size); height: var(--size); flex: none; border-radius: 50%;
  display: inline-grid; place-items: center;
  font-weight: 700; font-size: calc(var(--size) * 0.38); letter-spacing: 0.02em; color: #fff;
  background: hsl(var(--h) 55% 23%);
  user-select: none;
}
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar.clear { background: none; border-color: transparent !important; }
.avatar.clear img { border-radius: 0; } /* la forma la da la propia foto */
.avatar-edit { position: relative; padding: 0; border-color: transparent; background: none; border-radius: 50%; }
.avatar-edit:hover .cam, .avatar-edit:active .cam { background: var(--text); }
.avatar-edit .cam {
  position: absolute; right: -2px; bottom: -2px; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent); color: var(--bg); border: 3px solid var(--card);
}
.avatar-edit .cam .icon { width: 14px; height: 14px; }
.avatar.sm { --size: 32px; }
.avatar.lg { --size: 72px; }

/* --- Formularios --- */
label { display: block; margin-bottom: 12px; }
label > span { display: block; font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
input, textarea {
  width: 100%; font: inherit; color: inherit; background: var(--field);
  border: 1px solid var(--line); border-radius: min(8px, var(--radius)); padding: 12px;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:focus, textarea:focus { background: var(--card); border-color: var(--accent); }
textarea { resize: none; min-height: 48px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.error { color: var(--danger); font-size: 0.9rem; margin: 4px 0 10px; }
.ok { color: var(--ok); font-size: 0.9rem; margin: 4px 0 10px; }
.error:empty, .ok:empty { display: none; }

/* --- Botones --- */
:where(button, .navlink, .btn-link, .look-option) {
  border: 1px solid var(--button-border, var(--line));
  border-radius: min(8px, var(--radius));
  background: var(--button-bg, var(--field));
  color: var(--button-text, var(--text));
  cursor: pointer;
}
:where(button, .navlink, .btn-link, .look-option):where(:not(:disabled, [aria-disabled="true"])):hover {
  border-color: var(--button-hover-border, var(--accent));
  background-color: var(--button-hover, var(--accent-soft));
}
:where(button, .navlink, .btn-link, .look-option):where(:not(:disabled, [aria-disabled="true"])):active {
  border-color: var(--button-hover-border, var(--accent));
  background-color: var(--button-press, color-mix(in srgb, var(--accent-soft) 92%, var(--accent)));
}
:where(button, .navlink, .btn-link, .look-option):is(:disabled, [aria-disabled="true"]) {
  opacity: 0.55;
  cursor: default;
}
:where(button, a, input, textarea, .look-option, .bubble):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
:where(button) {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 650; font-size: 0.95rem;
  min-height: 36px; padding: 8px 16px;
}
:where(button:not([class]), button[class=""], button.primary) {
  --button-bg: var(--accent);
  --button-text: var(--bg);
  --button-border: var(--accent);
  --button-hover: color-mix(in srgb, var(--accent) 88%, var(--text));
  --button-press: color-mix(in srgb, var(--accent) 76%, var(--text));
}
button.block { width: 100%; min-height: 44px; padding: 8px 12px; }
button.ghost { --button-bg: transparent; --button-text: var(--muted); --button-border: transparent; }
button.soft { --button-bg: var(--field); --button-text: var(--text); --button-border: var(--line); }
button.danger {
  --button-text: var(--danger);
  --button-hover: var(--danger-soft);
  --button-press: color-mix(in srgb, var(--danger-soft) 94%, var(--danger));
  --button-hover-border: var(--danger);
}
button.icon-only { min-width: 36px; padding: 4px; }
button.sm { min-height: 32px; padding: 4px 8px; font-size: 0.85rem; }

/* --- Login e invitación --- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-box { width: 100%; max-width: 380px; }
.auth-head { text-align: center; margin-bottom: 20px; }
.auth-head .brand-mark { width: 56px; height: 56px; margin-bottom: 12px; }
.auth-head p { color: var(--muted); }
.auth .card { padding: calc(var(--card-padding) + 4px); }

/* --- Composer --- */
.composer-top { display: flex; gap: 12px; align-items: flex-start; }
.composer textarea { background: transparent; padding: 8px 2px; border: 0; font-size: 1.05rem; }
.composer textarea:focus { background: transparent; }
.preview-wrap { position: relative; margin: 10px 0 0 52px; width: fit-content; max-width: calc(100% - 52px); }
.preview-wrap img { display: block; max-height: 280px; max-width: 100%; border-radius: 14px; }
.preview-wrap button { position: absolute; top: 8px; right: 8px; --button-bg: var(--card); }
.composer-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.composer-bar .primary { margin-left: auto; }
@media (max-width: 400px) { .composer-tools button { padding-inline: 8px; } }

/* --- Posts --- */
.post { padding: var(--card-padding); }
.post-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.post-head .who { flex: 1; min-width: 0; line-height: 1.25; }
.post-head strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.post-head time { color: var(--muted); font-size: 0.82rem; }
.post-tools { display: flex; flex: none; }
.post-tools button { padding: 4px; }
.edited { color: var(--muted); font-size: 0.78rem; }
.edit-form { margin: 0 0 10px; }
.edit-form textarea { background: var(--field); border: 1px solid var(--line); }
.edit-form .row { margin-top: 6px; }
.comment .edit-form { flex: 1; margin: 0; }
.comment .post-tools { margin-left: auto; }
.post .body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 1.02rem; margin-bottom: 10px; }
.post .body:last-child { margin-bottom: 0; }
/* Fotos del post: una sola a todo el ancho; varias en grilla. */
.gallery { display: grid; gap: 3px; margin: 0 calc(-1 * var(--card-padding)); }
.gallery .cell { position: relative; overflow: hidden; cursor: zoom-in; background: var(--field); }
.gallery .photo { display: block; width: 100%; height: 100%; object-fit: cover; }
.gallery.n1 .photo { height: auto; max-height: 75vh; }
.gallery.n2 { grid-template-columns: 1fr 1fr; aspect-ratio: 2 / 1; }
.gallery.n3 { grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; aspect-ratio: 3 / 2; }
.gallery.n3 .cell:first-child { grid-row: span 2; }
.gallery.n4 { grid-template-columns: 1fr 1fr; aspect-ratio: 1; }
.gallery .more { position: absolute; inset: 0; display: grid; place-items: center; background: rgb(0 0 0 / 0.45); color: #fff; font-size: 1.7rem; font-weight: 700; }

/* --- Encuestas --- */
.composer-tools { display: flex; gap: 2px; }
.composer-tools button { color: var(--accent); }
.poll-editor { margin: 10px 0 0 52px; padding: 10px; border: 1px dashed var(--line); border-radius: 14px; }
.poll-editor-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.poll-option-row { display: flex; gap: 4px; align-items: center; margin-bottom: 6px; }
.poll { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.poll-option {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%;
  padding: 8px 12px; font-weight: 600; text-align: left;
  /* El corte de color conserva la barra de porcentaje de cada respuesta. */
  background-image: linear-gradient(to right, var(--poll-fill, var(--accent-soft)) var(--pct), transparent var(--pct));
}
.poll-option.mine { --button-border: var(--accent); }
.poll-option:where(:not(:disabled, [aria-disabled="true"])):hover { --poll-fill: color-mix(in srgb, var(--accent-soft) 96%, var(--accent)); }
.poll-option:where(:not(:disabled, [aria-disabled="true"])):active { --poll-fill: color-mix(in srgb, var(--accent-soft) 92%, var(--accent)); }
.poll-text { display: flex; align-items: center; gap: 6px; min-width: 0; overflow-wrap: anywhere; }
.poll-text .icon { color: var(--accent); }
.poll-pct { color: var(--muted); font-size: 0.88rem; flex: none; }
.poll-foot { display: flex; align-items: center; gap: 6px; }

/* --- Reacciones y comentarios --- */
.post-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; }
.post-foot > button { padding: 4px 8px; font-size: 0.9rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  min-height: 28px; padding: 4px 8px; font-size: 0.88rem; font-weight: 600;
}
.chip.mine { --button-bg: var(--accent-soft); --button-text: var(--accent); --button-border: var(--accent); }
.emoji-picker {
  display: flex; flex-wrap: wrap; gap: 4px; width: fit-content; margin-top: 8px; padding: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.emoji-picker .emoji, .msg-actions .emoji {
  --button-bg: transparent; --button-border: transparent;
  min-width: 32px; min-height: 32px; font-size: 1.2rem; padding: 2px 4px;
}
.comments { margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.comment { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 10px; }
.comment-bubble { background: var(--field); border-radius: min(4px, var(--radius)) var(--radius) var(--radius); padding: 8px 12px; min-width: 0; max-width: 100%; }
.comment-bubble strong { font-size: 0.85rem; }
.comment-bubble p { white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-bubble time { font-size: 0.75rem; color: var(--muted); }
.comment > button { margin-left: auto; }
.comment-form { display: grid; gap: 6px; }
.comment-input-row, .comment-attachments { display: flex; gap: 8px; align-items: center; }
.comment-input-row input { min-width: 0; padding: 8px 12px; }
.comment-attachments { padding-inline-start: 40px; flex-wrap: wrap; }
.comment-attachment {
  display: flex; align-items: center; gap: 4px; min-width: 0; max-width: 100%;
  padding-inline-start: 8px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--muted); font-size: 0.85rem;
}
.comment-attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.comment-attachment button { flex: none; }
.attachment-media { margin-block: 6px; color: var(--muted); font-size: 0.85rem; }
.attachment-media:empty { display: none; }
.attachment-media :is(img, video, audio) { display: block; max-width: 100%; }
.attachment-media :is(img, video) {
  max-height: 360px; object-fit: contain; border-radius: var(--radius); background: var(--card);
}
.attachment-media audio { width: 260px; }
.attachment-photo { display: block; max-width: 100%; padding: 0; border: 0; background: var(--card); border-radius: var(--radius); }
.attachment-photo img { cursor: zoom-in; }
.audio-recorder { min-width: 36px; }
/* Grabando: la barra de grabación ocupa todo el formulario (como en WhatsApp). */
.is-recording > :not(.rec-bar) { display: none !important; }
.rec-bar { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; width: 100%; }
.rec-dot { width: 10px; height: 10px; flex: none; border-radius: 50%; background: var(--danger); animation: rec-blink 1s ease-in-out infinite; }
.rec-bar.paused .rec-dot { animation: none; opacity: 0.4; }
.rec-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.rec-state { flex: 1; min-width: 0; color: var(--muted); font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-bar button { flex: none; width: 40px; height: 40px; padding: 0; border-radius: 50%; }
@keyframes rec-blink { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .rec-dot { animation: none; } }

/* --- Chat --- */
.chat-main { display: flex; flex-direction: column; height: calc(100dvh - 58px); padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 4px 4px 12px; }
.chat-head h1 { font-size: 1.25rem; margin: 0; }
.online { display: flex; align-items: center; gap: 8px; }
.stack { display: flex; }
.stack .avatar { border: 2px solid var(--bg); margin-left: -8px; }
.stack .avatar:first-child { margin-left: 0; }
.avatar.xs { --size: 26px; }
.chat-list {
  flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 12px; display: flex; flex-direction: column; gap: 2px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.chat-list .older { align-self: center; margin-bottom: 10px; }
.chat-list .empty { margin: auto; }
.msg { display: flex; align-items: flex-end; gap: 8px; max-width: 82%; }
.msg.first { margin-top: 8px; }
.msg.mine { align-self: flex-end; }
.avatar-gap { width: 32px; flex: none; }
.bubble { background: var(--field); padding: 8px 12px 4px; border: 1px solid transparent; border-radius: var(--radius); min-width: 0; }
.msg.first:not(.mine) .bubble { border-bottom-left-radius: min(4px, var(--radius)); }
.msg.mine .bubble { background: var(--accent-soft); color: var(--text); }
.msg.mine.first .bubble { border-bottom-right-radius: min(4px, var(--radius)); }
.bubble strong { display: block; font-size: 0.8rem; color: var(--accent); }
.bubble p { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble time { display: block; text-align: right; font-size: 0.7rem; color: var(--muted); margin-top: 2px; }
.msg-col { display: flex; flex-direction: column; min-width: 0; }
.msg.mine .msg-col { align-items: flex-end; }
.bubble { cursor: pointer; }
.bubble.active { border-color: var(--accent); }
.quote {
  display: block; width: 100%; text-align: left; margin: 0 0 4px; padding: 4px 8px;
  --button-bg: var(--card);
  --button-hover: var(--field);
  --button-press: var(--card);
  border-left: 3px solid var(--accent); font-weight: 400; font-size: 0.85rem;
}
.quote strong { display: block; font-size: 0.78rem; }
.quote span { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.msg-reactions .chip { padding: 1px 8px; font-size: 0.8rem; }
.msg-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin-top: 4px; padding: 4px 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.msg.flash .bubble { border-color: var(--accent); background: var(--accent-soft); }
.reply-bar {
  display: flex; align-items: center; gap: 8px; margin-top: 10px; padding: 8px 8px 8px 12px;
  background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 12px;
}
.reply-bar .grow { flex: 1; min-width: 0; }
.reply-bar strong { display: block; font-size: 0.82rem; }
.reply-bar span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; }
.chat-form textarea { max-height: 140px; }
.chat-form button { width: 46px; height: 46px; }
.feed-status { padding: 18px 0 8px; }
.empty { text-align: center; padding: 36px 16px; }
.empty .big { font-size: 2.4rem; margin-bottom: 8px; }

/* --- Panel desde abajo --- */
.sheet {
  width: min(520px, 100vw); max-height: 75dvh; margin: auto auto 0; padding: 0; border: 0;
  border-radius: var(--radius) var(--radius) 0 0; background: var(--card); color: var(--text); box-shadow: var(--shadow);
}
@media (min-width: 600px) { .sheet { margin: auto; border-radius: var(--radius); } }
.sheet::backdrop { background: rgb(8 8 12 / 0.5); }
.sheet[open] { animation: fade-in 0.2s ease-out; }
.sheet-head { padding: 16px 18px 6px; position: sticky; top: 0; background: var(--card); }
.sheet-head h2 { margin: 0; }
.sheet-body { padding: 4px 18px 22px; overflow-y: auto; }
.react-group { padding: 10px 0; border-bottom: 1px solid var(--line); }
.react-group:last-child { border-bottom: 0; }
.react-emoji { display: flex; align-items: center; gap: 8px; font-size: 1.3rem; margin-bottom: 6px; }
.person { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-radius: 10px; color: inherit; text-decoration: none; font-weight: 600; }
.person:hover { background: var(--field); }
.who-reacted {
  --button-bg: transparent; --button-text: var(--muted); --button-border: transparent;
  min-height: 28px; font-weight: 600; font-size: 0.85rem; padding: 4px 8px; text-decoration: underline;
}

/* --- Vistas previas al publicar --- */
.preview-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 0 52px; }
.preview-grid .preview-wrap { margin: 0; }
.preview-grid img { width: 92px; height: 92px; object-fit: cover; border-radius: 12px; max-height: none; }
.preview-grid .preview-wrap button { top: 4px; right: 4px; padding: 4px; }

/* --- Visor de fotos --- */
.lightbox { padding: 0; border: 0; background: transparent; max-width: 100vw; max-height: 100dvh; cursor: zoom-out; }
.lightbox::backdrop { background: rgb(8 8 12 / 0.88); }
.lightbox img { display: block; max-width: 96vw; max-height: 92dvh; border-radius: 10px; }
.lb-nav {
  position: fixed; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; padding: 0;
  --button-bg: var(--card);
  font-size: 2rem; line-height: 1;
}
.lb-nav.prev { left: 10px; }
.lb-nav.next { right: 10px; }
.lb-count { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); color: var(--text); background: var(--card); padding: 4px 12px; border-radius: min(8px, var(--radius)); font-size: 0.85rem; font-weight: 600; }

/* --- Links a perfiles --- */
.who-link { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.who-link:hover strong, a.name:hover strong { text-decoration: underline; }
a.name { color: inherit; text-decoration: none; }
.bubble a.name strong { color: var(--accent); }
.back { display: inline-block; margin: 4px 4px 0; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.9rem; }
.back:hover { color: var(--accent); }

/* --- Perfil público --- */
.avatar.xl { --size: 112px; border: 4px solid var(--card); }
.profile-card { text-align: center; padding: 0; overflow: hidden; }
.profile-body { padding: 0 16px 20px; }
.profile-card .avatar-view, .profile-card .profile-body > .avatar { margin-top: -56px; position: relative; }
.profile-card .avatar { margin-bottom: 12px; }
.cover { aspect-ratio: 3 / 1; background: var(--accent-soft); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover.small { border-radius: 12px; overflow: hidden; }
.bio { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 46ch; margin: 10px auto 0 !important; }
.field { margin-bottom: 12px; }
.field-label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.counter { display: block; text-align: right; margin-top: 4px; }
.profile-card p { margin-top: 4px; }
.avatar-view { padding: 0; background: none; border-color: transparent; border-radius: 50%; cursor: zoom-in; }
.avatar-view:hover .avatar, .avatar-view:active .avatar { border-color: var(--accent-soft); }
.btn-link {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 16px; padding: 8px 12px;
  text-decoration: none; font-weight: 650; font-size: 0.88rem;
}
.tabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 16px; background: var(--field); border-radius: var(--radius); }
.tab { flex: 1; --button-bg: transparent; --button-text: var(--muted); --button-border: transparent; padding: 8px; }
.tab.active { --button-bg: var(--card); --button-text: var(--text); --button-border: var(--accent); }
.tab .count { font-size: 0.78rem; padding: 0 4px; border-radius: min(4px, var(--radius)); background: var(--field); color: var(--muted); }
.tab.active .count { background: var(--accent-soft); color: var(--accent); }

/* --- Instalar la app --- */
.install { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.install img { width: 44px; height: 44px; border-radius: 11px; flex: none; }
.install .grow { flex: 1; min-width: 0; }
.install p { margin-top: 2px; }
.nudge-icon { width: 44px; height: 44px; border-radius: 11px; flex: none; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.nudge-icon .icon { width: 22px; height: 22px; }

/* --- Perfil --- */
.profile-head { display: flex; align-items: center; gap: 16px; }
.profile-head h1 { margin: 0; }

/* --- Etiquetas de estado --- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 650; background: var(--field); color: var(--muted); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge .icon { width: 0.9em; height: 0.9em; }

/* --- Admin --- */
.user-row { display: flex; gap: 12px; align-items: center; }
.user-row .who { flex: 1; min-width: 0; }
.user-row .who strong { margin-right: 6px; }
.user-row .badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.user.blocked .avatar { filter: grayscale(1); opacity: 0.6; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.linkbox { display: flex; gap: 8px; margin: 10px 0; }
.linkbox input { font-family: ui-monospace, 'Cascadia Code', Menlo, monospace; font-size: 0.82rem; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 4px 10px; }

/* --- Buscador --- */
.search-bar { display: flex; align-items: center; gap: 10px; padding: 6px 14px; color: var(--muted); }
.search-bar input { background: none; border: 0; padding: 10px 0; font-size: 1.05rem; }
.search-bar input:focus { background: none; }

/* --- Menciones --- */
.mention { color: var(--accent); font-weight: 600; text-decoration: none; }
.mention:hover { text-decoration: underline; }
.msg.mine .mention { text-decoration: underline; }
.mention-box {
  position: fixed; z-index: 60; padding: 4px; max-height: 230px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.mention-item {
  display: flex; justify-content: flex-start; align-items: center; gap: 8px; width: 100%; padding: 4px 8px;
  --button-bg: transparent; --button-border: transparent;
  font-weight: 600; text-align: left;
}
.mention-item.active { --button-bg: var(--accent-soft); --button-border: var(--accent); }

/* --- Avisos --- */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: var(--radius);
  font-weight: 600; font-size: 0.92rem; box-shadow: var(--shadow);
  transition: opacity 0.2s, transform 0.2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); }

@media (max-width: 480px) {
  .navlink .label { display: none; }
  main { padding-inline: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .fade-in, .sheet[open] { animation: none; }
  .toast { transition: none; }
}

/* --- Bienvenida: elegir apariencia la primera vez --- */
.welcome { max-width: 620px; margin: 0 auto; padding: max(28px, env(safe-area-inset-top)) 16px 40px; }
.welcome h1 { margin-bottom: 6px; }
.welcome > p { margin-bottom: 18px; }
.welcome .look-grid { margin-bottom: 8px; }
.welcome .tabs { margin-bottom: 22px; }
.subhead { font-size: 0.85rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 18px 0 8px; }

/* --- Editor de encuadre --- */
.frame-view { position: relative; width: 100%; overflow: hidden; background: var(--field); border-radius: var(--radius); touch-action: none; cursor: grab; user-select: none; }
.frame-view:active { cursor: grabbing; }
.frame-view.round { width: min(100%, 280px); margin: 0 auto; border-radius: 50%; }
.frame-view img { position: absolute; top: 0; left: 0; max-width: none; transform-origin: 0 0; pointer-events: none; }
.zoom { display: flex; align-items: center; gap: 10px; margin: 14px 0 6px; }
.zoom input { flex: 1; padding: 0; accent-color: var(--accent); }
.frame-actions { justify-content: flex-end; margin-top: 12px; }

/* --- Barra de scroll con los colores de la apariencia (en lugar de la gris del sistema) --- */
/* scrollbar-color se hereda: vale también para el chat, los paneles y las listas con scroll propio. */
html { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--accent) 55%, var(--line)) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--accent) 55%, var(--line)); border: 3px solid transparent; border-radius: 999px; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--accent); }
::-webkit-scrollbar-corner { background: transparent; }

/* --- Avisos en vivo (abajo a la derecha) --- */
.live-toasts { position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 70; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 32px)); pointer-events: none; }
.live-toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 6px 10px 12px; cursor: pointer; pointer-events: auto;
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: var(--radius); box-shadow: var(--shadow); animation: fade-in 0.2s ease-out;
}
.live-toast.red { border-left-color: var(--danger); }
.live-body { flex: 1; min-width: 0; }
.live-top { display: flex; align-items: center; gap: 6px; }
.live-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9rem; }
.live-tag { flex: none; padding: 1px 7px; border-radius: 999px; font-size: 0.7rem; font-weight: 700; background: var(--accent-soft); color: var(--accent); }
.live-toast.red .live-tag { background: var(--danger-soft); color: var(--danger); }
.live-body p { margin: 2px 0 0; font-size: 0.88rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.live-close { flex: none; padding: 4px; color: var(--muted); }
@media (max-width: 480px) { .live-toasts { right: 12px; left: 12px; width: auto; } }

/* --- Chat: volver al feed --- */
.chat-back { margin: 0; flex: none; }
.chat-title { flex: 1; min-width: 0; }
@media (max-width: 480px) { .chat-title h1 { font-size: 1.05rem; } }

/* --- Perfil con la apariencia y el fondo de su dueño --- */
.profile-page { color: var(--text); font-family: var(--font); }
.profile-page h1, .profile-page h2 { font-family: var(--font-title); }
.profile-bg { position: fixed; inset: 0; z-index: 0; background: var(--bg); pointer-events: none; }
.profile-bg img { width: 100%; height: 100%; object-fit: cover; display: block; }
.profile-page > :not(.profile-bg) { position: relative; z-index: 1; }
.profile-page .tabs { background: color-mix(in srgb, var(--card) 88%, transparent); }
.bg-preview { height: 120px; border-radius: 12px; overflow: hidden; background: var(--field); }
.bg-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.profile-page .feed-status:not(:empty) { background: color-mix(in srgb, var(--card) 90%, transparent); border-radius: var(--radius); padding: 14px; color: var(--muted); }

/* --- Chat: fotos, audios y encuestas --- */
.chat-tools { display: flex; align-items: center; flex: none; }
.chat-tools button { padding: 8px; color: var(--muted); }
.chat-tools button:hover { color: var(--accent); }
.bubble img, .bubble video { display: block; max-width: min(260px, 100%); max-height: 320px; border-radius: calc(var(--radius) * 0.6); margin: 4px 0; }
.bubble audio { display: block; width: min(260px, 70vw); margin: 4px 0; }
.chat-poll { min-width: min(240px, 66vw); margin: 6px 0 2px; }
.msg.mine .chat-poll .poll-option { color: var(--text); }
.msg.mine .chat-poll .poll-foot { color: inherit; opacity: 0.8; }
.chat-poll-form input { margin-bottom: 8px; }
.chat-form textarea { min-width: 0; flex: 1; }
@media (max-width: 480px) { .chat-tools button { padding: 6px; } .chat-form { gap: 6px; } }
/* En pantallas anchas, "← Feed" sale del encabezado del chat y queda al costado izquierdo, fuera del cuadro. */
@media (min-width: 900px) {
  .chat-main { position: relative; }
  .chat-back {
    position: absolute; right: 100%; top: 16px; margin-right: 12px; white-space: nowrap;
    padding: 8px 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text);
  }
  .chat-back:hover { border-color: var(--accent); color: var(--accent); }
}

/* --- Panel lateral plegable --- */
.top-left { display: flex; align-items: center; gap: 6px; }
.side {
  position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: 264px; max-width: 86vw;
  display: flex; flex-direction: column; gap: 2px; overflow-y: auto; overscroll-behavior: contain;
  padding: max(10px, env(safe-area-inset-top)) 10px max(14px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: var(--card); color: var(--text); font-family: var(--font); border-right: 1px solid var(--line);
  transform: translateX(-100%); visibility: hidden; transition: transform 0.2s ease, visibility 0.2s;
}
.side-open .side { transform: none; visibility: visible; }
.side-backdrop { position: fixed; inset: 0; z-index: 39; background: rgb(0 0 0 / 0.4); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.side-open .side-backdrop { opacity: 1; pointer-events: auto; }
.side-head { display: flex; align-items: center; justify-content: space-between; min-height: 36px; margin: 0 0 8px 6px; }
.side-close { --button-bg: transparent; --button-border: transparent; --button-text: var(--muted); padding: 6px; }
.side-link, .side-me, .side-person {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 10px; border-radius: var(--radius);
  color: inherit; text-decoration: none; font: inherit; font-weight: 600; font-size: 0.92rem; text-align: left;
  --button-bg: transparent; --button-border: transparent; --button-text: var(--text);
}
.side-link .icon { width: 19px; height: 19px; color: var(--muted); flex: none; }
.side-link:hover, .side-me:hover, .side-person:hover { background: var(--field); }
.side-link.active, .side-me.active, .side-person.active { background: var(--accent-soft); color: var(--accent); }
.side-link.active .icon { color: var(--accent); }
.side-link.danger, .side-link.danger .icon { color: var(--danger); --button-text: var(--danger); }
.side-me { margin-bottom: 6px; border: 1px solid var(--line); }
.side-who { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.side-who strong, .side-who small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-who small { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-title { display: flex; justify-content: space-between; align-items: baseline; margin: 16px 10px 4px; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.side-count { text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--ok); }
.side-people { display: flex; flex-direction: column; gap: 2px; }
.side-person { padding: 6px 10px; }
.side-avatar { position: relative; display: inline-flex; }
.side-person.online .side-avatar::after {
  content: ''; position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--ok); border: 2px solid var(--card);
}
.side-empty { padding: 6px 10px; font-size: 0.88rem; }
.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
@media (prefers-reduced-motion: reduce) { .side, .side-backdrop { transition: none; } }

/* --- Reproductor de audio (estilo mensaje de voz; igual en todos los navegadores) --- */
.audio-player { display: flex; align-items: center; gap: 10px; width: min(300px, 72vw); max-width: 100%; padding: 2px 0; }
.audio-play {
  flex: none; width: 38px; height: 38px; padding: 0; border-radius: 50%;
  --button-bg: var(--accent); --button-text: var(--bg); --button-border: transparent;
  --button-hover: color-mix(in srgb, var(--accent) 85%, var(--text)); --button-hover-border: transparent;
}
.audio-play .icon { width: 16px; height: 16px; }
.audio-wave { position: relative; flex: 1; min-width: 0; height: 30px; display: flex; align-items: center; gap: 2px; }
.audio-wave span { flex: 1; height: 30%; min-height: 3px; border-radius: 2px; background: color-mix(in srgb, var(--muted) 45%, transparent); transition: background-color 0.1s; }
.audio-wave span.on { background: var(--accent); }
/* El control real (accesible, se arrastra) va invisible encima de las barras. */
.audio-seek { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.audio-seek:focus-visible { opacity: 0.25; }
.audio-time { flex: none; min-width: 2.6em; font-size: 0.78rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.audio-speed {
  flex: none; min-width: 34px; padding: 2px 6px; border-radius: 999px; font-size: 0.75rem; font-weight: 700;
  --button-bg: transparent; --button-text: var(--muted);
}
@media (prefers-reduced-motion: reduce) { .audio-wave span { transition: none; } }
