/**
 * LLM-Powered App Builder - Custom Styles
 * Enhances Bulma framework with app-specific styling
 */

/* Root Variables */
:root {
    --primary-color: #3273dc;
    --success-color: #23d160;
    --warning-color: #ffdd57;
    --danger-color: #ff3860;
    --dark-color: #363636;
    --light-color: #f5f5f5;
    
    --editor-bg: #272822;
    --editor-text: #f8f8f2;
    
    --pane-header-height: 50px;
    --navbar-height: 60px;
    --resize-handle-width: 4px;
    
    --transition-speed: 0.2s;
}

/* Global Styles */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.container-fluid {
    padding: 0;
    height: calc(100vh - var(--navbar-height));
    overflow: hidden;
}

/* Material Icons Sizing */
.material-symbols-outlined.is-small {
    font-size: 18px !important;
}

.material-symbols-outlined {
    font-size: 24px;
    vertical-align: middle;
}

/* Rotating animation for loading */
@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.material-symbols-outlined.rotating {
    display: inline-block;
    animation: rotate 1s linear infinite;
}

/* Navigation Enhancements */
.navbar {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    min-height: var(--navbar-height);
}

.navbar-brand .navbar-item,
.navbar-end .navbar-item {
    display: flex;
    align-items: center;
    height: 100%;
}

.navbar-item .field.has-addons {
    margin-bottom: 0;
}

/* Split Pane Layout */
.split-container {
    display: flex;
    height: 100%;
    background: var(--light-color);
}

.split-pane {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.left-pane {
    width: 33.33%;
    border-right: 1px solid #dbdbdb;
    background: white;
}

.right-pane {
    width: 66.67%;
    background: white;
    position: relative;
}

.right-pane.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 1000;
    background: white;
}

.right-pane.fullscreen .pane-header {
    background: var(--dark-color);
    color: white;
}

.right-pane.fullscreen .tabs li.is-active a {
    color: white !important;
}

/* Resize Handle */
.resize-handle {
    width: var(--resize-handle-width);
    background: #dbdbdb;
    cursor: col-resize;
    position: relative;
    transition: background-color var(--transition-speed);
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.resize-handle:hover {
    background: var(--primary-color);
}

/* Bidirectional Generation Controls */
.generation-controls {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 15px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 3px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    cursor: move;
    user-select: none;
    transition: box-shadow 0.2s ease, opacity 0.2s ease;
}

.generation-controls.dragging {
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    opacity: 0.95;
}

.generation-controls button {
    min-width: 40px;
    pointer-events: auto;
    cursor: pointer;
    position: relative;
    z-index: 1001;
}

.logo-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    cursor: move;
}

.middle-logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
    transition: transform 0.3s ease;
    cursor: move;
}

.middle-logo.rotating {
    animation: spin 1s linear infinite;
}

.status-text {
    font-size: 0.7rem;
    color: #666;
    white-space: nowrap;
}

#syncIndicator {
    font-size: 0.7rem;
}



/* Drag overlay to prevent iframe interference */
.drag-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    cursor: col-resize;
    display: none;
}

.drag-overlay.active {
    display: block;
}

.resize-line {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 30px;
    background: white;
    border-radius: 1px;
    opacity: 0.8;
}

/* Pane Headers */
.pane-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: var(--pane-header-height);
    padding: 0 1rem;
    background: #f8f9fa;
    border-bottom: 1px solid #dbdbdb;
    flex-shrink: 0;
}

.pane-header .tabs {
    margin-bottom: 0;
    flex-grow: 1;
    height: 100%;
    display: flex;
    align-items: center;
}

.pane-header .tabs ul {
    border-bottom: none;
    margin: 0;
    height: 100%;
    display: flex;
    align-items: center;
}

.pane-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: 100%;
}

/* Pane Content */
.pane-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Editor Containers */
#editorContainer {
    flex: 1;
    overflow: hidden;
}

.CodeMirror {
    height: 100% !important;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.5;
}

.CodeMirror-scroll {
    padding-bottom: 20px;
}

/* Editor Status Bar - Removed for cleaner interface */
/* .editor-status {
    padding: 0.5rem 1rem;
    background: #f8f9fa;
    border-top: 1px solid #dbdbdb;
    flex-shrink: 0;
}

.editor-status .tag {
    margin-right: 0.5rem;
} */

