/* ═══════════════════════════════════════════════════
   Tweet Messenger — Light Salmon Theme (default)
   ═══════════════════════════════════════════════════ */

:root {
  --bg:           #EDE4DF;
  --surface:      #FFFFFF;
  --surface2:     #F5EEEA;
  --border:       #DDD0C8;
  --primary:      #C94F4F;
  --primary-dark: #A83838;
  --text:         #1A0808;
  --text-2:       #907070;
  --danger:       #C0392B;
  --online:       #27AE60;
  --away:         #E67E22;
  --busy:         #C94F4F;
  --offline:      #BBAFAF;
  --sent-bg:      #C94F4F;
  --recv-bg:      #FFFFFF;
  --radius:       18px;
  --sidebar-w:    320px;
  --header-grad:  linear-gradient(135deg, #D94F4F 0%, #A83030 100%);
}

/* ── Temas ───────────────────────────────────────────── */
[data-theme="oscuro"] {
  --bg: #0F0F0F; --surface: #1C1C1E; --surface2: #2C2C2E; --border: #38383A;
  --primary: #1D9BF0; --primary-dark: #1565C0; --text: #FFF; --text-2: #8E8E93;
  --danger: #FF453A; --online: #30D158; --away: #FFD60A; --busy: #FF453A; --offline: #636366;
  --sent-bg: #1D9BF0; --recv-bg: #1C1C1E;
  --header-grad: linear-gradient(135deg, #1A2A3A 0%, #0F1820 100%);
}
[data-theme="menta"]     { --primary: #2A9E58; --primary-dark: #1E7A42; --sent-bg: #2A9E58; --header-grad: linear-gradient(135deg,#2A9E58,#1E7A42); }
[data-theme="atardecer"] { --primary: #E07820; --primary-dark: #C06010; --sent-bg: #E07820; --header-grad: linear-gradient(135deg,#E07820,#C06010); }
[data-theme="orquidea"]  { --primary: #8B3DBF; --primary-dark: #6A2A9E; --sent-bg: #8B3DBF; --header-grad: linear-gradient(135deg,#8B3DBF,#6A2A9E); }
[data-theme="oceano"]    { --primary: #1878D0; --primary-dark: #1060A8; --sent-bg: #1878D0; --header-grad: linear-gradient(135deg,#1878D0,#1060A8); }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* ── Utilidades ────────────────────────────────────── */
.hidden { display: none !important; }
.screen { display: none; width: 100%; height: 100%; }
.screen.active { display: flex; }

/* ── Spinner ────────────────────────────────────────── */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--surface2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Botones base ───────────────────────────────────── */
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }

.btn-icon {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  color: var(--text-2);
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--surface2); color: var(--text); }
.btn-icon.btn-danger:hover { background: rgba(192,57,43,.12); color: var(--danger); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-radius: 24px;
  padding: 10px 28px;
  font-weight: 600;
  font-size: 14px;
  transition: opacity .15s;
}
.btn-primary:hover { opacity: .85; }

/* ══════════════════════════════════════════════════════
   LOGIN
══════════════════════════════════════════════════════ */
#screen-login {
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 40px;
  background: var(--surface);
  border-radius: 24px;
  border: 1px solid var(--border);
  width: 360px;
  box-shadow: 0 8px 40px rgba(0,0,0,.08);
}

.login-logo { margin-bottom: 8px; }

.login-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-2);
  margin-bottom: 16px;
}

.btn-google {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 20px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  transition: background .15s, border-color .15s;
}
.btn-google:hover { background: var(--border); }

.login-error {
  width: 100%;
  padding: 10px 14px;
  background: rgba(192,57,43,.1);
  border: 1px solid rgba(192,57,43,.3);
  border-radius: 10px;
  color: var(--danger);
  font-size: 13px;
  text-align: center;
}

.login-loading {
  display: flex;
  justify-content: center;
  padding: 8px;
}

/* ══════════════════════════════════════════════════════
   APP SHELL
══════════════════════════════════════════════════════ */
#screen-app {
  flex-direction: row;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  color: var(--primary);
}

/* Online bar */
.online-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--header-grad);
  color: rgba(255,255,255,.9);
  font-size: 12px;
  font-weight: 500;
}
.online-bar-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #fff;
  opacity: .85;
}

/* Tabs */
.sidebar-tabs {
  display: flex;
  padding: 8px 12px 0;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  border-radius: 0;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-content { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.tab-content.active { display: flex; }

/* Search box */
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 12px;
  padding: 8px 12px;
  background: var(--surface2);
  border-radius: 12px;
  border: 1px solid var(--border);
}
.search-icon { color: var(--text-2); flex-shrink: 0; }
.search-box input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
}
.search-box input::placeholder { color: var(--text-2); }

