.playground-container {
    display: grid;
    grid-template-columns: 1fr 2fr;
    /* gap: 24px; */
    margin-top: 24px;
    /* height: calc(100vh - 240px); */
    min-height: 600px;
    grid-template-areas:
        "toolbar toolbar"
        "editor chart";
}

.editor-toolbar {
    grid-area: toolbar;
}
.editor-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    grid-area: editor;
}
.editor-panel.active {
    min-height:600px;
}



.editor-container {
    padding: 0;
    border-radius: 8px;
    border: 1px solid #0f172a;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
    flex: 1;
    margin-top: 0;
}
.layout-tabs .editor-container {
    border-radius: 0 0 8px 8px;
    border-top: 0px;
}

/* Toolbar Styling - Always Visible */
.editor-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #0f172a;
    border: 1px solid rgba(51, 65, 85, 0.6);
    border-radius: 8px;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.toolbar-section {
    display: contents; /* Allows children to be direct flex items of editor-toolbar on desktop */
}

/* Push actions to right on desktop */
.toolbar-section.secondary > #run-btn {
    margin-left: auto;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.toolbar-group.left, .toolbar-group.right {
    flex: 0 0 auto;
}

.toolbar-group.center {
    flex: 1 1 auto;
    justify-content: center;
}

/* Input Groups */
.input-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.toolbar-select {
    background: #1e293b;
    border: 1px solid #334155;
    color: #cbd5e1;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 13px;
    outline: none;
    cursor: pointer;
    min-width: 60px;
    height: 28px;
}

.toolbar-select:hover {
    border-color: #475569;
    background: #252f40;
}

.toolbar-select:focus {
    border-color: #38c0fd;
}

/* File Operations Group */
.file-ops {
    display: flex;
    gap: 4px;
    border-left: 1px solid #334155;
    padding-left: 12px;
}

/* Run Button */
.run-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border: none;
    padding: 0;
    width: 32px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

.run-btn svg {
    display: block;
}

.run-btn:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    box-shadow: 0 4px 8px rgba(37, 99, 235, 0.3);
    transform: translateY(-1px);
}

.run-btn:active {
    transform: translateY(0);
}

.run-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    background: #475569;
}

/* Icon Buttons */
.icon-btn {
    background: transparent;
    border: 1px solid transparent;
    color: #94a3b8;
    cursor: pointer;
    padding: 0 6px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    color: #f1f5f9;
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

#pine-code {
    border: none;
    border-radius: 0;
    flex: 1;
    width: 100%;
    min-height: 0; /* Important for flex children */
}

/* Ace Editor styling overrides */
.ace_editor {
    font-size: 14px !important;
    line-height: 1.6 !important;
    border-radius: 6px !important;
}

.ace_gutter {
    background: #1a1f2e !important;
    color: #64748b !important;
    border-right: 1px solid #334155 !important;
}

.ace_gutter-active-line {
    background: #334155 !important;
}

.ace_cursor {
    color: #38c0fd !important;
}

.ace_selection {
    background: rgba(56, 192, 253, 0.2) !important;
}

/* Custom Scrollbar for Ace Editor */
.ace_scrollbar::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.ace_scrollbar::-webkit-scrollbar-track {
    background: #1a1f2e;
    border-radius: 6px;
}

.ace_scrollbar::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #475569 0%, #334155 100%);
    border-radius: 6px;
    border: 2px solid #1a1f2e;
    transition: background 0.2s ease;
}

.ace_scrollbar::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #38c0fd 0%, #2563eb 100%);
    border-color: #1e293b;
}

.ace_scrollbar::-webkit-scrollbar-corner {
    background: #1a1f2e;
}

/* Firefox scrollbar */
.ace_scrollbar {
    scrollbar-width: thin;
    scrollbar-color: #475569 #1a1f2e;
}

/* Scrollbar for the entire editor container */
.ace_editor .ace_scrollbar-v,
.ace_editor .ace_scrollbar-h {
    z-index: 10;
}

.ace_scrollbar-v::-webkit-scrollbar,
.ace_scrollbar-h::-webkit-scrollbar {
    width: 12px;
    height: 12px;
    background: transparent;
}

.ace_scrollbar-v::-webkit-scrollbar-track,
.ace_scrollbar-h::-webkit-scrollbar-track {
    background: rgba(26, 31, 46, 0.8);
    border-radius: 6px;
    margin: 2px;
}

.ace_scrollbar-v::-webkit-scrollbar-thumb,
.ace_scrollbar-h::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #475569 0%, #334155 100%);
    border-radius: 6px;
    border: 2px solid rgba(26, 31, 46, 0.8);
    transition: all 0.2s ease;
}

.ace_scrollbar-v::-webkit-scrollbar-thumb:hover,
.ace_scrollbar-h::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #38c0fd 0%, #2563eb 100%);
    box-shadow: 0 0 8px rgba(56, 192, 253, 0.4);
}

