@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg-main: #f0f2f5;
    --bg-content: #ffffff;
    --bg-panel: #f8f9fa;
    --bg-input-area: #ffffff;
    --bg-hover: #e9ecef;
    --bg-active: #dbe4f2;
    --bg-system-message: #f1f1f1;
    --bg-mention: #fff3cd;
    --text-primary: #050505;
    --text-secondary: #65676b;
    --text-placeholder: #8a8d91;
    --text-system: #65676b;
    --border-color: #ddd;
    --shadow-light: rgba(0, 0, 0, 0.05);
    --primary-color: #0088cc;
    --primary-color-hover: #0077b3;
    --my-message-bubble: #e6f3ff;
    --other-message-bubble: #f1f1f1;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

html, body {
  overflow: hidden;
  width: 100%;
  height: 100%;
}

body { 
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-primary);
    transition: background-color 0.3s, color 0.3s;
}

.hidden { 
    display: none !important; 
}

/* ======================================================= */
/* ===         2. PANTALLA DE BIENVENIDA               === */
/* ======================================================= */
#welcome-container { display: flex; justify-content: center; align-items: center; height: 100vh; background-image: url('../image/welcome-background.png'); background-size: cover; background-position: center; }
.welcome-box { background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(10px); padding: 30px 40px; border-radius: 12px; box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15); text-align: center; width: 100%; max-width: 450px; border: 1px solid rgba(255, 255, 255, 0.18); }
.welcome-box h1 { margin-top: 0; color: #1c1e21; font-weight: 700; }
.auth-tabs { display: flex; margin-bottom: 20px; border-bottom: 1px solid #e0e0e0; }
.auth-tab { flex: 1; padding: 12px; border: none; background: none; cursor: pointer; font-size: 1rem; font-weight: 600; color: var(--text-secondary); border-bottom: 3px solid transparent; transition: all 0.2s ease-in-out; }
.auth-tab.active { color: var(--primary-color); border-bottom-color: var(--primary-color); }
#login-form input, #register-form input, #login-form select, #guest-form input, #guest-form select { width: 100%; padding: 12px; font-size: 1rem; border: 1px solid #ccd0d5; border-radius: 6px; margin-bottom: 15px; background-color: #f5f6f7; }
#login-form input:focus, #register-form input:focus, #guest-form input:focus { border-color: var(--primary-color); background-color: white; box-shadow: 0 0 0 2px rgba(0, 136, 204, 0.2); outline: none; }
.room-label { display: block; text-align: left; margin-bottom: 5px; color: var(--text-secondary); font-weight: 600; }
#login-button, #register-button, #guest-join-button { width: 100%; padding: 12px 20px; font-size: 1.1rem; font-weight: 700; background-color: var(--primary-color); color: white; border: none; border-radius: 6px; cursor: pointer; transition: background-color 0.2s; }
#login-button:hover, #register-button:hover, #guest-join-button:hover { background-color: var(--primary-color-hover); }

/* ======================================================= */
/* ===         3. ESTRUCTURA Y PANELES LATERALES       === */
/* ======================================================= */
#chat-container { display: grid; grid-template-columns: 260px 1fr 260px; grid-template-rows: minmax(0, 1fr); height: 100vh; background-color: var(--bg-main); overflow: hidden; }
#conversations-panel, #user-list-container { background-color: var(--bg-panel); padding: 10px; display: flex; flex-direction: column; border-right: 1px solid var(--border-color); }
#user-list-container { border-right: none; border-left: 1px solid var(--border-color); }
#chat-area-wrapper { display: flex; flex-direction: column; overflow: hidden; position: relative; background-color: var(--bg-content); }
#conversations-panel h3, #user-list-container h3 { margin: 10px 10px 15px; font-size: 1.1rem; color: var(--text-primary); font-weight: 600; }
#conversation-list-container, #user-list { flex-grow: 1; overflow-y: auto; list-style-type: none; padding: 0 5px; margin: 0; min-height: 0; }
.conversation-group { margin-bottom: 15px; }

.group-header { font-size: 0.8rem; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; padding: 8px 10px; margin: 0 0 5px 0; cursor: pointer; user-select: none; display: flex; align-items: center; position: relative; }
.group-header::before { content: '▼'; font-size: 0.7em; margin-right: 8px; transition: transform 0.2s ease-in-out; }
.conversation-group.collapsed .group-header::before { transform: rotate(-90deg); }
.conversation-group.collapsed ul { display: none; }
#room-list li, #private-chat-list li, #user-list li { padding: 6px 10px; margin-bottom: 4px; cursor: pointer; border-radius: 8px; display: flex; align-items: center; gap: 10px; transition: background-color 0.2s; word-break: break-all; }
#room-list li:hover, #private-chat-list li:hover, #user-list li:hover { background-color: var(--bg-hover); }
#room-list li.active, #private-chat-list li.active { background-color: var(--bg-active); font-weight: 600; color: var(--primary-color); }
#room-list .unread-marker, #private-chat-list .unread-marker { width: 8px; height: 8px; background-color: var(--primary-color); border-radius: 50%; margin-left: auto; }
#user-list li.self { font-weight: 600; background-color: var(--bg-hover); }
.user-list-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
#action-buttons-container { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border-color); display: flex; flex-direction: column; gap: 5px; }
#profile-button, #admin-panel-button { width: 100%; background: var(--bg-content); border: 1px solid var(--border-color); border-radius: 8px; padding: 10px; cursor: pointer; font-weight: 600; transition: background-color 0.2s, border-color 0.2s; }
#profile-button:hover { background-color: var(--bg-hover); border-color: #ccc; }
#admin-panel-button { background-color: #5604fa; color: white; border: none; }
#admin-panel-button:hover { background-color: #170973; }

.user-search-wrapper { position: relative; margin: 0 10px 15px 10px; }
.user-search-wrapper::before { content: ''; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; opacity: 0.6; pointer-events: none; background-color: var(--text-placeholder); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'%3E%3Cpath d='M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3C/svg%3E"); mask-repeat: no-repeat; mask-position: center; transition: background-color 0.2s ease; }
.user-search-wrapper:focus-within::before { background-color: var(--primary-color); opacity: 1; }
#user-search-input { width: 100%; padding: 8px 12px 8px 35px; border: 1px solid var(--border-color); border-radius: 20px; background-color: var(--bg-main); color: var(--text-primary); font-size: 0.9em; outline: none; transition: all 0.2s ease; }
#user-search-input:focus { border-color: var(--primary-color); background-color: var(--bg-content); box-shadow: 0 0 0 2px rgba(0, 136, 204, 0.2); }

/* ======================================================= */
/* ===         4. ÁREA CENTRAL DEL CHAT                === */
/* ======================================================= */

.room-header-container { padding: 12px 20px; background-color: var(--bg-panel); border-bottom: 1px solid var(--border-color); text-align: center; flex-shrink: 0; user-select: none; box-shadow: 0 2px 4px var(--shadow-light); position: relative; z-index: 10; }
.room-header-container h2 { font-size: 1.2rem; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; }
.room-header-container h2::after { content: '▼'; font-size: 0.7em; opacity: 0.7; transition: transform 0.2s ease-in-out; }
.room-switcher { display: none; position: absolute; top: calc(100% + 5px); left: 50%; transform: translateX(-50%); width: 280px; background-color: var(--bg-content); border: 1px solid var(--border-color); border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); z-index: 100; max-height: 40vh; overflow-y: auto; }
.room-switcher.show { display: block; }
#room-switcher-list { list-style: none; padding: 5px; margin: 0; }
#room-switcher-list li { padding: 10px 15px; border-radius: 6px; display: flex; justify-content: space-between; align-items: center; cursor: pointer; transition: background-color 0.2s; }
#room-switcher-list li:hover { background-color: var(--bg-hover); }
#room-switcher-list li.current-room { font-weight: 600; background-color: var(--bg-active); color: var(--primary-color); cursor: default; }
#room-switcher-list li.current-room:hover { background-color: var(--bg-active); }
#room-switcher-list .user-count { font-size: 0.9em; color: var(--text-secondary); background-color: var(--bg-main); padding: 2px 8px; border-radius: 10px; }

#private-chat-view .chat-header { display: flex; align-items: center; padding: 8px 12px; background-color: #caf9ce; border-bottom: 1px solid #c8e6c9; flex-shrink: 0; position: relative; }
#private-chat-with-user { flex-grow: 1; text-align: center; margin: 0; font-size: 1.1rem; font-weight: 600; color: #1e4620; }
#private-chat-back-button { flex-shrink: 0; }
#main-chat-area, #private-chat-view { flex-grow: 1; display: flex; flex-direction: column; overflow: hidden; }
#chat-window, #private-chat-window { 
    flex-grow: 1; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
    background-image: url('image/background..png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}
#messages, #private-chat-window ul { list-style-type: none; padding: 20px; flex-grow: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }

#messages > li, #private-chat-window ul li { position: relative; display: flex; max-width: 100%; align-items: flex-start; gap: 10px; padding: 2px 0; }
.message-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; margin-top: 2px; flex-shrink: 0; }
.message-main-wrapper { position: relative; display: flex; flex-direction: column; align-items: flex-start; max-width: calc(100% - 46px); }

#messages > li.sent-by-me .message-main-wrapper, 
#private-chat-window ul li.sent .message-main-wrapper { 
    align-items: flex-end; 
}

#messages > li.sent-by-me .message-main-wrapper, #private-chat-window ul li.sent .message-main-wrapper { align-items: flex-end; }

.message-content { padding: 8px 12px; border-radius: 18px; line-height: 1.4; word-break: break-word; overflow-wrap: break-word; }
#messages > li .message-content, #private-chat-window ul li.received .message-content { background-color: var(--other-message-bubble); border-radius: 4px 18px 18px 18px; }
#chat-window #messages > li.sent-by-me, #private-chat-window ul li.sent { align-self: flex-end; flex-direction: row-reverse; }
#messages > li.sent-by-me .message-content, #private-chat-window ul li.sent .message-content { background-color: var(--my-message-bubble); border-radius: 18px 4px 18px 18px; }

.message-content:not(.media-only-content) { display: flex; flex-wrap: wrap; align-items: baseline; }
.media-only-content { display: flex; flex-direction: column; background-color: var(--bg-content) !important; padding: 8px !important; border-radius: 16px; overflow: visible; border: none; }

.message-header { margin-right: 0.5ch; font-size: 1em; color: var(--text-secondary); white-space: nowrap; }
.message-header strong { font-weight: 600; color: var(--primary-color); }
/* #private-chat-window ul li .message-header { display: none; } */
.media-only-content .message-header { display: block !important; margin-bottom: 6px; }

.media-message { margin-top: 6px; }
.media-message.image-message { display: block; max-width: 250px; max-height: 250px; width: auto; height: auto; border-radius: 12px; cursor: zoom-in; border: 1px solid var(--border-color); }
.media-message.image-message:hover { filter: brightness(0.9); }
.media-message.audio-message { width: 300px; max-width: 100%; }

.message-timestamp { font-size: 0.75em; color: var(--text-secondary); margin-left: 8px; white-space: nowrap; align-self: flex-end; padding-bottom: 2px; }
.media-only-content .message-timestamp { position: static; background-color: transparent; padding: 0; margin-top: 4px; }

#form { position: relative; background: var(--bg-input-area); padding: 10px 20px; display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--border-color); flex-shrink: 0; box-shadow: 0 -2px 4px var(--shadow-light); }
#input { border: none; background: var(--bg-main); padding: 12px 18px; flex-grow: 1; border-radius: 22px; font-size: 1rem; color: var(--text-primary); outline: none; transition: background-color 0.2s; }
#input:focus { background-color: #fff; box-shadow: 0 0 0 2px var(--primary-color); }
.chat-action-button { background: transparent; color: var(--text-secondary); border: none; width: 40px; height: 40px; cursor: pointer; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 22px; transition: background-color 0.2s, color 0.2s; }
.chat-action-button:hover { background-color: var(--bg-hover); color: var(--primary-color); }
#send-icon-button { background-color: var(--primary-color); color: white; }
#send-icon-button:hover { background-color: var(--primary-color-hover); }

.system-message { color: var(--text-system); font-style: italic; text-align: center; background: none !important; font-size: 0.85rem; padding: 5px 0; align-self: center; }
.system-message.error { color: #d93025; font-weight: 500; }
.system-message.warning { color: #e97406; font-weight: 500; }
.system-message.highlight { background-color: rgba(0, 136, 204, 0.1) !important; color: #005c8a; border-radius: 8px; font-style: normal; padding: 10px 15px !important; white-space: pre-wrap; text-align: left; }
#messages > li.mencion .message-content { background-color: var(--bg-mention) !important; border-left: 3px solid #ffc107; }
#typing-indicator, #private-typing-indicator { height: 24px; padding: 0 20px; font-style: italic; color: var(--text-secondary); flex-shrink: 0; }

.reply-quote { background-color: rgba(0, 0, 0, 0.05); border-left: 3px solid var(--primary-color); padding: 6px 10px; margin-bottom: 6px; border-radius: 4px; font-size: 0.9em; opacity: 0.8; width: 100%; }
.reply-quote strong { color: var(--primary-color); display: block; font-weight: 600; }
.reply-quote p { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-secondary); }

/* ======================================================= */
/* ===         5. MODALES Y POPUPS                     === */
/* ======================================================= */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.6); display: flex; justify-content: center; align-items: center; z-index: 2000; backdrop-filter: blur(4px); }
.modal-content { background-color: var(--bg-content); color: var(--text-primary); padding: 20px 30px; border-radius: 12px; width: 90%; max-width: 500px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 5px 20px rgba(0,0,0,0.2); position: relative; animation: fadeIn 0.3s ease-in-out; }
@keyframes fadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.modal-close-button { position: absolute; top: 10px; right: 20px; font-size: 28px; font-weight: bold; cursor: pointer; color: var(--text-secondary); }
.modal-close-button:hover { color: var(--text-primary); }

#welcome-popup-content { max-width: 600px; text-align: center; }
.popup-body { text-align: left; line-height: 1.6; margin-bottom: 25px; max-height: 60vh; overflow-y: auto; padding-right: 15px; }
.popup-body h2 { text-align: center; margin-top: 0; margin-bottom: 20px; font-weight: 700; }
.popup-body strong { color: var(--primary-color); }
#confirm-welcome-popup { font-size: 1rem; font-weight: 700; padding: 12px 25px; background-color: var(--primary-color); color: white; border: none; border-radius: 8px; cursor: pointer; transition: background-color 0.2s; }
#confirm-welcome-popup:hover { background-color: var(--primary-color-hover); }

#emoji-picker { position: absolute; bottom: calc(100% + 10px); right: 20px; z-index: 50; background-color: var(--bg-content); border: 1px solid var(--border-color); box-shadow: 0 4px 12px rgba(0,0,0,0.1); border-radius: 12px; padding: 10px; padding-right: 5px; width: 330px; max-height: 250px; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 5px; }
#emoji-picker::-webkit-scrollbar { width: 8px; }
#emoji-picker::-webkit-scrollbar-track { background: transparent; }
#emoji-picker::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 10px; border: 2px solid var(--bg-content); }
#emoji-picker span { cursor: pointer; font-size: 26px; border-radius: 8px; transition: background-color 0.2s; display: flex; justify-content: center; align-items: center; aspect-ratio: 1 / 1; }
#emoji-picker span:hover { background-color: var(--bg-hover); }

.message-main-wrapper:hover .message-actions { opacity: 1; transform: translateY(0); pointer-events: auto; }
.message-actions { position: absolute; top: -12px; right: 0; z-index: 5; background-color: var(--bg-content); border: 1px solid var(--border-color); border-radius: 20px; padding: 2px 4px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); display: flex; gap: 4px; opacity: 0; transition: opacity 0.2s ease, transform 0.2s ease; transform: translateY(5px); pointer-events: none; }
.message-actions .action-btn { background: none; border: none; cursor: pointer; font-size: 16px; padding: 4px; color: var(--text-secondary); border-radius: 50%; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; transition: background-color 0.2s, color 0.2s; }
.message-actions .action-btn:hover { background-color: var(--bg-hover); color: var(--text-primary); }

