/* ===========================================
   EARTHS Pro - CSS Grid Layout System
   Professional 3-Panel Layout (After Effects Style)
   =========================================== */

/* ===========================================
   Layout Variables
   =========================================== */
:root {
    --left-panel-width: 320px;
    --left-panel-min-width: 260px;
    --left-panel-max-width: 450px;
    --right-panel-width: 300px;
    --toolbar-height: 48px;
    --timeline-min-height: 180px;
    --timeline-max-height: 400px;
    --timeline-default-height: 220px;
    --panel-bg: rgba(15, 15, 20, 0.75);
    --panel-bg-solid: rgba(15, 15, 20, 0.95);
    --panel-bg-darker: rgba(20, 20, 24, 0.98);
    --panel-border: rgba(255, 255, 255, 0.12);
    --panel-border-light: rgba(255, 255, 255, 0.12);
    --panel-backdrop: blur(25px) saturate(1.2);
    --panel-radius: 10px;
    --panel-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --glass-bg: rgba(255, 255, 255, 0.06);
    --glass-bg-hover: rgba(255, 255, 255, 0.12);
    --glass-border: rgba(255, 255, 255, 0.08);
    --resize-handle-size: 6px;
    /* Color palette */
    --accent-primary: #00ffff;
    --accent-secondary: #ff8c00;
    --accent-danger: #ff5555;
    --accent-success: #50fa7b;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-muted: rgba(255, 255, 255, 0.4);
    --bg-dark: #0d0d12;
    --bg-panel: #1a1a1e;
    --bg-input: rgba(255, 255, 255, 0.06);
    --bg-input-hover: rgba(255, 255, 255, 0.1);
}

/* ===========================================
   Main App Container - CSS Grid
   =========================================== */
.app-container {
    display: grid;
    grid-template-columns: var(--left-panel-width) 1fr var(--right-panel-width);
    grid-template-rows: var(--toolbar-height) 1fr auto;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    background: var(--bg-dark);
}

/* ===========================================
   Top Toolbar
   =========================================== */
.top-toolbar {
    grid-row: 1;
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    padding: 0 16px;
    background: var(--panel-bg);
    backdrop-filter: var(--panel-backdrop);
    -webkit-backdrop-filter: var(--panel-backdrop);
    border-bottom: 1px solid var(--panel-border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 200;
    gap: 12px;
}

.toolbar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-right: 16px;
    border-right: 1px solid var(--panel-border);
    margin-right: 4px;
}

.toolbar-logo h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.15em;
    color: var(--accent-primary);
    text-shadow: 0 0 20px rgba(0, 255, 255, 0.4);
    margin: 0;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    border-right: 1px solid var(--panel-border);
}

.toolbar-group:last-child {
    border-right: none;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.toolbar-btn:hover {
    background: var(--bg-input-hover);
    color: var(--text-primary);
}

.toolbar-btn:active {
    transform: scale(0.95);
}

.toolbar-btn.active {
    background: rgba(0, 255, 255, 0.15);
    color: var(--accent-primary);
}

.toolbar-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.toolbar-btn svg {
    width: 18px;
    height: 18px;
}

.toolbar-spacer {
    flex: 1;
}

.restore-session-btn {
    width: auto !important;
    gap: 6px;
    padding: 0 12px !important;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent-primary) !important;
    border: 1px solid var(--accent-primary) !important;
    background: rgba(0, 255, 255, 0.05) !important;
}
.restore-session-btn:hover {
    background: rgba(0, 255, 255, 0.15) !important;
}
.restore-session-btn span {
    white-space: nowrap;
}
.restore-session-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.toolbar-status {
    font-size: 12px;
    color: var(--text-muted);
    padding: 0 12px;
}

/* Toolbar Select Dropdowns */
.toolbar-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-right: 6px;
    white-space: nowrap;
}