/* Conv list */
.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Conv item */
.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background .12s;
  border-radius: 12px;
  margin: 2px 8px;
}
.conv-item:hover { background: var(--surface2); }
.conv-item.active { background: rgba(201,79,79,.1); }

.conv-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.conv-info { flex: 1; min-width: 0; }
.conv-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.conv-last {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.conv-time { font-size: 11px; color: var(--text-2); }
.unread-badge {
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}

/* Avatars */
.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface2);
  flex-shrink: 0;
}
.avatar-sm  { width: 36px; height: 36px; }
.avatar-md  { width: 44px; height: 44px; }
.avatar-lg  { width: 52px; height: 52px; }
.avatar-xl  { width: 88px; height: 88px; }

/* Status dots */
.status-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  position: absolute;
  bottom: 0; right: 0;
}
.status-dot.online  { background: var(--online); }
.status-dot.away    { background: var(--away); }
.status-dot.busy    { background: var(--busy); }
.status-dot.offline { background: var(--offline); }

/* Empty & loading states */
.empty-state, .loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 12px;
  color: var(--text-2);
  font-size: 14px;
  text-align: center;
}
.empty-icon { font-size: 40px; }

/* Sidebar footer */
.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  margin-top: auto;
  background: var(--surface);
}
.me-avatar-wrap { position: relative; }
.me-name {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

/* ── Chat area ────────────────────────────────────────── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-2);
  text-align: center;
  padding: 40px;
}
.chat-empty h2 { font-size: 22px; color: var(--text); }
.chat-empty p  { font-size: 14px; max-width: 280px; }

#chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Chat header — gradient */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--header-grad);
  border-bottom: none;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.chat-header .btn-icon { color: rgba(255,255,255,.85); }
