/**
 * Sandbox & Live Preview Styles
 * Feature #1334: Project Playground Sandbox & Live Preview
 */

/* ===========================================
   Quick Preview Button on Cards
   =========================================== */

.preview-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.preview-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.5);
}

.preview-btn:active {
    transform: scale(0.95);
}

/* ===========================================
   Sandbox Panel - Overlay & Container
   =========================================== */

.sandbox-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sandbox-panel.visible {
    opacity: 1;
    visibility: visible;
}

.sandbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.sandbox-container {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 50%;
    min-width: 400px;
    background: var(--bg-primary, #0f172a);
    border-left: 1px solid var(--border-color, #334155);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), width 0.3s ease;
}

.sandbox-panel.visible .sandbox-container {
    transform: translateX(0);
}

/* ===========================================
   Sandbox Header
   =========================================== */

.sandbox-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-secondary, #1e293b);
    border-bottom: 1px solid var(--border-color, #334155);
    flex-shrink: 0;
}

.sandbox-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary, #f1f5f9);
}

.sandbox-title i {
    font-size: 20px;
    color: #10b981;
}

.sandbox-badge {
    padding: 2px 8px;
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

.sandbox-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color, #334155);
    margin: 0 4px;
}

/* Control Buttons */
.sandbox-size-controls,
.sandbox-device-controls,
.sandbox-actions {
    display: flex;
    gap: 4px;
}

.size-btn,
.device-btn,
.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--bg-tertiary, #374151);
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-secondary, #94a3b8);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.size-btn:hover,
.device-btn:hover,
.action-btn:hover {
    background: var(--bg-hover, #475569);
    color: var(--text-primary, #f1f5f9);
}

.size-btn.active,
.device-btn.active {
    background: rgba(16, 185, 129, 0.15);
    border-color: #10b981;
    color: #10b981;
}

.action-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.sandbox-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-secondary, #94a3b8);
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sandbox-close-btn:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

/* ===========================================
   Sandbox Body - Editor & Preview
   =========================================== */

.sandbox-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===========================================
   Editor Section
   =========================================== */

.sandbox-editor-section {
    display: flex;
    flex-direction: column;
    height: 35%;
    min-height: 150px;
    border-bottom: 1px solid var(--border-color, #334155);
    transition: height 0.3s ease;
}

.sandbox-editor-section.collapsed {
    height: 40px;
    min-height: 40px;
}

.sandbox-editor-section.collapsed .editor-panels {
    display: none;
}

.editor-tabs {
    display: flex;
    align-items: center;
    background: var(--bg-secondary, #1e293b);
    border-bottom: 1px solid var(--border-color, #334155);
    padding: 0 8px;
    flex-shrink: 0;
}

.editor-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary, #94a3b8);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.editor-tab:hover {
    color: var(--text-primary, #f1f5f9);
    background: var(--bg-hover, rgba(255, 255, 255, 0.03));
}

.editor-tab.active {
    color: #10b981;
    border-bottom-color: #10b981;
}

.editor-tab i {
    font-size: 16px;
}

.toggle-editor-btn {
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--bg-tertiary, #374151);
    border: none;
    border-radius: 4px;
    color: var(--text-secondary, #94a3b8);
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-editor-btn:hover {
    background: var(--bg-hover, #475569);
    color: var(--text-primary, #f1f5f9);
}

.editor-panels {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.editor-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
}

.editor-panel.active {
    display: block;
}

.code-editor {
    width: 100%;
    height: 100%;
    padding: 16px;
    background: var(--bg-primary, #0f172a);
    border: none;
    color: var(--text-primary, #f1f5f9);
    font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.6;
    resize: none;
    outline: none;
    tab-size: 4;
}

.code-editor::placeholder {
    color: var(--text-muted, #64748b);
}

.code-editor::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.code-editor::-webkit-scrollbar-track {
    background: var(--bg-secondary, #1e293b);
}

.code-editor::-webkit-scrollbar-thumb {
    background: var(--border-color, #334155);
    border-radius: 4px;
}

.code-editor::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted, #64748b);
}

/* ===========================================
   Preview Section
   =========================================== */

.sandbox-preview-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: var(--bg-secondary, #1e293b);
    overflow: hidden;
}

.preview-device-frame {
    position: relative;
    width: 100%;
    height: 100%;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

/* Phone Frame */
.preview-device-frame.phone {
    width: 375px;
    max-height: 667px;
    border-radius: 36px;
    border: 12px solid #1a1a1a;
    box-shadow: 
        0 0 0 2px #333,
        0 20px 50px rgba(0, 0, 0, 0.4);
}

.preview-device-frame.phone .sandbox-iframe {
    border-radius: 24px;
}

/* Tablet Frame */
.preview-device-frame.tablet {
    width: 768px;
    max-width: 100%;
    max-height: 600px;
    border-radius: 20px;
    border: 16px solid #1a1a1a;
    box-shadow: 
        0 0 0 2px #333,
        0 20px 50px rgba(0, 0, 0, 0.4);
}

/* Device Notch */
.device-notch {
    display: none;
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 24px;
    background: #1a1a1a;
    border-radius: 0 0 16px 16px;
    z-index: 10;
}

.sandbox-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

.preview-info {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-muted, #64748b);
}

.preview-info span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ===========================================
   Resize Handle
   =========================================== */

.sandbox-resize-handle {
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 48px;
    background: var(--bg-tertiary, #374151);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: ew-resize;
    color: var(--text-muted, #64748b);
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

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

.sandbox-resize-handle:hover {
    background: var(--accent, #10b981);
    color: white;
}

/* ===========================================
   Sandbox Notification
   =========================================== */

.sandbox-notification {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    background: var(--bg-secondary, #1e293b);
    border: 1px solid var(--border-color, #334155);
    border-radius: 12px;
    font-size: 14px;
    color: var(--text-primary, #f1f5f9);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 10001;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

.sandbox-notification.show {
    opacity: 1;
    transform: translateY(0);
}

.sandbox-notification.success {
    border-color: #10b981;
}

.sandbox-notification.success i {
    color: #10b981;
}

.sandbox-notification.error {
    border-color: #ef4444;
}

.sandbox-notification.error i {
    color: #ef4444;
}

/* ===========================================
   Fullscreen Mode
   =========================================== */

.sandbox-container[style*="width: 100%"] {
    border-left: none;
}

.sandbox-container[style*="width: 100%"] .sandbox-resize-handle {
    display: none;
}

/* ===========================================
   Responsive Styles
   =========================================== */

@media (max-width: 1200px) {
    .sandbox-container {
        width: 70% !important;
    }
    
    .preview-device-frame.tablet {
        width: 100%;
        max-width: 600px;
    }
}

@media (max-width: 768px) {
    .sandbox-container {
        width: 100% !important;
        min-width: 100%;
    }
    
    .sandbox-header {
        padding: 8px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .sandbox-title span:last-of-type {
        display: none;
    }
    
    .sandbox-size-controls {
        display: none;
    }
    
    .sandbox-divider {
        display: none;
    }
    
    .sandbox-resize-handle {
        display: none;
    }
    
    .sandbox-editor-section {
        height: 40%;
    }
    
    .editor-tab span {
        display: none;
    }
    
    .preview-device-frame.phone,
    .preview-device-frame.tablet {
        width: 100%;
        max-width: 100%;
        border-width: 8px;
        border-radius: 12px;
    }
    
    .device-notch {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .sandbox-header {
        padding: 8px;
    }
    
    .sandbox-title {
        font-size: 13px;
    }
    
    .size-btn,
    .device-btn,
    .action-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    
    .code-editor {
        font-size: 12px;
        padding: 12px;
    }
    
    .sandbox-preview-section {
        padding: 8px;
    }
}

/* ===========================================
   Dark/Light Theme Adjustments
   =========================================== */

[data-theme="light"] .sandbox-container {
    background: #ffffff;
}

[data-theme="light"] .sandbox-header,
[data-theme="light"] .editor-tabs {
    background: #f8fafc;
}

[data-theme="light"] .code-editor {
    background: #f1f5f9;
    color: #1e293b;
}

[data-theme="light"] .sandbox-preview-section {
    background: #e2e8f0;
}

[data-theme="light"] .size-btn,
[data-theme="light"] .device-btn,
[data-theme="light"] .action-btn,
[data-theme="light"] .toggle-editor-btn {
    background: #e2e8f0;
    color: #475569;
}

[data-theme="light"] .size-btn:hover,
[data-theme="light"] .device-btn:hover,
[data-theme="light"] .action-btn:hover,
[data-theme="light"] .toggle-editor-btn:hover {
    background: #cbd5e1;
    color: #1e293b;
}

[data-theme="light"] .sandbox-notification {
    background: #ffffff;
    border-color: #e2e8f0;
}

/* ===========================================
   Animation Enhancements
   =========================================== */

@keyframes sandboxSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes sandboxFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.sandbox-panel.visible .sandbox-container {
    animation: sandboxSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.sandbox-panel.visible .sandbox-overlay {
    animation: sandboxFadeIn 0.3s ease;
}

/* Preview loading shimmer */
.sandbox-iframe.loading {
    background: linear-gradient(
        90deg,
        var(--bg-secondary, #1e293b) 0%,
        var(--bg-tertiary, #374151) 50%,
        var(--bg-secondary, #1e293b) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}