/* Template Info Panel */
#templateInfo {
    margin: 1rem;
    flex-shrink: 0;
}

#templateInfo .content {
    margin-bottom: 0;
}

/* Tab Content */
.tab-content {
    flex: 1;
    overflow: auto;
    position: relative;
    height: 100%;
}

#previewTab {
    background: #f0f0f0;
    overflow: hidden;
}

#previewFrame {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

#codeTab {
    background: var(--editor-bg);
    overflow: auto;
    height: 100%;
}

#codeTab .CodeMirror {
    height: 100% !important;
}

/* Console Styles */
.console-output {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
}

.console-header {
    padding: 0.75rem 1rem;
    background: #2d2d2d;
    border-bottom: 1px solid #404040;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.console-content {
    flex: 1;
    padding: 0.5rem;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #404040 #1e1e1e;
}

.console-content::-webkit-scrollbar {
    width: 8px;
}

.console-content::-webkit-scrollbar-track {
    background: #1e1e1e;
}

.console-content::-webkit-scrollbar-thumb {
    background: #404040;
    border-radius: 4px;
}

.console-line {
    margin-bottom: 0.25rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    line-height: 1.4;
}

.console-timestamp {
    color: #888;
    font-size: 11px;
    white-space: nowrap;
}

.console-prompt {
    color: #4fc3f7;
    font-weight: bold;
}

.console-icon {
    font-size: 16px !important;
    margin-top: 1px;
}

.console-icon.console-error {
    color: #f44336;
}

.console-icon.console-warning {
    color: #ff9800;
}

.console-icon.console-success {
    color: #4caf50;
}

.console-icon.console-info {
    color: #2196f3;
}

.console-text {
    flex: 1;
    word-wrap: break-word;
}

/* Loading State */
.loading-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    z-index: 10;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Rotating animation for loading icon */
.rotating {
    animation: spin 2s linear infinite;
}

/* Empty State */
.empty-state {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    z-index: 5;
}

/* Modal Enhancements */
.modal-card {
    max-width: 500px;
    margin: 0 auto;
}

.modal-card-head {
    align-items: center;
}

.modal-card-head .material-symbols-outlined {
    color: inherit;
}

/* Notification Positioning */
#successNotification {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    min-width: 300px;
    animation: slideIn 0.3s ease-out;
}

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

/* Button Enhancements */
.button {
    transition: all var(--transition-speed);
}

.button:hover {
    transform: translateY(-1px);
}

.button .material-symbols-outlined {
    margin-right: 0.5rem;
}

.button.is-small .material-symbols-outlined {
    margin-right: 0.25rem;
    font-size: 18px !important;
}

/* Form Enhancements */
.field .control .select select {
    min-width: 150px;
}

.input, .textarea, .select select {
    transition: border-color var(--transition-speed);
}

.input:focus, .textarea:focus, .select select:focus {
    box-shadow: 0 0 0 0.125em rgba(50, 115, 220, 0.25);
}

/* Responsive Design */
@media screen and (max-width: 1024px) {
    .split-container {
        flex-direction: column;
    }
    
    .left-pane, .right-pane {
        width: 100% !important;
        height: 50%;
    }
    
    .resize-handle {
        width: 100%;
        height: var(--resize-handle-width);
        cursor: row-resize;
    }
    
    .resize-line {
        width: 30px;
        height: 2px;
    }
    
    .navbar-menu {
        background-color: var(--dark-color);
    }
}

@media screen and (max-width: 768px) {
    .navbar-item .field.has-addons {
        flex-wrap: wrap;
    }
    
    .navbar-item .field.has-addons .control {
        margin-bottom: 0.5rem;
    }
    
    .pane-header {
        padding: 0.5rem;
    }
    
    .pane-controls {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.25rem;
    }
    
    #successNotification {
        right: 10px;
        left: 10px;
        min-width: auto;
    }
    
    .CodeMirror {
        font-size: 12px;
    }
    
    .console-output {
        font-size: 11px;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .split-container {
        border: 2px solid black;
    }
    
    .pane-header {
        border-bottom: 2px solid black;
    }
    
    .resize-handle {
        background: black;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .spinner {
        animation: none;
        border-top-color: transparent;
    }
}

/* Print Styles */
@media print {
    .navbar, .pane-header, .resize-handle, .modal, #successNotification {
        display: none !important;
    }
    
    .split-container {
        flex-direction: column;
    }
    
    .left-pane, .right-pane {
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
    }
    
    .CodeMirror {
        height: auto !important;
    }
}