.chat-header .btn-icon:hover { background: rgba(255,255,255,.18); color: #fff; }

.back-btn { display: none; }
.chat-header-avatar-wrap { position: relative; flex-shrink: 0; }
.chat-header-info { flex: 1; min-width: 0; }
.chat-title   { display: block; font-weight: 700; font-size: 15px; color: #fff; }
.chat-subtitle { display: block; font-size: 12px; color: rgba(255,255,255,.75); }

/* Reply bar */
.reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.reply-bar-accent {
  width: 3px; align-self: stretch;
  background: var(--primary);
  border-radius: 2px;
  flex-shrink: 0;
}
.reply-bar-body { flex: 1; min-width: 0; font-size: 13px; }
.reply-bar-label { color: var(--text-2); margin-right: 4px; }
.reply-bar-name  { color: var(--primary); font-weight: 600; margin-right: 6px; }
.reply-bar-text  { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.messages-container::-webkit-scrollbar { width: 4px; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: auto;
}

/* Animations */
@keyframes wpop {
  0%   { transform: scale(0.82) translateY(6px); opacity: 0; }
  65%  { transform: scale(1.04) translateY(-1px); }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  15%     { transform: translateX(-9px) rotate(-1deg); }
  30%     { transform: translateX(9px)  rotate(1deg); }
  45%     { transform: translateX(-6px) rotate(-.5deg); }
  60%     { transform: translateX(6px)  rotate(.5deg); }
  75%     { transform: translateX(-3px); }
  90%     { transform: translateX(3px); }
}
.shake { animation: shake 0.65s ease; }

/* Message bubbles */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 72%;
}
.msg-row.sent  { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.recv  { align-self: flex-start; }

.msg-avatar { flex-shrink: 0; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.45;
  word-break: break-word;
  font-size: 15px;
  position: relative;
  animation: wpop 0.22s ease-out;
}
.sent  .bubble { background: var(--sent-bg); color: #fff; border-bottom-right-radius: 4px; }
.recv  .bubble { background: var(--recv-bg); color: var(--text); border-bottom-left-radius: 4px; border: 1px solid var(--border); }

.bubble-sender {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 3px;
}

.bubble-image {
  width: 220px; height: 220px;
  object-fit: cover;
  border-radius: 12px;
  display: block;
  cursor: pointer;
}

.bubble-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 4px;
}
.bubble-time {
  font-size: 10px;
  opacity: .65;
}

.bubble-reactions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.reaction-chip {
  background: var(--surface2);
  border-radius: 12px;
  padding: 2px 7px;
  font-size: 12px;
  cursor: pointer;
  transition: background .12s;
  border: 1px solid var(--border);
}
.reaction-chip:hover { background: var(--border); }

/* Reply inside bubble */
.bubble-reply {
  background: rgba(0,0,0,.08);
  border-left: 3px solid rgba(0,0,0,.2);
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: 12px;
  opacity: .85;
}
.sent .bubble-reply  { background: rgba(0,0,0,.15); border-left-color: rgba(255,255,255,.5); }
.recv .bubble-reply  { border-left-color: var(--primary); background: rgba(201,79,79,.07); }
.bubble-reply-name { font-weight: 600; margin-bottom: 2px; }

/* @mention */
.mention {
  color: var(--primary);
  font-weight: 600;
  background: rgba(201,79,79,.08);
  border-radius: 4px;
  padding: 0 2px;
}
.sent .bubble .mention { color: rgba(255,255,255,.9); background: rgba(255,255,255,.18); }

/* System message (zumbido, etc.) */
.system-msg {
  text-align: center;
  font-size: 12px;
  color: var(--text-2);
  padding: 6px 16px;
  font-style: italic;
  user-select: none;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
}
.typing-indicator span {
  width: 8px; height: 8px;
  background: var(--text-2);
  border-radius: 50%;
  animation: bounce .8s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .15s; }
.typing-indicator span:nth-child(3) { animation-delay: .30s; }
@keyframes bounce {
  0%,80%,100% { transform: translateY(0); }
  40%          { transform: translateY(-6px); }
}

/* Message input */
.message-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrap {
  flex: 1;
  background: var(--surface2);
  border-radius: 24px;
  border: 1px solid var(--border);
  overflow: hidden;
}

#message-input {
  width: 100%;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  padding: 10px 16px;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
}
#message-input::placeholder { color: var(--text-2); }

.btn-send {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, transform .1s;
  flex-shrink: 0;
}
.btn-send:hover { opacity: .85; transform: scale(1.05); }
.btn-send:disabled { opacity: .4; transform: none; cursor: default; }

/* ══════════════════════════════════════════════════════
   MODALES
══════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0,0,0,.15);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--header-grad);
}
.modal-header h2 { font-size: 17px; font-weight: 700; color: #fff; }
.modal-header .btn-icon { color: rgba(255,255,255,.85); }
.modal-header .btn-icon:hover { background: rgba(255,255,255,.18); color: #fff; }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--surface);
}
.modal-body::-webkit-scrollbar { width: 4px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  background: var(--surface);
}

/* Profile modal */
.profile-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.btn-change-avatar {
  font-size: 13px;
  color: var(--primary);
  padding: 4px 0;
}
.btn-change-avatar:hover { opacity: .75; }

/* Form */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.form-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  width: 100%;
  resize: vertical;
  transition: border-color .15s;
}
.form-input:focus { border-color: var(--primary); }

/* ── Context menu ────────────────────────────────────── */
.context-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  z-index: 200;
  min-width: 160px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.context-menu button {
  display: block;
  width: 100%;
  padding: 9px 14px;
  text-align: left;
  font-size: 14px;
  border-radius: 8px;
  color: var(--text);
  transition: background .12s;
}
.context-menu button:hover { background: var(--surface2); }
.context-menu button.danger { color: var(--danger); }

/* ── Emoji picker (reacciones) ───────────────────────── */
.emoji-picker {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  z-index: 200;
  display: flex;
  gap: 6px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.emoji-picker button {
  font-size: 22px;
  padding: 4px;
  border-radius: 8px;
  transition: background .12s;
}
.emoji-picker button:hover { background: var(--surface2); }

/* ── Emoji input picker ──────────────────────────────── */
.emoji-input-picker {
  position: fixed;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 12px 12px;
  z-index: 300;
  box-shadow: 0 12px 48px rgba(0,0,0,.2);
  width: min(420px, 94vw);
  max-height: 260px;
  overflow-y: auto;
}
.emoji-input-picker::-webkit-scrollbar { width: 4px; }
.emoji-input-picker::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 2px;
}
.emoji-grid button {
  font-size: 22px;
  padding: 5px 2px;
  border-radius: 8px;
  text-align: center;
  transition: background .1s, transform .1s;
  line-height: 1.2;
}
.emoji-grid button:hover { background: var(--surface2); transform: scale(1.25); }

/* ── Theme picker ────────────────────────────────────── */
.theme-picker {
  display: flex;
  gap: 14px;
  padding: 4px 0;
}
.theme-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color .2s, transform .15s;
  outline: none;
}
.theme-btn:hover { transform: scale(1.12); }
.theme-btn.active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(201,79,79,.25); }

/* ══════════════════════════════════════════════════════
   RESPONSIVE — móvil
══════════════════════════════════════════════════════ */
@media (max-width: 700px) {
  .sidebar {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    z-index: 50;
    transform: translateX(0);
    transition: transform .25s ease;
    width: 100%;
    min-width: unset;
  }
  .sidebar.hidden-mobile { transform: translateX(-100%); }

  .chat-area { width: 100%; }
  .back-btn  { display: flex; }

  .form-row { grid-template-columns: 1fr; }
  .modal { border-radius: 20px 20px 0 0; align-self: flex-end; max-height: 85vh; }
}
