/* Photo Canvas / Design Canvas Specific Stylesheet */

/* Layout & Main Containers */
.canvas-app-container {
    display: flex;
    flex-grow: 1;
    height: calc(100vh - 72px); /* Subtract header height */
    overflow: hidden;
    background-color: #0b0b0d;
    position: relative;
    font-family: 'Inter', sans-serif;
}

/* Sidebar Panels */
.canvas-sidebar {
    width: 320px;
    height: 100%;
    background: rgba(15, 15, 18, 0.95);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    z-index: 10;
    transition: all 0.3s ease;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.canvas-sidebar.right {
    border-right: none;
    border-left: 1px solid var(--glass-border);
}

/* Left Sidebar Tabs */
.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
}

.tab-btn {
    flex: 1;
    padding: 1rem 0.5rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition-fast);
    border-bottom: 2px solid transparent;
}

.tab-btn i {
    font-size: 1.1rem;
}

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

.tab-btn.active {
    color: var(--primary-light);
    border-bottom-color: var(--primary);
    background: rgba(255, 255, 255, 0.04);
}

/* Tab Panels */
.tab-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1.25rem;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* Sidebar Headings & Controls */
.panel-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
    color: var(--text-primary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.5rem;
}

.control-group {
    margin-bottom: 1.25rem;
}

.control-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Inputs & Buttons */
.canvas-input {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.6rem 0.8rem;
    color: white;
    font-family: inherit;
    font-size: 0.9rem;
    transition: var(--transition-fast);
}

.canvas-input:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.input-row {
    display: flex;
    gap: 0.75rem;
}

.input-col {
    flex: 1;
}

/* Preset Cards & Grid Selection */
.preset-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.preset-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 0.75rem;
    cursor: pointer;
    text-align: center;
    transition: var(--transition-fast);
}

.preset-card:hover {
    border-color: rgba(59, 130, 246, 0.5);
    background: var(--glass-hover-bg);
}

.preset-card.active {
    border-color: var(--primary-light);
    background: rgba(37, 99, 235, 0.1);
}

.preset-ratio {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: block;
}

.preset-name {
    font-size: 0.85rem;
    font-weight: 600;
}

.preset-size {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.4);
}

/* Color Palettes */
.color-palette {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.color-swatch {
    aspect-ratio: 1;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: transform 0.1s ease;
}

.color-swatch:hover {
    transform: scale(1.1);
}

.gradient-swatch {
    aspect-ratio: 1.5;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: transform 0.1s ease;
}

.gradient-swatch:hover {
    transform: scale(1.05);
}

/* Workspace Area */
.canvas-workspace {
    flex-grow: 1;
    height: 100%;
    position: relative;
    overflow: auto;
    display: flex;
    padding: 4rem;
    background-color: #121215;
    /* Grid background */
    background-image: 
        radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 0),
        radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 0);
    background-size: 24px 24px;
    background-position: 0 0, 12px 12px;
}

#canvas_scale_wrapper {
    margin: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
}

/* Visual Canvas Frame */
.canvas-viewport {
    position: relative;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
    background-color: #ffffff;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transform-origin: center center;
    /* Prevent text selection and standard dragging of visual items */
    user-select: none;
    -webkit-user-select: none;
    box-sizing: content-box;
    flex-shrink: 0;
}

/* Layer Elements inside Canvas */
.canvas-layer {
    position: absolute;
    box-sizing: border-box;
    cursor: move;
    transform-origin: center center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.canvas-layer.text-layer {
    cursor: text;
}

.canvas-layer.locked {
    cursor: not-allowed !important;
}

.canvas-layer img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    pointer-events: none; /* Let parent handle clicks */
}

.canvas-layer svg {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
}

.canvas-layer .text-content {
    width: 100%;
    height: 100%;
    word-break: break-word;
    outline: none;
    white-space: pre-wrap;
    padding: 2px;
    line-height: normal;
}

/* Interaction Bounding Box Overlay */
.selection-box {
    position: absolute;
    border: 1.5px dashed var(--primary-light);
    pointer-events: none;
    z-index: 1000;
    transform-origin: center center;
}

/* Bounding Box Drag Handles */
.selection-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: #ffffff;
    border: 1.5px solid var(--primary);
    border-radius: 50%;
    pointer-events: auto;
    z-index: 1001;
}

/* Handle Positions */
.handle-tl { top: -5px; left: -5px; cursor: nwse-resize; }
.handle-tr { top: -5px; right: -5px; cursor: nesw-resize; }
.handle-bl { bottom: -5px; left: -5px; cursor: nesw-resize; }
.handle-br { bottom: -5px; right: -5px; cursor: nwse-resize; }

.handle-tc { top: -5px; left: calc(50% - 5px); cursor: ns-resize; }
.handle-bc { bottom: -5px; left: calc(50% - 5px); cursor: ns-resize; }
.handle-ml { top: calc(50% - 5px); left: -5px; cursor: ew-resize; }
.handle-mr { top: calc(50% - 5px); right: -5px; cursor: ew-resize; }

/* Rotation Control */
.handle-rotate-line {
    position: absolute;
    width: 1.5px;
    height: 25px;
    background-color: var(--primary-light);
    bottom: 100%;
    left: calc(50% - 0.75px);
    z-index: 1000;
}

.handle-rotate {
    position: absolute;
    width: 12px;
    height: 12px;
    background-color: var(--primary-light);
    border: 1.5px solid #ffffff;
    border-radius: 50%;
    bottom: calc(100% + 20px);
    left: calc(50% - 6px);
    cursor: grab;
    pointer-events: auto;
    z-index: 1001;
}

.handle-rotate:active {
    cursor: grabbing;
}

