/**
 * Essenciel Studio - Visual Editor Styles
 */

/* ============================================
   Admin Toolbar
   ============================================ */
.es-admin-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: linear-gradient(135deg, #1a365d 0%, #2d4a6f 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 10000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    font-family: 'Inter', sans-serif;
}

.es-admin-bar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.es-admin-logo {
    font-size: 1rem;
    font-weight: 700;
    color: white;
    letter-spacing: -0.02em;
}

.es-admin-status {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.8rem;
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
}

.es-admin-status.es-unsaved {
    background: rgba(255, 193, 7, 0.3);
    color: #ffc107;
}

.es-admin-bar-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.es-help-tip {
    display: flex;
    align-items: center;
    gap: 8px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.8rem;
}

.es-admin-bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Buttons */
.es-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.es-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.es-btn-primary {
    background: white;
    color: #1a365d;
}

.es-btn-primary:hover:not(:disabled) {
    background: #f0f4f8;
    transform: translateY(-1px);
}

.es-btn-secondary {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.es-btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.25);
}

.es-btn-danger {
    background: rgba(220, 53, 69, 0.2);
    color: #ff6b6b;
    border: 1px solid rgba(220, 53, 69, 0.3);
}

.es-btn-danger:hover:not(:disabled) {
    background: rgba(220, 53, 69, 0.3);
}

.es-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   Body offset when admin bar is visible
   ============================================ */
body.es-edit-mode {
    padding-top: 56px !important;
}

body.es-edit-mode .nav {
    top: 56px;
}

/* Preview mode hides editor UI */
body.es-preview-mode .es-admin-bar,
body.es-preview-mode .es-section-controls,
body.es-preview-mode .es-add-element-bar,
body.es-preview-mode .es-image-overlay,
body.es-preview-mode .es-format-toolbar {
    display: none !important;
}

body.es-preview-mode {
    padding-top: 0 !important;
}

body.es-preview-mode .nav {
    top: 0;
}

/* ============================================
   Editable Elements
   ============================================ */
body.es-edit-mode .es-editable {
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 4px;
}

body.es-edit-mode .es-editable:hover {
    outline: 2px dashed rgba(45, 74, 111, 0.5);
    outline-offset: 4px;
}

body.es-edit-mode .es-editable.es-editing {
    outline: 2px solid #2d4a6f;
    outline-offset: 4px;
    background-color: rgba(255, 255, 255, 0.95) !important;
    color: #1a1d21 !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    padding: 8px;
    margin: -8px;
}

/* New elements highlight */
.es-new-element {
    animation: highlight-new 2s ease-out;
}

@keyframes highlight-new {
    0% { box-shadow: 0 0 0 4px rgba(45, 74, 111, 0.5); }
    100% { box-shadow: none; }
}

/* ============================================
   Format Toolbar
   ============================================ */
.es-format-toolbar {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 4px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    padding: 8px;
    z-index: 10001;
}

.es-format-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: #4a5568;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.es-format-btn:hover {
    background: #f4f3f1;
    color: #1a365d;
}

.es-format-btn:active {
    background: #2d4a6f;
    color: white;
}

.es-format-divider {
    width: 1px;
    height: 20px;
    background: #e2e8f0;
    margin: 0 4px;
}

/* ============================================
   Image Editing
   ============================================ */
.es-image-wrapper {
    position: relative;
    display: inline-block;
    z-index: 1;
}

.es-image-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: 8px;
    z-index: 100;
    pointer-events: auto;
}

body.es-edit-mode .es-image-wrapper:hover .es-image-overlay {
    opacity: 1;
}

.es-image-actions {
    display: flex;
    gap: 12px;
}

.es-img-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 24px;
    background: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: #1a365d;
    transition: all 0.3s ease;
}

.es-img-btn:hover {
    background: #f0f4f8;
    transform: translateY(-2px);
}

.es-img-btn-danger {
    color: #dc3545;
}

.es-img-btn-danger:hover {
    background: #fff5f5;
}

.es-image-uploading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px;
    background: #f4f3f1;
    border-radius: 8px;
    color: #4a5568;
}

/* ============================================
   Section Controls
   ============================================ */
body.es-edit-mode .es-section {
    position: relative;
}

.es-section-controls {
    position: absolute;
    top: 16px;
    left: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: white;
    padding: 8px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
}

body.es-edit-mode .es-section:hover .es-section-controls {
    opacity: 1;
}

.es-section-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #718096;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-right: 8px;
}

