/* Slide Editor Overlay */
#slide-editor-menu {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 250px;
    background: rgba(31, 41, 55, 0.75);
    color: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    font-family: 'Inter', sans-serif;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transform: translateX(300px);
    /* Hidden by default */
    opacity: 0;
    visibility: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1), opacity 0.3s, visibility 0.3s;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

#slide-editor-menu.mode-editing .hide-on-edit {
    display: none !important;
}

#slide-editor-menu.active {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
}

#slide-editor-menu.draggable {
    cursor: grab;
}

#slide-editor-menu.draggable:active {
    cursor: grabbing;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 10px;
}

.editor-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.editor-close {
    cursor: pointer;
    opacity: 0.7;
}

.editor-close:hover {
    opacity: 1;
}

.editor-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.editor-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    padding: 10px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
}

.editor-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.editor-btn.primary {
    background: #5e50a0;
}

.editor-btn.primary:hover {
    background: #7866cc;
}

.editor-btn.active {
    background: #10b981;
    /* Green for active state */
}

/* Edit Mode Styles */
.reveal.edit-mode .slides section {
    border: 2px dashed rgba(94, 80, 160, 0.3);
}

.reveal.edit-mode [contenteditable="true"] {
    outline: 2px solid rgba(94, 80, 160, 0.5);
    background: rgba(255, 255, 255, 0.5);
}

.reveal.edit-mode img {
    cursor: move;
    outline: 2px solid transparent;
    transition: outline 0.2s;
}

.reveal.edit-mode img:hover {
    outline: 2px solid #5e50a0;
}

/* Status Indicator */
#save-status {
    margin-top: 15px;
    font-size: 12px;
    opacity: 0.7;
    text-align: center;
}

/* Media Controls (Resize/Delete) */
.media-wrapper {
    position: absolute;
    display: inline-block;
    /* Ensure it wraps tight */
    z-index: 10;
}

.media-wrapper.selected {
    outline: 2px solid #5e50a0;
    z-index: 20;
}

.resize-handle {
    display: none;
    position: absolute;
    width: 10px;
    height: 10px;
    background: white;
    border: 1px solid #5e50a0;
    z-index: 30;
}

.media-wrapper.selected .resize-handle {
    display: block;
}

.resize-handle.nw {
    top: -5px;
    left: -5px;
    cursor: nw-resize;
}

.resize-handle.ne {
    top: -5px;
    right: -5px;
    cursor: ne-resize;
}

.resize-handle.sw {
    bottom: -5px;
    left: -5px;
    cursor: sw-resize;
}

.resize-handle.se {
    bottom: -5px;
    right: -5px;
    cursor: se-resize;
}

.delete-btn {
    display: none;
    position: absolute;
    top: -15px;
    right: -15px;
    width: 24px;
    height: 24px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    text-align: center;
    line-height: 24px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    z-index: 30;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.media-wrapper.selected .delete-btn {
    display: block;
}

/* Override reveal's default media styling when wrapped */
.media-wrapper img,
.media-wrapper video,
.media-wrapper iframe {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    pointer-events: none;
    /* Disable internal interaction in Edit Mode by default (handled by wrapper) */
}

/* In Logic: We will set pointer-events: auto on iframe when NOT in edit mode */

/* Slide Preview (Gallery Thumbnails) */
body.slide-preview #slide-editor-menu,
body.slide-preview .editor-controls,
body.slide-preview .branding-footer,
body.slide-preview .copyright-footer,
body.slide-preview .reveal .progress,
body.slide-preview .reveal .controls {
    display: none !important;
}

body.slide-preview {
    background: #ffffff;
}

/* ===== Dirty State Indicator ===== */
#btn-save.has-changes {
    background: #f59e0b;
    animation: pulse-dirty 2s infinite;
}

#btn-save.has-changes:hover {
    background: #d97706;
}

@keyframes pulse-dirty {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ===== Undo/Redo Buttons ===== */
.undo-redo-group {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.editor-btn.small {
    padding: 8px 12px;
    font-size: 13px;
    flex: 1;
    justify-content: center;
}

.editor-btn.small span {
    font-size: 14px;
}

#btn-undo:disabled,
#btn-redo:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: rgba(255, 255, 255, 0.05);
}

#btn-undo:disabled:hover,
#btn-redo:disabled:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* ===== Auto-save Indicator ===== */
#save-status.auto-saved {
    color: #10b981;
    font-style: italic;
}

/* ===== Keyboard Shortcut Hints ===== */
.editor-btn[title]::after {
    content: attr(title);
    display: none;
}

.editor-btn .shortcut-hint {
    font-size: 10px;
    opacity: 0.6;
    margin-left: auto;
}

