@import url('./style.css');
@import url('./modal.css');

/* Main Layout - Full Height */
html, body {
    height: 100vh;
    overflow: hidden;
}

.main-content {
    display: flex;
    height: 100vh;
    width: 100vw;
    background-color: var(--background);
}

/* --- Sidebar --- */
.sidebar {
    width: 340px; /* Slightly wider for modern look */
    background: var(--surface);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 1.5rem;
    border-right: 1px solid var(--border-color);
    flex-shrink: 0;
    overflow-y: auto;
    z-index: 20;
    box-shadow: var(--shadow-xl); /* Stronger shadow */
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.brand {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    letter-spacing: -0.02em;
}

.tool-section {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    animation: fadeIn 0.4s ease-out;
}

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

.tool-section h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 0.25rem;
}

/* Control Groups */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.control-group label:not(.toggle-switch) {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Value Display Badge */
.value-badge {
    background: var(--surface-active);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius);
    font-size: 0.75rem;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    font-family: 'Inter', monospace;
    font-weight: 600;
}

/* --- Workspace Area --- */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    gap: 1.5rem;
    overflow: hidden;
    background: var(--background);
    position: relative;
    /* Dot Pattern Background */
    background-image: radial-gradient(var(--surface-hover) 1px, transparent 1px);
    background-size: 24px 24px;
}

.workspace-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0.5rem;
    min-height: 48px;
    z-index: 10;
}

.tool-title {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-primary);
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.workspace-actions {
    display: flex;
    gap: 0.75rem;
}

/* --- Comparison / Preview Area --- */
.split-view {
    display: flex;
    flex: 1;
    gap: 1.5rem;
    min-height: 0; /* Important for flex child scroll */
    position: relative;
}

.preview-pane {
    flex: 1;
    background: var(--surface);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

/* Animated Gradient Border */
@property --gradient-angle {
    syntax: "<angle>";
    initial-value: 0deg;
    inherits: false;
}

@keyframes rotation {
    0% { --gradient-angle: 0deg; }
    100% { --gradient-angle: 360deg; }
}

.preview-pane {
    /* Transparent border to show background */
    border: 4px solid transparent;

    /* Dual backgrounds: Surface color on top (padding-box), Gradient below (border-box) */
    background-image:
        linear-gradient(var(--surface), var(--surface)),
        conic-gradient(from var(--gradient-angle),
            #005eff,
            #8000ff,
            #005eff);

    background-origin: border-box;
    background-clip: padding-box, border-box;

    animation: rotation 10s linear infinite;
}

.pane-header {
    padding: 0.75rem 1.25rem;
    background: var(--surface);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.pane-content {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    user-select: none;

    /* Refined Checkerboard */
    background-color: var(--canvas-check-1);
    background-image:
        linear-gradient(45deg, var(--canvas-check-2) 25%, transparent 25%),
        linear-gradient(-45deg, var(--canvas-check-2) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--canvas-check-2) 75%),
        linear-gradient(-45deg, transparent 75%, var(--canvas-check-2) 75%);
    background-size: 20px 20px; /* Smaller pattern */
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

/* Canvas / Image Positioning */
.pane-content img,
.pane-content canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    box-shadow: var(--shadow-xl);
    transition: transform 0.2s cubic-bezier(0.2, 0, 0.2, 1);
}

/* Single View Mode (Comparison) */
.single-view .preview-pane {
    width: 100%;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--surface-active);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Empty State */
.empty-state {
    text-align: center;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    background: rgba(30, 41, 59, 0.3); /* Transparent background */
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    margin: auto;
    max-width: 600px;
    max-height: 400px;
    transition: var(--transition);
}

.empty-state:hover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.05);
}

.empty-state .icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    opacity: 0.5;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.1));
    transition: transform 0.3s ease;
}

.empty-state:hover .icon {
    transform: scale(1.1) rotate(5deg);
    opacity: 1;
}

.empty-state h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

/* Navigation List (Injected) */
.tool-nav-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-top: 0.5rem;
}

.nav-link {
    display: block;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-decoration: none;
    transition: var(--transition);
    font-weight: 500;
}

.nav-link:hover {
    background-color: var(--surface-hover);
    color: var(--text-primary);
}

.nav-link.active {
    background-color: var(--surface-active);
    color: var(--text-primary);
    font-weight: 600;
}

/* Range Input Enhancements */
.range-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
}

/* Ensure range slider takes available space */
.range-wrapper input[type="range"] {
    flex: 1;
    margin: 0;
}

