:root {
    --md-sys-color-background: #fdfcff;
    --md-sys-color-surface: #edf0f5;
    --md-sys-color-primary: #0061a4;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-secondary-container: #d1e4ff;
    --md-sys-color-on-secondary-container: #001d36;
    --border-radius-large: 28px;
    --border-radius-medium: 16px;
    font-family: 'Roboto', sans-serif;
}

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

html, body {
    height: 100%;
    height: -webkit-fill-available;
    overflow: hidden;
    margin: 0;
    background-color: var(--md-sys-color-background); 
    color: #1a1c1e;
}
#app-container {
    height: 100%;
    height: -webkit-fill-available;
    display: flex; 
    flex-direction: column;
}

/* ======== LOGIN SCREEN ======== */
.login-screen { display: flex; justify-content: center; align-items: center; height: 100%; padding: 20px; }
.surface-card { background: var(--md-sys-color-surface); padding: 40px; border-radius: var(--border-radius-large); width: 100%; max-width: 400px; text-align: center; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.logo-icon { font-size: 64px; color: var(--md-sys-color-primary); margin-bottom: 10px; }
.surface-card h1 { font-size: 24px; font-weight: 500; margin-bottom: 5px; }
.server-info { font-size: 14px; color: #73777f; margin-bottom: 30px; }

.input-group { display: flex; align-items: center; background: #fff; border-radius: var(--border-radius-medium); padding: 5px 15px; margin-bottom: 20px; }
.input-icon { color: #73777f; margin-right: 10px; }
.input-group input { border: none; outline: none; background: transparent; font-size: 16px; padding: 15px 0; width: 100%; font-family: inherit; }
.btn-primary { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); border: none; border-radius: var(--border-radius-large); padding: 15px 30px; font-size: 16px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 10px; width: 100%; justify-content: center; transition: opacity 0.2s; }
.btn-primary:active { opacity: 0.8; }

/* ======== CHAT LAYOUT ======== */
.chat-layout { display: flex; flex-direction: column; height: 100%; }
.top-app-bar { background: var(--md-sys-color-surface); padding: 10px 15px; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;}
.title-section { display: flex; align-items: center; gap: 5px; color: var(--md-sys-color-primary); flex-shrink: 0; }
.title-section h2 { font-size: 20px; font-weight: 500; }
.actions { display: flex; align-items: center; flex-shrink: 0; gap: 2px; }
.icon-btn { background: none; border: none; cursor: pointer; padding: 8px; color: #44474e; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: rgba(0,0,0,0.05); }

.chat-body { display: flex; flex: 1; overflow: hidden; position: relative;}
.message-area { flex: 1; padding: 20px; overflow-y: auto; background: var(--md-sys-color-background); }
.message { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 15px; }
.message.system { color: #73777f; font-size: 14px; font-weight: 500; }
.info-icon { color: #0061a4; font-size: 18px; }
.success-icon { color: #146c2e; font-size: 18px; }
.msg-nick { font-weight: bold; color: var(--md-sys-color-primary); }

.user-list { width: 250px; background: var(--md-sys-color-surface); padding: 20px; overflow-y: auto; transition: transform 0.3s ease; }
.list-header { font-size: 13px; font-weight: 700; color: #73777f; margin-bottom: 15px; text-transform: uppercase;}
.user-list ul { list-style: none; }
.user-list li { padding: 10px 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.prefix { font-weight: bold; font-family: monospace; width: 15px; text-align: center; }
.prefix.op { color: #b3261e; }
.prefix.voice { color: #0061a4; }

.bottom-input-bar { padding: 15px 20px; background: var(--md-sys-color-surface); flex-shrink: 0;}
.input-wrapper { display: flex; background: var(--md-sys-color-secondary-container); border-radius: var(--border-radius-large); padding: 5px; }
.input-wrapper input { flex: 1; border: none; background: transparent; padding: 15px 20px; outline: none; font-size: 16px; color: var(--md-sys-color-on-secondary-container); font-family: inherit; }
.btn-send { background: var(--md-sys-color-primary); color: #fff; border: none; border-radius: 50%; width: 50px; height: 50px; display: flex; justify-content: center; align-items: center; cursor: pointer; }

/* ======== RESPONSIVE Y MOBILE ======== */
.mobile-only { display: none; }
@media (max-width: 768px) {
    .mobile-only { display: inline-flex; }
    .user-list { position: absolute; right: 0; top: 0; bottom: 0; z-index: 1000; box-shadow: -4px 0 15px rgba(0,0,0,0.1); transform: translateX(100%); }
    .user-list.active { transform: translateX(0); }
}

/* ======== OCULTAMIENTO INTELIGENTE ======== */
.hide-users-panel .user-list { display: none !important; }
.hide-users-panel #toggleUsersBtn { display: none !important; }

/* ======== PESTAÑAS Y NUEVO TOPIC ======== */
.tabs-bar { display: flex; background: var(--md-sys-color-surface); border-bottom: 1px solid #ddd; overflow-x: auto; flex-shrink: 0;}
.chat-tab { padding: 10px 20px; cursor: pointer; border-right: 1px solid #ddd; display: flex; align-items: center; gap: 8px; color: #73777f; font-size: 14px; user-select: none; }
.chat-tab:hover { background: rgba(0,0,0,0.02); }
.chat-tab.active { background: var(--md-sys-color-background); color: var(--md-sys-color-primary); border-bottom: 2px solid var(--md-sys-color-primary); font-weight: 500; }
.chat-tab .unread { font-weight: bold; color: #b3261e; }
.close-tab { font-size: 16px; cursor: pointer; opacity: 0.5; }
.close-tab:hover { opacity: 1; color: red; }

.channel-topic-bar { background: #e8f0fe; padding: 8px 15px; font-size: 13px; color: #1a73e8; border-bottom: 1px solid #ddd; display: none; word-break: break-word; flex-shrink: 0; }

.messages-container { flex: 1; position: relative; background: var(--md-sys-color-background); overflow: hidden; }
.message-area { display: none; position: absolute; top: 0; left: 0; right: 0; bottom: 0; padding: 20px; overflow-y: auto; }
.message-area.active { display: block; }

/* ======== ESTILOS EXCLUSIVOS MOTD ======== */
.motd-line {
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    white-space: pre-wrap;
    margin-bottom: 2px;
    word-break: break-word;
}

/* ======== PANEL DE OPCIONES ======== */
.options-panel { display: flex; flex-direction: column; gap: 20px; max-width: 400px; margin: 0 auto; padding-top: 20px;}
.options-card { background: var(--md-sys-color-surface); padding: 25px; border-radius: var(--border-radius-medium); box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
.options-card h3 { margin-bottom: 15px; font-size: 18px; color: var(--md-sys-color-primary); display: flex; align-items: center; gap: 8px; }
.options-card input { width: 100%; padding: 12px 15px; border: 1px solid #ddd; border-radius: 8px; margin-bottom: 15px; font-family: inherit; font-size: 15px; outline: none; transition: border 0.3s;}
.options-card input:focus { border-color: var(--md-sys-color-primary); }
.options-card button { width: 100%; padding: 12px; background: var(--md-sys-color-primary); color: white; border: none; border-radius: 8px; cursor: pointer; font-weight: bold; font-size: 15px; display: flex; align-items: center; justify-content: center; gap: 8px; transition: opacity 0.2s;}
.options-card button:hover { opacity: 0.9; }

/* ======== VENTANAS MODALES ======== */
.modal { display: none; position: fixed; z-index: 2000; left: 0; top: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); align-items: center; justify-content: center; padding: 20px; }
.modal.active { display: flex; }
.modal-content { background: var(--md-sys-color-surface); max-width: 450px; width: 100%; padding: 25px; border-radius: var(--border-radius-large); box-shadow: 0 10px 30px rgba(0,0,0,0.2); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; border-bottom: 1px solid rgba(0,0,0,0.1); padding-bottom: 10px; }
.modal-header h3 { font-size: 18px; color: var(--md-sys-color-primary); display: flex; align-items: center; gap: 8px; }
.modal-body p { margin-bottom: 10px; font-size: 14px; line-height: 1.4; word-break: break-word; }
.modal-input { width: 100%; padding: 12px 15px; border: 1px solid #ddd; border-radius: 8px; margin-bottom: 15px; font-family: inherit; font-size: 15px; outline: none; }
.modal-input:focus { border-color: var(--md-sys-color-primary); }

/* ======== MENÚ DE USUARIO COMPACTO ======== */
.context-menu { position: absolute; display: none; z-index: 1100; background: var(--md-sys-color-surface); border-radius: var(--border-radius-medium); box-shadow: 0 4px 15px rgba(0,0,0,0.2); }
.compact-menu { width: 230px; padding: 12px; }
.ctx-header { text-align: center; font-weight: bold; font-size: 15px; margin-bottom: 10px; color: var(--md-sys-color-primary); border-bottom: 1px solid rgba(0,0,0,0.1); padding-bottom: 8px; }
.ctx-row { display: flex; gap: 6px; margin-bottom: 6px; }
.ctx-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 5px; padding: 8px 0; background: rgba(0,0,0,0.04); border: none; border-radius: 8px; font-size: 13px; cursor: pointer; color: var(--md-sys-color-on-secondary-container); font-family: inherit; transition: background 0.2s; }
.ctx-btn:hover { background: rgba(0,0,0,0.08); }
.ctx-btn .material-symbols-outlined { font-size: 16px; }
.danger-btn { width: 100%; color: #b3261e; background: rgba(179,38,30,0.1); margin-top: 4px; }
.danger-btn:hover { background: rgba(179,38,30,0.2); }

/* ======== 3 PUNTITOS EN LISTA DE USUARIOS ======== */
.user-list li { position: relative; cursor: pointer; padding-right: 25px; transition: background 0.2s;}
.user-list li:hover { background: rgba(0,0,0,0.03); border-radius: 6px;}
.user-more-icon { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); color: #888; font-size: 18px; display: none; cursor: pointer; }
.user-list li:hover .user-more-icon { display: block; }
@media (max-width: 768px) { .user-more-icon { display: block; opacity: 0.5; } }

/* ======== ADAPTACIÓN MODO OSCURO ======== */
body.dark-theme { --md-sys-color-background: #121212; --md-sys-color-surface: #1e1e1e; --md-sys-color-primary: #64b5f6; --md-sys-color-on-primary: #000000; --md-sys-color-secondary-container: #2c2c2c; --md-sys-color-on-secondary-container: #e0e0e0; color: #e0e0e0; }
body.dark-theme .top-app-bar, body.dark-theme .bottom-input-bar, body.dark-theme .tabs-bar { border-color: #333; }
body.dark-theme .chat-tab { border-right-color: #333; color: #aaa; }
body.dark-theme .chat-tab:hover { background: #222; }
body.dark-theme .chat-tab.active { background: var(--md-sys-color-background); color: var(--md-sys-color-primary); border-bottom-color: var(--md-sys-color-primary); }
body.dark-theme .ctx-header { border-bottom-color: #333; }
body.dark-theme .ctx-btn { background: #2a2a2a; color: #ddd; }
body.dark-theme .ctx-btn:hover { background: #3a3a3a; }
body.dark-theme .user-list li:hover { background: #222; }
body.dark-theme .message .msg-nick { color: var(--md-sys-color-primary); }
body.dark-theme input, body.dark-theme .modal-input { color: #e0e0e0; background: var(--md-sys-color-background); border-color: #444; }
body.dark-theme .options-card { border: 1px solid #333; }
body.dark-theme .channel-topic-bar { background: #1e1e1e; color: #64b5f6; border-bottom-color: #333; }
body.dark-theme .modal-header { border-bottom-color: #333; }