/* ===== Splash Screen ===== */
.splash-screen {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: var(--bg-app, #0D0D0D);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity var(--anim-splash-exit, 0.5s) ease,
        transform var(--anim-splash-exit, 0.5s) ease;
}

.splash-screen.fade-out {
    opacity: 0;
    transform: scale(1.05);
    pointer-events: none;
}

.splash-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    animation: splash-enter var(--anim-splash-duration, 0.8s) cubic-bezier(0.22, 1, 0.36, 1) forwards;
    opacity: 0;
    transform: translateY(20px);
}

@keyframes splash-enter {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.splash-logo {
    position: relative;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.splash-ring {
    position: absolute;
    inset: 0;
    border: 2px solid rgba(10, 132, 255, 0.15);
    border-top: 2px solid var(--accent);
    border-radius: 50%;
    animation: splash-spin 1.2s linear infinite;
}

@keyframes splash-spin {
    to {
        transform: rotate(360deg);
    }
}

.splash-icon {
    font-size: 28px;
    color: var(--accent);
    animation: splash-pulse 2s ease-in-out infinite;
    text-shadow: 0 0 20px rgba(10, 132, 255, 0.4);
}

@keyframes splash-pulse {

    0%,
    100% {
        opacity: 0.7;
        transform: scale(1);
    }

    50% {
        opacity: 1;
        transform: scale(1.1);
    }
}

.splash-title {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 4px;
    color: var(--text-primary);
    margin: 0;
    font-family: var(--font-sans);
}

.splash-sub {
    font-size: 11px;
    letter-spacing: 2px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    margin: 0;
    font-family: var(--font-sans);
}

.splash-progress {
    width: 200px;
    height: 3px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}

.splash-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--color-purple));
    border-radius: 2px;
    transition: width 0.4s ease;
    box-shadow: 0 0 8px rgba(10, 132, 255, 0.3);
}

.splash-status {
    font: var(--text-caption);
    color: var(--text-tertiary);
    letter-spacing: 0.5px;
    font-family: var(--font-sans);
}

/* Main App Grid Layout */
body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    margin: 0;
    padding: 0;
    background-color: var(--bg-app);
    overflow: hidden;
    font-family: var(--font-sans);
}

.app-layout {
    display: grid;
    grid-template-areas:
        "header header"
        "toolbar workspace"
        "status status";
    grid-template-rows: auto 1fr auto;
    grid-template-columns: auto 1fr;
    height: 100vh;
    overflow: hidden;
}

.app-toolbar {
    grid-area: toolbar;
}

.app-header {
    grid-area: header;
}

.app-workspace {
    grid-area: workspace;
    display: flex;
    overflow: hidden;
    position: relative;
}

.app-statusbar {
    grid-area: status;
}


/* Calibration Mode (Stage 1) - Full Width & HUD Style */
.app-layout.mode-calibration .app-toolbar {
    position: absolute;
    top: 30px;
    left: 30px;
    height: auto;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: var(--radius-lg);
    padding: 8px 16px 8px 8px;
    z-index: 1000;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    cursor: default;
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
    /* Ensure Glass Panel fits */
    min-width: 280px;
    padding: 0;
    /* Remove padding to let panel fill */
    overflow: hidden;
    /* clean corners */
}

.app-layout.mode-calibration .app-toolbar.dragging {
    box-shadow: 0 15px 50px rgba(0, 87, 255, 0.3);
    border-color: rgba(0, 87, 255, 0.5);
    cursor: grabbing;
}

.app-layout.mode-calibration .drag-handle {
    color: rgba(255, 255, 255, 0.3);
    cursor: grab;
    font-size: 18px;
    padding: 4px;
    user-select: none;
    transition: color 0.2s;
}

.app-layout.mode-calibration .drag-handle:hover {
    color: var(--primary);
}

.app-layout.mode-calibration .app-toolbar .tool-group {
    flex-direction: row;
    background: transparent;
    padding: 0;
    gap: 8px;
}


.app-layout.mode-calibration .app-viewport {
    flex: 1;
    border: 1px solid var(--accent);
    box-shadow: inset 0 0 20px rgba(10, 132, 255, 0.15);
    margin: 8px;
    border-radius: var(--radius-md);
    position: relative;
    overflow: hidden;
}


/* Immersive Scanline Effect Overlay */
.viewport-scanline {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%,
            rgba(0, 0, 0, 0.1) 50%), linear-gradient(90deg,
            rgba(255, 0, 0, 0.02),
            rgba(0, 255, 0, 0.01),
            rgba(0, 0, 255, 0.02));
    background-size: 100% 2px, 3px 100%;
    opacity: 0.3;
}