.range-number-input {
    background: var(--surface-active) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
    padding: 0 0.5rem !important; /* Horizontal only, height handles vert */
    border-radius: var(--radius) !important;
    font-size: 0.85rem !important;
    height: 36px !important; /* Updated to match new input size approx */
    text-align: center;
    width: 72px !important;
    flex-shrink: 0;
}

/* Mobile Menu Button (Hidden on Desktop) */
.mobile-menu-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 0.5rem;
    cursor: pointer;
    border-radius: var(--radius);
    margin-right: 0.5rem;
}

.mobile-menu-btn:hover {
    background: var(--surface-active);
}

.mobile-menu-btn svg {
    width: 24px;
    height: 24px;
    stroke-width: 2.5;
}

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    z-index: 998; /* Below sidebar (1000) but above everything else */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: all;
}

/* Responsive */
@media (max-width: 900px) {
    .main-content {
        flex-direction: row; /* Keep row so sidebar (fixed) doesn't push workspace down */
        overflow-y: auto; /* Allow workspace to scroll */
        /* height stays 100vh from global to allow scrolling within container */
    }

    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 1rem;
        left: 1rem;
        z-index: 1100;
        background: var(--surface); /* Ensure visibility against content */
        box-shadow: var(--shadow);
        border: 1px solid var(--border-color);
        border-radius: 50%; /* Circle shape for FAB look */
        width: 40px;
        height: 40px;
        padding: 0;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px; /* Drawer width */
        max-width: 85vw;
        height: 100vh;
        transform: translateX(-100%); /* Hidden by default */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        border-right: 1px solid var(--border-color);
        box-shadow: none;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 20px 0 50px rgba(0,0,0,0.5);
    }

    /* Remove horizontal nav logic, stick to vertical drawer */
    .tool-nav-list {
        flex-direction: column;
        overflow-x: visible;
        padding-bottom: 0;
    }

    .nav-link {
        white-space: normal;
        background: transparent;
        border: none;
        padding: 0.5rem 0.75rem;
    }

    .nav-link.active {
        background-color: var(--surface-active);
        border-color: transparent;
    }

    .workspace {
        width: 100%;
        margin-left: 0;
        padding: 0.5rem;
        padding-top: 3.5rem; /* Space for fixed menu button */
        height: 100vh; /* Full viewport height */
        min-height: 0;
        overflow: hidden; /* Prevent scrolling */
        display: flex;
        flex-direction: column;
    }

    .workspace-header {
        padding-left: 3.5rem; /* Space for fixed menu button */
        flex-shrink: 0;
        margin-bottom: 0.5rem;
        gap: 0.5rem; /* Ensure gap between title group and toggle */
    }

    .tool-title {
        font-size: 1.25rem; /* Smaller title on mobile */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 140px; /* Force truncation for long titles */
    }

    .tool-header-icon {
        width: 24px;
        height: 24px;
        margin-right: 0.5rem;
    }

    .tool-header-group {
        gap: 0.25rem !important; /* Tighter gap */
        min-width: 0; /* Allow flex shrink */
    }

    .view-toggle {
        margin-left: 0 !important; /* Reset auto margin */
        flex-shrink: 0;
    }

    .toggle-btn {
        padding: 4px 8px;
        font-size: 0.75rem;
    }

    .help-btn, .icon-btn {
        padding: 0.25rem; /* Smaller touch target visual, kept accessible via transform scale on active if needed */
    }

    .split-view {
        flex-direction: column;
        height: 100%;
        min-height: 0;
        flex: 1;
        overflow: hidden;
    }

    .preview-pane {
        min-height: 0;
        flex: 1;
        height: 100%;
        margin-bottom: 0;
    }

    .pane-content {
        /* Ensure image fits and is centered */
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .pane-content img,
    .pane-content canvas {
        max-height: 100%;
        max-width: 100%;
        object-fit: contain;
    }
}

/* Selection Overlay */
.selection-overlay {
    position: absolute;
    pointer-events: none;
    z-index: 20;
}

.selection-box {
    position: absolute;
    border: 1px dashed rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    cursor: move;
    pointer-events: auto;
}

.selection-box.is-circle {
    border-radius: 50%;
}

.selection-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: white;
    border: 1px solid rgba(0,0,0,0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 21;
    pointer-events: auto;
}

