:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel-2: #202c33;
  --line: #2a3942;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --accent-dark: #008069;
  --bubble: #202c33;
  --bubble-me: #005c4b;
  --shadow: 0 12px 40px rgba(0, 0, 0, .5);
  --radius: 14px;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

button, input, textarea { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: currentColor; flex: none; }
.hidden { display: none !important; }

.screen { height: 100%; display: flex; flex-direction: column; }

/* ---------- login ---------- */

#login { justify-content: center; align-items: center; padding: 24px; background: radial-gradient(circle at 50% 0%, #12312c, var(--bg) 60%); }

.card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 24px 22px;
  box-shadow: var(--shadow);
  text-align: center;
}

.logo { border-radius: 18px; }
.card h1 { margin: 14px 0 4px; font-size: 22px; }
.sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
label { display: block; text-align: left; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

#name-input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  outline: none;
}

#name-input:focus { border-color: var(--accent); }

.btn {
  width: 100%;
  margin-top: 14px;
  padding: 13px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #04231d;
  font-weight: 700;
  cursor: pointer;
}

.btn:active { background: var(--accent-dark); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); font-weight: 500; }
.btn.small { margin-top: 10px; padding: 9px; font-size: 13px; }
.status { min-height: 18px; margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.status.error { color: #f15c6d; }

/* ---------- topbar ---------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent-dark);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #e9edef;
  flex: none;
}

.titles { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.titles strong { font-size: 16px; }
.titles span { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: none;
}

.icon-btn:active { background: var(--panel-2); }
.icon-btn.tiny { width: 30px; height: 30px; }
.icon-btn.tiny svg { width: 17px; height: 17px; }

/* ---------- mensajes ---------- */

#log {
  flex: 1;
  overflow-y: auto;
  padding: 14px 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background-color: var(--bg);
  background-image: radial-gradient(rgba(255, 255, 255, .028) 1px, transparent 1px);
  background-size: 22px 22px;
}

.day { align-self: center; margin: 14px 0 8px; }
.day span {
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  text-transform: capitalize;
}

.sys { align-self: center; margin: 6px 0; }
.sys span {
  background: rgba(32, 44, 51, .85);
  color: var(--muted);
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 999px;
  text-align: center;
  display: inline-block;
  max-width: 85%;
}

.row-wrap { display: flex; margin-top: 2px; }
.row-wrap.me { justify-content: flex-end; }

.bubble {
  max-width: min(78%, 560px);
  background: var(--bubble);
  border-radius: 10px;
  box-shadow: 0 1px .5px rgba(0, 0, 0, .3);
  padding: 7px 9px 5px;
  position: relative;
  user-select: none;
}

.me .bubble { background: var(--bubble-me); }
.bubble.group-start { border-top-left-radius: 4px; margin-top: 8px; }
.me .bubble.group-start { border-top-left-radius: 10px; border-top-right-radius: 4px; }

.bubble .author { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.bubble p { margin: 0; font-size: 15px; line-height: 1.35; white-space: pre-wrap; word-break: break-word; }

.quote {
  display: block;
  border-left: 4px solid var(--accent);
  background: rgba(0, 0, 0, .22);
  border-radius: 6px;
  padding: 5px 8px;
  margin-bottom: 5px;
  font-size: 13px;
  color: var(--muted);
  max-height: 54px;
  overflow: hidden;
}

.quote b { display: block; color: var(--accent); font-size: 12.5px; }
.quote i { font-style: normal; }

.bubble img.photo {
  display: block;
  max-width: 100%;
  max-height: 340px;
  width: auto;
  border-radius: 8px;
  margin-bottom: 4px;
  background: var(--panel-2);
  cursor: zoom-in;
}

.meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  float: right;
  margin: 6px -2px -2px 8px;
  font-size: 11px;
  color: var(--muted);
  user-select: none;
}

.meta .checks { color: #53bdeb; display: inline-flex; }
.meta .checks svg { width: 16px; height: 16px; }

.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin: 5px -2px -2px; }
.react {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12.5px;
  line-height: 1.5;
  cursor: pointer;
}

.react.mine { border-color: var(--accent); background: rgba(0, 168, 132, .18); }
.react.pop { animation: pop .28s ease; }

@keyframes pop { 0% { transform: scale(.5); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }

/* ---------- composer ---------- */

#composer {
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 8px 10px max(10px, env(safe-area-inset-bottom));
  z-index: 5;
}

.row { display: flex; align-items: flex-end; gap: 8px; }
.row textarea {
  flex: 1;
  max-height: 116px;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 22px;
  border: 0;
  background: var(--panel-2);
  resize: none;
  outline: none;
  line-height: 1.35;
}

.send-btn {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #04231d;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: none;
  transition: transform .16s, opacity .16s;
}

.send-btn:disabled { opacity: .35; cursor: default; }
.send-btn:active:not(:disabled) { transform: scale(.9); }
.attach-btn { background: transparent; }

.reply-bar, .attach {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 7px 8px 7px 12px;
  margin-bottom: 8px;
}

.reply-meta { flex: 1; min-width: 0; }
.reply-meta strong { font-size: 13px; color: var(--accent); display: block; }
.reply-meta p { margin: 1px 0 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attach { border-left-color: transparent; }
.attach img { max-height: 62px; max-width: 90px; border-radius: 6px; }

/* ---------- varios ---------- */

.typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 16px 8px;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--panel);
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1.2s infinite;
}