/* Vignette for cinematic depth */
.viewport-vignette {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 6;
    background: radial-gradient(circle, transparent 40%, rgba(0, 0, 0, 0.4) 100%);
}

/* [FIX] Viewport Overlay - Prevent blocking canvas events */
.viewport-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    /* Crucial: Let clicks pass through */
    z-index: 10;
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    padding: 10px;
}

.overlay-info {
    pointer-events: auto;
    /* Allow interaction with info if needed (e.g. selection) */
    font-family: monospace;
    color: rgba(255, 255, 255, 0.5);
    font-size: 12px;
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 4px;
}


.app-viewport {
    flex: 1;
    background-color: var(--bg-primary);
    position: relative;
    overflow: hidden;
    height: 100%;
}

/* Context Inspector Panel & Tool Slots (Right side) */
.app-sidebar-right {
    display: flex;
    flex-direction: column;
    width: 280px;
    min-width: 280px;
    max-width: 280px;
    flex-shrink: 0;
    background: var(--glass-bg-thick);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-left: 1px solid var(--separator-light);
    z-index: var(--z-sidebar);
    transition: transform var(--duration-normal) var(--ease-spring);
    height: 100%;
    overflow: hidden;
}

#tool-settings-slot {
    /* Reserved for dynamically injected panels */
    display: flex;
    flex-direction: column;
    width: 100%;
    /* Let the tools fill available space, scrollable */
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    /* Critical for flex scroll */
}

#img-inspector {
    display: flex !important;
    flex-direction: column;
    width: 100% !important;
    flex: 1 1 auto;
    color: #fff;
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto;
}

.prop-row {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.prop-row label {
    font-size: 11px;
    color: #888;
}

.vector3 {
    display: flex;
    gap: 5px;
}

.axis-input {
    flex: 1;
    display: flex;
    align-items: center;
    background: #000;
    border: 1px solid #333;
    padding: 2px 5px;
    border-radius: 4px;
}

.axis-input span {
    font-size: 10px;
    font-weight: bold;
    margin-right: 4px;
}

.axis-input input {
    width: 100%;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 12px;
    outline: none;
}

.app-statusbar {
    height: var(--statusbar-height);
    background-color: var(--bg-primary);
    border-top: 1px solid var(--separator-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    font: var(--text-caption);
    font-family: var(--font-mono);
    color: var(--text-tertiary);
    z-index: var(--z-toolbar);
}

/* --- Glass Panel UI --- */
.glass-panel {
    width: 280px;
    background: var(--glass-bg-thick);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-right: 1px solid var(--separator-light);
    display: flex;
    flex-direction: column;
    color: var(--text-primary);
    font: var(--text-body);
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.3);
    height: 100%;
    overflow-y: auto;
}

.panel-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--separator-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.1);
}

.panel-header h3 {
    margin: 0;
    font: var(--text-overline);
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--text-tertiary);
}

