/* ============================================================
   Shrill Wave Chat — Estilos
   Diseño moderno, oscuro, optimizado para móvil / PWA
   ============================================================ */

:root {
  --bg: #0B0D14;
  --bg-elev: #12151F;
  --bg-elev-2: #1A1E2B;
  --border: #262B3A;
  --text: #F1F3F9;
  --text-muted: #8891A7;
  --accent: #7C5CFF;
  --accent-2: #00C2A8;
  --accent-grad: linear-gradient(135deg, #7C5CFF, #00C2A8);
  --danger: #FF6B6B;
  --bubble-me: linear-gradient(135deg, #7C5CFF, #6a4de0);
  --bubble-other: #1A1E2B;
  --radius: 18px;
  --radius-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #F5F6FA;
    --bg-elev: #FFFFFF;
    --bg-elev-2: #EDEFF6;
    --border: #E2E5EF;
    --text: #14161F;
    --text-muted: #6B7288;
    --bubble-other: #EDEFF6;
  }
}

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

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

button { font-family: inherit; }

.hidden { display: none !important; }

/* ---------- Layout de pantallas ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}
.screen.active { display: flex; }

/* ---------- Home ---------- */
.home-wrap, .share-wrap {
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex: 1;
  justify-content: center;
}

.brand { text-align: center; margin-bottom: 8px; }
.brand-logo {
  width: 72px; height: 72px;
  margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-elev);
  border-radius: 22px;
  box-shadow: 0 8px 30px rgba(124,92,255,0.25);
}
.brand h1 { font-size: 28px; margin: 0 0 6px; font-weight: 800; letter-spacing: -0.02em; }
.tagline { color: var(--text-muted); margin: 0; font-size: 15px; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.divider { display: flex; align-items: center; gap: 12px; color: var(--text-muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.join-form { display: flex; gap: 10px; }
.join-form input {
  flex: 1;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  color: var(--text);
  font-size: 16px;
  min-width: 0;
}
.join-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.hint { font-size: 13px; color: var(--text-muted); text-align: center; line-height: 1.5; margin: 0; }

/* ---------- Botones ---------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .12s ease, opacity .12s ease, filter .12s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent-grad); color: white; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--bg-elev-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn-lg { width: 100%; padding: 15px; font-size: 16px; }
.btn-tiny { padding: 8px 14px; font-size: 13px; border-radius: 10px; }
.btn-back {
  background: none; border: none; color: var(--text);
  font-size: 22px; align-self: flex-start; cursor: pointer; padding: 4px 8px;
}

.install-banner {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 16px; font-size: 13px; color: var(--text-muted);
  gap: 12px;
}

/* ---------- Share screen ---------- */
.share-wrap h2 { margin: 8px 0 4px; font-size: 24px; }
.muted { color: var(--text-muted); font-size: 14px; margin: 0 0 8px; }
.room-link-box {
  display: flex; gap: 8px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px;
}
.room-link-box input {
  flex: 1; background: transparent; border: none; color: var(--text);
  padding: 10px 12px; font-size: 14px; min-width: 0;
}

/* ---------- Chat header ---------- */
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky; top: 0; z-index: 5;
}
.chat-title { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-title strong { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.presence { font-size: 12px; color: var(--accent-2); }

.icon-btn {
  background: none; border: none; color: var(--text);
  font-size: 20px; width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; cursor: pointer; flex-shrink: 0;
}
.icon-btn:active { background: var(--bg-elev-2); }

.connection-banner {
  background: #FFB84D; color: #1a1a1a; text-align: center;
  font-size: 13px; padding: 6px; font-weight: 600;
}

/* ---------- Messages ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  -webkit-overflow-scrolling: touch;
}

.msg-row { display: flex; flex-direction: column; max-width: 78%; margin-bottom: 6px; }
.msg-row.me { align-self: flex-end; align-items: flex-end; }
.msg-row.other { align-self: flex-start; align-items: flex-start; }

.msg-sender { font-size: 12px; font-weight: 700; margin-bottom: 3px; padding: 0 4px; }

.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-row.me .bubble { background: var(--bubble-me); color: white; border-bottom-right-radius: 6px; }
.msg-row.other .bubble { background: var(--bubble-other); color: var(--text); border-bottom-left-radius: 6px; }

.msg-meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; padding: 0 4px; }

.bubble-image { padding: 4px; }
.bubble-image img { max-width: 100%; max-height: 320px; border-radius: 14px; display: block; cursor: pointer; }

.bubble-file { display: flex; align-items: center; gap: 10px; }
.bubble-file .file-icon { font-size: 22px; }
.bubble-file .file-info { display: flex; flex-direction: column; }
.bubble-file .file-name { font-size: 14px; font-weight: 600; }
.bubble-file .file-size { font-size: 12px; opacity: 0.8; }

.bubble-audio { display: flex; align-items: center; gap: 8px; min-width: 200px; }
.bubble-audio audio { width: 100%; height: 36px; }

.system-msg {
  align-self: center;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-elev-2);
  padding: 4px 12px;
  border-radius: 12px;
  margin: 6px 0;
}

.typing-indicator {
  padding: 4px 16px;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* ---------- Composer ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
}
.composer-input-wrap { flex: 1; }
.composer textarea {
  width: 100%;
  resize: none;
  max-height: 120px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 11px 16px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.3;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }

.send-btn {
  background: var(--accent-grad);
  color: white;
}

.recording-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: var(--bg-elev-2);
  border-top: 1px solid var(--border);
}
.rec-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger);
  animation: pulse 1s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  max-width: 90vw;
}

/* ---------- Image viewer ---------- */
.image-viewer {
  position: fixed; inset: 0; background: rgba(0,0,0,0.92);
  z-index: 200; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.image-viewer img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.viewer-close {
  position: absolute; top: calc(16px + var(--safe-top)); right: 16px;
  background: rgba(255,255,255,0.1); color: white;
}

/* ---------- Scrollbar ---------- */
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

@media (min-width: 700px) {
  .screen#screen-chat { max-width: 600px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