.toolbar-select {
    background: var(--bg-input);
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 12px;
    padding: 6px 10px;
    cursor: pointer;
    min-width: 140px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.toolbar-select:hover {
    border-color: var(--accent-primary);
}

.toolbar-select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(0, 200, 255, 0.2);
}

.toolbar-select option {
    background: #1a1a1e;
    color: #ffffff;
    padding: 8px;
}

.theme-selector-group,
.palette-selector-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ===========================================
   Left Panel (Sidebar)
   =========================================== */
.left-panel {
    grid-row: 2;
    grid-column: 1;
    display: flex;
    flex-direction: row;
    background: var(--panel-bg);
    backdrop-filter: var(--panel-backdrop);
    -webkit-backdrop-filter: var(--panel-backdrop);
    border-right: 1px solid var(--panel-border);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: var(--panel-shadow);
    overflow: hidden;
    z-index: 100;
    position: relative;
    min-width: var(--left-panel-min-width);
    max-width: var(--left-panel-max-width);
}

/* Left Panel Resize Handle */
.left-panel-resize {
    position: absolute;
    top: 0;
    right: 0;
    width: var(--resize-handle-size);
    height: 100%;
    cursor: ew-resize;
    background: transparent;
    z-index: 10;
    transition: background 0.2s;
}

.left-panel-resize:hover,
.left-panel-resize.active {
    background: var(--accent-primary);
    opacity: 0.5;
}

/* Panel Tabs */
.panel-tabs {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 48px;
    min-width: 48px;
    padding: 8px 4px;
    gap: 4px;
    background: rgba(0, 0, 0, 0.3);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.panel-tab {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0;
}

.panel-tab svg {
    width: 20px;
    height: 20px;
}

.panel-tab:hover {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.8);
}

.panel-tab.active {
    background: rgba(0, 255, 255, 0.08);
    color: var(--accent-primary, #00ffff);
    border-left-color: var(--accent-primary, #00ffff);
}

.panel-tab.active svg {
    filter: drop-shadow(0 0 4px rgba(0, 255, 255, 0.5));
}

/* Tab Content */
.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
}

.tab-content.active {
    display: block;
}

.left-panel-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-width: 0;
}

/* Scrollbar for left panel */
.left-panel-content::-webkit-scrollbar {
    width: 6px;
}

.left-panel-content::-webkit-scrollbar-track {
    background: transparent;
}

.left-panel-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.left-panel-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ===========================================
   Main Viewport (Map Area)
   =========================================== */
.main-viewport {
    grid-row: 2;
    grid-column: 2;
    position: relative;
    overflow: hidden;
    background: var(--bg-dark);
}

/* Map container fills the viewport */
.main-viewport #map {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Labels container */
.main-viewport #labels-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

/* Vignette overlay */
.main-viewport #vignette-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 3;
    background: radial-gradient(circle at center, rgba(0,0,0,0) 40%, rgba(0,0,0,0.7) 100%);
    box-shadow: inset 0 0 150px rgba(0,0,0,0.9);
}

/* ===========================================
   Timeline Panel (Bottom)
   =========================================== */
.timeline-panel {
    grid-row: 3;
    grid-column: 1 / -1; /* Spans full width */
    min-height: var(--timeline-min-height);
    max-height: var(--timeline-max-height);
    height: var(--timeline-default-height);
    background: var(--panel-bg);
    backdrop-filter: var(--panel-backdrop);
    -webkit-backdrop-filter: var(--panel-backdrop);
    border-top: 1px solid var(--panel-border);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 100;
    position: relative;
}

/* Timeline resize handle (top edge) */
.timeline-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: var(--resize-handle-size);
    cursor: ns-resize;
    background: transparent;
    z-index: 10;
    transition: background 0.2s;
}

.timeline-resize-handle:hover,
.timeline-resize-handle.active {
    background: rgba(0, 255, 255, 0.3);
}

/* Timeline inner content — no padding so the renderer's own layout isn't pushed */
.timeline-panel-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    padding: 0;
}

