/**
 * LOHMIA MAIL - ESTILOS ADICIONALES FASE 3
 * Firma, Borradores, Carpetas, Autocompletado, Filtros
 */

/* =====================================================
   FIRMA DE EMAIL
   ===================================================== */

.lm-signature-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.lm-signature-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.lm-signature-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px 12px 0 0;
}

.lm-signature-header h3 {
    margin: 0;
    font-size: 18px;
}

.lm-signature-body {
    padding: 20px;
}

.lm-signature-editor {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    box-sizing: border-box;
}

.lm-signature-options {
    margin: 16px 0;
}

.lm-signature-option {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0;
}

.lm-signature-preview {
    margin-top: 16px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 3px solid #667eea;
}

.lm-signature-preview-label {
    font-size: 12px;
    color: #666;
    margin-bottom: 8px;
}

.lm-signature-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* =====================================================
   BORRADORES AUTO-GUARDADOS
   ===================================================== */

.lm-autosave-notice {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: #4caf50;
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    animation: fadeInOut 3s ease-in-out;
    z-index: 100;
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translateY(10px); }
    20% { opacity: 1; transform: translateY(0); }
    80% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-10px); }
}

.lm-drafts-recover {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
    border: 1px solid #ffb74d;
    border-radius: 8px;
    margin-bottom: 12px;
}

.lm-drafts-recover-text {
    flex: 1;
}

.lm-drafts-recover-text strong {
    display: block;
    color: #e65100;
    margin-bottom: 4px;
}

.lm-drafts-recover-text small {
    color: #666;
}

.lm-drafts-recover-actions {
    display: flex;
    gap: 8px;
}

/* =====================================================
   AUTOCOMPLETADO DE CONTACTOS
   ===================================================== */

.lm-autocomplete {
    position: relative;
    width: 100%;
}

.lm-autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
}

.lm-autocomplete-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.15s;
}

.lm-autocomplete-item:last-child {
    border-bottom: none;
}

.lm-autocomplete-item:hover {
    background: #f5f5f5;
}

.lm-autocomplete-email {
    display: block;
    font-weight: 500;
    color: #333;
}

.lm-autocomplete-name {
    display: block;
    font-size: 12px;
    color: #666;
    margin-top: 2px;
}

/* =====================================================
   FILTROS Y REGLAS - UI COMPLETA
   ===================================================== */

/* Panel de gestión de filtros */
.lm-filters-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.lm-filters-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.lm-filters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px 12px 0 0;
}

.lm-filters-header h3 {
    margin: 0;
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.lm-filters-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid #e0e0e0;
    background: #f8f9fa;
}

.lm-filters-count {
    color: #666;
    font-size: 13px;
}

.lm-filters-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.lm-filters-empty {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.lm-filters-empty p {
    margin: 8px 0;
}

.lm-filters-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Item de filtro */
.lm-filter-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    transition: all 0.2s;
}

.lm-filter-item:hover {
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.lm-filter-item.lm-filter-disabled {
    opacity: 0.6;
}

.lm-filter-info {
    flex: 1;
    min-width: 0;
}

.lm-filter-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.lm-filter-conditions,
.lm-filter-actions {
    font-size: 12px;
    color: #666;
    margin: 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lm-filter-status {
    margin-right: 8px;
}

.lm-filter-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.lm-filter-badge.lm-filter-enabled {
    background: #e8f5e9;
    color: #2e7d32;
}

.lm-filter-badge.lm-filter-disabled {
    background: #fafafa;
    color: #999;
}

.lm-filter-buttons {
    display: flex;
    gap: 4px;
}

.lm-filter-buttons .lm-btn-icon {
    padding: 6px;
    border-radius: 6px;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
}

.lm-filter-buttons .lm-btn-icon:hover {
    background: #e0e0e0;
}

.lm-filter-buttons .lm-btn-danger {
    color: #e53935;
}

.lm-filter-buttons .lm-btn-danger:hover {
    background: #ffebee;
}

/* Modal de crear/editar filtro */
.lm-filter-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
}

.lm-filter-modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.lm-filter-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
    background: #f8f9fa;
    border-radius: 12px 12px 0 0;
}

.lm-filter-modal-header h3 {
    margin: 0;
    font-size: 18px;
}

.lm-filter-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.lm-filter-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid #e0e0e0;
    background: #f8f9fa;
    border-radius: 0 0 12px 12px;
}

/* Secciones del filtro */
.lm-filter-section {
    margin-bottom: 20px;
}

.lm-filter-section > label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: #333;
}

.lm-filter-match {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    color: #666;
    font-size: 14px;
    flex-wrap: wrap;
}

.lm-filter-match .lm-select {
    width: auto;
}

/* Filas de condición y acción */
.lm-filter-conditions-list,
.lm-filter-actions-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.lm-filter-condition-row,
.lm-filter-action-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 6px;
}

