:root {
    --bg-color: #1e1e2e; /* Base */
    --sidebar-bg: rgba(24, 24, 37, 0.7); /* Mantle */
    --border-color: rgba(147, 153, 178, 0.2); /* Overlay2 with opacity */
    --text-primary: #cdd6f4; /* Text */
    --text-secondary: #a6adc8; /* Subtext0 */
    --accent-color: #cba6f7; /* Mauve */
    --accent-hover: #b4befe; /* Lavender */
    --accent-glow: rgba(203, 166, 247, 0.5); /* Mauve glow */
    --danger-color: #f38ba8; /* Red */
    --success-color: #a6e3a1; /* Green */
    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1.25rem;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.3);
    --blur-md: blur(16px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
}

/* App Layout & Background Elements */
.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    z-index: 0;
    opacity: 0.6;
    animation: float 20s infinite alternate ease-in-out;
}

.orb-1 {
    width: 40vw;
    height: 40vw;
    background: radial-gradient(circle, rgba(203, 166, 247, 0.35) 0%, rgba(0,0,0,0) 70%); /* Mauve */
    top: -10vw;
    left: -10vw;
    animation-delay: 0s;
}

.orb-2 {
    width: 35vw;
    height: 35vw;
    background: radial-gradient(circle, rgba(245, 194, 231, 0.3) 0%, rgba(0,0,0,0) 70%); /* Pink */
    bottom: 10vw;
    right: -5vw;
    animation-delay: -5s;
}

.orb-3 {
    width: 25vw;
    height: 25vw;
    background: radial-gradient(circle, rgba(137, 180, 250, 0.25) 0%, rgba(0,0,0,0) 70%); /* Blue */
    top: 30vh;
    left: 40vw;
    animation-delay: -10s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(5vw, 5vh) scale(1.1); }
    100% { transform: translate(-5vw, -2vh) scale(0.9); }
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    position: relative;
    z-index: 1;
}

.sidebar {
    width: 320px;
    height: 100vh;
    background-color: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    overflow-y: auto;
    flex-shrink: 0;
    transition: margin-left 0.4s cubic-bezier(0.4, 0, 0.2, 1), transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
}

header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    margin-bottom: 2rem;
}

