/* 1. Basic Grid Styles */
.grid-row {
    padding: 8px;
    border: 1px solid ThreeDShadow;
    background-color: Window;
    transition: background-color 0.3s ease;
}

.grid-row:hover {
    background-color: #fafafa;
}

.datafield {
    padding: 5px;
    font-size: 14px;
    color: WindowText;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Responsive Grid */
@media (max-width: 768px) {
    .grid-row {
        padding: 6px;
    }
    .datafield {
        font-size: 13px;
    }
}

/* Basic Grid System with Enhanced Layout Options */

/* Grid Container */
.grid-container {
    width: 100%;
    margin-right: auto;
    margin-left: auto;
    padding: 15px;
}

/* Grid Row */
.grid-row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -15px;
    margin-left: -15px;
}

/* Grid Columns */
.grid-col {
    position: relative;
    width: 100%;
    padding-right: 15px;
    padding-left: 15px;
}

/* Column Sizes */
.col-1 { flex: 0 0 8.333333%; max-width: 8.333333%; }
.col-2 { flex: 0 0 16.666667%; max-width: 16.666667%; }
.col-3 { flex: 0 0 25%; max-width: 25%; }
.col-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }
.col-6 { flex: 0 0 50%; max-width: 50%; }
.col-8 { flex: 0 0 66.666667%; max-width: 66.666667%; }
.col-9 { flex: 0 0 75%; max-width: 75%; }
.col-12 { flex: 0 0 100%; max-width: 100%; }

/* Auto Column */
.col-auto { flex: 0 0 auto; width: auto; max-width: 100%; }

/* Grid Gaps */
.grid-gap-sm { gap: 0.5rem; }
.grid-gap-md { gap: 1rem; }
.grid-gap-lg { gap: 1.5rem; }

/* Grid Alignment */
.grid-start { justify-content: flex-start; }
.grid-center { justify-content: center; }
.grid-end { justify-content: flex-end; }
.grid-between { justify-content: space-between; }
.grid-around { justify-content: space-around; }

/* Vertical Alignment */
.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }

/* RTL Support */
[dir="rtl"] .grid-row {
    flex-direction: row-reverse;
}

/* Responsive Breakpoints */
@media (min-width: 576px) {
    .grid-container { max-width: 540px; }
    .col-sm-6 { flex: 0 0 50%; max-width: 50%; }
    .col-sm-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }
}

@media (min-width: 768px) {
    .grid-container { max-width: 720px; }
    .col-md-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }
    .col-md-3 { flex: 0 0 25%; max-width: 25%; }
}

@media (min-width: 992px) {
    .grid-container { max-width: 960px; }
    .col-lg-3 { flex: 0 0 25%; max-width: 25%; }
    .col-lg-2 { flex: 0 0 16.666667%; max-width: 16.666667%; }
}

/* Grid Cards */
.grid-card {
    padding: 1rem;
    background: #fff;
    border: 1px solid ThreeDShadow;
    border-radius: 4px;
    transition: box-shadow 0.3s ease;
}

.grid-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Nested Grids */
.grid-row .grid-row {
    margin-right: 0;
    margin-left: 0;
}

/* Grid Utilities */
.grid-nowrap { flex-wrap: nowrap !important; }
.grid-wrap-reverse { flex-wrap: wrap-reverse !important; }
.grid-fill > * { flex: 1 1 0%; }

/* Grid System RTL Enhancements */

/* Maintain original styles */

/* Enhanced RTL Grid Support */
[dir="rtl"] {
    .grid-container {
        direction: rtl;
    }

    .grid-col {
        float: right;
    }

    /* RTL Column Offsets */
    .offset-rtl-1 { margin-right: 8.333333%; margin-left: 0; }
    .offset-rtl-2 { margin-right: 16.666667%; margin-left: 0; }
    .offset-rtl-3 { margin-right: 25%; margin-left: 0; }
    .offset-rtl-4 { margin-right: 33.333333%; margin-left: 0; }

    /* RTL Text Alignment */
    .text-rtl-right { text-align: left; }
    .text-rtl-left { text-align: right; }

    /* RTL Ordering */
    .order-rtl-first { order: -1; }
    .order-rtl-last { order: 13; }
    .order-rtl-0 { order: 0; }
}

/* Enhanced Nesting Support */
.grid-nested {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 1rem;
    padding: 0;
}

/* Auto-fit Grid */
.grid-auto-fit {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

/* Grid Areas Support */
.grid-areas {
    display: grid;
    grid-template-areas: 
        "header header header"
        "sidebar main main"
        "footer footer footer";
}

/* Responsive Grid Areas */
@media (max-width: 768px) {
    .grid-areas {
        grid-template-areas: 
            "header"
            "sidebar"
            "main"
            "footer";
    }

    [dir="rtl"] .grid-auto-fit {
        direction: rtl;
    }
}