/**
 * WebMail v65.0 - Estilos principales
 * Cliente de correo completo con carpetas limpias, selección persistente y selección múltiple
 * CORREGIDO: Modal con position:fixed para evitar desplazamiento
 */

/* ============================================================================
   RESET Y ESTILOS BASE
   ============================================================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Evita el desplazamiento al abrir modales - scrollbar siempre visible */
html {
    overflow-y: scroll;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f2f5;
    height: 100vh;
    overflow: hidden;
}

/* ============================================================================
   LAYOUT PRINCIPAL
   ============================================================================ */

.container {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* Panel de carpetas (izquierdo) */
.folders-panel {
    width: 260px;
    background: linear-gradient(135deg, #2c3e50, #1a252f);
    color: white;
    overflow-y: auto;
    flex-shrink: 0;
}

.folders-header {
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
}

.folders-header h2 {
    font-size: 18px;
    margin-bottom: 15px;
}

.version-badge {
    font-size: 10px;
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 5px;
}

.btn-header {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

/* Botones generales */
.btn {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-purple {
    background: #8e44ad;
    color: white;
}

.btn-orange {
    background: #fd7e14;
    color: white;
}

.btn-blue {
    background: #3498db;
    color: white;
}

.btn-green {
    background: #27ae60;
    color: white;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-small {
    padding: 4px 8px;
    font-size: 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.btn-help {
    background: #6f42c1;
    color: white;
}

/* Lista de carpetas */
.folder-list {
    list-style: none;
    padding: 10px 0;
}

.folder-item {
    padding: 12px 20px;
    cursor: pointer;
    border-left: 3px solid transparent;
    display: flex;
    gap: 10px;
    transition: all 0.2s ease;
}

.folder-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Carpeta activa */
.folder-item.active {
    background: rgba(52, 152, 219, 0.35);
    border-left: 3px solid #3498db;
    font-weight: 600;
    position: relative;
}

/* Indicador de carpeta activa */
.folder-item.active::after {
    content: "📍";
    position: absolute;
    right: 15px;
    font-size: 12px;
    opacity: 0.8;
}

/* ============================================================================
   PANEL DE EMAILS (central)
   ============================================================================ */

.emails-panel {
    width: 480px;
    background: white;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #dee2e6;
    flex-shrink: 0;
}

.emails-header {
    padding: 15px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.search-bar {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.search-bar input {
    flex: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.search-bar input:focus {
    outline: none;
    border-color: #3498db;
}

.search-bar select,
.search-bar button {
    padding: 8px;
    border-radius: 6px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
}

.email-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    font-size: 13px;
}

.pagination {
    display: flex;
    gap: 5px;
    align-items: center;
}

.pagination button {
    padding: 4px 10px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pagination button:hover:not(:disabled) {
    background: #e9ecef;
}

.pagination button.active {
    background: #007bff;
    color: white;
    border-color: #007bff;
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Lista de emails */
.emails-list {
    flex: 1;
    overflow-y: auto;
}

/* Cabecera de la lista de emails con checkbox de seleccionar todo */
.email-list-header {
    padding: 10px 15px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    font-size: 13px;
    font-weight: 500;
}

.select-all-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.select-all-container input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    margin: 0;
}

.select-all-container label {
    cursor: pointer;
    margin: 0;
    font-weight: normal;
}

/* Checkbox individual en cada email */
.email-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    border-bottom: 1px solid #e9ecef;
    cursor: pointer;
    transition: background 0.2s ease;
}

.email-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
    margin: 0;
}

.email-content-wrapper {
    flex: 1;
    cursor: pointer;
}

.email-item:hover {
    background: #f8f9fa;
}

.email-item.unread {
    background: #fff3e0;
    font-weight: bold;
}

/* Email seleccionado (el que se está viendo) */
.email-item.selected {
    background: #e3f2fd !important;
    border-left: 3px solid #2196f3;
    position: relative;
    box-shadow: inset 0 0 0 1px rgba(33, 150, 243, 0.15);
}

.email-item.selected.unread {
    background: #fff8e1 !important;
    border-left-color: #ff9800;
}

.email-item.selected:hover {
    background: #bbdef5 !important;
}

.email-item.selected.unread:hover {
    background: #ffe0b2 !important;
}

.email-from {
    font-size: 14px;
    font-weight: 500;
}

.email-subject {
    font-size: 13px;
    margin-top: 3px;
    color: #495057;
}

.email-date {
    font-size: 11px;
    color: #6c757d;
    margin-top: 3px;
}

/* Barra de acciones masivas */
.bulk-actions-bar {
    background: #e3f2fd;
    border: 1px solid #bbdef5;
    border-radius: 8px;
    padding: 10px 15px;
    margin: 0 15px 15px 15px;
    display: none;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.bulk-actions-bar.visible {
    display: flex;
}

.bulk-actions-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 500;
    color: #1976d2;
}

.bulk-actions-buttons {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.bulk-actions-buttons select {
    padding: 6px 10px;
    border: 1px solid #bbdef5;
    border-radius: 6px;
    background: white;
    font-size: 13px;
    cursor: pointer;
}

.bulk-actions-buttons button {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.bulk-actions-buttons button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-bulk-delete {
    background: #dc3545;
    color: white;
}

.btn-bulk-delete:hover:not(:disabled) {
    background: #c82333;
}

.btn-bulk-move {
    background: #6c757d;
    color: white;
}

.btn-bulk-move:hover:not(:disabled) {
    background: #5a6268;
}

/* ============================================================================
   PANEL DE CONTENIDO (derecho)
   ============================================================================ */

.content-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.content-header {
    padding: 15px 20px;
    background: white;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tools-bar {
    display: flex;
    gap: 10px;
}

.tools-bar button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: white;
    transition: all 0.2s ease;
}

.tools-bar button:hover {
    opacity: 0.85;
}

.btn-contacts { background: #3498db; }
.btn-tasks { background: #27ae60; }
.btn-notes { background: #fd7e14; }
.btn-help { background: #6f42c1; }

.content-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* ============================================================================
   MODALES CORREGIDOS - position: fixed para evitar desplazamiento
   ============================================================================ */

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 90%;
    max-height: 90%;
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-sat {
    width: 900px;
    max-width: 90%;
}

.modal-header {
    background: #2c3e50;
    padding: 15px 20px;
    border-radius: 12px 12px 0 0;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
}

.close-modal-btn {
    cursor: pointer;
    font-size: 28px;
    line-height: 1;
    transition: opacity 0.2s;
}

.close-modal-btn:hover {
    opacity: 0.8;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 15px 20px;
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    position: sticky;
    bottom: 0;
}

/* ============================================================================
   FORMULARIOS
   ============================================================================ */

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    font-weight: bold;
    margin-bottom: 5px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #3498db;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.checkbox-label input {
    width: auto;
}

.help-text {
    display: block;
    color: #666;
    margin-top: 5px;
    font-size: 12px;
}

.button-group {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

/* ============================================================================
   TABS
   ============================================================================ */

.tab-bar {
    display: flex;
    border-bottom: 1px solid #ddd;
    margin-bottom: 15px;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    background: white;
    z-index: 5;
}

.tab {
    padding: 10px 20px;
    cursor: pointer;
    background: none;
    border: none;
    font-size: 14px;
    transition: all 0.2s ease;
}

.tab:hover {
    background: #f8f9fa;
}

.tab.active {
    border-bottom: 2px solid #007bff;
    color: #007bff;
    font-weight: bold;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ============================================================================
   LISTAS DE DATOS
   ============================================================================ */

.data-list {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #eee;
    border-radius: 6px;
}

.data-item {
    padding: 10px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.data-item:last-child {
    border-bottom: none;
}

.empty-list {
    text-align: center;
    padding: 40px;
    color: #6c757d;
}

.btn-delete-item {
    background: #dc3545;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.btn-delete-item:hover {
    background: #c82333;
}

/* ============================================================================
   TOAST NOTIFICATIONS
   ============================================================================ */

.toast-message {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #28a745;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    z-index: 10000;
    animation: slideIn 0.3s ease-out;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toast-message.error {
    background: #dc3545;
}

.toast-message.info {
    background: #2196f3;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ============================================================================
   GESTIÓN DE CARPETAS
   ============================================================================ */

.folders-list-container {
    border: 1px solid #ddd;
    border-radius: 6px;
    max-height: 400px;
    overflow-y: auto;
}

.folder-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
}

.folder-list-item:last-child {
    border-bottom: none;
}

.folder-actions {
    display: flex;
    gap: 8px;
}

.folder-actions button {
    padding: 4px 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
}

.btn-empty-folder {
    background: #ffc107;
    color: #333;
}

.btn-empty-folder:hover {
    background: #e0a800;
}

.btn-delete-folder {
    background: #dc3545;
    color: white;
}

.btn-delete-folder:hover {
    background: #c82333;
}

.create-folder-box {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.create-folder-box input {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* ============================================================================
   MENSAJES DE ESTADO
   ============================================================================ */

.loading {
    text-align: center;
    padding: 40px;
    color: #6c757d;
}

.error {
    color: #721c24;
    background: #f8d7da;
    padding: 10px;
    border-radius: 6px;
    margin: 10px;
}

.success-message {
    background: #d4edda;
    color: #155724;
    padding: 10px;
    border-radius: 6px;
}

.error-message {
    background: #f8d7da;
    color: #721c24;
    padding: 10px;
    border-radius: 6px;
}

.info-box {
    background: #e7f3ff;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 10px;
}

.no-config-message {
    text-align: center;
    padding: 40px;
    background: #fff3cd;
    border-radius: 12px;
    margin: 20px;
}

.no-config-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.test-result-container {
    margin-top: 10px;
}

.test-result {
    margin-left: 10px;
}

/* ============================================================================
   SECCIONES Y DIVISORES
   ============================================================================ */

.section-divider {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #ddd;
}

.section-divider h4 {
    margin-bottom: 15px;
}

/* ============================================================================
   ATTACHMENTS
   ============================================================================ */

.attachment-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid #eee;
}

.attachment-item:last-child {
    border-bottom: none;
}

.remove-attachment {
    background: #dc3545;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

/* ============================================================================
   EMAIL CONTENT
   ============================================================================ */

.email-content {
    border: 1px solid #ddd;
    border-radius: 8px;
    background: white;
}

/* ============================================================================
   SCROLLBARS PERSONALIZADOS
   ============================================================================ */

.folders-panel::-webkit-scrollbar {
    width: 6px;
}

.folders-panel::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.folders-panel::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.folders-panel::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

.emails-list::-webkit-scrollbar {
    width: 8px;
}

.emails-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.emails-list::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.emails-list::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.content-body::-webkit-scrollbar {
    width: 8px;
}

.content-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.content-body::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.content-body::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* ============================================================================
   MEDIA QUERIES
   ============================================================================ */

@media (max-width: 768px) {
    .folders-panel {
        width: 200px;
    }
    
    .emails-panel {
        width: 350px;
    }
    
    .btn-header {
        flex-direction: column;
    }
    
    .tools-bar {
        flex-direction: column;
        gap: 5px;
    }
    
    .bulk-actions-bar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .bulk-actions-buttons {
        justify-content: space-between;
    }
    
    .email-item {
        gap: 8px;
    }
    
    .email-checkbox {
        width: 16px;
        height: 16px;
    }
    
    .modal-content {
        width: 95%;
        max-height: 95%;
    }
}

@media print {
    .folders-panel,
    .emails-panel,
    .reply-btn,
    .replyall-btn,
    .forward-btn,
    #moveFolderSelect,
    #moveEmailBtn,
    #extractSatBtn,
    #exportPdfBtn,
    .download-attachment-btn,
    [class*="btn"],
    .tools-bar,
    .pagination {
        display: none !important;
    }
    
    .content-panel {
        width: 100% !important;
    }
    
    .email-content {
        border: none !important;
    }
    
    body {
        background: white !important;
        color: black !important;
    }
    
    @page {
        margin: 2cm;
    }
}

/* ============================================================================
   EDITOR HTML Y BARRA DE HERRAMIENTAS - v65.0
   ============================================================================ */

/* Barra de herramientas del editor */
.compose-toolbar {
    border: 1px solid #ddd;
    padding: 8px;
    background: #f5f5f5;
    border-radius: 6px 6px 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
}

.compose-toolbar button {
    padding: 4px 10px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    border-radius: 4px;
    font-size: 14px;
    transition: all 0.2s ease;
}

.compose-toolbar button:hover {
    background: #e9ecef;
    border-color: #bbb;
}

.compose-toolbar select,
.compose-toolbar input {
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    background: white;
}

.compose-toolbar select:hover,
.compose-toolbar input:hover {
    border-color: #bbb;
}

/* Editor HTML (contenteditable) */
.compose-editor {
    border: 1px solid #ddd;
    border-top: none;
    padding: 15px;
    min-height: 350px;
    overflow-y: auto;
    font-family: 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    background: white;
    border-radius: 0 0 6px 6px;
}

.compose-editor:focus {
    outline: none;
    border-color: #3498db;
}

/* Modal de redacción más ancho */
#composeModal .modal-content {
    width: 90%;
    max-width: 1200px;
}

/* Mejoras para el editor en móvil */
@media (max-width: 768px) {
    .compose-toolbar {
        gap: 3px;
    }
    
    .compose-toolbar button {
        padding: 4px 8px;
        font-size: 12px;
    }
    
    .compose-editor {
        min-height: 250px;
        font-size: 16px;
    }
}

/* ============================================================================
   MEJORAS PARA MODALES - Evita desbordamiento
   ============================================================================ */

/* Asegura que el body no tenga scroll cuando el modal está abierto */
body.modal-open {
    overflow: hidden;
}

/* Scroll suave para el contenido del modal */
.modal-content {
    scroll-behavior: smooth;
}

/* Headers y footers sticky dentro del modal */
.modal-header,
.modal-footer {
    position: sticky;
}

/* Modal de ayuda con tamaño adecuado */
#helpModal .modal-content {
    max-width: 1000px;
    width: 90%;
}

/* Ajuste para el contenido del modal de ayuda */
#helpModalContent {
    max-height: 65vh;
    overflow-y: auto;
}

/* ============================================================================
   ANIMACIONES ADICIONALES
   ============================================================================ */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Transición suave para carpetas */
.folder-item {
    transition: all 0.2s ease;
}

/* Sombra sutil para elementos interactivos */
button, .folder-item, .email-item {
    transition: all 0.2s ease;
}

/* ============================================================================
   ESTILOS PARA EL CONTENIDO DE AYUDA (dentro del modal)
   ============================================================================ */

.help-content {
    line-height: 1.6;
}

.help-content h1, .help-content h2, .help-content h3 {
    margin-top: 20px;
    margin-bottom: 10px;
}

.help-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
    font-size: 13px;
}

.help-content th, 
.help-content td {
    border: 1px solid #ddd;
    padding: 8px 10px;
    text-align: center;
}

.help-content th {
    background: #2c3e50;
    color: white;
}

.help-content .check {
    color: #27ae60;
    font-weight: bold;
}

.help-content .cross {
    color: #e74c3c;
    font-weight: bold;
}

.help-content .info-box {
    background: #e8f4fd;
    border-left: 4px solid #3498db;
    padding: 12px 15px;
    margin: 15px 0;
    border-radius: 8px;
}

.help-content .warning-box {
    background: #fef3e8;
    border-left: 4px solid #e67e22;
    padding: 12px 15px;
    margin: 15px 0;
    border-radius: 8px;
}