/* Flexible row-based grid system - like Notion */

.flex-grid-container {
    display: flex;
    flex-direction: column;
    gap: 0;
    position: relative;
    transition: gap 0.2s ease;
    align-items: stretch;
}

/* Add gaps when editing mode is active */
.flex-grid-container.editing-mode {
    gap: 0;
}

/* Row styles */
.block-row {
    display: flex;
    justify-content: center;
    gap: 20px;
    width: 100%;
    min-height: 0;
    position: relative;
    transition: gap 0.2s ease;
    margin: 0;
}

/* Add gaps when editing mode is active */
.flex-grid-container.editing-mode .block-row {
    gap: 20px;
}

.block-wrapper {
    flex: 1;
    min-width: 200px;
    position: relative;
}

/* Block wrappers inside sub-rows should not have flex properties that interfere */
.sub-row .block-wrapper,
.column-wrapper .block-wrapper {
    flex: none;
    min-width: auto;
    width: 100%;
}

/* Column wrapper for handling sub-rows */
.column-wrapper {
    flex: 1;
    min-width: 200px;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0;
    align-items: stretch;
}

/* Sub-row styles */
.column-wrapper.column-with-subrows {
    gap: 10px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
}

.sub-row {
    position: relative;
    transition: all 0.2s ease;
}

/* Add spacing between sub-rows without affecting first sub-row alignment */
.column-wrapper.column-with-subrows .sub-row:not(:first-child) {
    margin-top: 10px;
}

/* Ensure blocks in sub-rows align properly */
.column-wrapper .block {
    margin: 0;
}

.sub-row .block {
    width: 100%;
    box-sizing: border-box;
}

/* Row drop zones */
.drop-zone-row {
    width: 100%;
    height: 0;
    background: transparent;
    border: none;
    border-radius: var(--border-radius);
    margin: 0;
    padding: 0;
    opacity: 0;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-sm);
    color: var(--color-blue-accent);
    position: relative;
    overflow: hidden;
    pointer-events: none;
}

.drop-zone-top {
    margin-top: 0;
}

.drop-zone-between {
    margin: 0;
}

.dragging-active .drop-zone-row {
    opacity: 0.6;
    height: 20px;
    margin: var(--spacing-xs) 0;
    background: rgba(107, 143, 181, 0.15);
    border: 2px dashed var(--color-blue-accent);
    pointer-events: all;
}

.drop-zone-row.drag-over {
    opacity: 1 !important;
    background: var(--color-blue-accent-light);
    border: 2px solid var(--color-blue-accent);
    height: 30px;
    margin: var(--spacing-sm) 0;
    pointer-events: all;
}

.drop-zone-row::before {
    content: 'Drop here to add as new row';
    opacity: 0;
    transition: opacity 0.3s ease;
}

.dragging-active .drop-zone-row::before {
    opacity: 1;
}

.drop-zone-row.drag-over::before {
    content: 'Release to add here';
    font-weight: 600;
}

/* Block-level drop zones */
.drop-zone-block-side {
    background: rgba(35, 131, 226, 0.2);
    border: 2px dashed var(--color-blue-accent);
    border-radius: var(--border-radius);
    opacity: 0;
    transition: all 0.2s ease;
    cursor: pointer;
}

.dragging-active .drop-zone-block-side {
    opacity: 0.7;
}

.drop-zone-left {
    border-right: 4px dashed var(--color-blue-accent);
    background: linear-gradient(to right, rgba(107, 143, 181, 0.4), rgba(35, 131, 226, 0.1));
}

.drop-zone-right {
    border-left: 4px dashed var(--color-blue-accent);
    background: linear-gradient(to left, rgba(107, 143, 181, 0.4), rgba(35, 131, 226, 0.1));
}

.drop-zone-block-side.drag-over {
    background: var(--color-blue-accent) !important;
    opacity: 1 !important;
    transform: scaleX(1.2);
    box-shadow: 0 0 15px rgba(107, 143, 181, 0.6);
}