/* ===========================================
   Panel Sections
   =========================================== */
.panel-section {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.panel-section:last-child {
    border-bottom: none;
}

.panel-section h3 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 12px;
}

/* ===========================================
   Responsive Adjustments
   =========================================== */
@media (max-width: 1200px) {
    :root {
        --left-panel-width: 280px;
        --right-panel-width: 260px;
    }
}

@media (max-width: 900px) {
    :root {
        --left-panel-width: 260px;
        --right-panel-width: 240px;
    }
}

@media (max-width: 768px) {
    /* Stack layout for mobile/tablet */
    .app-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }

    .left-panel {
        grid-row: 1;
        grid-column: 1;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--panel-border);
    }

    .main-viewport {
        grid-row: 2;
        grid-column: 1;
    }

    .right-panel {
        display: none;
    }

    .timeline-panel {
        grid-row: 3;
        grid-column: 1;
        min-height: 150px;
        max-height: 250px;
    }
}

/* ===========================================
   Utility Classes
   =========================================== */
.hidden {
    display: none !important;
}

.invisible {
    visibility: hidden;
}

.no-scroll {
    overflow: hidden;
}

/* ===========================================
   Loading Screen (full overlay)
   =========================================== */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0a0a15 0%, #1a1a2e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

#loading-screen.hidden {
    display: none;
}

/* ===========================================
   Modals and Overlays
   =========================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.hidden {
    display: none;
}

/* ===========================================
   Keyframe Editor Panel (floating overlay)
   =========================================== */
.editor-panel {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 300px;
    max-height: calc(100vh - var(--timeline-default-height) - 100px);
    background: var(--panel-bg);
    border: 1px solid rgba(0, 255, 255, 0.2);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 20px rgba(0, 255, 255, 0.1);
    z-index: 500;
    overflow: hidden;
    display: none;
}

.editor-panel.visible {
    display: block;
}

/* ===========================================
   Notification Container
   =========================================== */
.notification-container {
    position: fixed;
    bottom: calc(var(--timeline-default-height) + 20px);
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    pointer-events: none;
}

/* ===========================================
   Resizing State
   =========================================== */
body.resizing {
    cursor: ns-resize !important;
    user-select: none;
}

body.resizing * {
    cursor: ns-resize !important;
}

body.resizing iframe,
body.resizing canvas {
    pointer-events: none;
}

/* ===========================================
   Left Panel Internal Structure
   =========================================== */
/* (Glassmorphism styles merged into main .left-panel rule above) */

/* ===========================================
   Timeline Panel Internal Structure
   =========================================== */
/* (Glassmorphism styles merged into main .timeline-panel rule above) */

/* Timeline content area — no padding so the renderer's own layout isn't pushed */
.timeline-panel-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    padding: 0;
}

/* ===========================================
   Ensure Map Renders Correctly
   =========================================== */
.main-viewport {
    min-width: 0;
    min-height: 0;
}

/* Mapbox GL overrides for grid layout */
.main-viewport .mapboxgl-map {
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
}

/* Navigation controls positioning */
.main-viewport .mapboxgl-ctrl-top-right {
    top: 10px;
    right: 10px;
}

/* ===========================================
   Right Panel (Editor Sidebar)
   =========================================== */
.right-panel {
    grid-row: 2;
    grid-column: 3;
    display: flex;
    flex-direction: column;
    background: var(--panel-bg);
    backdrop-filter: var(--panel-backdrop);
    -webkit-backdrop-filter: var(--panel-backdrop);
    border-left: 1px solid var(--panel-border);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    z-index: 100;
}

.right-panel-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
}

/* Right panel scrollbar */
.right-panel-content::-webkit-scrollbar {
    width: 6px;
}

.right-panel-content::-webkit-scrollbar-track {
    background: transparent;
}

.right-panel-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.right-panel-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}
