/* ===== Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --primary: #4f6ef7;
  --primary-dark: #3b56d4;
  --mine: #dce4ff;
  --theirs: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --green: #16a34a;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }
.screen { height: 100vh; }

/* ===== Login ===== */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #4f6ef7 0%, #7c3aed 100%);
}

.login-card {
  background: var(--panel);
  border-radius: 16px;
  padding: 36px 32px;
  width: min(440px, 92vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.login-logo { font-size: 42px; }
.login-card h1 { margin: 6px 0 4px; font-size: 26px; }
.login-subtitle { color: var(--muted); font-size: 13px; margin-bottom: 22px; }

.field-label {
  display: block;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 14px 0 6px;
}

#login-userid {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  outline: none;
}
#login-userid:focus { border-color: var(--primary); }

.role-picker { display: flex; gap: 10px; }

.role-card {
  flex: 1;
  background: #f9fafb;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 14px 10px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.role-card.selected { border-color: var(--primary); background: #eef2ff; }
.role-emoji { font-size: 28px; display: block; }
.role-name { font-weight: 700; font-size: 15px; display: block; margin-top: 4px; }
.role-desc { font-size: 11px; color: var(--muted); display: block; margin-top: 4px; line-height: 1.35; }

.btn-primary {
  width: 100%;
  margin-top: 22px;
  padding: 13px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { background: var(--primary-dark); }

.login-error { color: #dc2626; font-size: 13px; margin-top: 12px; }

/* ===== Layout del chat ===== */
#chat-screen { display: flex; }

.sidebar {
  width: 300px;
  min-width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.me-avatar, .contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 17px;
  flex-shrink: 0;
}

.me-info { flex: 1; min-width: 0; }
.me-info strong { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-role { font-size: 12px; color: var(--muted); }

.icon-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
  padding: 6px;
  border-radius: 8px;
}
.icon-btn:hover { background: var(--bg); }

.new-chat {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.new-chat input {
  flex: 1;
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  min-width: 0;
}
.new-chat input:focus { border-color: var(--primary); }

.btn-small {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-small:hover { background: var(--primary-dark); }

.conversation-list { flex: 1; overflow-y: auto; }

.conversation-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.conversation-item:hover { background: #f9fafb; }
.conversation-item.active { background: #eef2ff; }

.conv-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: #94a3b8; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; flex-shrink: 0;
}

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

.conv-badge {
  background: var(--green);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 2px 7px;
  flex-shrink: 0;
}

/* ===== Panel principal ===== */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 8px;
}
.chat-empty span { font-size: 40px; }

.chat-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.contact-avatar { background: #7c3aed; }

.typing-indicator { font-size: 12px; color: var(--green); font-style: italic; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ===== Burbujas ===== */
.bubble-row { display: flex; }
.bubble-row.mine { justify-content: flex-end; }

.bubble {
  max-width: 68%;
  background: var(--theirs);
  border-radius: 14px;
  padding: 9px 13px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  position: relative;
}
.bubble-row.mine .bubble { background: var(--mine); }

.bubble-content { font-size: 14.5px; line-height: 1.4; word-wrap: break-word; }

.bubble-original {
  font-size: 12px;
  color: var(--muted);
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px dashed var(--border);
}

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

.ticks { letter-spacing: -2px; }
.ticks.read { color: #2563eb; font-weight: 700; }

.edited-tag { font-style: italic; }

.edit-msg-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  padding: 0 2px;
}
.edit-msg-btn:hover { color: var(--primary); }

.pending-tag { color: #d97706; }

/* ===== Composer ===== */
.edit-banner {
  padding: 8px 18px;
  background: #fef3c7;
  font-size: 13px;
  border-top: 1px solid #fde68a;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
  text-decoration: underline;
}

.composer {
  display: flex;
  gap: 10px;
  padding: 12px 18px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}

#message-input {
  flex: 1;
  padding: 11px 15px;
  border: 1.5px solid var(--border);
  border-radius: 22px;
  font-size: 14.5px;
  outline: none;
}
#message-input:focus { border-color: var(--primary); }

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 17px;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-send:hover { background: var(--primary-dark); }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .sidebar { width: 220px; min-width: 180px; }
  .bubble { max-width: 85%; }
}
