* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  background: #ECE5DD;
  overscroll-behavior: none;
}
.hidden { display: none !important; }

/* ---------- Bienvenida ---------- */
.welcome {
  position: fixed; inset: 0; background: #f0f2f5;
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.welcome-card {
  background: #fff; border-radius: 12px; padding: 36px 28px;
  width: min(90vw, 380px); text-align: center; box-shadow: 0 4px 24px rgba(0,0,0,.12);
}
.welcome-card h1 { margin: 12px 0 4px; color: #075E54; }
.welcome-card p { color: #667781; font-size: 14px; margin-bottom: 20px; }
.welcome-card input {
  width: 100%; padding: 12px 14px; border: 1px solid #d1d7db; border-radius: 8px;
  font-size: 15px; margin-bottom: 14px; outline: none;
}
.welcome-card input:focus { border-color: #25D366; }
.welcome-card button {
  width: 100%; padding: 12px; background: #075E54; color: #fff; border: none;
  border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.welcome-card button:hover { background: #064c44; }

/* ---------- App shell ---------- */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  background: #075E54; color: #fff; display: flex; align-items: center;
  justify-content: space-between; padding: 10px 16px; flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: #0b7269;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.title { font-weight: 600; font-size: 16px; }
.subtitle { font-size: 12px; opacity: .85; }
.topbar-right { display: flex; gap: 4px; }
.icon-btn {
  background: transparent; border: none; cursor: pointer; padding: 8px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(255,255,255,.15); }
.icon-btn.dark:hover { background: rgba(0,0,0,.06); }

/* ---------- Chat area ---------- */
.chat {
  flex: 1; overflow: hidden; position: relative;
  background-color: #ECE5DD;
  background-image:
    linear-gradient(rgba(255,255,255,.55), rgba(255,255,255,.55)),
    repeating-linear-gradient(45deg, rgba(0,0,0,.02) 0 2px, transparent 2px 40px);
}
.messages {
  height: 100%; overflow-y: auto; padding: 16px 6% 90px;
  display: flex; flex-direction: column; gap: 4px;
}
.empty-state {
  margin: auto; text-align: center; color: #8696a0; font-size: 14px; max-width: 260px;
}

.bubble-row { display: flex; flex-direction: column; max-width: 78%; }
.bubble-row.me { align-self: flex-end; align-items: flex-end; }
.bubble-row.other { align-self: flex-start; align-items: flex-start; }

.sender-label { font-size: 12px; color: #06cf9c; font-weight: 600; margin: 6px 2px 2px; }

.bubble {
  background: #fff; border-radius: 8px; padding: 6px 7px 6px 8px;
  box-shadow: 0 1px 0.5px rgba(0,0,0,.13); position: relative; min-width: 160px;
}
.bubble.bubble-text { min-width: 60px; }
.bubble-row.me .bubble { background: #DCF8C6; }

.file-row { display: flex; align-items: center; gap: 10px; padding: 4px; }
.file-icon {
  width: 42px; height: 42px; border-radius: 8px; background: #f0f2f5;
  display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0;
}
.file-info { min-width: 0; }
.file-name { font-size: 14px; color: #111b21; word-break: break-word; }
.file-size { font-size: 12px; color: #667781; margin-top: 2px; }
.download-link {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%; background: #075E54;
  flex-shrink: 0; text-decoration: none;
}

.img-preview { max-width: 260px; max-height: 260px; border-radius: 6px; display: block; cursor: pointer; }
.media-preview video, .media-preview audio { max-width: 260px; border-radius: 6px; display: block; }

.meta-row { display: flex; justify-content: flex-end; align-items: center; gap: 4px; margin-top: 2px; padding: 0 2px; }
.time { font-size: 11px; color: #667781; }
.ticks { color: #53bdeb; }

.progress-wrap { width: 220px; height: 4px; background: #d1d7db; border-radius: 2px; margin-top: 6px; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: #25D366; transition: width .15s; }

/* ---------- Composer ---------- */
.composer {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: #f0f2f5; flex-shrink: 0; border-top: 1px solid #d1d7db;
}
.composer-hint { color: #667781; font-size: 13px; }
.contact-list { flex: 1; overflow-y: auto; background: #fff; }
.contact-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 18px;
  cursor: pointer; border-bottom: 1px solid #f0f2f5;
}
.contact-item:hover { background: #f5f6f6; }
.contact-item .avatar { background: #075E54; flex-shrink: 0; }
.contact-item .ci-info { min-width: 0; flex: 1; }
.contact-item .ci-name { font-size: 16px; color: #111b21; }
.contact-item .ci-hint { font-size: 12px; color: #8696a0; margin-top: 2px; }
.contact-empty { padding: 40px 24px; text-align: center; color: #8696a0; font-size: 14px; }
.text-input {
  flex: 1; border: none; border-radius: 20px; padding: 10px 16px;
  font-size: 14px; outline: none; background: #fff;
}
.text-message { font-size: 14px; color: #111b21; white-space: pre-wrap; word-break: break-word; padding: 2px 4px; }

/* ---------- Preview bar (before sending) ---------- */
.preview-bar {
  position: absolute; left: 0; right: 0; bottom: 0; background: #f0f2f5;
  border-top: 1px solid #d1d7db; padding: 10px 14px; display: flex;
  flex-direction: column; gap: 8px; max-height: 45vh;
}
.chat { position: relative; }
.preview-list { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.preview-item {
  width: 84px; flex-shrink: 0; text-align: center; position: relative;
  background: #fff; border-radius: 8px; padding: 6px; box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
.preview-item img { width: 100%; height: 56px; object-fit: cover; border-radius: 4px; }
.preview-item .pi-icon { font-size: 28px; height: 56px; display: flex; align-items: center; justify-content: center; }
.preview-item .pi-name { font-size: 10px; color: #333; word-break: break-word; margin-top: 4px; max-height: 26px; overflow: hidden; }
.preview-item .pi-remove {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%;
  background: #075E54; color: #fff; border: none; cursor: pointer; font-size: 12px; line-height: 20px;
}
.preview-actions { display: flex; justify-content: space-between; align-items: center; }
.icon-btn-outline {
  border: 1px solid #8696a0; background: transparent; color: #54656f; border-radius: 20px;
  padding: 8px 16px; cursor: pointer; font-size: 13px;
}
.send-fab {
  width: 46px; height: 46px; border-radius: 50%; background: #075E54; border: none;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.send-fab:hover { background: #064c44; }

/* ---------- Drop overlay ---------- */
.drop-overlay {
  position: absolute; inset: 8px; border: 3px dashed #25D366; border-radius: 12px;
  background: rgba(37, 211, 102, .12); display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: #075E54; font-size: 16px; pointer-events: none;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex;
  align-items: center; justify-content: center; z-index: 60;
}
.modal-card {
  background: #fff; border-radius: 12px; padding: 24px; width: min(90vw, 340px);
  text-align: center; position: relative;
}
.modal-card h2 { margin-top: 4px; color: #075E54; font-size: 18px; }
.modal-card p { color: #667781; font-size: 13px; }
.modal-card img { border-radius: 8px; margin: 10px 0; }
.qr-url { word-break: break-all; font-size: 12px; color: #075E54; }
.modal-close {
  position: absolute; top: 8px; right: 10px; background: none; border: none;
  font-size: 22px; cursor: pointer; color: #667781;
}

@media (max-width: 560px) {
  .bubble-row { max-width: 88%; }
}