.es-section-buttons {
    display: flex;
    gap: 4px;
}

.es-section-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f4f3f1;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    color: #4a5568;
}

.es-section-btn:hover:not(:disabled) {
    background: #2d4a6f;
    color: white;
}

.es-section-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.es-section-btn-danger:hover:not(:disabled) {
    background: #dc3545;
}

/* Hidden section style */
body.es-edit-mode .es-hidden {
    opacity: 0.3;
    position: relative;
}

body.es-edit-mode .es-hidden::after {
    content: 'Section masquée';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    pointer-events: none;
}

/* ============================================
   Add Element Bar
   ============================================ */
.es-add-element-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    margin-top: 24px;
    background: rgba(45, 74, 111, 0.05);
    border: 2px dashed rgba(45, 74, 111, 0.2);
    border-radius: 12px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

body.es-edit-mode .es-section:hover .es-add-element-bar,
body.es-edit-mode .es-add-element-bar:hover {
    opacity: 1;
}

.es-add-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #718096;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.es-add-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    color: #4a5568;
    transition: all 0.2s ease;
}

.es-add-btn:hover {
    background: #2d4a6f;
    color: white;
    border-color: #2d4a6f;
}

.es-add-icon {
    font-size: 1rem;
}

/* ============================================
   Modal
   ============================================ */
.es-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10002;
    padding: 20px;
}

.es-modal-content {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.es-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #e2e8f0;
}

.es-modal-header h3 {
    font-family: 'Playfair Display', serif;
    font-size: 1.25rem;
    font-weight: 500;
    color: #1a1d21;
    margin: 0;
}

.es-modal-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f4f3f1;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5rem;
    color: #718096;
    transition: all 0.2s ease;
}

.es-modal-close:hover {
    background: #e2e8f0;
    color: #1a1d21;
}

.es-modal-body {
    padding: 24px;
    overflow-y: auto;
    max-height: calc(90vh - 160px);
}

.es-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid #e2e8f0;
    background: #f8f9fa;
}

/* Upload Zone */
.es-upload-zone {
    border: 2px dashed #cbd5e0;
    border-radius: 12px;
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.es-upload-zone:hover,
.es-upload-zone.es-dragover {
    border-color: #2d4a6f;
    background: rgba(45, 74, 111, 0.05);
}

.es-upload-zone svg {
    color: #a0aec0;
    margin-bottom: 16px;
}

.es-upload-zone p {
    color: #4a5568;
    margin: 8px 0;
}

.es-upload-zone small {
    color: #a0aec0;
    display: block;
    margin-top: 16px;
}

.es-upload-preview {
    text-align: center;
}

.es-upload-preview img {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    margin-bottom: 16px;
}

.es-upload-progress {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px;
}

/* ============================================
   Spinners
   ============================================ */
.es-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e2e8f0;
    border-radius: 50%;
    border-top-color: #2d4a6f;
    animation: spin 0.8s linear infinite;
}

.es-spinner-small {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   Toast Notifications
   ============================================ */
.es-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: white;
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10003;
    transform: translateX(120%);
    transition: transform 0.3s ease;
    max-width: 400px;
}

.es-toast.es-toast-show {
    transform: translateX(0);
}

.es-toast-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 14px;
    flex-shrink: 0;
}

.es-toast-success .es-toast-icon {
    background: #d4edda;
    color: #28a745;
}

.es-toast-error .es-toast-icon {
    background: #f8d7da;
    color: #dc3545;
}

.es-toast-info .es-toast-icon {
    background: #d1ecf1;
    color: #17a2b8;
}

.es-toast-success {
    border-left: 4px solid #28a745;
}

.es-toast-error {
    border-left: 4px solid #dc3545;
}

.es-toast-info {
    border-left: 4px solid #17a2b8;
}

/* ============================================
   Image Resize Handles
   ============================================ */
.es-image-wrapper.es-resizing-active {
    outline: 2px solid #2d4a6f;
    outline-offset: 2px;
}

.es-resize-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #2d4a6f;
    border: 2px solid white;
    border-radius: 2px;
    z-index: 150;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.es-image-wrapper:hover .es-resize-handle,
.es-image-wrapper.es-resizing-active .es-resize-handle {
    opacity: 1;
}

/* Corner handles */
.es-resize-se { bottom: -6px; right: -6px; cursor: se-resize; }
.es-resize-sw { bottom: -6px; left: -6px; cursor: sw-resize; }
.es-resize-ne { top: -6px; right: -6px; cursor: ne-resize; }
.es-resize-nw { top: -6px; left: -6px; cursor: nw-resize; }