/* Status Bar adjustments */
.status {
    margin: 0;
    border-radius: 0;
    border-top: 1px solid #334155;
    padding: 8px 16px;
    font-size: 12px;
    background: #1e293b;
    min-height: 40px;
    box-sizing: border-box;
    display: none; /* Hidden by default, shown via JS */
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

/* Specific status types overrides */
.status.success, .status.error, .status.loading {
    display: flex; /* Ensure flex is preserved when active */
}

.report-issue-btn {
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: inherit;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    flex-shrink: 0; /* Prevent button from shrinking */
    margin-left: auto; /* Push to the right */
}

.report-issue-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.report-issue-btn:active {
    transform: translateY(0);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.status.success {
    background: #064e3b;
    color: #6ee7b7;
    border-top: 1px solid #059669;
}

.status.error {
    background: #7f1d1d;
    color: #fca5a5;
    border-top: 1px solid #dc2626;
}

.status.loading {
    background: #1e3a8a;
    color: #93c5fd;
    border-top: 1px solid #2563eb;
}

.status.loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    to {
        left: 100%;
    }
}

/* View Tabs Styling */
.view-tabs {
    display: none; /* Hidden by default (Split View) */
    justify-content: space-between;
    align-items: center;
    background: #0f172a;
    border: 1px solid #0f172a;
    padding: 0 16px;
    height: 40px;
    margin-bottom: 16px;
    border-radius: 8px 8px 0 0;
}

.tabs-left, .tabs-right {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 100%;
}

.tab-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 0 12px;
    height: 100%;
    border-bottom: 2px solid transparent;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.03);
}

.tab-btn.active {
    color: #38c0fd;
    border-bottom-color: #38c0fd;
}

/* Layout Modes */
.layout-split .view-tabs {
    display: none;
}

.layout-tabs .view-tabs {
    display: flex;
}

.layout-tabs .playground-container {
    display: flex;
    flex-direction: column;
    position: relative;
    grid-template-columns: none;
    grid-template-areas: none;
    margin-top: 0;
    overflow: hidden;
}

.layout-tabs .editor-toolbar {
    position: relative;
    z-index: 20;
    margin-bottom: 16px;
    order: 0;
}

.layout-tabs .view-tabs {
    order: 1;
    margin-bottom: 0;
    border-bottom: none;
}

.layout-tabs .editor-container {
    border-top: none;
}

.layout-tabs .editor-panel, .layout-tabs .chart-panel {
    /* display: flex !important; */
    width: 100%;
    /* position: absolute; */
    /* top: 114px; */
    left: 0;
    /* height: calc(100% - 114px); */
    opacity: 0;
    z-index: 0;
    pointer-events: none;
    background: #0f172a;
    order: 2;
    /* min-height: 600px; */
}
.layout-tabs .editor-panel {
    height: 0px;
}
.layout-tabs .editor-panel.active,
.layout-tabs .chart-panel.active {
    opacity: 1;
    z-index: 10;
    pointer-events: auto;
}

.layout-tabs .chart-panel.active {
    display: block; /* Chart panel is block */
}

/* Chart Panel specific adjustment for layout modes */
.layout-tabs #main-chart {
    height: 100%;
    min-height: 100%;
}

.chart-panel {
    min-height: 600px;
    background: rgba(30, 41, 59, 0.3);
    border-radius: 8px;
    padding: 0px;
    
    display: flex;
    flex-direction: column;
    grid-area: chart;
}
.layout-tabs .chart-panel {
    position:absolute;
    border-radius: 0 0 8px 8px;
    border-top: 0px;
    height: 600px;
}
.layout-tabs .chart-panel.active {
    position:relative;
}

#main-chart {
    min-height: 600px;
    border-radius: 6px;
    overflow: hidden;
    flex: 1;
    height: 100%;
}

/* Fullscreen Editor Modal */
.fullscreen-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(10px);
    z-index: 9999;
    display: none;
    flex-direction: column;
    animation: fadeIn 0.2s ease;
}

.fullscreen-modal.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fullscreen-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: rgba(30, 41, 59, 0.6);
    border-bottom: 1px solid rgba(51, 65, 85, 0.6);
}

.fullscreen-title {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #38c0fd;
    font-size: 16px;
    font-weight: 600;
}

.fullscreen-title svg {
    color: #38c0fd;
}

.close-fullscreen-btn {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 6px;
    padding: 8px;
    color: #f87171;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
}

.close-fullscreen-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.fullscreen-editor {
    flex: 1;
    margin: 16px;
    border-radius: 8px;
    border: 1px solid rgba(51, 65, 85, 0.6);
    overflow: hidden;
}

.fullscreen-editor .ace_editor {
    height: 100% !important;
}

/* Mobile Responsive Styles */
@media (max-width: 1024px) {
    .playground-container {
        grid-template-columns: 1fr;
        grid-template-areas:
            "toolbar"
            "editor"
            "chart";
        gap: 16px;
    }
    
    .editor-panel {
        order: 1;
        min-height: 400px;
    }
    
    .chart-panel {
        order: 2;
        min-height: 500px;
    }
    
    /* Fix for split view on tablet/small desktop - ensure panels are visible */
    .layout-split .editor-panel,
    .layout-split .chart-panel {
        position: static !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        height: auto !important;
    }
}