/* Visual hints for block sides */
.drop-zone-left::before {
    content: '←';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    color: var(--color-blue-accent);
    font-size: 14px;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.drop-zone-right::before {
    content: '→';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    color: var(--color-blue-accent);
    font-size: 14px;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.dragging-active .drop-zone-left::before,
.dragging-active .drop-zone-right::before {
    opacity: 1;
}

/* Sub-row drop zones */
.drop-zone-subrow {
    width: 100%;
    height: 12px;
    background: rgba(74, 144, 226, 0.12);
    border: 1px dashed var(--color-blue-accent);
    border-radius: 4px;
    margin: 5px 0;
    opacity: 0;
    transition: all 0.2s ease;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: var(--color-blue-accent);
    position: relative;
}

.drop-zone-subrow-top {
    margin-top: 0;
}

/* Absolutely positioned top drop zones */
.drop-zone-subrow-top[style*="position: absolute"] {
    margin: 0;
    border-radius: 6px;
}

.drop-zone-subrow-top[style*="position: absolute"]::before {
    content: 'Drop here to add above';
    font-size: 10px;
    font-weight: 500;
}

.drop-zone-subrow-between {
    margin: 8px 0;
}

.dragging-active .drop-zone-subrow {
    opacity: 0.5;
    display: flex;
}

.drop-zone-subrow.drag-over {
    opacity: 1 !important;
    background: var(--color-blue-accent-light);
    border-color: var(--color-blue-accent);
    border-style: solid;
    border-width: 2px;
    transform: scaleY(1.8);
    height: 16px;
}

.drop-zone-subrow::before {
    content: 'Drop here to add below';
    opacity: 0;
    transition: opacity 0.3s ease;
    font-size: 10px;
    font-weight: 500;
}

.dragging-active .drop-zone-subrow::before {
    opacity: 0.8;
}

.drop-zone-subrow.drag-over::before {
    content: 'Release to add here';
    font-weight: 600;
    opacity: 1;
}

/* Block styles in flex system */
.flex-grid-container .block {
    position: relative;
    background: transparent;
    border: none;
    border-radius: 8px;
    padding: 20px;
    min-height: 0;
    cursor: move;
    transition: all 0.2s ease;
    box-shadow: none;
    width: 100%;
    box-sizing: border-box;
}

.flex-grid-container .block:hover {
    background: transparent;
    border: 2px solid var(--color-blue-accent);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 18px;
    transform: translateY(-2px);
}

.flex-grid-container .block.dragging {
    background: transparent;
    border: 2px solid var(--color-blue-accent);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    opacity: 0.5;
    transform: rotate(2deg);
    z-index: 1000;
    padding: 18px;
}


/* Responsive behavior */
@media (max-width: 768px) {
    .block-row {
        flex-direction: column;
        gap: 20px;
    }
    
    .flex-grid-container.editing-mode .block-row {
        gap: 20px;
    }
    
    .block-wrapper {
        flex-basis: auto !important;
        min-width: 0;
    }
    
    .drop-zone-block-side {
        display: none; /* Hide side drop zones on mobile */
    }
}

/* Animation for smooth layout changes */
.block-row {
    transition: all 0.3s ease;
}

.block-wrapper {
    transition: flex-basis 0.3s ease;
}

/* Column resize handles */
.column-resize-handle {
    width: 8px;
    background: transparent;
    cursor: col-resize;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    margin: 0 -4px; /* Overlap slightly for better grab area */
    z-index: 10;
    align-self: stretch; /* Stretch to match row height */
}

.column-resize-handle::before {
    content: '';
    width: 4px; /* Thicker line */
    height: 90%; /* Much longer line spanning most of block height */
    background: var(--color-border);
    border-radius: 2px;
    transition: all 0.2s ease;
    opacity: 0;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.column-resize-handle::after {
    content: '⋮⋮'; /* Double vertical dots as grip handle */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--color-blue-accent);
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 3px 4px;
    border-radius: 3px;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 2;
    line-height: 0.7;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.column-resize-handle:hover::before {
    opacity: 1;
    background: var(--color-blue-accent);
    width: 4px;
    height: 95%; /* Nearly full height on hover */
}

.column-resize-handle:hover::after {
    opacity: 1;
}

.column-resize-handle:active::before {
    background: var(--color-blue-accent);
    opacity: 1;
    width: 5px; /* Even thicker when active */
    height: 98%; /* Nearly full height when active */
}

.column-resize-handle:active::after {
    opacity: 1;
    background: var(--color-blue-accent);
    transform: translate(-50%, -50%) scale(1.1);
}

/* Visual feedback during resize */
body.resizing-columns {
    cursor: col-resize !important;
    user-select: none;
}

body.resizing-columns * {
    cursor: col-resize !important;
    pointer-events: none;
}

body.resizing-columns .column-resize-handle {
    pointer-events: all;
}

/* Ensure resize handles are visible during resize */
body.resizing-columns .column-resize-handle::before {
    opacity: 1;
    background: var(--color-blue-accent);
    height: 98%;
    width: 5px;
}

body.resizing-columns .column-resize-handle::after {
    opacity: 1;
    background: var(--color-blue-accent);
    transform: translate(-50%, -50%) scale(1.1);
}

/* Empty state */
.flex-grid-container:empty::before {
    content: 'Click the + button to add your first block';
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--color-text-light);
    font-style: italic;
    border: 2px dashed var(--color-border);
    border-radius: var(--border-radius-large);
    margin: var(--spacing-lg);
}

/* Section styles - Force full viewport width */
.canvas-section {
    width: 100vw;
    position: relative;
    margin: 0 !important;
    padding: 0 !important;
    left: 50%;
    transform: translateX(-50%);
    transition: background-color 0.3s ease;
    min-height: 0;
    box-sizing: border-box;
    flex-shrink: 0;
    overflow: hidden;
}

/* First section should extend to very top - but only in editor (respect page nav) */
.canvas-section:first-child {
    margin-top: 0; /* No canvas padding to account for */
    padding-top: 0; /* No padding */
}

/* Last section should extend to very bottom */
.canvas-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
}

/* Section content wrapper to center content within sections */
.section-content-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Section controls */
.section-controls {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 100;
}

.canvas-section:hover .section-controls {
    opacity: 1;
}

.section-color-btn {
    width: 32px;
    height: 32px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.section-color-btn:hover {
    background: var(--color-hover);
    transform: scale(1.1);
    box-shadow: var(--shadow-md);
}

/* Unified Background Container for Apply-to-All sections */
.unified-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    pointer-events: none;
}

/* Enhanced Section Background Picker */
.section-background-picker-content {
    min-width: 380px;
    padding: var(--spacing-md);
}

/* Apply to All button */
.apply-all-group {
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--color-border);
}

