.smart-grid {
    display: grid;
    width: 100%;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    min-width: 0;
    box-sizing: border-box;

    /* Default is 1-1 */
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.smart-grid > * {
    min-width: 0;
}

.sg-width-article {
    width: min(100%, var(--article-media-width, 940px));
    max-width: min(100%, var(--article-media-width, 940px));
}

.sg-width-site,
.sg-width-wide,
.sg-width-xwide {
    margin-left: 50%;
    margin-right: 0;
    transform: translateX(-50%);
}

.sg-width-site {
    width: min(calc(100vw - 2rem), var(--container-width, 1200px));
    max-width: min(calc(100vw - 2rem), var(--container-width, 1200px));
}

.sg-width-wide {
    width: min(calc(100vw - 2rem), var(--article-wide-width, 1180px));
    max-width: min(calc(100vw - 2rem), var(--article-wide-width, 1180px));
}

.sg-width-xwide {
    width: min(96vw, 1400px);
    max-width: min(96vw, 1400px);
}

.sg-width-full {
    width: 100vw !important;
    position: relative !important;
    left: 50% !important;
    right: 50% !important;
    margin-left: -50vw !important;
    margin-right: -50vw !important;
    max-width: 100vw !important;
    box-sizing: border-box;
    padding-left: 2rem;
    /* Safe padding */
    padding-right: 2rem;
}

/* Alignments */
.sg-align-start {
    align-items: start;
}

.sg-align-center {
    align-items: center;
}

.sg-align-end {
    align-items: end;
}

.sg-align-stretch {
    align-items: stretch;
}

/* Templates with minmax to avoid column squeezing/overflow */
.sg-cols-1-1 {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.sg-cols-1-1-1 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.sg-cols-1-1-1-1 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.sg-cols-2-1 {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
}

.sg-cols-1-2 {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
}

.sg-cols-3-1 {
    grid-template-columns: minmax(0, 3fr) minmax(0, 1fr);
}

.sg-cols-1-3 {
    grid-template-columns: minmax(0, 1fr) minmax(0, 3fr);
}

.sg-cols-1-2-1 {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr);
}

/* Responsive stack on tablets and mobile devices */
@media (max-width: 1024px) {
    .sg-stack-mobile {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 2rem !important;
    }
}