.lm-filter-condition-row .lm-select,
.lm-filter-condition-row .lm-input {
    flex: 1;
}

.lm-filter-field {
    flex: 0 0 140px !important;
}

.lm-filter-operator {
    flex: 0 0 120px !important;
}

.lm-filter-value {
    flex: 1 !important;
    min-width: 100px;
}

.lm-filter-action-row .lm-filter-action-type {
    flex: 0 0 160px;
}

.lm-filter-action-extra {
    flex: 1;
    display: flex;
}

.lm-filter-action-extra .lm-select,
.lm-filter-action-extra .lm-input {
    width: 100%;
}

.lm-filter-toggle {
    padding-top: 10px;
    border-top: 1px solid #e0e0e0;
}

.lm-filter-toggle label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: normal !important;
}

/* Inputs y selects del mail */
.lm-input {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s;
    font-family: inherit;
}

.lm-input:focus {
    border-color: #667eea;
    outline: none;
}

.lm-select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    font-family: inherit;
}

.lm-select:focus {
    border-color: #667eea;
    outline: none;
}

/* Botones */
.lm-btn {
    padding: 8px 16px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.lm-btn:hover {
    background: #f5f5f5;
}

.lm-btn-small {
    padding: 6px 12px;
    font-size: 13px;
}

.lm-btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
}

.lm-btn-primary:hover {
    opacity: 0.9;
}

.lm-btn-icon {
    padding: 6px;
    min-width: auto;
}

/* Responsive */
@media (max-width: 600px) {
    .lm-filters-content,
    .lm-filter-modal-content {
        width: 95%;
        max-height: 90vh;
    }

    .lm-filter-condition-row,
    .lm-filter-action-row {
        flex-wrap: wrap;
    }

    .lm-filter-field,
    .lm-filter-operator,
    .lm-filter-action-type {
        flex: 1 1 100% !important;
        margin-bottom: 4px;
    }

    .lm-filter-value,
    .lm-filter-action-extra {
        flex: 1 1 100% !important;
    }

    .lm-filters-toolbar {
        flex-direction: column;
        gap: 10px;
    }
}

/* =====================================================
   MEJORAS FILTROS - ESTILOS ADICIONALES
   ===================================================== */

/* Toolbar mejorada */
.lm-filters-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid #e0e0e0;
    background: #f8f9fa;
    flex-wrap: wrap;
    gap: 10px;
}

.lm-filters-toolbar-left {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.lm-filters-toolbar-left .lm-btn {
    font-size: 13px;
    padding: 6px 12px;
}

/* Botones de filtro mejorados */
.lm-filter-buttons {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.lm-filter-buttons .lm-btn-icon {
    padding: 6px 8px;
    border-radius: 6px;
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 12px;
}

.lm-filter-buttons .lm-btn-icon:hover {
    background: #e3f2fd;
    border-color: #90caf9;
}

.lm-filter-buttons .lm-btn-danger:hover {
    background: #ffebee;
    border-color: #ef9a9a;
}

/* Modal footer mejorado */
.lm-filter-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid #e0e0e0;
    background: #f8f9fa;
    border-radius: 0 0 12px 12px;
    flex-wrap: wrap;
}

.lm-filter-modal-footer .lm-btn:first-child {
    margin-right: auto;
}

/* Toggle section mejorada */
.lm-filter-toggle {
    padding-top: 10px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.lm-filter-toggle label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: normal !important;
    white-space: nowrap;
}

/* Campos especiales de condición */
.lm-filter-condition-row .lm-filter-value[data-field="has_attachment"],
.lm-filter-condition-row .lm-filter-value[data-field="size_greater_than"],
.lm-filter-condition-row .lm-filter-value[data-field="size_less_than"] {
    max-width: 120px;
}

/* Responsive mejorado */
@media (max-width: 600px) {
    .lm-filters-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .lm-filters-toolbar-left {
        justify-content: center;
    }

    .lm-filters-count {
        text-align: center;
    }

    .lm-filter-modal-footer {
        flex-direction: column;
    }

    .lm-filter-modal-footer .lm-btn {
        width: 100%;
        justify-content: center;
    }

    .lm-filter-modal-footer .lm-btn:first-child {
        margin-right: 0;
        order: 3;
    }

    .lm-filter-toggle {
        flex-direction: column;
    }

    .lm-filter-toggle label {
        margin-left: 0 !important;
    }

    .lm-filter-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .lm-filter-status {
        margin: 8px 0;
    }

    .lm-filter-buttons {
        align-self: flex-end;
        margin-top: 8px;
    }
}

/* Animación para acciones */
.lm-filter-item.applying {
    opacity: 0.7;
    pointer-events: none;
}

.lm-filter-item.applying::after {
    content: "Aplicando...";
    position: absolute;
    right: 16px;
    color: #1976d2;
    font-size: 12px;
}
