/*
  Dos temas: "light" (clásico: barras oscuras y mensajes sobre fondo claro) y "dark" (todo oscuro).
  Un canal puede cambiar --surface (fondo de los mensajes), --text y --accent; el resto se deriva.
*/
body {
  color-scheme: dark;
  --surface: #232c37;
  --text: #e8edf2;
  --accent: #3b6fd4;
  --bar: #1a222b;
  --bar-text: #ffffff;
  --bar-muted: #9aa6b4;
  --field: #10161d;
  --field-text: #ffffff;
  --field-border: #3a4757;
  --bg: color-mix(in srgb, var(--surface), #000 40%);
  --hover: color-mix(in srgb, var(--surface), var(--text) 5%);
  --alt: color-mix(in srgb, var(--surface), #000 22%);
  --line: color-mix(in srgb, var(--surface), var(--text) 10%);
  --muted: color-mix(in srgb, var(--text) 52%, var(--surface));
  --link: #8fb4e8;
  --danger: #ee8a8a;
}
body.light {
  color-scheme: light;
  --surface: #f3f4f6;
  --text: #2c343e;
  --accent: #55606e;
  --bar: #2b333d;
  --field: #ffffff;
  --field-text: #2c343e;
  --field-border: #ffffff;
  --bg: color-mix(in srgb, var(--surface), #2c343e 14%);
  --hover: color-mix(in srgb, var(--surface), #ffffff 60%);
  --alt: color-mix(in srgb, var(--surface), #2c343e 9%);
  --line: color-mix(in srgb, var(--surface), #2c343e 12%);
  --link: #2f5fc0;
  --danger: #c0392b;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid #7fa6f5; outline-offset: 2px; }

.chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  background: var(--surface);
}

/* --- Panel superior: saludo y caja para escribir --- */

.panel { background: var(--bar); color: var(--bar-text); }
.login { display: flex; flex-direction: column; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 16px; border: 0;
  background: #3b6fd4; color: #fff; font-size: 15px; font-weight: 700;
}
.google-btn:hover { background: #4a7de0; }
.google-btn .g {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff; color: #3b6fd4; font-weight: 900;
}
.dev-form { display: flex; gap: 8px; padding: 10px 12px; }
.dev-form input { flex: 1; min-width: 0; }

.session { display: flex; align-items: center; gap: 10px; padding: 10px 12px 0; }
.hello { flex: 1; min-width: 0; font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: #e0a030; color: #1f2a36; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 3px; }
.panel .link { color: var(--bar-muted); }
.panel .link:hover { color: var(--bar-text); }

.composer { padding: 10px 12px 12px; }
.row { display: flex; gap: 8px; align-items: stretch; }
textarea, input {
  padding: 9px 10px; border-radius: 3px; border: 1px solid var(--field-border);
  background: var(--field); color: var(--field-text); font-size: 14px;
}
.field { position: relative; flex: 1; min-width: 0; display: flex; }
textarea { flex: 1; min-width: 0; resize: none; line-height: 1.35; padding-right: 40px; }
textarea:focus, input:focus { outline: 2px solid #7fa6f5; outline-offset: 0; }
textarea::placeholder, input::placeholder { color: #8b96a3; }
.send-btn, .dev-form button {
  padding: 8px 14px; border: 0; border-radius: 3px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; letter-spacing: .03em; text-transform: uppercase;
}
.send-btn { min-width: 104px; padding: 0 22px; font-size: 16px; }
.send-btn:hover:not(:disabled) { filter: brightness(1.12); }
.send-btn:disabled { opacity: .6; cursor: default; }
.emoji-btn {
  position: absolute; right: 6px; bottom: 6px; width: 30px; height: 30px; padding: 0;
  border: 0; border-radius: 50%; background: transparent; font-size: 19px; line-height: 1;
}
.emoji-btn:hover, .emoji-btn[aria-expanded="true"] { background: rgba(127, 127, 127, .22); }
.emoji-panel {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 2px;
  max-height: 170px; overflow-y: auto; margin-top: 8px; padding: 6px;
  background: var(--field); border-radius: 3px;
}
.emoji-panel button { background: none; border: 0; padding: 4px 0; font-size: 22px; line-height: 1.2; border-radius: 3px; }
.emoji-panel button:hover { background: rgba(127, 127, 127, .2); }
.notice { margin-top: 8px; color: #ffb4a8; font-size: 13px; }
.notice.info { color: var(--bar-text); }
.note { margin: 0; padding: 12px; text-align: center; color: var(--bar-muted); }
.note.warn { color: #ffb4a8; }

.status { background: #b8860b; color: #fff; text-align: center; padding: 6px; font-size: 13px; }

.bans { background: var(--hover); border-bottom: 1px solid var(--line); padding: 8px 12px; font-size: 13px; }
.bans summary { cursor: pointer; color: var(--muted); }
.bans ul { list-style: none; margin: 8px 0 0; padding: 0; }
.bans li { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }

/* --- Mensajes (los más nuevos arriba) --- */

.feed { position: relative; flex: 1; min-height: 0; }
.messages { height: 100%; overflow-y: auto; }
.empty { color: var(--muted); text-align: center; padding: 32px 16px; }
.empty p { margin: 0 0 4px; }
.empty-title { font-weight: 700; color: var(--text); }

.msg { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.msg.alt { background: var(--alt); }
.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 2px; object-fit: cover;
  display: inline-flex; align-items: center; justify-content: center;
  background: #4a6fa5; color: #fff; font-weight: 700; font-size: 17px;
}
.avatar.small { width: 26px; height: 26px; font-size: 12px; }
.body { flex: 1; min-width: 0; }
.head { display: flex; align-items: baseline; gap: 8px; }
.name { font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.time { flex: none; margin-left: auto; font-size: 11.5px; color: var(--muted); }
.text { margin-top: 2px; line-height: 1.4; overflow-wrap: anywhere; white-space: pre-wrap; }
.text.jumbo { font-size: 30px; line-height: 1.2; }
.meta { display: flex; gap: 12px; margin-top: 4px; }

.link { background: none; border: 0; padding: 0; color: var(--link); font-size: 12px; text-decoration: none; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--danger); }

.new-btn {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%);
  padding: 7px 14px; border: 0; border-radius: 3px; font-size: 13px; font-weight: 700;
  background: #3b6fd4; color: #fff; box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
}

/* --- Pie --- */

.foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px));
  background: var(--bar); color: var(--bar-muted); font-size: 11.5px;
}
.foot a { color: var(--bar-muted); text-decoration: none; }
.foot a:hover { color: var(--bar-text); text-decoration: underline; }
.foot-brand { font-weight: 700; letter-spacing: .02em; }
