/* ========================================
   EMAIL WINDOW - Style Finder/Explorer
   ======================================== */

.email-window {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 900px;
    height: 600px;
    min-width: 600px;
    min-height: 400px;
    background: #f5f5f5;
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35),
                0 0 0 1px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    z-index: 3000;
    overflow: hidden;
    resize: both;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}

.email-window.active {
    opacity: 1;
    visibility: visible;
}

.email-window.maximized {
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh !important;
    transform: none;
    border-radius: 0;
    resize: none;
}

/* ========================================
   WINDOW HEADER - 2 boutons seulement
   ======================================== */

.email-window-header {
    height: 52px;
    background: linear-gradient(180deg, #e8e8e8 0%, #d4d4d4 100%);
    border-bottom: 1px solid #b0b0b0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}

.email-window-header:active,
.email-window-header.dragging {
    cursor: grabbing;
}

.window-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.window-btn {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    color: transparent;
    transition: all 0.2s ease;
}

.window-btn:hover {
    color: rgba(0, 0, 0, 0.5);
}

.window-btn.close { background: #ff5f57; }
.window-btn.maximize { background: #28c840; }

.window-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 13px;
    font-weight: 600;
    color: #4a4a4a;
    display: flex;
    align-items: center;
    gap: 8px;
}

.window-title i {
    font-size: 14px;
    color: #666;
}

/* ========================================
   WINDOW BODY - Split view
   ======================================== */

.email-window-body {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ========================================
   SIDEBAR GAUCHE
   ======================================== */

.email-sidebar {
    width: 260px;
    min-width: 200px;
    max-width: 350px;
    background: #f0f0f0;
    border-right: 1px solid #d0d0d0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    resize: horizontal;
}

.sidebar-section {
    padding: 16px;
    border-bottom: 1px solid #d0d0d0;
}

.sidebar-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: #666;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sidebar-field {
    margin-bottom: 12px;
}

.sidebar-field:last-child {
    margin-bottom: 0;
}

.sidebar-field label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: #555;
    margin-bottom: 4px;
}

.sidebar-field input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #c0c0c0;
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
    transition: all 0.2s ease;
}

.sidebar-field input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.sidebar-field input::placeholder {
    color: #aaa;
}

/* Templates list */

.templates-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.template-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 4px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.template-item:hover {
    background: #e0e0e0;
}

.template-item.active {
    background: #dbeafe;
    border-color: #3b82f6;
}

.template-item i {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border-radius: 8px;
    font-size: 16px;
    color: #666;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.template-item.active i {
    color: #3b82f6;
}

.template-info {
    flex: 1;
}

.template-name {
    font-size: 13px;
    font-weight: 600;
    color: #333;
    margin-bottom: 2px;
}

.template-desc {
    font-size: 11px;
    color: #888;
}

/* ========================================
   CONTENT DROIT - Zone principale
   ======================================== */

.email-content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    overflow: hidden;
    position: relative;
}

/* Toolbar - 3 boutons */

.email-editor-toolbar {
    height: 44px;
    background: #fafafa;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
}

.editor-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.editor-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 16px;
}

.editor-btn:hover {
    background: #e0e0e0;
    color: #333;
}

.editor-btn.active {
    background: #3b82f6;
    color: white;
}

/* Bouton Appliquer (visible seulement en mode code) */
.editor-btn.apply {
    background: #10b981;
    color: white;
    width: auto;
    padding: 0 12px;
    font-size: 13px;
    font-weight: 500;
}

.editor-btn.apply:hover {
    background: #059669;
}

.editor-btn.apply.hidden {
    display: none;
}

/* Input fichier caché */
.file-input {
    display: none;
}

/* Divider visuel */
.editor-divider {
    width: 1px;
    height: 20px;
    background: #d0d0d0;
    margin: 0 4px;
}

/* Badge template */
.template-badge {
    display: inline-block;
    padding: 4px 12px;
    background: #e0e0e0;
    border-radius: 12px;
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

.template-badge.active {
    background: #dbeafe;
    color: #3b82f6;
}

/* ========================================
   ZONE CONTENU - 3 modes possibles
   ======================================== */

.content-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* Mode 1: Aperçu iframe (templates et fichiers importés) */
.email-preview-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #e5e5e5;
    overflow: auto;
    padding: 20px;
}

.email-preview-container.hidden {
    display: none;
}