/* Session Management Styles */
.sessions-list {
    max-height: 400px;
    overflow-y: auto;
    margin: 1rem 0;
}

.session-item {
    border: 1px solid #dbdbdb;
    border-radius: 4px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    transition: all 0.2s ease;
}

.session-item:hover {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border-color: #b5b5b5;
}

.session-item.is-active {
    border-color: var(--primary-color);
    background-color: #f0f7ff;
    border-width: 2px;
    padding: calc(1rem - 1px);
}

.session-item .level-left[data-action="open"]:hover {
    background: rgba(0, 0, 0, 0.02);
    margin: -8px;
    padding: 8px;
    border-radius: 4px;
}

.session-item .level {
    margin-bottom: 0.5rem;
}

.session-item .session-title {
    font-weight: 600;
    font-size: 1.1rem;
}

.session-item .session-meta {
    color: #666;
    font-size: 0.85rem;
}

.session-item .session-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.9rem;
    color: #888;
}

/* Navbar Session Dropdown */
#recentSessionsList .navbar-item {
    padding-right: 2rem;
}

#recentSessionsList .session-recent {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

#recentSessionsList .session-time {
    font-size: 0.8rem;
    color: #999;
    margin-left: 1rem;
}

/* Storage Indicator */
#storageIndicator {
    min-width: 60px;
    text-align: center;
}

.navbar-item .tags {
    margin-bottom: 0;
}

/* Undo/Redo Buttons */
.pane-controls .field.has-addons {
    display: inline-flex;
    align-items: center;
    margin: 0;
}

#promptUndoBtn:disabled,
#promptRedoBtn:disabled,
#codeUndoBtn:disabled,
#codeRedoBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Session Modal Enhancements */
.modal-card {
    width: 600px;
    max-width: 90vw;
}

.modal-card-body {
    max-height: 60vh;
    overflow-y: auto;
}

#sessionSearchInput {
    margin-bottom: 1rem;
}

/* Session Title Input */
.session-title-input {
    font-weight: 600;
    font-size: 1.1rem !important;
}

.session-title-input[readonly] {
    border: none;
    background-color: transparent;
    cursor: default;
    padding-left: 0;
}

.session-title-input:not([readonly]) {
    border-color: #3273dc;
    background-color: white;
}

.sessions-list:empty::after {
    content: "No sessions found";
    display: block;
    text-align: center;
    color: #999;
    padding: 2rem;
}

/* Progress Bar Enhancement */
#storageProgress {
    width: 200px;
}

/* Toast Notification */
.toast-notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: #48c774;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    z-index: 9999;
    max-width: 400px;
    min-width: 250px;
    animation: slideInRight 0.3s ease-out;
}

.toast-notification .delete {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background-color: rgba(255,255,255,0.2);
}

.toast-notification .delete:hover {
    background-color: rgba(255,255,255,0.3);
}

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

/* Focus Management */
.focus-trap {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

/* Accessibility Enhancements */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Dark Mode Support (Future Enhancement) */
@media (prefers-color-scheme: dark) {
    :root {
        --light-color: #2d2d2d;
        --editor-bg: #1e1e1e;
    }
    
    body {
        background-color: #1e1e1e;
        color: #d4d4d4;
    }
    
    .split-pane {
        background: #2d2d2d;
        border-color: #404040;
    }
    
    .pane-header {
        background: #363636;
        border-color: #404040;
        color: #d4d4d4;
    }
    
    /* .editor-status {
        background: #363636;
        border-color: #404040;
        color: #d4d4d4;
    } */
    
    #previewTab {
        background: #2d2d2d;
    }
    
    .empty-state {
        background: #2d2d2d;
        color: #d4d4d4;
    }
    
    .loading-container {
        background: #2d2d2d;
        color: #d4d4d4;
    }
}