/* ===== Animation Modal ===== */
.animation-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.animation-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.animation-modal {
    background: #1f2937;
    border-radius: 16px;
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    overflow: hidden;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
}

.animation-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.animation-modal-header h2 {
    margin: 0;
    color: white;
    font-size: 20px;
    font-weight: 600;
}

.animation-modal-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.animation-modal-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.animation-modal-tabs {
    display: flex;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0 24px;
}

.animation-tab {
    padding: 12px 20px;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    font-size: 14px;
    font-weight: 500;
}

.animation-tab:hover {
    color: rgba(255, 255, 255, 0.9);
}

.animation-tab.active {
    color: #a78bfa;
    border-bottom-color: #a78bfa;
}

.animation-modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.animation-tab-content {
    display: none;
}

.animation-tab-content.active {
    display: block;
}

/* AI Generator Tab */
.ai-generator-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ai-prompt-input {
    width: 100%;
    padding: 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: white;
    font-size: 14px;
    resize: vertical;
    min-height: 100px;
    font-family: inherit;
}

.ai-prompt-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.ai-prompt-input:focus {
    outline: none;
    border-color: #a78bfa;
}

.ai-generator-options {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.ai-style-chip {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    color: white;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-style-chip:hover {
    background: rgba(255, 255, 255, 0.15);
}

.ai-style-chip.selected {
    background: #5e50a0;
    border-color: #7866cc;
}

.ai-generate-btn {
    padding: 14px 28px;
    background: linear-gradient(135deg, #5e50a0 0%, #7866cc 100%);
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.ai-generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(94, 80, 160, 0.4);
}

.ai-generate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.ai-generate-btn .spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.ai-preview-area {
    margin-top: 16px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px dashed rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.4);
}

.ai-preview-area.has-content {
    border-style: solid;
    border-color: rgba(167, 139, 250, 0.3);
    background: rgba(255, 255, 255, 0.05);
}

.ai-preview-area svg {
    max-width: 100%;
    max-height: 300px;
    width: auto;
    height: auto;
}

/* AI Suggestions */
.ai-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.ai-suggestion-chip {
    padding: 6px 12px;
    background: rgba(167, 139, 250, 0.1);
    border: 1px solid rgba(167, 139, 250, 0.3);
    border-radius: 16px;
    color: #a78bfa;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-suggestion-chip:hover {
    background: rgba(167, 139, 250, 0.2);
    border-color: #a78bfa;
}

/* Lottie Library Tab */
.lottie-categories {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.lottie-category-btn {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 20px;
    color: white;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.lottie-category-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.lottie-category-btn.active {
    background: #5e50a0;
}

.lottie-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
}

/* Wider items for diagrams */
.lottie-grid[data-category="diagrams"] {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.lottie-item {
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid transparent;
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.lottie-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.lottie-item.selected {
    border-color: #a78bfa;
    background: rgba(167, 139, 250, 0.15);
}

.lottie-preview {
    width: 100%;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Allow wider previews for diagrams */
.lottie-preview svg {
    width: 100%;
    height: 100%;
    max-width: 100%;
    object-fit: contain;
}

.lottie-name {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    text-align: center;
}

/* Modal Footer */
.animation-modal-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.animation-modal-footer button {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.animation-cancel-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
}

.animation-cancel-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.animation-insert-btn {
    background: linear-gradient(135deg, #5e50a0 0%, #7866cc 100%);
    border: none;
    color: white;
}

.animation-insert-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(94, 80, 160, 0.3);
}

.animation-insert-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Animation size selector */
.animation-size-selector {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}

.animation-size-selector label {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
}

.animation-size-selector select {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: white;
    font-size: 14px;
}

.animation-size-selector select:focus {
    outline: none;
    border-color: #a78bfa;
}

/* ===== Animation Container (inserted SVGs) ===== */
.animation-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

.animation-container svg {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
}

/* Media wrapper handling for animation containers */
.media-wrapper .animation-container {
    width: 100% !important;
    height: 100% !important;
    position: relative !important;
    left: auto !important;
    top: auto !important;
    transform: none !important;
}

/* ===== ESC Notification Toast ===== */
#esc-notification {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(31, 41, 55, 0.95);
    color: white;
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-family: 'Inter', -apple-system, sans-serif;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    z-index: 10001;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#esc-notification.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

#esc-notification kbd {
    display: inline-block;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-family: 'SF Mono', 'Monaco', monospace;
    font-size: 12px;
    margin: 0 4px;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

#esc-notification .esc-progress {
    width: 100%;
    height: 3px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

#esc-notification .esc-progress::after {
    content: '';
    display: block;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #a78bfa, #5e50a0);
    animation: esc-countdown 2s linear forwards;
}

@keyframes esc-countdown {
    from { transform: translateX(0); }
    to { transform: translateX(-100%); }
}
