/* ══════════════════════════════════════════
   Chat Institucional · LeCaroz
   Modern Dark Theme
   ══════════════════════════════════════════ */

:root {
  --bg-primary: #0f0f14;
  --bg-secondary: #16161e;
  --bg-tertiary: #1c1c28;
  --bg-hover: #22223a;
  --bg-active: #2a2a45;
  --surface: #1e1e2e;
  --surface-hover: #252540;

  --text-primary: #e8e8f0;
  --text-secondary: #9494a8;
  --text-muted: #6b6b80;

  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --accent-dark: #4834d4;
  --accent-glow: rgba(108, 92, 231, 0.15);

  --green: #00cec9;
  --green-soft: rgba(0, 206, 201, 0.15);
  --red: #ff6b6b;
  --red-soft: rgba(255, 107, 107, 0.15);
  --orange: #ffa502;

  --msg-own: #6c5ce7;
  --msg-own-text: #ffffff;
  --msg-other: #1e1e2e;
  --msg-other-text: #e8e8f0;

  --border: rgba(255, 255, 255, 0.06);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --sidebar-width: 320px;

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── SCROLLBAR ────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ── LOGIN MODAL ──────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow);
  animation: modalIn 0.4s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-logo {
  text-align: center;
  margin-bottom: 36px;
}

.logo-icon {
  font-size: 48px;
  margin-bottom: 12px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.modal-logo h1 {
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

.modal-form label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.modal-form textarea {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: 'Courier New', monospace;
  font-size: 12px;
  resize: none;
  outline: none;
  transition: border var(--transition);
}

.modal-form textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.modal-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 12px 0 20px;
  line-height: 1.6;
}

.modal-hint code {
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--accent-light);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(108, 92, 231, 0.4);
}

.btn-primary:active { transform: translateY(0); }

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.error-msg {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--red-soft);
  color: var(--red);
  border-radius: var(--radius-sm);
  font-size: 13px;
  text-align: center;
}

/* ── CHAT APP LAYOUT ──────────────────── */
.chat-app {
  display: flex;
  height: 100vh;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── SIDEBAR ──────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition);
}

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

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon { font-size: 24px; }

.brand-text {
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-user {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-status {
  font-size: 12px;
  color: var(--green);
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.sidebar-section {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.sidebar-section h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: 8px 20px;
  font-weight: 600;
}

.room-list {
  list-style: none;
}

.room-item {
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background var(--transition);
  border-left: 3px solid transparent;
}

.room-item:hover { background: var(--bg-hover); }

.room-item.active {
  background: var(--accent-glow);
  border-left-color: var(--accent);
}

.room-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.room-details {
  flex: 1;
  overflow: hidden;
}

.room-details-name {
  font-size: 14px;
  font-weight: 500;
}

.room-details-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  transition: color var(--transition);
}

.btn-text:hover { color: var(--red); }

/* ── MAIN CHAT ────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  padding: 16px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
}

.chat-header-info {
  flex: 1;
}

.chat-header-info h2 {
  font-size: 16px;
  font-weight: 600;
}

.room-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.conn-badge {
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.conn-badge.connected {
  background: var(--green-soft);
  color: var(--green);
}

.conn-badge.disconnected {
  background: var(--red-soft);
  color: var(--red);
}

.conn-badge.connecting {
  background: rgba(255, 165, 2, 0.15);
  color: var(--orange);
}

/* ── MESSAGES AREA ────────────────────── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  background: var(--bg-primary);
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 100%;
  justify-content: flex-end;
}

.welcome-msg {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.welcome-icon { font-size: 48px; margin-bottom: 16px; }
.welcome-msg h3 { font-size: 18px; color: var(--text-secondary); margin-bottom: 8px; }
.welcome-msg p { font-size: 14px; }

/* ── MESSAGE BUBBLES ──────────────────── */
.message-group {
  display: flex;
  gap: 10px;
  max-width: 75%;
  animation: msgIn 0.25s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-group.own {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-group .msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #74b9ff, #0984e3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  margin-top: 4px;
}

.message-group.own .msg-avatar {
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
}

.msg-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.msg-sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-light);
  padding: 0 4px;
}

.message-group.own .msg-sender {
  text-align: right;
}

.msg-bubble {
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  position: relative;
}

.message-group:not(.own) .msg-bubble {
  background: var(--msg-other);
  color: var(--msg-other-text);
  border-bottom-left-radius: 4px;
}

.message-group.own .msg-bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: var(--msg-own-text);
  border-bottom-right-radius: 4px;
}

.msg-time {
  font-size: 10px;
  color: var(--text-muted);
  padding: 0 4px;
}

.message-group.own .msg-time {
  text-align: right;
  color: rgba(255,255,255,0.4);
}

/* Date separator */
.date-separator {
  text-align: center;
  padding: 16px 0;
}

.date-separator span {
  background: var(--bg-tertiary);
  padding: 4px 16px;
  border-radius: var(--radius-full);
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── TYPING INDICATOR ─────────────────── */
.typing-indicator {
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg-primary);
}

.typing-dots {
  display: flex;
  gap: 3px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ── MESSAGE INPUT ────────────────────── */
.chat-input-area {
  padding: 16px 24px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.input-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  padding: 4px 4px 4px 20px;
  border: 1px solid var(--border);
  transition: border var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#messageInput {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  padding: 10px 0;
}

#messageInput::placeholder { color: var(--text-muted); }

#messageInput:disabled { opacity: 0.5; }

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}

.btn-send:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(108, 92, 231, 0.4);
}

.btn-send:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ── MOBILE RESPONSIVE ────────────────── */
.mobile-only { display: none; }

@media (max-width: 768px) {
  .mobile-only { display: flex; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    box-shadow: var(--shadow);
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    display: none;
  }

  .sidebar-overlay.open { display: block; }

  .messages-area { padding: 16px; }
  .chat-input-area { padding: 12px 16px; }
  .message-group { max-width: 85%; }
}