/* Quick Action Overlay inside workspace */
.quick-actions {
    position: absolute;
    background: rgba(9, 9, 11, 0.95);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.3rem;
    display: flex;
    gap: 0.25rem;
    z-index: 1002;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
}

.quick-action-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.4rem;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 4px;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.quick-action-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

.quick-action-btn.delete:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* Top Toolbar */
.workspace-header {
    position: absolute;
    top: 1.5rem;
    left: 340px;
    right: 340px;
    height: 48px;
    background: rgba(15, 15, 18, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 9;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toolbar-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: var(--transition-fast);
}

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

.toolbar-btn.active {
    color: var(--primary-light);
    background: rgba(37, 99, 235, 0.15);
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.08);
}

/* Zoom Indicator */
.zoom-indicator {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
    min-width: 48px;
    text-align: center;
}

/* Layers panel in Right Sidebar */
.layers-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 250px;
    overflow-y: auto;
    padding-right: 2px;
    margin-bottom: 1.5rem;
}

.layer-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: var(--transition-fast);
}

.layer-item:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.15);
}

.layer-item.active {
    background: rgba(37, 99, 235, 0.08);
    border-color: var(--primary-light);
}

.layer-info {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    overflow: hidden;
    flex-grow: 1;
}

.layer-icon {
    color: var(--accent);
    font-size: 0.9rem;
    width: 18px;
    text-align: center;
}

.layer-name {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layer-actions {
    display: flex;
    gap: 0.3rem;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.layer-item:hover .layer-actions {
    opacity: 1;
}

.layer-action-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.25rem;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.75rem;
    transition: var(--transition-fast);
}

.layer-action-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

.layer-action-btn.active {
    color: var(--primary-light);
}

/* Shapes Category Selection */
.shape-selector-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}

.shape-btn {
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 1.25rem;
    transition: var(--transition-fast);
}

.shape-btn:hover {
    border-color: var(--primary-light);
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
}

/* Icons Selection Grid */
.icon-selector-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
}

.icon-item-btn {
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 1.1rem;
    transition: var(--transition-fast);
}

.icon-item-btn:hover {
    border-color: var(--primary-light);
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
}

/* Style Select / Font Controls */
.font-select {
    width: 100%;
}

.range-control {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.range-control input[type="range"] {
    flex-grow: 1;
    accent-color: var(--primary-light);
}

.range-val {
    font-size: 0.8rem;
    color: var(--text-secondary);
    min-width: 32px;
    text-align: right;
}

/* Quick Align buttons */
.align-grid {
    display: flex;
    gap: 0.5rem;
}

.align-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    padding: 0.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: var(--transition-fast);
}

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

/* Empty states */
.empty-layers-msg {
    color: rgba(255, 255, 255, 0.25);
    text-align: center;
    padding: 1.5rem;
    border: 1px dashed rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    font-size: 0.8rem;
}

/* Export / Dialog Layout styles */
.export-dropdown {
    position: relative;
}

.export-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 5px);
    background: #0f0f12;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.4rem;
    display: none;
    flex-direction: column;
    gap: 0.25rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.export-menu.show {
    display: flex;
}

.export-item {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    text-align: left;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 4px;
    white-space: nowrap;
    transition: var(--transition-fast);
}

.export-item:hover {
    color: white;
    background: var(--primary);
}

.export-item i {
    margin-right: 0.5rem;
}

/* Text alignment buttons active state */
.align-btn.active {
    color: var(--primary-light);
    border-color: var(--primary-light);
    background: rgba(37, 99, 235, 0.1);
}

/* Custom styled checkbox toggles */
.toggle-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 22px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .3s;
    border-radius: 34px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background-color: var(--primary-light);
}

input:checked + .toggle-slider:before {
    transform: translateX(22px);
}

/* Success Section Override for Full Screen Workspace */
.success-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    flex-grow: 1;
    width: 100%;
    min-height: 100vh;
    overflow-y: auto;
    background-color: #0b0b0d;
}

.success-section.hidden {
    display: none !important;
}

/* Sidebar Toggle Buttons */
.sidebar-toggle-btn {
    display: none; /* hidden on desktop */
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(15, 15, 18, 0.9);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    z-index: 8;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: var(--transition-fast);
}

.sidebar-toggle-btn:hover {
    background: var(--primary);
    border-color: var(--primary-light);
}

.sidebar-toggle-btn.left {
    left: 1rem;
}

.sidebar-toggle-btn.right {
    right: 1rem;
}

/* Responsive media queries */
@media (max-width: 1024px) {
    .canvas-sidebar {
        position: absolute;
        top: 0;
        bottom: 0;
        height: 100%;
        transform: translateX(-100%);
        z-index: 1000;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
    }
    
    .canvas-sidebar.right {
        right: 0;
        transform: translateX(100%);
        box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
    }
    
    .canvas-sidebar.open {
        transform: translateX(0);
    }
    
    .workspace-header {
        left: 1rem;
        right: 1rem;
    }
    
    /* Show floating sidebar toggles */
    .sidebar-toggle-btn {
        display: flex !important;
    }
}

@media (max-width: 768px) {
    .canvas-app-container {
        height: calc(100vh - 60px); /* Adjust header height on mobile */
    }
    
    .workspace-header {
        top: 0.75rem;
        height: auto;
        padding: 0.5rem;
        flex-direction: column;
        gap: 0.5rem;
        border-radius: 8px;
        align-items: stretch;
    }
    
    .toolbar-group {
        justify-content: space-between;
        width: 100%;
    }
    
    .toolbar-divider {
        display: none;
    }
    
    .canvas-workspace {
        padding: 8rem 1rem 2rem 1rem;
    }
    
    .canvas-sidebar {
        width: 280px;
    }
}