.panel-content {
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Collapsible Sections */
.section-group {
    background: var(--fill-quaternary);
    border-radius: var(--radius-md);
    border: 1px solid var(--separator-light);
    overflow: hidden;
    transition: all var(--duration-normal) var(--ease-default);
}

.section-group.collapsed .section-body {
    display: none;
}

.section-group.collapsed .chevron {
    transform: rotate(-90deg);
}

.section-header {
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font: 500 12px/1 var(--font-sans);
    color: var(--text-secondary);
    user-select: none;
    transition: background var(--duration-fast);
}

.section-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.chevron {
    font-size: 10px;
    color: var(--text-tertiary);
    transition: transform var(--duration-fast);
}

.section-body {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Form Controls */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-group label {
    font-size: 11px;
    color: #888;
    font-weight: 500;
}

.glass-input,
.glass-select {
    background: var(--fill-quaternary);
    border: 1px solid var(--separator-light);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font: 400 12px/1 var(--font-sans);
    width: 100%;
    box-sizing: border-box;
    transition: border-color var(--duration-fast);
}

.glass-input:focus,
.glass-select:focus {
    outline: none;
    border-color: var(--accent);
    background: rgba(10, 132, 255, 0.06);
    box-shadow: var(--accent-glow);
}

.input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.glass-input.small {
    text-align: center;
}

.divider {
    color: #555;
    font-size: 10px;
}

.row-spread {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.value-tag {
    font: var(--text-overline);
    color: var(--accent);
    background: var(--accent-dim);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Range Slider */
.glass-range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: var(--fill-tertiary);
    border-radius: 2px;
    outline: none;
}

.glass-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* Buttons */
.btn-primary,
.btn-secondary {
    padding: 8px 12px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(10, 132, 255, 0.2);
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

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

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-icon {
    background: transparent;
    border: none;
    color: #888;
    font-size: 14px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}

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

/* Pattern Grid */
.pattern-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
}

.btn-pattern {
    aspect-ratio: 1;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.3);
    color: #aaa;
    border-radius: 44px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    transition: all 0.2s;
    padding: 0;
}

.btn-pattern:hover {
    border-color: rgba(255, 255, 255, 0.3);
    color: #fff;
}

.btn-pattern.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(10, 132, 255, 0.2);
    color: #fff;
}

.btn-pattern.color-btn {
    opacity: 0.8;
}

.btn-pattern.color-btn.active {
    opacity: 1;
    transform: scale(1.1);
}

.divider-line {
    height: 1px;
    background: rgba(255, 255, 255, 0.05);
    margin: 4px 0;
}

/* Stats Footer */
.panel-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
    padding: 12px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.stat-item {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
    padding: 6px 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-item .icon {
    font-size: 14px;
    opacity: 0.7;
}

.stat-item b {
    font-size: 11px;
    font-weight: 500;
    color: #ddd;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===================================================================
   Responsive Layout Additions for Medium Desktop
   =================================================================== */
@media screen and (max-width: 1500px) {

    /* Prevent the right-side header buttons from overflowing and cutting off */
    .header-actions .btn .btn-text {
        display: none;
    }

    .header-actions .btn {
        padding: 6px 8px;
    }

    /* Condense the huge 8-step workflow on medium screens */
    .workflow-nav .nav-step .step-text {
        display: none;
    }

    .workflow-nav .nav-step {
        padding: 6px;
    }

    /* Hide the AI label to save space, but keep the sparkle */
    #btn-auto-design {
        position: relative;
        padding: 6px 10px;
        font-size: 0;
    }

    #btn-auto-design::before {
        content: "✨";
        font-size: 14px;
    }
}

/* ===================================================================
   Mobile & iPad Responsive Layout (max-width: 1024px)
   =================================================================== */

/* FAB Buttons Default Hidden */
.fab-mobile {
    position: absolute;
    bottom: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 900;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.fab-mobile:active {
    transform: scale(0.95);
    background: var(--accent-hover);
}

.fab-left {
    left: 20px;
}

.fab-right {
    right: 20px;
}

/* Mobile Overlay */
.mobile-drawer-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    z-index: 990;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.mobile-drawer-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

@media screen and (max-width: 1024px) {

    /* 1. App Layout Reorganization */
    .app-layout {
        grid-template-areas:
            "header header"
            "workspace workspace"
            "status status";
        grid-template-columns: 1fr 1fr;
    }

    /* 2. Turn sidebars into off-canvas drawers */
    .app-toolbar {
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        max-width: 80px;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
        display: flex !important;
        /* Override potential none */
    }

    .app-toolbar.active {
        transform: translateX(0);
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
    }

    .glass-panel,
    .app-sidebar-right {
        position: absolute;
        right: 0;
        top: 0;
        height: 100%;
        max-width: 320px;
        z-index: 1000;
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    }

    .glass-panel:not(.hidden),
    /* Original class used by some panels */
    .app-sidebar-right.active,
    .glass-panel.active {
        transform: translateX(0);
        box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
    }

    /* 3. Show FABs on Tablet */
    .fab-mobile {
        display: flex !important;
    }

    /* 4. Ensure modals and alerts fit */
    .modal-content {
        width: 95% !important;
        margin: 10px auto;
        max-height: 90vh;
        /* Prevent overflow */
        overflow-y: auto;
    }

    .pm-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* ===================================================================
   Mobile Layout (max-width: 768px)
   =================================================================== */
@media screen and (max-width: 768px) {

    /* Header modifications to fit */
    .app-header {
        position: relative;
        padding: 0 10px;
    }

    .mobile-only {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }

    /* Hide the huge 8-step workflow on true mobile header */
    .workflow-nav {
        display: none !important;
    }

    /* Convert header actions into a dropdown menu */
    .header-actions {
        position: absolute;
        top: 50px;
        left: 0;
        right: 0;
        background: var(--glass-bg-thick);
        backdrop-filter: var(--glass-blur);
        border-bottom: 1px solid var(--separator-light);
        flex-direction: column;
        padding: 10px;
        gap: 10px;
        transform: translateY(-150%);
        opacity: 0;
        transition: transform 0.3s ease, opacity 0.3s ease;
        z-index: 1100;
        pointer-events: none;
    }

    .header-actions.active {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    }

    .header-actions .btn {
        width: 100%;
        justify-content: flex-start;
        padding: 10px 16px;
        font-size: 14px;
        border-radius: 8px;
    }

    /* Make system status fit nicely */
    .system-status {
        width: 100%;
        justify-content: center;
        margin: 5px 0;
    }

    /* Hide right status stats if space is tight */
    .status-right {
        font-size: 10px;
    }
}