:root {
    /* Colors */
    --primary-color: #1565c0;
    --primary-light: #1976d2;
    --primary-dark: #0d47a1;
    --secondary-color: #546e7a;
    --accent-color: #e3f2fd;
    --bg-gradient: linear-gradient(135deg, #ffffff 0%, #e3f2fd 50%, #bbdefb 100%);
    --header-gradient: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
    --header-hover-gradient: linear-gradient(135deg, #1565c0 0%, #0d47a1 100%);
    
    /* Semantic Colors */
    --success-color: #2e7d32;
    --success-bg: #e8f5e9;
    --success-border: #a5d6a7;
    --success-gradient: linear-gradient(135deg, #43a047 0%, #388e3c 100%);
    
    --error-color: #c62828;
    --error-bg: #ffebee;
    --error-border: #ef9a9a;
    --error-gradient: linear-gradient(135deg, #e53935 0%, #c62828 100%);
    
    --warning-color: #e65100;
    --warning-bg: #fff3e0;
    --warning-gradient: linear-gradient(135deg, #ff9800 0%, #f4511e 100%);
    
    --info-color: #0288d1;
    --info-dark: #01579b;
    --info-gradient: linear-gradient(135deg, #0288d1 0%, #01579b 100%);
    
    --neutral-color: #78909c;
    --neutral-dark: #607d8b;
    --neutral-gradient: linear-gradient(135deg, #78909c 0%, #607d8b 100%);
    --neutral-hover-gradient: linear-gradient(135deg, #607d8b 0%, #455a64 100%);
    
    /* Spacing & Borders */
    --border-radius-lg: 16px;
    --border-radius-md: 12px;
    --border-radius-sm: 8px;
    --spacing-lg: 20px;
    --spacing-md: 16px;
    --spacing-sm: 12px;
    --card-shadow: 0 4px 20px rgba(21, 101, 192, 0.15);
    --card-border: 2px solid rgba(21, 101, 192, 0.15);
}

* { box-sizing: border-box; }
body { 
    font-family: 'Segoe UI', Arial, sans-serif; 
    padding: var(--spacing-lg); 
    min-height: 100vh;
    background: var(--bg-gradient);
    margin: 0;
}
.container { max-width: 420px; margin: 0 auto; }
h2 { 
    color: var(--primary-color); 
    text-align: center;
    margin-bottom: 5px;
    font-size: 22px;
}
.subtitle { 
    text-align: center; 
    color: var(--secondary-color); 
    font-size: 12px; 
    margin-bottom: var(--spacing-lg);
}
.card {
    background: rgba(255, 255, 255, 0.98);
    border-radius: var(--border-radius-lg);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
    box-shadow: var(--card-shadow);
    border: var(--card-border);
}
.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: var(--spacing-sm);
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--accent-color);
}
.btn { 
    background: var(--header-gradient); 
    color: white; 
    padding: 14px 28px; 
    border: none; 
    cursor: pointer; 
    margin: 5px; 
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 3px 10px rgba(21, 101, 192, 0.3);
    width: 100%;
    display: block;
}
.btn:disabled { 
    background: linear-gradient(135deg, #9e9e9e 0%, #757575 100%); 
    cursor: not-allowed; 
    box-shadow: none; 
    transform: none;
    opacity: 0.6;
}
.btn:hover:not(:disabled) { 
    background: var(--header-hover-gradient);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(21, 101, 192, 0.4);
}
.btn:active:not(:disabled) { transform: translateY(0); }

/* Spinner */
.spinner {
    display: none;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, .3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    margin-right: 10px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.btn.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.btn.loading .spinner {
    display: inline-block;
}

/* Status refinements */
#processingStatus {
    transition: all 0.3s ease;
    min-height: 20px;
}

.status-pulse {
    animation: pulse 2s infinite;
}

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

/* Mejoras en el contenedor de acción principal */
/* Header */
.main-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(21, 101, 192, 0.1);
}
.logo-container {
    width: 45px;
    height: 45px;
    background: white;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.logo { max-width: 80%; max-height: 80%; }
.title-container h1 {
    margin: 0;
    font-size: 18px;
    color: var(--primary-dark);
    font-weight: 700;
    letter-spacing: -0.5px;
}
.title-container .subtitle {
    margin: 0;
    text-align: left;
    font-size: 12px;
    opacity: 0.8;
}

/* Skeleton Loader */
.skeleton-item {
    height: 60px;
    margin: 10px;
    background: linear-gradient(90deg, #f0f0f0 25%, #f8f8f8 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 8px;
}
@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Badges & Labels */
.badge {
    background: var(--accent-color);
    color: var(--primary-color);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid rgba(21, 101, 192, 0.2);
}
.selection-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--secondary-color);
}

/* Config Grid */
.config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 15px;
}

/* Custom Checkbox */
.checkbox-group { margin: 15px 0; }
.checkbox-container {
    display: flex;
    align-items: center;
    position: relative;
    padding-left: 30px;
    cursor: pointer;
    font-size: 13px;
    user-select: none;
    color: #37474f;
}
.checkbox-container input { position: absolute; opacity: 0; cursor: pointer; height: 0; width: 0; }
.checkmark {
    position: absolute;
    top: 0;
    left: 0;
    height: 20px;
    width: 20px;
    background-color: #eee;
    border-radius: 6px;
    transition: all 0.2s ease;
}
.checkbox-container:hover input ~ .checkmark { background-color: #ccc; }
.checkbox-container input:checked ~ .checkmark { background-color: var(--primary-light); }
.checkmark:after {
    content: "";
    position: absolute;
    display: none;
    left: 7px;
    top: 3px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.checkbox-container input:checked ~ .checkmark:after { display: block; }

/* Status Indicators */
.status-msg {
    font-size: 11px;
    margin-top: 5px;
    min-height: 15px;
    font-weight: 600;
    transition: opacity 0.3s ease;
}
.status-indicator {
    margin-top: 10px;
    font-size: 13px;
    color: var(--secondary-color);
    text-align: center;
    font-weight: 500;
}

.icon { margin-right: 8px; font-size: 16px; }

.action-card {
    background: white;
    padding: var(--spacing-lg);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 8px 30px rgba(21, 101, 192, 0.12);
    border: 2px solid var(--accent-color);
    margin-bottom: var(--spacing-lg);
    position: sticky;
    bottom: 0;
    z-index: 100;
}

/* Transiciones para el contenido colapsable */
.collapsible-content {
    padding: var(--spacing-lg);
    max-height: 1000px;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), padding 0.4s ease, opacity 0.4s ease;
    opacity: 1;
}

.collapsible-content.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    pointer-events: none;
}
.error { background: var(--error-bg); color: var(--error-color); border: 1px solid var(--error-border); }
.success { background: var(--success-bg); color: var(--success-color); border: 1px solid var(--success-border); }
.loading { background: var(--warning-bg); color: var(--warning-color); }
#info { margin-top: 10px; font-size: 12px; color: var(--secondary-color); white-space: pre-line; }

textarea {
    width: 100%;
    padding: var(--spacing-sm);
    border: 2px solid var(--accent-color);
    border-radius: 10px;
    font-size: 13px;
    font-family: Arial, sans-serif;
    resize: vertical;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    background: #fafafa;
    margin-bottom: 8px;
}
textarea:focus {
    outline: none;
    border-color: var(--primary-light);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
}
textarea::placeholder { color: #90a4ae; }

.config-content-inner { padding: 0; }
.config-group label { 
    display: block; 
    font-weight: 600; 
    margin-bottom: 6px; 
    font-size: 12px; 
    color: #37474f;
}
.config-group select, 
.config-group input[type="text"], 
.config-group input[type="password"] { 
    width: 100%; 
    padding: var(--spacing-sm) 14px; 
    border: 2px solid var(--accent-color); 
    border-radius: var(--border-radius-sm); 
    font-size: 13px; 
    box-sizing: border-box; 
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    background: #fafafa;
}
.config-group select:focus,
.config-group input[type="text"]:focus, 
.config-group input[type="password"]:focus {
    outline: none;
    border-color: var(--primary-light);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
}
.config-group input[type="checkbox"] { margin-right: 8px; width: 18px; height: 18px; accent-color: var(--primary-light); }
.btn-small { 
    background: var(--neutral-gradient); 
    color: white; 
    padding: 10px 18px; 
    border: none; 
    cursor: pointer; 
    font-size: 12px; 
    margin-top: 10px;
    margin-right: 8px;
    border-radius: var(--border-radius-sm);
    transition: all 0.3s ease;
}
.btn-small:hover { 
    background: var(--neutral-hover-gradient);
    transform: translateY(-1px);
}
.btn-save { 
    background: var(--success-gradient);
}
.btn-save:hover { background: linear-gradient(135deg, #388e3c 0%, #2e7d32 100%); }
#configStatus { margin-top: 12px; font-size: 12px; color: #43a047; font-weight: 500; }

.btn-storage { 
    background: var(--neutral-gradient); 
    color: white; 
    padding: 10px 16px; 
    border: none; 
    cursor: pointer; 
    font-size: 12px; 
    margin-right: 8px; 
    border-radius: var(--border-radius-sm);
    transition: all 0.3s ease;
}
.btn-storage:hover { 
    background: var(--neutral-hover-gradient);
    transform: translateY(-1px);
}
.btn-almacenar { background: var(--success-gradient); }
.btn-almacenar:hover { background: linear-gradient(135deg, #388e3c 0%, #2e7d32 100%); }
.btn-restaurar { background: var(--error-gradient); }
.btn-restaurar:hover { background: linear-gradient(135deg, #c62828 0%, #b71c1c 100%); }
.storage-buttons { margin-top: 10px; display: flex; gap: 8px; flex-wrap: nowrap; }
.btn-storage {
    flex: 1 1 0;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#storageStatus { margin-top: 8px; font-size: 12px; font-weight: 500; min-height: 18px; }

.api-key-group { margin-bottom: 18px; padding-bottom: 18px; border-bottom: 2px solid var(--accent-color); }
.api-key-group small { 
    display: block; 
    margin-top: 6px; 
    color: var(--neutral-color); 
    font-size: 11px; 
    line-height: 1.4;
}
.api-key-buttons { margin-top: 12px; display: flex; gap: 8px; flex-wrap: nowrap; }
.btn-api-key {
    flex: 1 1 0;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.btn-api-key { 
    background: var(--neutral-gradient); 
    color: white; 
    padding: 10px 16px; 
    border: none; 
    cursor: pointer; 
    font-size: 12px; 
    border-radius: var(--border-radius-sm);
    transition: all 0.3s ease;
}
.btn-api-key:hover { 
    background: var(--neutral-hover-gradient);
    transform: translateY(-1px);
}
.btn-api-guardar { background: var(--success-gradient); }
.btn-api-guardar:hover { background: linear-gradient(135deg, #388e3c 0%, #2e7d32 100%); }
.btn-api-limpiar { background: var(--error-gradient); }
.btn-api-limpiar:hover { background: linear-gradient(135deg, #c62828 0%, #b71c1c 100%); }
#apiKeyStatus { margin-top: 8px; font-size: 12px; font-weight: 500; min-height: 18px; }

.email-selector-panel { 
    padding: var(--spacing-md); 
    background: #f5f9fc;
    border: 2px solid var(--accent-color);
    border-radius: var(--border-radius-md);
}
.email-selector-header { 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    margin-bottom: var(--spacing-sm); 
    flex-wrap: wrap;
    gap: 10px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--accent-color);
}
.email-selector-header h4 { 
    margin: 0; 
    font-size: 14px; 
    color: var(--primary-color);
    font-weight: 600;
}
.email-selector-actions { display: flex; gap: 6px; }
.btn-select { 
    background: var(--neutral-gradient); 
    color: white; 
    padding: 8px 14px; 
    border: none; 
    cursor: pointer; 
    font-size: 11px; 
    border-radius: 6px;
    transition: all 0.3s ease;
}
.btn-select:hover { 
    background: var(--neutral-hover-gradient);
    transform: translateY(-1px);
}
.btn-select-all { background: var(--success-gradient); }
.btn-select-all:hover { background: linear-gradient(135deg, #388e3c 0%, #2e7d32 100%); }
.btn-deselect-all { background: var(--error-gradient); }
.btn-deselect-all:hover { background: linear-gradient(135deg, #c62828 0%, #b71c1c 100%); }
.email-list { 
    max-height: 180px; 
    overflow-y: auto; 
    border: 2px solid var(--accent-color); 
    border-radius: 10px; 
    background: #fff;
}
.email-item { 
    display: flex; 
    align-items: flex-start; 
    padding: var(--spacing-sm) 14px; 
    border-bottom: 1px solid var(--accent-color); 
    cursor: pointer; 
    transition: background 0.2s;
}
.email-item:hover { background: #f5f9fc; }
.email-item:last-child { border-bottom: none; }
.email-item input[type="checkbox"] { 
    margin-top: 2px; 
    margin-right: 12px; 
    cursor: pointer;
    width: 18px;
    height: 18px;
    accent-color: var(--primary-light);
}
.email-item-content { flex: 1; min-width: 0; }
.email-item-from { 
    font-weight: 600; 
    font-size: 13px; 
    color: var(--primary-color); 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
}
.email-item-subject { 
    font-size: 12px; 
    color: var(--secondary-color); 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    margin-top: 4px; 
}
.email-item-date { 
    font-size: 11px; 
    color: #90a4ae; 
    margin-top: 4px; 
}
.email-item-preview { 
    font-size: 11px; 
    color: var(--neutral-color); 
    margin-top: 4px; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
}
.email-count { 
    font-size: 12px; 
    color: var(--secondary-color); 
    margin-top: var(--spacing-sm); 
    text-align: center; 
    font-weight: 600;
}
.email-count span { 
    font-weight: bold; 
    color: var(--primary-light); 
}

#inicio {
    padding: 14px;
    background: var(--accent-color);
    border: 2px solid var(--primary-light);
    border-radius: var(--border-radius-md);
    margin-bottom: 15px;
    text-align: center;
    color: var(--primary-color);
    font-weight: 600;
    font-size: 13px;
}

/* ======================================================
   TARJETAS COLAPSABLES
   ====================================================== */

.collapsible-card {
    background: rgba(255, 255, 255, 0.98);
    border-radius: var(--border-radius-lg);
    margin-bottom: var(--spacing-lg);
    box-shadow: var(--card-shadow);
    border: var(--card-border);
    overflow: hidden;
}

.collapsible-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px var(--spacing-lg);
    background: var(--header-gradient);
    cursor: pointer;
    user-select: none;
    color: white;
    transition: background 0.3s ease;
}

.collapsible-header:hover {
    background: var(--header-hover-gradient);
}

.collapsible-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.collapsible-arrow {
    font-size: 14px;
    transition: transform 0.3s ease;
}

.collapsible-arrow.rotated {
    transform: rotate(180deg);
}

/* ======================================================
   DIÁLOGO MODAL
   ====================================================== */

.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(3px);
}

.dialog-container {
    background: white;
    border-radius: var(--border-radius-lg);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    animation: dialogFadeIn 0.3s ease;
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-lg) 24px;
    background: var(--header-gradient);
    color: white;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
}

.dialog-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.dialog-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.dialog-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.dialog-body {
    padding: 24px;
    color: #37474f;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
}

.dialog-footer {
    padding: var(--spacing-lg) 24px;
    background: #f5f5f5;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.dialog-btn {
    padding: 10px 24px;
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.dialog-btn-primary {
    background: var(--header-gradient);
    color: white;
}

.dialog-btn-primary:hover {
    background: var(--header-hover-gradient);
    transform: translateY(-1px);
}

.dialog-btn-secondary {
    background: #f5f5f5;
    color: #37474f;
}

.dialog-btn-secondary:hover {
    background: #e0e0e0;
}

/* Estilos por tipo de diálogo */
.dialog-type-error .dialog-header {
    background: var(--error-gradient);
}

.dialog-type-warning .dialog-header {
    background: var(--warning-gradient);
}

.dialog-type-success .dialog-header {
    background: var(--success-gradient);
}

.dialog-type-info .dialog-header {
    background: var(--info-gradient);
}

/* Animación */
@keyframes dialogFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