.sidebar-header .header-text h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 0.5rem 0;
    background: linear-gradient(135deg, var(--accent-color), var(--secondary-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-header .header-text p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0;
    line-height: 1.4;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.sidebar.collapsed {
    margin-left: -320px;
}

/* Floating Toggle Button (Open Menu) */
.floating-toggle {
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
    z-index: 90;
    background-color: var(--sidebar-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    padding: 0.75rem;
    display: none; /* Hidden by default if sidebar is open */
}

.sidebar.collapsed ~ .preview-area .floating-toggle {
    display: flex; /* Show when sidebar is closed */
}

.upload-section {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

/* Drag & Drop */
.dropzone {
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-lg);
    padding: 2.5rem 1rem;
    text-align: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background-color: rgba(0, 0, 0, 0.2);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    position: relative;
    overflow: hidden;
}

.dropzone::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(circle at center, var(--accent-glow) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.dropzone:hover, .dropzone.drag-active {
    border-color: var(--accent-color);
    background-color: rgba(203, 166, 247, 0.05);
    transform: translateY(-2px);
    box-shadow: 0 10px 25px -5px rgba(203, 166, 247, 0.15);
}

.dropzone:hover::before, .dropzone.drag-active::before {
    opacity: 0.3;
}

.dropzone svg {
    color: var(--accent-color);
    margin-bottom: 0.5rem;
    transition: transform 0.3s ease;
}

.dropzone:hover svg {
    transform: scale(1.1) translateY(-4px);
}

.dropzone p {
    font-size: 0.875rem;
    font-weight: 500;
}

.dropzone span {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Controls */
.controls {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.controls.active {
    opacity: 1;
    pointer-events: auto;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

select {
    width: 100%;
    padding: 0.75rem 1rem;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    outline: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
    cursor: pointer;
}

select:focus, select:hover {
    border-color: var(--accent-color);
    background-color: rgba(203, 166, 247, 0.05);
}

select option {
    background-color: #181825; /* Mantle */
    color: var(--text-primary);
}

/* Segmented Control */
.segmented-control {
    display: flex;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-md);
    padding: 0.35rem;
    border: 1px solid var(--border-color);
    position: relative;
}

.segmented-control input[type="radio"] {
    display: none;
}

.segmented-control label {
    flex: 1;
    text-align: center;
    padding: 0.625rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
}

.segmented-control label:hover {
    color: var(--text-primary);
}

.segmented-control input[type="radio"]:checked + label {
    background-color: var(--accent-color);
    color: white;
    box-shadow: 0 4px 12px var(--accent-glow);
}

/* Range Input */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    margin-top: -6px;
    box-shadow: 0 0 10px rgba(203, 166, 247, 0.5);
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Toggle Checkbox */
.toggle-checkbox {
    appearance: none;
    width: 40px;
    height: 24px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    outline: none;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.toggle-checkbox::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle-checkbox:checked {
    background: var(--accent-color);
    border-color: var(--accent-color);
}

.toggle-checkbox:checked::after {
    left: 18px;
    background: white;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

/* Buttons */
.btn-primary, .btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
    font-family: inherit;
    letter-spacing: 0.025em;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-color), #89b4fa); /* Mauve to Blue */
    color: #11111b; /* Crust for contrast */
    width: 100%;
    margin-top: 1rem;
    box-shadow: 0 4px 14px 0 rgba(203, 166, 247, 0.39);
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 6px 20px 0 rgba(203, 166, 247, 0.5);
    transform: translateY(-2px);
}

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

.btn-primary:disabled {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    border-color: var(--border-color);
    cursor: not-allowed;
    box-shadow: none;
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--border-color);
    color: var(--text-primary);
    backdrop-filter: blur(4px);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

/* Preview Area */
.preview-area {
    flex: 1;
    background-color: transparent; /* Changed to let orbs show through */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2.5rem;
    overflow: auto;
    background-image: 
        radial-gradient(rgba(255,255,255,0.05) 1px, transparent 1px),
        radial-gradient(rgba(255,255,255,0.02) 1px, transparent 1px);
    background-size: 20px 20px, 100px 100px;
}

/* Zoom Controls */
.zoom-controls {
    position: fixed;
    bottom: 2.5rem;
    right: 2.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: rgba(24, 24, 37, 0.85);
    backdrop-filter: var(--blur-md);
    -webkit-backdrop-filter: var(--blur-md);
    padding: 0.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    z-index: 50;
    transition: all 0.3s ease;
}

.zoom-controls button {
    padding: 0.5rem;
    border-radius: var(--radius-md);
    border: none;
    background: transparent;
    color: var(--text-primary);
}

.zoom-controls button:hover {
    background: rgba(255, 255, 255, 0.1);
}

.zoom-controls span {
    min-width: 3.5rem;
    text-align: center;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.preview-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3rem;
    min-height: 100%;
    width: 100%;
    perspective: 1000px;
    padding: 3rem 0;
}

.page-preview {
    background-color: white; /* Changed back to white to represent paper */
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255,255,255,0.05);
    display: grid;
    position: relative;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
                height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                padding 0.4s ease;
    border-radius: 2px;
    flex-shrink: 0;
    width: 408px;
    height: 528px;
}

.page-preview.empty-state {
    background-color: #1e1e2e; /* Base */
    background-image: linear-gradient(135deg, rgba(255,255,255,0.03), transparent);
}

.placeholder-text {
    position: absolute;
    inset: 1.5rem; /* Indent to create a nice border */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    background-color: rgba(0, 0, 0, 0.2);
    border: 2px dashed rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    animation: gentlePulse 4s infinite ease-in-out;
}

@keyframes gentlePulse {
    0%, 100% { border-color: rgba(255, 255, 255, 0.1); background-color: rgba(0,0,0,0.2); }
    50% { border-color: rgba(203, 166, 247, 0.3); background-color: rgba(203, 166, 247, 0.05); }
}

.preview-image-container {
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 2px;
    position: relative;
    box-sizing: border-box;
}

.cut-marks .preview-image-container,
.cut-marks .print-image-container {
    border: 1px dashed rgba(0, 0, 0, 0.3);
}

.preview-image-container img {
    width: 100%;
    height: 100%;
    object-position: center;
    transition: width 0.3s, height 0.3s;
    user-select: none;
    -webkit-user-drag: none;
}

.img-cover {
    object-fit: cover;
    cursor: grab;
}

.img-cover:active {
    cursor: grabbing;
}

.img-contain {
    object-fit: contain;
}

/* Hide print layout on screen */
.print-only {
    display: none;
}

/* Print Styles */
@media print {
    @page {
        margin: 0; /* Let our CSS handle the margins */
    }

    body {
        background-color: white;
    }

    .no-print {
        display: none !important;
    }

    .print-only {
        display: block;
    }

    /* Print Pages */
    .print-page {
        width: 100vw;
        height: 100vh;
        page-break-after: always;
        display: grid;
        box-sizing: border-box;
    }
    
    .print-page:last-child {
        page-break-after: auto;
    }

    .print-image-container {
        overflow: hidden;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .print-image-container img {
        width: 100%;
        height: 100%;
        object-position: center;
}

/* --- Mobile Responsive Styles --- */
@media (max-width: 800px) {
    body {
        overflow-y: hidden; /* Prevent body scrolling if sidebar is over it, handle in preview-area instead */
    }

    .app-container {
        flex-direction: row; /* Keep row for off-canvas drawer */
        height: 100vh;
        min-height: auto;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 85%;
        max-width: 340px;
        box-shadow: 10px 0 25px rgba(0,0,0,0.5);
        margin-left: 0; /* Override desktop margin */
        transform: translateX(0);
        border-right: 1px solid var(--border-color);
    }

    .sidebar.collapsed {
        margin-left: 0;
        transform: translateX(-100%);
        box-shadow: none;
    }

    .sidebar.collapsed ~ .preview-area .floating-toggle {
        display: flex;
    }

    .preview-area {
        height: 100vh;
        min-height: auto;
        overflow: auto;
    }

    .preview-container {
        padding: 6rem 0 2rem 0; /* Add top padding so image isn't hidden by the floating toggle */
    }

    .controls.active {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
        align-items: end;
    }

    .control-group {
        margin-bottom: 0;
    }

    .control-group:last-child {
        grid-column: 1 / -1; /* Print button spans both columns */
    }

    .zoom-controls {
        bottom: 1.5rem;
        right: 1.5rem;
        padding: 0.4rem;
    }

    .zoom-controls button {
        padding: 0.4rem;
    }
}