.handle-nw { top: 0; left: 0; cursor: nwse-resize; }
.handle-n  { top: 0; left: 50%; cursor: ns-resize; }
.handle-ne { top: 0; left: 100%; cursor: nesw-resize; }
.handle-e  { top: 50%; left: 100%; cursor: ew-resize; }
.handle-se { top: 100%; left: 100%; cursor: nwse-resize; }
.handle-s  { top: 100%; left: 50%; cursor: ns-resize; }
.handle-sw { top: 100%; left: 0%; cursor: nesw-resize; }
.handle-w  { top: 50%; left: 0%; cursor: ew-resize; }

/* Transform Overlay */
.transform-overlay {
    position: absolute;
    pointer-events: none;
    z-index: 30;
    overflow: visible;
}

.transform-box {
    position: absolute;
    border: 2px solid var(--primary-color);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5);
    cursor: move;
    pointer-events: auto;
}

.transform-rotator {
    position: absolute;
    top: -30px;
    left: 50%;
    width: 12px;
    height: 12px;
    background: white;
    border: 2px solid var(--primary-color);
    border-radius: 50%;
    transform: translateX(-50%);
    cursor: grab;
    z-index: 32;
}

.transform-rotator::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    width: 2px;
    height: 16px;
    background: var(--primary-color);
    transform: translateX(-50%);
}

.transform-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    background: white;
    border: 2px solid var(--primary-color);
    border-radius: 50%;
    z-index: 31;
    pointer-events: auto;
}

.transform-handle.handle-nw { top: -7px; left: -7px; cursor: nwse-resize; }
.transform-handle.handle-ne { top: -7px; right: -7px; cursor: nesw-resize; }
.transform-handle.handle-se { bottom: -7px; right: -7px; cursor: nwse-resize; }
.transform-handle.handle-sw { bottom: -7px; left: -7px; cursor: nesw-resize; }

/* --- Custom Select Component --- */
.tool-switcher-container {
    position: relative;
    width: 100%;
    z-index: 100; /* Ensure it floats above other content */
}

.custom-select-container {
    position: relative;
    width: 100%;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
    box-shadow: var(--shadow-sm);
}

.custom-select-trigger:hover {
    border-color: var(--text-secondary);
    background: var(--surface-hover);
}

.custom-select-trigger .trigger-icon {
    margin-right: 0.5rem;
    font-size: 1.1em;
}

.custom-select-trigger .trigger-chevron {
    margin-left: 0.5rem;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.custom-select-container.open .trigger-chevron {
    transform: rotate(180deg);
}

.custom-select-container.open .custom-select-trigger {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.custom-select-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 999;
    overflow: hidden;
    /* Glass Effect if supported */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background: rgba(30, 41, 59, 0.95);
}

.custom-select-container.open .custom-select-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.custom-select-search {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0,0,0,0.2);
}

.custom-select-search input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
}

.custom-select-search input:focus {
    border-color: var(--primary-color);
}

.custom-select-options {
    max-height: 280px;
    overflow-y: auto;
    padding: 0.5rem;
}

.custom-select-option {
    display: flex;
    align-items: center;
    padding: 0.6rem 0.75rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.1s ease;
    justify-content: space-between; /* Ensure star is pushed to end */
}

.custom-select-option .option-icon {
    margin-right: 0.75rem;
    font-size: 1.1em;
}

.custom-select-option:hover {
    background-color: var(--surface-active);
    color: var(--text-primary);
}

.custom-select-option.selected {
    background-color: rgba(99, 102, 241, 0.15);
    color: var(--primary-color);
    font-weight: 600;
}

.custom-select-empty {
    padding: 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* --- View Toggle --- */
.view-toggle {
    display: flex;
    background: var(--surface-active);
    padding: 4px;
    border-radius: var(--radius);
    gap: 4px;
}

.toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 4px 12px;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
}

.toggle-btn:hover {
    color: var(--text-primary);
}

.toggle-btn.active {
    background: var(--surface); /* Or primary? Let's try surface with shadow */
    background: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-sm);
}

/* --- Compare Slider --- */
.compare-slider-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.compare-wrapper {
    /* Style handled by JS mostly, but defaults here */
    box-shadow: var(--shadow-xl);
    max-width: 100%;
    max-height: 100%;
}

.compare-handle {
    transition: transform 0.1s ease;
}

.compare-handle:active {
    transform: translate(-50%, -50%) scale(1.1) !important;
}

.handle-icon {
    font-size: 1.2rem;
    font-weight: bold;
    user-select: none;
}