@media (max-width: 768px) {
    /* Hide header elements to maximize screen space */
    /*#container > h1,*/
    #container > p,
    #container > hr {
        display: none;
    }

    #container {
        padding: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        height: 100vh;
        overflow: hidden;
    }
    
    .playground-container {        
        height: calc(100vh - 60px);
        min-height: 0;
        display: flex;
        flex-direction: column;
        gap: 0;
        border-radius: 0;
        grid-template-columns: none;
        grid-template-areas: none;
    }
    
    /* Toolbar is first, then panels */
    .playground-container .editor-toolbar {
        order: 0;
    }

    /* Force Split Layout Styles on Mobile */
    .layout-tabs .playground-container,
    .layout-split .playground-container {
        display: flex;
        position: static;
        overflow: hidden;
    }
    
    .editor-panel,
    .chart-panel,
    .layout-tabs .editor-panel,
    .layout-tabs .chart-panel {
        position: static;
        opacity: 1;
        pointer-events: auto;
        display: flex !important;
        width: 100%;
        height: auto;
        border-radius: 0;
        border: none;
        border-bottom: 1px solid #334155;
    }

    /* Distribute height: Editor on top, Chart on bottom */
    .editor-panel {
        flex: 1; /* Adjusts dynamically */
        height: 45%; /* Approximate starting height */
        min-height: 200px;
        order: 1;
    }
    
    .chart-panel {
        flex: 1.2; /* Give chart slightly more space */
        height: 55%;
        min-height: 200px;
        order: 2;
        border-bottom: none;
        padding: 0;
        background: #0f172a;
    }
    
    .editor-container {
        border-radius: 0;
        border: none;
    }
    
    #main-chart {
        border-radius: 0;
        min-height: 0;
    }

    /* Toolbar Optimization */
    .editor-toolbar {
        flex-direction: column;
        align-items: stretch;
        padding: 8px;
        gap: 8px;
        overflow-x: hidden; /* Prevent horizontal scroll on container */
        height: auto;
        margin-bottom: 0;
        border-radius: 0;
        border: none;
        border-bottom: 1px solid #334155;
    }
    
    .toolbar-section {
        display: flex;
        gap: 8px;
        width: 100%;
        align-items: center;
    }

    /* Primary Row: Examples + File Ops */
    .toolbar-section.primary {
        justify-content: space-between;
    }

    /* Allow examples select to grow */
    .input-group.flex-grow {
        flex: 1;
        min-width: 0; /* Allow shrinking */
    }
    .input-group.flex-grow .toolbar-select {
        width: 100%;
    }

    /* Secondary Row: Controls */
    .toolbar-section.secondary {
        justify-content: flex-start;
        overflow-x: auto; /* Enable scroll if needed */
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    
    .toolbar-section.secondary::-webkit-scrollbar {
        display: none;
    }

    /* Reset run button margin on mobile */
    .toolbar-section.secondary > #run-btn {
        margin-left: 0;
    }
    
    /* Prevent shrinking of toolbar items */
    .input-group, .file-ops, .run-btn, .icon-btn {
        flex-shrink: 0;
    }
    
    /* Adjust input sizes */
    .toolbar-select {
        height: 32px;
        font-size: 14px;
        padding: 0 8px;
    }
    
    /* Bigger touch targets for buttons */
    .run-btn, .icon-btn {
        width: 36px;
        height: 32px;
    }

    /* Hide specific controls not needed or too big on mobile */
    #layout-toggle, 
    #layout-toggle-tabs,
    .view-tabs {
        display: none !important;
    }

    /* Fullscreen modal adjustments */
    .fullscreen-modal {
        padding: 0;
    }
    
    .fullscreen-header {
        padding: 12px;
    }
    
    .fullscreen-editor {
        margin: 0;
        border: none;
        border-radius: 0;
    }

    /* Tooltip adjustments */
    .custom-tooltip {
        display: none !important; /* Tooltips often annoy on touch */
    }
    
    /* Ensure Ace Editor text is readable */
    .ace_editor {
        font-size: 14px !important;
    }
}

/* Custom Tooltip */
.custom-tooltip {
    position: fixed;
    background: #0f172a;
    border: 1px solid #334155;
    color: #e2e8f0;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    pointer-events: none;
    z-index: 10000;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.15s ease;
    transform: translateY(4px);
    white-space: nowrap;
}

.custom-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Onboarding Tooltip */
.onboarding-tooltip {
    position: absolute;
    background: #38c0fd;
    color: #0f172a;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    z-index: 10001;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
    animation: bounceIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.onboarding-tooltip::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 20px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid #38c0fd;
}

.onboarding-tooltip .ok-btn {
    background: #0f172a;
    color: #fff;
    border: none;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    font-weight: bold;
    transition: background 0.2s ease;
}

.onboarding-tooltip .ok-btn:hover {
    background: #1e293b;
}

@keyframes bounceIn {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}
