/* --- THEME DESIGN TOKENS --- */
:root {
    --color-bg-main: #1e1e24;
    --color-bg-surface: #2a2a35;
    --color-bg-canvas: #121214;
    --color-text-main: #f5f5fa;
    --color-text-muted: #a0a0b0;
    --color-primary: #4f46e5;
    --color-accent: #10b981;
    --color-border: #3f3f46;
    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-stack);
    background-color: var(--color-bg-main);
    color: var(--color-text-main);
    height: 100vh;
    /* CRITICAL: Locks the root window layout */
    max-height: 100vh;
    overflow: hidden;
    /* Disables browser/body-level scrollbars completely */
}

#app-container {
    width: 100%;
    height: 100vh;
    position: relative;
    overflow: hidden;
}

.view-panel {
    width: 100%;
    height: 100vh;
    /* Matches exact monitor viewport */
    max-height: 100vh;
    padding: 1.5rem;
    display: flex;
    /* Structured layout to easily compute remaining heights */
    flex-direction: column;
    overflow: hidden;
    overflow-y: auto;
    transition: opacity 0.2s ease-in-out;
}

.hidden {
    display: none !important;
}

/* --- MAIN DASHBOARD HUB --- */
.app-header {
    margin-bottom: 1.5rem;
    /* Reduced to provide more canvas workspace */
    text-align: center;
    flex-shrink: 0;
    /* Prevents the header from flattening */
}

.app-header h1 {
    font-size: 2.2rem;
    margin-bottom: 0.25rem;
}

.app-header p {
    color: var(--color-text-muted);
}

.menu-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.menu-card {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 2rem;
    text-align: left;
    cursor: pointer;
    color: inherit;
    transition: transform 0.2s, border-color 0.2s;
}

.menu-card:hover:not(:disabled) {
    transform: translateY(-4px);
    border-color: var(--color-primary);
}

.menu-card .icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 1rem;
}

.menu-card h3 {
    margin-bottom: 0.5rem;
}

.menu-card p {
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.menu-card:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- DUAL-PANE PDF COMPILER MODULE --- */
.dual-pane-layout {
    display: flex;
    gap: 1.5rem;
    flex: 1;
    /* Dynamically absorbs all remaining monitor height */
    min-height: 0;
    /* CRITICAL Flexbox constraint: allows deep child items to scale downward */
    height: 0;
    /* Prevents content layout overflow blowouts */
    margin-bottom: 0.5rem;
}

.left-pane,
.right-pane {
    flex: 1;
    min-width: 0;
    height: 100%;
    /* Fills vertical space assigned by layout */
    min-height: 0;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    overflow-y: auto;
    /* Prevents the frames themselves from expanding */
}

.pane-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.action-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.hidden-input {
    display: none;
}

/* --- BUTTON MATRIX --- */
.btn {
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover {
    background: #4338ca;
}

.btn-secondary {
    background: #3f3f46;
    color: var(--color-text-main);
}

.btn-secondary:hover {
    background: #52525b;
}

.btn-accent {
    background: var(--color-accent);
    color: white;
}

.btn-accent:hover {
    background: #059669;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #27272a !important;
    color: var(--color-text-muted) !important;
}

.btn-square {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* --- INTERACTIVE VIEWPORT REORDERING --- */
.list-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* Allows list layout box to shrink inside space safely */
}

.section-title {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin-bottom: 0.5rem;
    flex-shrink: 0;
}

.interactive-list-container {
    display: flex;
    gap: 1rem;
    flex: 1;
    min-height: 0;
}

#file-listbox {
    flex: 1;
    background: var(--color-bg-canvas);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    list-style: none;
    overflow-y: auto;
    /* Safely handle large file listings locally */
}

#file-listbox li {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #27272a;
    cursor: grab;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    touch-action: none;
}

#file-listbox li:active {
    cursor: grabbing;
}

#file-listbox li.dragging {
    opacity: 0.5;
    background: #1f1f23;
    border: 1px dashed var(--color-primary);
}

#file-listbox li.selected {
    background: var(--color-primary);
    color: white;
}

.order-controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    justify-content: center;
    flex-shrink: 0;
}

.pane-footer {
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
    margin-top: 1rem;
}

/* --- CONTINUOUS LIVE PRINT PREVIEW ENGINE --- */
.right-pane h3 {
    text-align: center;
    margin-bottom: 1rem;
    font-size: 1.1rem;
    flex-shrink: 0;
}

/* Unified Frame Workspace Container Settings */
#preview-canvas-container,
#ext-canvas-container,
#rem-canvas-container,
#mrg-canvas-scroll-container {
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 0;
    /* Overrides standard content min-bounds */
    max-height: none;
    /* Removed rigid pixel limits */
    background: var(--color-bg-canvas);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    /* Handles oversized documents safely with internal boundaries */
    padding: 1rem;
    box-sizing: border-box;
}

.preview-viewport-empty {
    color: var(--color-text-muted);
    font-style: italic;
}

/* Scalable Master Viewport Rule Constraints */
#preview-render-canvas,
#mrg-render-canvas,
#ext-render-canvas,
#rem-render-canvas {
    max-width: 100% !important;
    max-height: 100% !important;
    width: auto !important;
    height: auto !important;
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    display: block;
    margin: auto;
    object-fit: contain;
    /* Locks rendering transformations strictly down to container bounds */
}

.preview-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    gap: 1rem;
    flex-shrink: 0;
    /* Guarantees nav utility rows stay locked in view layout */
}

#preview-page-indicator,
#rem-page-indicator {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.view-navigation-footer {
    flex-shrink: 0;
    margin-top: 0.5rem;
}

/* ==========================================================================
   --- RESPONSIVE DESIGN INTERFACES (MOBILE & TABLET MEDIA QUERIES) ---
   ========================================================================== */

@media (max-width: 1024px) {
    .view-panel {
        padding: 1rem;
    }

    .dual-pane-layout {
        gap: 1rem;
    }
}

@media (max-width: 768px) {
    body {
        overflow: hidden;
    }

    .view-panel {
        padding: 0.5rem;
        height: 100vh;
    }

    .app-header {
        margin-bottom: 0.5rem;
    }

    .app-header h1 {
        font-size: 1.4rem;
    }

    .dual-pane-layout {
        flex-direction: column;
        height: calc(100vh - 4.5rem);
        gap: 0.5rem;
    }

    .left-pane,
    .right-pane {
        width: 100%;
        height: 50%;
        padding: 0.5rem;
    }

    #file-listbox {
        max-height: 80px;
    }

    #preview-canvas-container,
    #ext-canvas-container,
    #rem-canvas-container {
        padding: 0.25rem;
    }

    #edt-overlay-canvas {
        touch-action: auto;
        user-select: none;
        -webkit-user-select: none;
    }

    /* Hard locking gestures only when an explicit editing tool is selected */
    #edt-overlay-canvas.interact-locked {
        touch-action: none !important;
        overscroll-behavior: none !important;
        cursor: crosshair;
    }
}