/* CMS Grid Positioning and Component Edit Indicators */

/* Grid Container */
.cms-grid-container {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 24px;
    width: 100%;
    min-height: 400px;
    padding: 24px;
    position: relative;
}

/* Grid Component Wrapper */
.cms-grid-component {
    position: relative;
    min-height: 120px;
    background-color: white;
    border-radius: 8px;
    transition: all 0.15s ease;
}

/* Editable State */
.cms-component-editable {
    cursor: pointer;
    border: 1px solid transparent;
}

.cms-component-editable:hover {
    border-color: rgba(25, 118, 210, 0.5);
}

/* Hovered State */
.cms-component-hovered {
    background-color: rgba(25, 118, 210, 0.05);
    box-shadow: 0 2px 8px rgba(25, 118, 210, 0.15);
}

/* Selected State */
.cms-component-selected {
    border: 2px solid #1976d2 !important;
    box-shadow: 0 4px 12px rgba(25, 118, 210, 0.2);
    z-index: 10;
}

/* Edit Indicators Container */
.cms-component-indicators {
    position: absolute;
    top: -32px;
    left: 0;
    right: 0;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    background-color: #1976d2;
    border-radius: 4px 4px 0 0;
    color: white;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 20;
}

.cms-component-editable:hover .cms-component-indicators,
.cms-component-selected .cms-component-indicators {
    opacity: 1;
}

/* Move Handle */
.cms-component-move-handle {
    display: flex;
    align-items: center;
    cursor: move;
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.15s ease;
}

.cms-component-move-handle:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Component Label */
.cms-component-label {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.cms-component-label .mud-typography {
    color: white;
    font-size: 0.75rem;
    line-height: 1;
}

/* Delete Button */
.cms-component-delete {
    width: 28px;
    height: 28px;
}

.cms-component-delete .mud-icon-root {
    font-size: 18px;
}

/* Resize Handles */
.cms-component-resize-handle {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 40px;
    background-color: #1976d2;
    border-radius: 6px;
    cursor: ew-resize;
    opacity: 0;
    transition: opacity 0.15s ease, background-color 0.15s ease;
    z-index: 30;
}

.cms-component-resize-handle:hover {
    background-color: #1565c0;
}

.cms-component-editable:hover .cms-component-resize-handle,
.cms-component-selected .cms-component-resize-handle {
    opacity: 1;
}

.cms-resize-left {
    left: -6px;
}

.cms-resize-right {
    right: -6px;
}

/* Resize Tooltip */
.cms-resize-tooltip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 8px 16px;
    background-color: rgba(25, 118, 210, 0.95);
    color: white;
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    z-index: 40;
    animation: tooltipFadeIn 0.2s ease;
}

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* Component Content */
.cms-component-content {
    width: 100%;
    height: 100%;
    padding: 16px;
    overflow: hidden;
}

/* Grid Snap Guides (shown during drag) */
.cms-snap-guide {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: rgba(240, 179, 35, 0.8);
    pointer-events: none;
    z-index: 50;
    animation: snapGuidePulse 1s ease-in-out infinite;
}

@keyframes snapGuidePulse {
    0%, 100% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
}

/* Drop Zone Highlight */
.cms-drop-zone-valid {
    background-color: rgba(76, 175, 80, 0.1);
    border: 2px dashed #4caf50;
    border-radius: 8px;
}

.cms-drop-zone-invalid {
    background-color: rgba(244, 67, 54, 0.1);
    border: 2px dashed #f44336;
    border-radius: 8px;
}

/* Invalid Position Error */
.cms-component-error {
    border: 2px solid #f44336 !important;
    animation: shake 0.4s ease;
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-4px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(4px);
    }
}

/* Reflow Animation */
.cms-component-reflow {
    transition: all 0.3s ease-in-out;
}

/* Empty Grid State */
.cms-grid-empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    border: 2px dashed #ccc;
    border-radius: 8px;
    background-color: #f9f9f9;
}

/* Responsive Behavior */
@media (max-width: 959px) {
    .cms-grid-container {
        grid-template-columns: repeat(6, 1fr);
        gap: 16px;
        padding: 16px;
    }

    .cms-component-indicators {
        top: -28px;
        height: 28px;
        font-size: 0.7rem;
    }

    .cms-component-resize-handle {
        width: 10px;
        height: 32px;
    }
}

@media (max-width: 599px) {
    .cms-grid-container {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 12px;
    }

    .cms-component-indicators {
        position: relative;
        top: 0;
        margin-bottom: 8px;
        border-radius: 4px;
    }

    .cms-component-resize-handle {
        display: none;
    }
}

/* Focus States */
.cms-component-editable:focus-visible {
    outline: 2px solid #1976d2;
    outline-offset: 4px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .cms-grid-component,
    .cms-component-indicators,
    .cms-component-resize-handle,
    .cms-component-reflow {
        transition: none;
        animation: none;
    }
}

/* Accessibility - High Contrast */
@media (prefers-contrast: high) {
    .cms-component-selected {
        border-width: 3px !important;
    }

    .cms-component-indicators {
        border: 2px solid white;
    }

    .cms-component-resize-handle {
        border: 2px solid white;
    }
}

/* Component Dragging State */
.cms-component-dragging {
    opacity: 0.5;
    cursor: grabbing !important;
    z-index: 100;
}

.cms-component-dragging * {
    pointer-events: none;
}

/* Grid Column Indicators (for debugging/development) */
.cms-show-grid-columns .cms-grid-container {
    background-image: repeating-linear-gradient(
        to right,
        rgba(13, 93, 44, 0.05) 0,
        rgba(13, 93, 44, 0.05) calc(100% / 12),
        transparent calc(100% / 12),
        transparent calc(100% / 12 * 2)
    );
}