#user-action-popup { position: absolute; background-color: var(--bg-content); border: 1px solid var(--border-color); border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 1500; padding: 10px; width: 200px; }
#user-action-popup .user-info { padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid var(--border-color); text-align: center; }
#popup-user-nick { font-size: 1.1em; font-weight: 600; word-break: break-all; }
.user-id-display { display: block; font-size: 0.8em; color: var(--text-secondary); margin-top: 4px; font-family: monospace; }
#user-action-popup .action-buttons { display: flex; flex-direction: column; gap: 5px; }
#user-action-popup .action-buttons button { width: 100%; padding: 8px; border: 1px solid var(--border-color); background-color: var(--bg-hover); color: var(--text-primary); border-radius: 6px; cursor: pointer; font-weight: 600; text-align: left; }
#user-action-popup .action-buttons button:hover { background-color: var(--bg-active); border-color: #ccc; }
#popup-report-button { background-color: #fceceb; border-color: #e74c3c; color: #c0392b; }

#avatar-hover-popup { position: fixed; z-index: 3000; background-color: var(--bg-content); border: 1px solid var(--border-color); border-radius: 8px; box-shadow: 0 5px 15px rgba(0,0,0,0.3); padding: 5px; pointer-events: none; transition: opacity 0.2s ease-in-out, transform 0.2s ease-in-out; opacity: 0; transform: scale(0.95); }
#avatar-hover-popup.visible { opacity: 1; transform: scale(1); pointer-events: auto; }
#avatar-hover-popup img { display: block; width: 200px; height: 200px; border-radius: 4px; }
/* ======================================================= */
/* ===         6. PANEL DE MODERACIÓN Y PERFIL         === */
/* ======================================================= */
#admin-modal .modal-content { max-width: 950px; width: 95vw; height: 90vh; padding: 0; display: flex; flex-direction: column; }
#admin-modal h2 { padding: 20px 24px; font-size: 1.5rem; font-weight: 700; border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
.admin-tabs { display: flex; border-bottom: 1px solid var(--border-color); padding: 0 24px; flex-shrink: 0; flex-wrap: wrap; }
.admin-tab { padding: 12px 18px; cursor: pointer; background: none; border: none; font-size: 1rem; font-weight: 600; color: var(--text-secondary); border-bottom: 3px solid transparent; transition: all 0.2s ease; }
.admin-tab:hover { background-color: var(--bg-hover); color: var(--text-primary); }
.admin-tab.active { font-weight: 700; color: var(--primary-color); border-bottom-color: var(--primary-color); }
.admin-panel { flex-grow: 1; overflow-y: auto; padding: 24px; }
.admin-panel h3 { margin-top: 0; margin-bottom: 16px; }
.table-container { overflow-x: auto; border: 1px solid var(--border-color); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 0.9em; min-width: 800px; }
thead th { background-color: var(--bg-hover); padding: 12px 16px; text-align: left; font-weight: 600; text-transform: uppercase; font-size: 0.8em; letter-spacing: 0.5px; color: var(--text-secondary); border-bottom: 1px solid var(--border-color); }
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border-color); color: var(--text-primary); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) { background-color: var(--bg-panel); }
.action-button.unban-btn, .action-button.unmute-btn { color: white; font-weight: 600; padding: 6px 12px; border: none; border-radius: 6px; font-size: 0.85em; transition: opacity 0.2s; }
.action-button.unban-btn { background-color: #27ae60; }
.action-button.unmute-btn { background-color: #2980b9; }
.action-button:hover { opacity: 0.85; }

.profile-avatar { display: block; width: 150px; height: 150px; object-fit: cover; border-radius: 50%; margin: 0 auto 20px; border: 3px solid var(--border-color); box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
#profile-modal .modal-content { max-width: 420px; }
.profile-content { display: flex; flex-direction: column; align-items: center; gap: 20px; width: 100%; }
.profile-avatar-container { position: relative; width: 150px; height: 150px; }
.profile-avatar { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; border: 4px solid var(--bg-content); box-shadow: 0 0 0 2px var(--border-color), 0 5px 15px rgba(0,0,0,0.1); }
.avatar-edit-label { position: absolute; bottom: 5px; right: 5px; width: 36px; height: 36px; background-color: var(--bg-hover); border: 2px solid var(--bg-content); border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 18px; transition: transform 0.2s ease, background-color 0.2s ease; }
.avatar-edit-label:hover { transform: scale(1.1); background-color: var(--bg-active); }
.profile-nick-display { font-size: 1.1rem; color: var(--text-secondary); text-align: center; margin-top: -10px; margin-bottom: 10px; border-bottom: 1px solid var(--border-color); width: 100%; padding-bottom: 20px; }
.profile-nick-display strong { color: var(--text-primary); }
.profile-section { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.profile-section label { font-weight: 600; color: var(--text-secondary); font-size: 0.9rem; }
.input-group { display: flex; width: 100%; }
.input-group input[type="text"] { flex-grow: 1; border: 1px solid var(--border-color); padding: 10px 12px; border-radius: 6px 0 0 6px; background-color: var(--bg-main); color: var(--text-primary); outline: none; }
.input-group input[type="text"]:focus { border-color: var(--primary-color); box-shadow: 0 0 0 2px rgba(0, 136, 204, 0.2); z-index: 1; }
.input-group .action-button { border-radius: 0 6px 6px 0; border: 1px solid var(--border-color); border-left: none; background-color: var(--bg-hover); font-weight: 600; }
.file-input-label { padding: 10px 15px; background-color: var(--bg-hover); border: 1px solid var(--border-color); border-radius: 6px 0 0 6px; cursor: pointer; white-space: nowrap; font-weight: 600; color: var(--text-primary); }
#file-name-display { flex-grow: 1; padding: 10px 12px; border: 1px solid var(--border-color); border-left: none; border-radius: 0 6px 6px 0; background-color: var(--bg-main); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.9em; }
.profile-section .action-button.primary { width: 100%; background-color: var(--primary-color); color: white; font-weight: 700; border: none; padding: 12px; margin-top: 5px; }
.profile-section .action-button.primary:hover { background-color: var(--primary-color-hover); }

/* ======================================================= */
/* ===         7. ESTILOS RESPONSIVOS (MÓVIL)          === */
/* ======================================================= */
@media (max-width: 1024px) {
    #chat-container { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
    #chat-area-wrapper { flex-grow: 1; }
    #room-header-container { display: grid; grid-template-columns: 50px 1fr 50px; align-items: center; padding: 0 8px; height: 56px; }
    #room-name-header { display: block; text-align: center; margin: 0; }
    .mobile-nav-button { display: flex; justify-content: center; align-items: center; width: 40px; height: 40px; font-size: 24px; border-radius: 50%; }
    #toggle-conversations-btn { grid-column: 1; justify-self: center; }
    #toggle-users-btn { grid-column: 3; justify-self: center; }
    #conversations-panel, #user-list-container { position: fixed; top: 0; height: 100%; z-index: 999; width: 280px; max-width: 80vw; box-shadow: 0 0 15px rgba(0,0,0,0.2); transition: transform 0.3s ease-in-out; }
    #conversations-panel { left: 0; transform: translateX(-100%); }
    #user-list-container { right: 0; transform: translateX(100%); border-left: none; }
    #conversations-panel.show, #user-list-container.show { transform: translateX(0); }
    #mobile-overlay.show { display: block; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); z-index: 998; }

    #form {
        padding: 5px;
        gap: 3px;
    }

    #input {
        padding: 8px 12px;
        font-size: 16px;
    }

    .chat-action-button {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }

    #reply-context-bar {
        align-items: flex-start;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .reply-info {
        flex-grow: 1;
        min-width: 0;
        margin-right: 10px;
    }

    .reply-info .reply-text-preview {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        max-width: 100%;
        word-break: break-word;
    }
    
    .reply-quote p {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        word-break: break-word;
    }
}

@media (min-width: 1025px) {
    #private-chat-back-button { display: none; }
    .mobile-nav-button { display: none; }
    #mobile-overlay { display: none !important; }
}

/* ======================================================= */
/* ===         8. MODO OSCURO                        === */
/* ======================================================= */
body.dark-mode { --bg-main: #18191a; --bg-content: #242526; --bg-panel: #242526; --bg-input-area: #242526; --bg-hover: #3a3b3c; --bg-active: #3a3b3c; --bg-mention: #574a21; --text-primary: #e4e6eb; --text-secondary: #b0b3b8; --border-color: #3a3b3c; --shadow-light: rgba(0, 0, 0, 0.2); --primary-color: #4dabf7; --primary-color-hover: #74c0fc; --my-message-bubble: #005c9e; --other-message-bubble: #3a3b3c; }
body.dark-mode .welcome-box { background: rgba(36, 37, 38, 0.9); border-color: rgba(58, 59, 60, 0.8); }
body.dark-mode .welcome-box h1 { color: #e4e6eb; }
body.dark-mode #login-form input, body.dark-mode #register-form input, body.dark-mode #guest-form input { background-color: #3a3b3c; border-color: #4e4f50; color: #e4e6eb; }
body.dark-mode #login-form input:focus, body.dark-mode #register-form input:focus, body.dark-mode #guest-form input:focus { background-color: #4e4f50; box-shadow: 0 0 0 2px rgba(77, 171, 247, 0.3); }
body.dark-mode #input { background-color: #3a3b3c; color: #e4e6eb; }
body.dark-mode #input:focus { background-color: #4e4f50; box-shadow: 0 0 0 2px var(--primary-color); }
body.dark-mode .system-message.highlight { background-color: rgba(77, 171, 247, 0.15) !important; color: #a5d8ff; }
body.dark-mode #room-list li.active, body.dark-mode #private-chat-list li.active { background-color: #003c75; }
body.dark-mode tbody tr:nth-child(even) { background-color: rgba(0,0,0,0.2); }
body.dark-mode #popup-report-button { background-color: #5c2b29; border-color: #a53125; color: #ff8a80; }
body.dark-mode #profile-button { background: #333; border-color: #555; color: #f1f1f1; }
body.dark-mode #profile-button:hover { background-color: #444; }
body.dark-mode .reply-quote { background-color: rgba(255, 255, 255, 0.08); }
body.dark-mode #private-chat-view .chat-header { background-color: #2e4b32; border-bottom-color: #395d3c; }
body.dark-mode #private-chat-with-user { color: #c8e6c9; }
body.dark-mode .input-group input[type="text"]:focus { box-shadow: 0 0 0 2px rgba(77, 171, 247, 0.3); }

.edited-indicator { display: inline-block; font-size: 0.8em; color: var(--text-secondary); margin-left: 5px; font-style: italic; }
#command-suggestions { position: absolute; bottom: calc(100% + 5px); left: 20px; right: 20px; z-index: 20; background-color: var(--bg-content); border: 1px solid var(--border-color); border-bottom: none; border-radius: 8px 8px 0 0; box-shadow: 0 -4px 12px var(--shadow-light); max-height: 150px; overflow-y: auto; }
#command-suggestions ul { list-style: none; padding: 0; margin: 0; }
#command-suggestions li { padding: 10px 15px; cursor: pointer; border-bottom: 1px solid var(--border-color); color: var(--text-primary); font-weight: 500; }
#command-suggestions li:last-child { border-bottom: none; }
#command-suggestions li:hover, #command-suggestions li.active-suggestion { background-color: var(--bg-hover); color: var(--primary-color); }
#nick-context-menu { position: absolute; z-index: 1600; background-color: var(--bg-content); border: 1px solid var(--border-color); border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); padding: 5px; display: flex; flex-direction: column; gap: 3px; }
#nick-context-menu button { width: 100%; padding: 8px 12px; border: none; background-color: transparent; color: var(--text-primary); border-radius: 6px; cursor: pointer; font-weight: 500; text-align: left; }
#nick-context-menu button:hover { background-color: var(--bg-hover); color: var(--primary-color); }
#self-context-menu { position: absolute; z-index: 1600; background-color: var(--bg-content); border: 1px solid var(--border-color); border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); padding: 5px; display: flex; flex-direction: column; gap: 3px; width: 180px; }
#self-context-menu button, #self-context-menu label.context-menu-button { width: 100%; padding: 10px 15px; border: none; background-color: transparent; color: var(--text-primary); border-radius: 6px; cursor: pointer; font-weight: 500; text-align: left; font-size: 1rem; line-height: 1.2; display: block; box-sizing: border-box; }
#self-context-menu button:hover, #self-context-menu label.context-menu-button:hover { background-color: var(--bg-hover); color: var(--primary-color); }
#reply-context-bar { position: absolute; bottom: 100%; left: 0; right: 0; background-color: var(--bg-panel); border-top: 1px solid var(--border-color); padding: 8px 20px; display: flex; justify-content: space-between; align-items: center; font-size: 0.9em; animation: slideInUp 0.2s ease-out; }
@keyframes slideInUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.reply-info .reply-label { color: var(--text-secondary); }
.reply-info .reply-text-preview { color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; margin-top: 2px; }
.cancel-reply-btn { background: none; border: none; font-size: 20px; font-weight: bold; color: var(--text-secondary); cursor: pointer; }
#sexo-warning-modal .modal-content { border-top: 5px solid #d9534f; max-width: 550px; }
#sexo-warning-modal h2 { text-align: center; color: #d9534f; margin-bottom: 15px; }
#sexo-warning-modal ul { list-style-type: '🚫 '; padding-left: 25px; margin: 15px 0; }
#sexo-warning-modal li { margin-bottom: 8px; font-weight: 500; }
#sexo-warning-modal .warning-consequence { font-weight: bold; color: #c9302c; text-align: center; margin-top: 20px; padding-top: 15px; border-top: 1px solid var(--border-color); }
#accept-sexo-warning { width: 100%; background-color: #d9534f; color: white; font-weight: bold; padding: 12px; font-size: 1.1em; border: none; border-radius: 6px; cursor: pointer; transition: background-color 0.2s; }
#accept-sexo-warning:hover { background-color: #c9302c; }
#image-modal-overlay { background-color: rgba(0, 0, 0, 0.85); backdrop-filter: blur(5px); cursor: zoom-out; }
#modal-image { display: block; max-width: 90vw; max-height: 90vh; object-fit: contain; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.4); cursor: default; }
#close-image-modal { color: white; font-size: 40px; position: absolute; top: 15px; right: 35px; text-shadow: 0 0 8px black; cursor: zoom-out; }
#toggle-conversations-btn { position: relative; }
#private-unread-badge { position: absolute; top: 2px; right: 2px; background-color: #d9534f; color: white; border-radius: 50%; border: 2px solid var(--bg-panel); min-width: 20px; height: 20px; padding: 2px; font-size: 11px; font-weight: bold; line-height: 1; display: flex; justify-content: center; align-items: center; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); transform: scale(0); transition: transform 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28); }
#private-unread-badge:not(.hidden) { transform: scale(1); animation: pulse-badge 2s infinite 1s; }
@keyframes pulse-badge { 0% { box-shadow: 0 0 0 0 rgba(217, 83, 79, 0.7); } 70% { box-shadow: 0 0 0 8px rgba(217, 83, 79, 0); } 100% { box-shadow: 0 0 0 0 rgba(217, 83, 79, 0); } }
.action-button-logout { width: 100%; background-color: #e74c3c; color: white; border: none; border-radius: 8px; padding: 10px; cursor: pointer; font-weight: 600; transition: background-color 0.2s; margin-top: 10px; }
.action-button-logout:hover { background-color: #c0392b; }
body.dark-mode .action-button-logout { background-color: #a53125; }
body.dark-mode .action-button-logout:hover { background-color: #c0392b; }
#form.is-recording { gap: 15px; }
#form.is-recording #input, #form.is-recording #emoji-button, #form.is-recording .file-label, #form.is-recording #send-icon-button, #form.is-recording #record-audio-button { display: none; }
#audio-recording-controls { display: flex; align-items: center; gap: 8px; background-color: var(--bg-hover); padding: 4px 8px; border-radius: 20px; flex-grow: 1; justify-content: space-between; }
#recording-timer { font-weight: 600; color: var(--text-secondary); font-family: monospace; font-size: 0.9em; margin: 0 10px; }

.password-container {
    position: relative;
}

#toggle-password {
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    cursor: pointer;
}

/* Estilo para emojis de Twemoji */
.message-content img.emoji {
    width: 1.5em;
    height: 1.5em;
    margin: 0 .05em 0 .1em;
    vertical-align: -0.4em;
}

.chat-image {
    max-width: 100%;
    max-height: 300px;
    display: block;
    margin-top: 5px;
    border-radius: 8px;
}

#admin-agreement-text {
    max-height: 40vh;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    padding: 10px;
    border-radius: 5px;
    background-color: var(--bg-main);
    margin-bottom: 15px;
}

#accept-agreement-button {
    background-color: #28a745; /* Verde */
    color: white;
}

#accept-agreement-button:disabled {
    background-color: #8f8f8f;
    cursor: not-allowed;
}

#decline-agreement-button {
    background-color: #dc3545; /* Rojo */
    color: white;
}

/* ======================================================= */
/* ===         9. LINK PREVIEWS                        === */
/* ======================================================= */

.link-preview-card {
    display: block;
    max-width: 100%;
    margin-top: 8px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    background-color: var(--bg-main);
}

.link-preview-card:hover {
    border-color: var(--primary-color);
}

.preview-image-container {
    width: 100%;
    max-height: 200px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #000;
}

.preview-image-container img {
    width: 100%;
    height: auto;
    object-fit: cover;
}

.preview-info {
    padding: 10px 12px;
}

.preview-title {
    display: block;
    font-weight: 600;
    font-size: 0.95em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.preview-description {
    font-size: 0.85em;
    color: var(--text-secondary);
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

[data-preview-type="youtube"] .preview-image-container {
    position: relative;
}

[data-preview-type="youtube"] .preview-image-container::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 42px;
    background-image: url('data:image/svg+xml;utf8,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 68 48"%3E%3Cpath d="M66.52 7.74c-.78-2.93-2.49-5.41-5.42-6.19C55.79.13 34 0 34 0S12.21.13 6.9 1.55c-2.93.78-4.63 3.26-5.42 6.19C.06 13.05 0 24 0 24s.06 10.95 1.48 16.26c.78 2.93 2.49 5.41 5.42 6.19C12.21 47.87 34 48 34 48s21.79-.13 27.1-1.55c2.93-.78 4.64-3.26 5.42-6.19C67.94 34.95 68 24 68 24s-.06-10.95-1.48-16.26z" fill="%23ff0000"/%3E%3Cpath d="M45 24L27 14v20" fill="%23fff"/%3E%3C/svg%3E');
    background-repeat: no-repeat;
    background-size: contain;
    opacity: 0.9;
    transition: transform 0.2s ease;
}

[data-preview-type="youtube"]:hover .preview-image-container::after {
    transform: translate(-50%, -50%) scale(1.15);
}

@media (max-width: 768px) {
    .preview-image-container {
        max-height: 180px;
    }
}

.message-text iframe {
    aspect-ratio: 16 / 9;
    width: 100%;
    max-width: 480px;
    border-radius: 12px;
    border: none;
    display: block;
    margin-top: 8px;
}
/* ======================================================= */
/* ===         ESTILOS PERSONALIZADOS PARA EMOJIS      === */
/* ======================================================= */

.message-text img.emoji, .reply-quote p img.emoji {
    width: 1.4em;
    height: 1.4em;
    margin: 0 .1em;
    vertical-align: -0.3em;
}