/* Edge handles */
.es-resize-e { top: 50%; right: -6px; transform: translateY(-50%); cursor: e-resize; }
.es-resize-w { top: 50%; left: -6px; transform: translateY(-50%); cursor: w-resize; }
.es-resize-s { bottom: -6px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.es-resize-n { top: -6px; left: 50%; transform: translateX(-50%); cursor: n-resize; }

.es-resize-handle:hover {
    background: #1a365d;
    transform: scale(1.2);
}

/* Keep transform for positioned handles */
.es-resize-e:hover, .es-resize-w:hover { transform: translateY(-50%) scale(1.2); }
.es-resize-s:hover, .es-resize-n:hover { transform: translateX(-50%) scale(1.2); }

/* Image being resized - no size limits */
body.es-edit-mode .es-image-wrapper img {
    max-width: none;
    max-height: none;
}

/* ============================================
   Text Formatting Extended
   ============================================ */
.es-size-btn {
    font-weight: 700 !important;
    font-size: 0.85rem !important;
    min-width: 32px;
}

.es-size-btn[data-size="decrease"] {
    font-size: 0.7rem !important;
}

.es-size-btn[data-size="increase"] {
    font-size: 1rem !important;
}

.es-color-picker-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.es-color-picker-wrapper input[type="color"] {
    width: 28px;
    height: 28px;
    border: 2px solid #e2e8f0;
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
    background: none;
}

.es-color-picker-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.es-color-picker-wrapper input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

/* ============================================
   Drag & Drop
   ============================================ */
body.es-edit-mode .es-editable[draggable="true"] {
    cursor: grab;
}

body.es-edit-mode .es-editable[draggable="true"]:active {
    cursor: grabbing;
}

body.es-edit-mode .es-editable.es-dragging {
    opacity: 0.5;
    transform: scale(0.98);
}

body.es-edit-mode .es-editable.es-drag-over {
    border-top: 3px solid #2d4a6f;
    padding-top: 8px;
    margin-top: -3px;
}

body.es-edit-mode .es-editable.es-drag-over::before {
    content: 'Déposer ici';
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    background: #2d4a6f;
    color: white;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
}

/* Drag handle indicator */
body.es-edit-mode .es-editable::after {
    content: '⋮⋮';
    position: absolute;
    left: -20px;
    top: 50%;
    transform: translateY(-50%);
    color: #a0aec0;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

body.es-edit-mode .es-editable:hover::after {
    opacity: 1;
}

/* ============================================
   Undo/Redo Buttons
   ============================================ */
.es-history-btns {
    display: flex;
    gap: 4px;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid rgba(255, 255, 255, 0.2);
}

.es-history-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: white;
    transition: all 0.2s ease;
}

.es-history-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
}

.es-history-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Delete button in toolbar */
.es-format-btn-danger {
    color: #dc3545 !important;
}

.es-format-btn-danger:hover {
    background: #fff5f5 !important;
}

/* ============================================
   Decorative Elements
   ============================================ */
body.es-edit-mode .es-decorative-editable {
    position: relative;
    cursor: pointer;
    transition: outline 0.2s ease;
}

body.es-edit-mode .es-decorative-editable:hover {
    outline: 2px dashed rgba(220, 53, 69, 0.5);
    outline-offset: 4px;
}

.es-decorative-delete {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 32px;
    background: #dc3545;
    color: white;
    border: 2px solid white;
    border-radius: 50%;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

body.es-edit-mode .es-decorative-editable:hover .es-decorative-delete {
    opacity: 1;
}

.es-decorative-delete:hover {
    background: #c82333;
    transform: translate(-50%, -50%) scale(1.1);
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .es-admin-bar {
        padding: 0 12px;
        height: 50px;
    }

    .es-admin-bar-center {
        display: none;
    }

    .es-btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .es-btn span {
        display: none;
    }

    .es-btn svg {
        margin: 0;
    }

    body.es-edit-mode {
        padding-top: 50px !important;
    }

    body.es-edit-mode .nav {
        top: 50px;
    }

    .es-section-controls {
        top: 8px;
        left: 8px;
        padding: 6px 12px;
    }

    .es-add-element-bar {
        flex-wrap: wrap;
        padding: 12px;
        gap: 8px;
    }

    .es-add-btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .es-history-btns {
        display: none;
    }

    body.es-edit-mode .es-editable::after {
        display: none;
    }
}
