/**
 * CMS Grid System - 12 Column Layout (CSS Grid)
 * EAA Ballpark CMS Page Builder
 *
 * Implements a responsive 12-column grid using CSS Grid.
 * Simple, predictable alignment that matches the overlay exactly.
 */

/* === Grid Variables === */
:root {
    --cms-gutter: 24px;
    --cms-gutter-half: 12px;
    --cms-container-sm: 600px;
    --cms-container-md: 960px;
    --cms-container-lg: 1280px;
    --cms-container-xl: 1600px;
    --cms-grid-color: rgba(13, 93, 44, 0.15); /* EAA green tint */
}

/* === Grid Container === */
.cms-grid-container {
    width: 100%;
    padding-right: var(--cms-gutter-half);
    padding-left: var(--cms-gutter-half);
    margin-right: auto;
    margin-left: auto;
    box-sizing: border-box;
    position: relative;
}

/* Container max-widths at breakpoints */
@media (min-width: 600px) {
    .cms-grid-container {
        max-width: var(--cms-container-sm);
    }
}

@media (min-width: 960px) {
    .cms-grid-container {
        max-width: var(--cms-container-md);
    }
}

@media (min-width: 1280px) {
    .cms-grid-container {
        max-width: var(--cms-container-lg);
    }
}

@media (min-width: 1600px) {
    .cms-grid-container {
        max-width: var(--cms-container-xl);
    }
}

/* === Grid Row (CSS Grid) === */
.cms-grid-row {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: var(--cms-gutter);
    box-sizing: border-box;
}

/* Mobile-first: Single column on xs (0-600px) */
@media (max-width: 599px) {
    .cms-grid-row {
        grid-template-columns: 1fr;
        gap: var(--cms-gutter-half);
    }

    [class*="cms-grid-col-"] {
        grid-column: span 1 !important;
    }
}

/* === Grid Columns (CSS Grid) === */
[class*="cms-grid-col-"] {
    position: relative;
    box-sizing: border-box;
    min-width: 0; /* Prevent overflow */
}

/* Column spans - how many of the 12 columns to span */
.cms-grid-col-1 { grid-column: span 1; }
.cms-grid-col-2 { grid-column: span 2; }
.cms-grid-col-3 { grid-column: span 3; }
.cms-grid-col-4 { grid-column: span 4; }
.cms-grid-col-5 { grid-column: span 5; }
.cms-grid-col-6 { grid-column: span 6; }
.cms-grid-col-7 { grid-column: span 7; }
.cms-grid-col-8 { grid-column: span 8; }
.cms-grid-col-9 { grid-column: span 9; }
.cms-grid-col-10 { grid-column: span 10; }
.cms-grid-col-11 { grid-column: span 11; }
.cms-grid-col-12 { grid-column: span 12; }

/* === Column Offsets (CSS Grid - use grid-column-start) === */
.cms-grid-offset-1 { grid-column-start: 2; }
.cms-grid-offset-2 { grid-column-start: 3; }
.cms-grid-offset-3 { grid-column-start: 4; }
.cms-grid-offset-4 { grid-column-start: 5; }
.cms-grid-offset-5 { grid-column-start: 6; }
.cms-grid-offset-6 { grid-column-start: 7; }
.cms-grid-offset-7 { grid-column-start: 8; }
.cms-grid-offset-8 { grid-column-start: 9; }
.cms-grid-offset-9 { grid-column-start: 10; }
.cms-grid-offset-10 { grid-column-start: 11; }
.cms-grid-offset-11 { grid-column-start: 12; }

/* === Grid Overlay (Fixed - for general use) === */
.cms-grid-overlay {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    height: 100vh;
    width: 100%;
    max-width: var(--cms-container-xl);
    pointer-events: none;
    z-index: 9999;
    display: flex;
    padding: 0 var(--cms-gutter-half);
    box-sizing: border-box;
}

/* === Grid Overlay Inline (Absolute - aligned with container) === */
.cms-grid-overlay-inline {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 9999;
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: var(--cms-gutter);
    box-sizing: border-box;
}

@media (min-width: 600px) {
    .cms-grid-overlay {
        max-width: var(--cms-container-sm);
    }
}

@media (min-width: 960px) {
    .cms-grid-overlay {
        max-width: var(--cms-container-md);
    }
}

@media (min-width: 1280px) {
    .cms-grid-overlay {
        max-width: var(--cms-container-lg);
    }
}

@media (min-width: 1600px) {
    .cms-grid-overlay {
        max-width: var(--cms-container-xl);
    }
}

.cms-grid-overlay-column {
    position: relative;
    box-sizing: border-box;
    background: var(--cms-grid-color);
    border-radius: 4px;
}

.cms-grid-overlay-column:first-child {
    border-left: 2px solid rgba(13, 93, 44, 0.3);
}

.cms-grid-overlay-column:last-child {
    border-right: 2px solid rgba(13, 93, 44, 0.3);
}

/* Column number labels */
.cms-grid-overlay-label {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(13, 93, 44, 0.8);
    color: white;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
    font-family: monospace;
    pointer-events: all;
    cursor: help;
    z-index: 10000;
}

.cms-grid-overlay-label:hover {
    background: rgba(13, 93, 44, 1);
}

/* === Grid Snap Guides === */
.cms-snap-guide {
    position: absolute;
    pointer-events: none;
    z-index: 9998;
}

.cms-snap-guide-vertical {
    width: 2px;
    height: 100%;
    background: rgba(240, 179, 35, 0.6); /* EAA gold */
    box-shadow: 0 0 4px rgba(240, 179, 35, 0.8);
}

.cms-snap-guide-horizontal {
    width: 100%;
    height: 2px;
    background: rgba(240, 179, 35, 0.6); /* EAA gold */
    box-shadow: 0 0 4px rgba(240, 179, 35, 0.8);
}

/* Snap indicator (shows when component aligns to grid) */
.cms-snap-indicator {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(240, 179, 35, 0.9);
    border: 2px solid white;
    box-shadow: 0 0 6px rgba(240, 179, 35, 1);
    pointer-events: none;
    z-index: 10001;
    animation: cms-snap-pulse 0.3s ease-in-out;
}

@keyframes cms-snap-pulse {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* === Edit Mode Helpers === */
.cms-component-dragging {
    opacity: 0.7;
    cursor: move;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.cms-component-resizing {
    outline: 2px dashed rgba(13, 93, 44, 0.5);
    outline-offset: 2px;
}

/* === Utility Classes === */
.cms-grid-debug {
    outline: 1px dashed red;
}

.cms-grid-debug [class*="cms-grid-col-"] {
    outline: 1px dashed blue;
    min-height: 50px;
}