.apply-all-btn {
    width: 100%;
    justify-content: center;
    gap: var(--spacing-sm);
    background: var(--color-primary, #6366f1);
    color: white;
    border: none;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
}

.apply-all-btn:hover {
    background: var(--color-primary-dark, #4f46e5);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.reset-unified-btn {
    width: 100%;
    justify-content: center;
    gap: var(--spacing-sm);
    background: transparent;
    color: var(--color-text);
    border: 1px solid var(--color-border);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: var(--spacing-sm);
}

.reset-unified-btn:hover {
    background: var(--color-bg-secondary, #f8f9fa);
    border-color: var(--color-primary, #6366f1);
    color: var(--color-primary, #6366f1);
}

/* Background type tabs */
.background-type-tabs {
    display: flex;
    gap: var(--spacing-xs);
    margin-top: var(--spacing-sm);
    background: var(--color-bg-secondary, #f8f9fa);
    border-radius: var(--border-radius);
    padding: 4px;
}

.background-type-tab {
    flex: 1;
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    background: transparent;
    border-radius: calc(var(--border-radius) - 2px);
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text-light);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    position: relative;
    overflow: hidden;
}

.background-type-tab:hover {
    background: rgba(255, 255, 255, 0.8);
    color: var(--color-text);
    transform: translateY(-1px);
}

.background-type-tab.active {
    background: white;
    color: var(--color-accent);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    font-weight: 600;
}

.background-type-tab.active::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--color-accent);
    border-radius: 1px;
}

/* Background controls container */
.background-controls-container {
    margin-top: var(--spacing-lg);
    animation: fadeInControls 0.3s ease;
}

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

/* Color presets */
.section-color-presets {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--spacing-xs);
    margin-top: var(--spacing-sm);
}

.section-color-preset {
    width: 50px;
    height: 50px;
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    background-size: cover;
    background-position: center;
}

.section-color-preset:hover {
    transform: scale(1.1);
    border-color: var(--color-accent);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1;
}

.section-color-preset:active {
    transform: scale(0.95);
}

/* Gradient presets */
.section-gradient-presets {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.section-gradient-preset {
    width: 100%;
    height: 60px;
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 500;
    font-size: var(--font-size-sm);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.section-gradient-preset::before {
    content: '✨ Gradient';
    opacity: 0;
    transition: opacity 0.2s ease;
}

.section-gradient-preset:hover {
    transform: scale(1.05);
    border-color: var(--color-accent);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 1;
}

.section-gradient-preset:hover::before {
    opacity: 1;
}

.section-gradient-preset:active {
    transform: scale(0.98);
}

/* Image upload controls */
.image-upload-container {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

/* Current image preview */
.current-image-container {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.current-image-label {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text-light);
}

.image-preview {
    width: 100%;
    height: 120px;
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative;
}

.remove-image-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--color-error);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: var(--font-size-sm);
    font-weight: 500;
    align-self: flex-start;
}

.remove-image-btn:hover {
    background: #e85a4f;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

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

/* Upload area and button */
.image-upload-area {
    border: 2px dashed var(--color-border);
    border-radius: var(--border-radius);
    padding: var(--spacing-lg);
    text-align: center;
    transition: all 0.2s ease;
    background: rgba(255, 255, 255, 0.5);
}

.image-upload-area:hover {
    border-color: var(--color-accent);
    background: var(--color-accent-light);
}

.image-upload-area.drag-over {
    border-color: var(--color-accent);
    background: var(--color-accent-light);
    border-style: solid;
    transform: scale(1.02);
}

.upload-image-btn {
    width: 100%;
    padding: var(--spacing-lg);
    background: transparent;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    color: var(--color-text);
}

.upload-image-btn:hover {
    background: rgba(255, 255, 255, 0.8);
    transform: translateY(-2px);
}

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

.upload-image-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.upload-image-btn:disabled:hover {
    transform: none;
    background: transparent;
}

.upload-icon {
    font-size: 48px;
    line-height: 1;
}

.upload-text {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    text-align: center;
}

.upload-primary {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--color-text);
}

.upload-secondary {
    font-size: var(--font-size-sm);
    color: var(--color-text-light);
}

/* Enhanced property groups for background picker */
.section-background-picker-content .property-group {
    margin-bottom: var(--spacing-lg);
    padding: var(--spacing-md);
    background: rgba(255, 255, 255, 0.5);
    border-radius: var(--border-radius);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.section-background-picker-content .property-group:last-child {
    margin-bottom: 0;
}

.section-background-picker-content .property-label {
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--spacing-sm);
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

/* Add icons to labels */
.section-background-picker-content .property-label::before {
    font-size: 14px;
}

.section-background-picker-content .property-group:has(.section-color-presets) .property-label::before {
    content: '🎨';
}

.section-background-picker-content .property-group:has(.section-gradient-presets) .property-label::before {
    content: '🌈';
}

.section-background-picker-content .property-group:has(.image-upload-container) .property-label::before {
    content: '📁';
}

/* Responsive adjustments for background picker */
@media (max-width: 768px) {
    .section-background-picker-content {
        min-width: 320px;
    }
    
    .background-type-tabs {
        flex-direction: column;
    }
    
    .section-gradient-presets {
        grid-template-columns: 1fr;
    }
    
    .section-color-presets {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .section-gradient-preset {
        height: 50px;
    }
}

/* Section content styling */
.canvas-section .block-row {
    margin: 0;
    position: relative;
}

/* Override gap in sections to prevent double spacing */
.canvas-section .block-row:not(:last-child) {
    margin-bottom: 0;
}

/* Ensure sections don't interfere with drop zones */
.canvas-section .drop-zone-row {
    position: relative;
    z-index: 50;
}



/* Responsive section styling */
@media (max-width: 768px) {
    .canvas-section {
        padding-left: 0;
        padding-right: 0;
    }
    
    .section-controls {
        top: 4px;
        right: 4px;
    }
    
    .section-color-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    
    .section-color-presets {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .section-color-preset {
        width: 35px;
        height: 35px;
    }
}