.email-preview-frame {
    width: 100%;
    height: 100%;
    min-height: 400px;
    background: #fff;
    border: 1px solid #d0d0d0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

/* Mode 2: Édition libre (mode libre par défaut) */
.email-edit-libre {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #e5e5e5;
    overflow: auto;
    padding: 40px;
}

.email-edit-libre.hidden {
    display: none;
}

.email-editable {
    width: 100%;
    min-height: 400px;
    padding: 40px;
    background: #fff;
    border: 1px solid #d0d0d0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    font-family: Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    outline: none;
}

.email-editable:empty:before {
    content: 'Commencez à écrire votre email ici...';
    color: #999;
    font-style: italic;
}

.email-editable:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Mode 3: Édition code HTML */
.email-edit-code {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #1e1e1e;
    display: none;
    flex-direction: column;
}

.email-edit-code.active {
    display: flex;
}

.code-header {
    height: 36px;
    background: #2d2d2d;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    border-bottom: 1px solid #3e3e3e;
}

.code-header-title {
    font-size: 12px;
    color: #ccc;
    display: flex;
    align-items: center;
    gap: 6px;
}

.code-actions {
    display: flex;
    gap: 8px;
}

.code-btn {
    padding: 4px 12px;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
}

.code-btn-save {
    background: #10b981;
    color: white;
}

.code-btn-save:hover {
    background: #059669;
}

.code-btn-cancel {
    background: #444;
    color: #ccc;
}

.code-btn-cancel:hover {
    background: #555;
}

.email-textarea {
    flex: 1;
    width: 100%;
    padding: 20px;
    border: none;
    resize: none;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: #d4d4d4;
    background: #1e1e1e;
    tab-size: 2;
}

.email-textarea:focus {
    outline: none;
}

/* Line numbers optionnel */
.email-textarea::placeholder {
    color: #666;
}

/* ========================================
   DROP ZONE INDICATOR
   ======================================== */

.drop-zone-active::after {
    content: 'Déposez votre fichier ici';
    position: absolute;
    top: 44px;
    left: 0;
    right: 0;
    bottom: 60px;
    background: rgba(59, 130, 246, 0.1);
    border: 3px dashed #3b82f6;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #3b82f6;
    font-size: 18px;
    font-weight: 500;
    z-index: 100;
    pointer-events: none;
}

/* ========================================
   FOOTER
   ======================================== */

.email-content-footer {
    height: 60px;
    background: #fafafa;
    border-top: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}

.email-status {
    font-size: 12px;
    color: #666;
    display: flex;
    align-items: center;
    gap: 6px;
}

.email-status.success { color: #10b981; }
.email-status.error { color: #ef4444; }
.email-status.editing { color: #3b82f6; }

.email-actions-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-footer {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.btn-footer-secondary {
    background: #e0e0e0;
    color: #555;
}

.btn-footer-secondary:hover {
    background: #d0d0d0;
}

.btn-footer-primary {
    background: #3b82f6;
    color: white;
}

.btn-footer-primary:hover {
    background: #2563eb;
}

/* ========================================
   RESIZE HANDLE
   ======================================== */

.resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 50%, #c0c0c0 50%);
    border-bottom-right-radius: 12px;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.resize-handle:hover {
    opacity: 1;
}

.email-window.maximized .resize-handle {
    display: none;
}

/* ========================================
   ANIMATIONS
   ======================================== */

@keyframes windowShake {
    0%, 100% { transform: translate(-50%, -50%) translateX(0); }
    25% { transform: translate(-50%, -50%) translateX(-5px); }
    75% { transform: translate(-50%, -50%) translateX(5px); }
}

.email-window.error {
    animation: windowShake 0.4s ease;
}

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

.sending {
    animation: pulse 1.5s infinite;
}

/* ========================================
   DARK MODE
   ======================================== */

[data-bs-theme="dark"] .email-window {
    background: #2a2a2a;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5),
                0 0 0 1px rgba(255, 255, 255, 0.1);
}

[data-bs-theme="dark"] .email-window-header {
    background: linear-gradient(180deg, #3a3a3a 0%, #2a2a2a 100%);
    border-bottom-color: #444;
}

[data-bs-theme="dark"] .window-title {
    color: #ccc;
}

[data-bs-theme="dark"] .window-btn {
    border-color: rgba(255, 255, 255, 0.1);
}

[data-bs-theme="dark"] .email-sidebar {
    background: #252525;
    border-right-color: #444;
}

[data-bs-theme="dark"] .sidebar-section {
    border-bottom-color: #444;
}

[data-bs-theme="dark"] .sidebar-section-title {
    color: #999;
}

[data-bs-theme="dark"] .sidebar-field label {
    color: #aaa;
}

[data-bs-theme="dark"] .sidebar-field input {
    background: #333;
    border-color: #555;
    color: #fff;
}

[data-bs-theme="dark"] .sidebar-field input::placeholder {
    color: #777;
}

[data-bs-theme="dark"] .template-item:hover {
    background: #333;
}

[data-bs-theme="dark"] .template-item.active {
    background: #1e3a5f;
    border-color: #3b82f6;
}

[data-bs-theme="dark"] .template-name {
    color: #fff;
}

[data-bs-theme="dark"] .template-desc {
    color: #888;
}

[data-bs-theme="dark"] .email-editor-toolbar {
    background: #2a2a2a;
    border-bottom-color: #444;
}

[data-bs-theme="dark"] .editor-btn {
    color: #aaa;
}

[data-bs-theme="dark"] .editor-btn:hover {
    background: #444;
    color: #fff;
}

[data-bs-theme="dark"] .template-badge {
    background: #444;
    color: #ccc;
}

[data-bs-theme="dark"] .template-badge.active {
    background: #1e3a5f;
    color: #60a5fa;
}

[data-bs-theme="dark"] .email-preview-container {
    background: #111;
}

[data-bs-theme="dark"] .email-preview-frame {
    background: #222;
    border-color: #444;
}

[data-bs-theme="dark"] .email-edit-libre {
    background: #111;
}

[data-bs-theme="dark"] .email-editable {
    background: #222;
    border-color: #444;
    color: #fff;
}

[data-bs-theme="dark"] .email-editable:empty:before {
    color: #777;
}

[data-bs-theme="dark"] .email-content-footer {
    background: #2a2a2a;
    border-top-color: #444;
}

[data-bs-theme="dark"] .email-status {
    color: #aaa;
}

[data-bs-theme="dark"] .btn-footer-secondary {
    background: #444;
    color: #ccc;
}

[data-bs-theme="dark"] .btn-footer-secondary:hover {
    background: #555;
}