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

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f8f9fa;
}

.container-fluid {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header Styles */
.bg-primary {
    background: linear-gradient(135deg, #007bff, #0056b3) !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.bg-primary h1 {
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Control Buttons */
.bg-light {
    border-bottom: 1px solid #dee2e6;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.btn {
    margin-right: 5px;
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.btn-success {
    background: linear-gradient(135deg, #28a745, #20c997);
    border: none;
}

.btn-primary {
    background: linear-gradient(135deg, #007bff, #0056b3);
    border: none;
}

.btn-warning {
    background: linear-gradient(135deg, #ffc107, #e0a800);
    border: none;
    color: #212529;
}

.btn-info {
    background: linear-gradient(135deg, #17a2b8, #138496);
    border: none;
}

.btn-danger {
    background: linear-gradient(135deg, #dc3545, #c82333);
    border: none;
}

/* Main Content Layout */
.row.flex-grow-1 {
    flex: 1;
    margin: 0;
}

.col-md-6 {
    padding: 0;
}

/* Blockly Workspace Styles */
.blockly-workspace {
    height: calc(100% - 50px);
    width: 100%;
    background: #ffffff;
    border-radius: 0;
    position: relative;
}

#blocklyDiv {
    height: 100%;
    width: 100%;
    background: linear-gradient(45deg, #f8f9fa 25%, transparent 25%), 
                linear-gradient(-45deg, #f8f9fa 25%, transparent 25%), 
                linear-gradient(45deg, transparent 75%, #f8f9fa 75%), 
                linear-gradient(-45deg, transparent 75%, #f8f9fa 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

/* Section Headers */
.bg-secondary {
    background: linear-gradient(135deg, #6c757d, #5a6268) !important;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.bg-dark {
    background: linear-gradient(135deg, #343a40, #23272b) !important;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Python Code Display - Resizable Window */
.python-code-window {
    position: fixed;
    top: 100px;
    right: 20px;
    width: 500px;
    height: 400px;
    background: #2d2d30;
    border: 1px solid #3e3e42;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    resize: both;
    overflow: hidden;
    min-width: 300px;
    min-height: 200px;
    display: flex;
    flex-direction: column;
}

.python-code-window.hidden {
    display: none;
}

.python-code-header {
    background: #007acc;
    color: white;
    padding: 8px 12px;
    cursor: move;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 8px 8px 0 0;
}

.python-code-header h5 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

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

.python-code-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    transition: background-color 0.2s;
}

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

.python-code-btn.close:hover {
    background: #e74c3c;
}

.code-container {
    flex: 1;
    overflow: auto;
    background: #1e1e1e;
    position: relative;
}

.code-container pre {
    margin: 0;
    padding: 20px;
    height: 100%;
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    border: none;
    border-radius: 0;
    overflow: auto;
}

.code-container code {
    background: transparent;
    color: inherit;
    padding: 0;
    font-size: inherit;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Toggle Button for Python Code Window */
.toggle-python-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1001;
    background: #007acc;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.toggle-python-btn:hover {
    background: #005a9e;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

/* Resize handle */
.python-code-window::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    background: linear-gradient(-45deg, transparent 0%, transparent 40%, #666 40%, #666 60%, transparent 60%);
    cursor: nw-resize;
    pointer-events: none;
}

/* Syntax Highlighting Overrides */
.hljs {
    background: #1e1e1e !important;
    color: #d4d4d4 !important;
}

.hljs-keyword {
    color: #569cd6 !important;
}

.hljs-string {
    color: #ce9178 !important;
}

.hljs-number {
    color: #b5cea8 !important;
}

.hljs-comment {
    color: #6a9955 !important;
    font-style: italic;
}

.hljs-function {
    color: #dcdcaa !important;
}

.hljs-built_in {
    color: #4ec9b0 !important;
}

.hljs-variable {
    color: #9cdcfe !important;
}

/* Border Styles */
.border-end {
    border-right: 2px solid #dee2e6 !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    .col-md-6 {
        height: 50vh;
    }
    
    .row.flex-grow-1 {
        flex-direction: column;
    }
    
    .border-end {
        border-right: none !important;
        border-bottom: 2px solid #dee2e6 !important;
    }
    
    .btn-group {
        flex-wrap: wrap;
    }
    
    .btn {
        margin-bottom: 5px;
        font-size: 12px;
        padding: 6px 12px;
    }
    
    .blockly-workspace {
        height: calc(100% - 45px);
    }
    
    .code-container {
        height: calc(100% - 45px);
    }
    
    .code-container pre {
        padding: 15px;
        font-size: 12px;
    }
}

@media (max-width: 576px) {
    .container-fluid {
        padding: 0;
    }
    
    .bg-primary h1 {
        font-size: 1.25rem;
    }
    
    .bg-primary p {
        font-size: 0.875rem;
    }
    
    .btn {
        font-size: 11px;
        padding: 5px 10px;
    }
    
    .code-container pre {
        padding: 10px;
        font-size: 11px;
    }
}

/* Custom Scrollbar */
.code-container::-webkit-scrollbar {
    width: 8px;
}

.code-container::-webkit-scrollbar-track {
    background: #2d2d30;
}

.code-container::-webkit-scrollbar-thumb {
    background: #464647;
    border-radius: 4px;
}

.code-container::-webkit-scrollbar-thumb:hover {
    background: #5a5a5c;
}

/* Loading Animation */
.loading {
    position: relative;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Blockly Customizations */
.blocklyToolboxDiv {
    background: #f8f9fa !important;
    border-right: 1px solid #dee2e6 !important;
}

.blocklyTreeLabel {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important;
    font-size: 14px !important;
}

.blocklyTreeSelected .blocklyTreeLabel {
    background: #007bff !important;
    color: white !important;
}

/* Hover Effects */
.btn-group .btn:hover {
    z-index: 1;
}

/* Focus States */
.btn:focus {
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

/* Animation for code updates */
.code-container.updating {
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.code-container.updated {
    opacity: 1;
    transition: opacity 0.2s ease;
}

/* Error States */
.error-message {
    background: #f8d7da;
    color: #721c24;
    padding: 10px;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    margin: 10px;
    display: none;
}

/* Success States */
.success-message {
    background: #d4edda;
    color: #155724;
    padding: 10px;
    border: 1px solid #c3e6cb;
    border-radius: 4px;
    margin: 10px;
    display: none;
}

/* Tooltip Styles */
.tooltip {
    font-size: 12px;
}

.tooltip-inner {
    background: #343a40;
    color: white;
    border-radius: 4px;
    padding: 6px 10px;
}

/* Print Styles */
@media print {
    .bg-primary,
    .bg-light,
    .btn-group {
        display: none !important;
    }
    
    .col-md-6 {
        width: 100% !important;
        height: auto !important;
    }
    
    .code-container {
        height: auto !important;
        background: white !important;
    }
    
    .code-container pre {
        background: white !important;
        color: black !important;
        border: 1px solid #ccc;
    }
}