.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; margin-right: 6px; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

.jump {
  position: absolute;
  right: 14px;
  bottom: 78px;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--panel-2);
  color: var(--text);
  border: 0;
  border-radius: 999px;
  padding: 9px 13px;
  box-shadow: var(--shadow);
  font-size: 13px;
  cursor: pointer;
  z-index: 6;
}

.jump svg { width: 18px; height: 18px; transform: rotate(180deg); }
#app { position: relative; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  background: #33404a;
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  z-index: 40;
}

/* ---------- sheets ---------- */

.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }
.sheet-body {
  position: relative;
  width: 100%;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  padding: 16px 14px max(18px, env(safe-area-inset-bottom));
  animation: rise .2s ease;
  max-height: 82vh;
  overflow-y: auto;
}

@keyframes rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-body h2 { margin: 0 0 4px; font-size: 17px; }
.sheet-body .sub { margin-bottom: 12px; }

.emoji-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.emoji-row button {
  width: 44px;
  height: 44px;
  font-size: 24px;
  background: var(--panel-2);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.emoji-row button:active { background: var(--accent-dark); }

.sheet-action {
  width: 100%;
  padding: 13px;
  margin-bottom: 8px;
  border: 0;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 15px;
}

.sheet-action:active { background: var(--line); }
.sheet-action.danger { color: #f15c6d; }
.bubble.gone { background: rgba(255, 255, 255, .07) !important; }
.bubble.gone span { font-size: 13px; font-style: italic; color: var(--muted); }

.people { list-style: none; margin: 0 0 12px; padding: 0; }
.people li { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.people .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none; }
.people .dot.off { background: var(--line); }
.people small { color: var(--muted); margin-left: auto; }

/* ---------- visor de fotos ---------- */

.viewer { position: fixed; inset: 0; background: #000; display: grid; place-items: center; z-index: 60; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .icon-btn { position: absolute; top: max(14px, env(safe-area-inset-top)); right: 14px; background: rgba(255, 255, 255, .14); color: #fff; }

/* ---------- audio ---------- */

.audio-row { display: flex; align-items: center; gap: 10px; min-width: 190px; padding: 2px 0; }
.audio-btn { width: 38px; height: 38px; border-radius: 50%; border: none; flex: none;
  background: rgba(255, 255, 255, .22); display: grid; place-items: center; cursor: pointer; }
.audio-btn svg { width: 18px; height: 18px; fill: #fff; }
.audio-wave { flex: 1; height: 26px; display: flex; align-items: center; gap: 2px; }
.audio-wave i { flex: 1; background: rgba(255, 255, 255, .38); border-radius: 2px; min-height: 4px; }
.audio-wave i.on { background: #fff; }
.audio-time { font-size: 11.5px; opacity: .8; font-variant-numeric: tabular-nums; min-width: 32px; text-align: right; }
.audio-playing { display: flex; align-items: center; gap: 8px; }

/* ---------- fotos de ver una vez ---------- */

.once-tile { width: 168px; height: 200px; border-radius: 10px; display: grid; place-items: center;
  gap: 8px; align-content: center; cursor: pointer; position: relative; overflow: hidden;
  background: repeating-linear-gradient(135deg, #2a3644 0 10px, #222d3a 10px 20px); color: #e8eef4; }
.once-tile svg { width: 34px; height: 34px; fill: #fff; opacity: .9; }
.once-tile b { font-size: 13px; font-weight: 600; }
.once-tile small { font-size: 11px; opacity: .75; }
.once-tile.done { cursor: default; opacity: .55; }
.once-tile.done b { font-weight: 500; }
.once-flag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; opacity: .8;
  margin-top: 4px; font-weight: 500; }
.once-flag svg { width: 12px; height: 12px; fill: currentColor; }

.no-save { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-user-drag: none; touch-action: manipulation; }
.viewer canvas { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-note { position: absolute; bottom: max(18px, env(safe-area-inset-bottom)); left: 0; right: 0;
  text-align: center; color: #dbe4ec; font-size: 13px; padding: 0 24px; }
.viewer-note b { color: #fff; }

/* ---------- grabadora ---------- */

.rec-bar { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin: 0 0 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.rec-dot { width: 11px; height: 11px; border-radius: 50%; background: #f15c6d; flex: none;
  animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
#rec-time { font-variant-numeric: tabular-nums; font-size: 15px; }
.rec-note { flex: 1; font-size: 13px; color: var(--muted); }
.rec-bar .send-btn { width: 40px; height: 40px; }

.once-pick { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 999px;
  background: rgba(0, 0, 0, .45); font-size: 13px; color: #fff; cursor: pointer;
  -webkit-tap-highlight-color: transparent; }
.once-pick input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; }

@media (min-width: 700px) {
  .bubble { max-width: 62%; }
  #log { padding-inline: 8%; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------------- modo dev ---------------- */

.dev-btn {
  font: 700 11px/1 inherit;
  letter-spacing: .08em;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  min-height: 30px;
}
.dev-btn:active { background: var(--line); }
.dev-btn.on { color: #1b1005; background: #ff9f43; border-color: #ff9f43; }

.bubble .author.dev,
.dev-name { color: #ff9f43 !important; }

.avatar.dev {
  box-shadow: 0 0 0 2px #ff9f43;
  color: #ff9f43;
}

.sheet-body h2 .dev-chip,
.dev-chip {
  display: inline-block;
  font: 700 10px/1 inherit;
  letter-spacing: .08em;
  color: #1b1005;
  background: #ff9f43;
  border-radius: 999px;
  padding: 4px 8px;
  vertical-align: middle;
}

.dev-input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin: 4px 0 10px;
}
.dev-input:focus { outline: 2px solid #ff9f43; }

.dev-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 8px;
  margin: 10px 0 14px;
}
.dev-stats div {
  background: var(--panel-2);
  border-radius: 10px;
  padding: 8px 10px;
}
.dev-stats b { display: block; font-size: 16px; }
.dev-stats span { font-size: 11px; color: var(--muted); }

.dev-block { margin-bottom: 14px; }
.dev-block > strong { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }

.dev-users { list-style: none; margin: 0 0 8px; padding: 0; }
.dev-users li {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 6px;
  font-size: 14px;
}
.dev-users li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-users button {
  font: 700 12px/1 inherit;
  color: #f15c6d;
  background: transparent;
  border: 1px solid #f15c6d;
  border-radius: 999px;
  padding: 6px 10px;
  min-height: 32px;
}
.dev-users button.back { color: #7ee0c0; border-color: #7ee0c0; }
.dev-users small { color: var(--muted); font-size: 11px; }
