/*
 * RegularStation UI/UX Fixes v1.0.0
 * GeneratePress-safe responsive layer.
 *
 * Scope:
 * - Homepage: .rs-home-ui
 * - Single posts/pages: .rs-single-ui
 * - RS calculators: .rs-calculator-page
 */

/* ---------------------------------------------------------
   1. Global safety
--------------------------------------------------------- */

html {
    overflow-x: clip;
}

body {
    overflow-x: clip;
}

img,
video,
iframe,
embed {
    max-width: 100%;
}

.wp-block-image img,
.entry-content img {
    height: auto;
}

/* Prevent long URLs / code from forcing the viewport wider. */
.entry-content,
.entry-summary,
.widget,
.site-main {
    overflow-wrap: break-word;
}

/* ---------------------------------------------------------
   2. GeneratePress calculator pages
--------------------------------------------------------- */

body.rs-calculator-page .site-content {
    width: 100% !important;
    max-width: 1240px !important;
    margin-inline: auto !important;
}

body.rs-calculator-page .content-area {
    width: 100% !important;
    max-width: 100% !important;
    float: none !important;
    margin: 0 !important;
}

body.rs-calculator-page .widget-area,
body.rs-calculator-page .site-content > .widget-area {
    display: none !important;
}

body.rs-calculator-page .site-main {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
}

body.rs-calculator-page .inside-article {
    width: 100% !important;
    max-width: 100% !important;
}

body.rs-calculator-page .entry-content {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
}

body.rs-calculator-page .entry-header {
    max-width: 1120px;
    margin-inline: auto;
}

body.rs-calculator-page .entry-title {
    max-width: 1000px;
}

body.rs-calculator-page .featured-image,
body.rs-calculator-page .post-image {
    max-width: 1120px;
    margin-inline: auto;
}

body.rs-calculator-page .entry-content > p,
body.rs-calculator-page .entry-content > h2,
body.rs-calculator-page .entry-content > h3,
body.rs-calculator-page .entry-content > ul,
body.rs-calculator-page .entry-content > ol,
body.rs-calculator-page .entry-content > table,
body.rs-calculator-page .entry-content > blockquote {
    max-width: 900px;
    margin-inline: auto;
}

/* The calculator itself is allowed to use the full content width. */
body.rs-calculator-page .entry-content > .rs-emi-calculator,
body.rs-calculator-page .entry-content > .rs-sip-calculator {
    width: 100% !important;
    max-width: 1120px !important;
    margin: 34px auto !important;
}

/* Calculator-specific overflow protection. */
body.rs-calculator-page .rs-emi-calculator,
body.rs-calculator-page .rs-sip-calculator {
    min-width: 0 !important;
    overflow: visible !important;
}

body.rs-calculator-page .rs-emi-calculator *,
body.rs-calculator-page .rs-sip-calculator * {
    min-width: 0;
}

/* ---------------------------------------------------------
   3. EMI/SIP spacing normalization inside GeneratePress
--------------------------------------------------------- */

body.rs-calculator-page .entry-content .rs-emi-calculator p,
body.rs-calculator-page .entry-content .rs-sip-calculator p {
    margin-top: 0;
}

body.rs-calculator-page .entry-content .rs-emi-calculator h2,
body.rs-calculator-page .entry-content .rs-emi-calculator h3,
body.rs-calculator-page .entry-content .rs-sip-calculator h2,
body.rs-calculator-page .entry-content .rs-sip-calculator h3 {
    margin-top: 0;
}

/* EMI desktop: give the inputs/results a little more breathing room. */
@media (min-width: 901px) {
    body.rs-calculator-page .rs-emi-layout {
        grid-template-columns: minmax(360px, 0.9fr) minmax(0, 1.1fr) !important;
        gap: 24px !important;
    }

    body.rs-calculator-page .rs-emi-input-panel {
        padding: 26px !important;
    }

    body.rs-calculator-page .rs-emi-primary-result {
        min-height: 164px !important;
    }
}

/* ---------------------------------------------------------
   4. Single-post reading layout
--------------------------------------------------------- */

body.rs-single-ui.single-post .site-content,
body.rs-single-ui.single-page .site-content {
    max-width: 1240px;
    margin-inline: auto;
}

body.rs-single-ui .inside-article {
    min-width: 0;
}

body.rs-single-ui .entry-title {
    max-width: 900px;
    line-height: 1.08;
    text-wrap: balance;
}

body.rs-single-ui .entry-content {
    font-size: 17px;
    line-height: 1.78;
}

body.rs-single-ui .entry-content > p,
body.rs-single-ui .entry-content > ul,
body.rs-single-ui .entry-content > ol,
body.rs-single-ui .entry-content > blockquote {
    max-width: 860px;
}

body.rs-single-ui .entry-content h2 {
    margin-top: 42px;
    margin-bottom: 14px;
    line-height: 1.2;
}

body.rs-single-ui .entry-content h3 {
    margin-top: 30px;
    margin-bottom: 10px;
    line-height: 1.25;
}

body.rs-single-ui .entry-content ul,
body.rs-single-ui .entry-content ol {
    padding-left: 1.35em;
}

body.rs-single-ui .entry-content li + li {
    margin-top: 7px;
}

body.rs-single-ui .entry-content blockquote {
    margin-block: 26px;
}

body.rs-single-ui .entry-content table {
    width: 100%;
    border-collapse: collapse;
}

body.rs-single-ui .entry-content pre {
    max-width: 100%;
    overflow-x: auto;
}

body.rs-single-ui .entry-content .wp-block-table {
    overflow-x: auto;
    max-width: 100%;
}

/* Sidebar cards: less oversized typography and cleaner spacing. */
body.rs-single-ui .widget-area .widget {
    margin-bottom: 26px;
}

body.rs-single-ui .widget-area .widget-title {
    line-height: 1.25;
}

/* ---------------------------------------------------------
   5. Homepage responsive cleanup
--------------------------------------------------------- */

body.rs-home-ui .site-content {
    width: 100%;
    max-width: 1240px;
    margin-inline: auto;
}

body.rs-home-ui .site-main {
    min-width: 0;
}

body.rs-home-ui img {
    max-width: 100%;
    height: auto;
}

body.rs-home-ui .widget,
body.rs-home-ui .wp-block-group,
body.rs-home-ui .wp-block-columns {
    min-width: 0;
}

body.rs-home-ui .wp-block-columns {
    flex-wrap: wrap;
}

body.rs-home-ui .wp-block-column {
    min-width: 0;
}

/* ---------------------------------------------------------
   6. Mobile: one-column reading experience
--------------------------------------------------------- */

@media (max-width: 768px) {

    /* GeneratePress content frame */
    body .site-content {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    body .inside-article {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    /* Homepage */
    body.rs-home-ui .site-content {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    body.rs-home-ui .entry-content {
        width: 100%;
    }

    /* Single posts */
    body.rs-single-ui .entry-title {
        font-size: clamp(30px, 8.5vw, 42px) !important;
        line-height: 1.08 !important;
        margin-bottom: 16px !important;
    }

    body.rs-single-ui .entry-content {
        font-size: 16px;
        line-height: 1.75;
    }

    body.rs-single-ui .entry-content h2 {
        font-size: 27px;
        margin-top: 34px;
    }

    body.rs-single-ui .entry-content h3 {
        font-size: 22px;
        margin-top: 27px;
    }

    body.rs-single-ui .entry-content img {
        width: 100%;
        height: auto;
    }

    /* Sidebar moves below content in GeneratePress; avoid oversized gaps. */
    body.rs-single-ui .widget-area {
        width: 100% !important;
        margin-top: 34px !important;
    }

    body.rs-single-ui .widget-area .widget {
        margin-bottom: 24px;
    }

    /* Calculator pages */
    body.rs-calculator-page .site-content {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    body.rs-calculator-page .entry-header {
        padding-left: 4px;
        padding-right: 4px;
    }

    body.rs-calculator-page .entry-title {
        font-size: clamp(30px, 8.5vw, 42px) !important;
        line-height: 1.08 !important;
    }

    body.rs-calculator-page .entry-content > p:not(.rs-emi-disclaimer) {
        max-width: 100%;
    }

    body.rs-calculator-page .entry-content > .rs-emi-calculator,
    body.rs-calculator-page .entry-content > .rs-sip-calculator {
        margin-top: 24px !important;
        margin-bottom: 24px !important;
    }

    /* EMI */
    body.rs-calculator-page .rs-emi-layout {
        grid-template-columns: 1fr !important;
    }

    body.rs-calculator-page .rs-emi-summary-grid {
        grid-template-columns: 1fr !important;
    }

    body.rs-calculator-page .rs-emi-tenure-inputs {
        grid-template-columns: minmax(0, 1fr) 112px !important;
    }

    body.rs-calculator-page .rs-emi-table-scroll {
        max-width: 100%;
        overflow-x: auto !important;
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
    }

    body.rs-calculator-page .rs-emi-table-scroll table {
        min-width: 680px !important;
    }

    /* SIP */
    body.rs-calculator-page .rs-sip-grid {
        grid-template-columns: 1fr !important;
    }

    body.rs-calculator-page .rs-sip-result-grid {
        grid-template-columns: 1fr 1fr;
    }

    body.rs-calculator-page .rs-sip-table-scroll {
        max-width: 100%;
        overflow-x: auto !important;
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 480px) {

    body .site-content {
        padding-left: 14px !important;
        padding-right: 14px !important;
    }

    body.rs-home-ui .site-content {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    body.rs-single-ui .entry-content {
        font-size: 16px;
    }

    body.rs-single-ui .entry-content h2 {
        font-size: 25px;
    }

    body.rs-single-ui .entry-content h3 {
        font-size: 21px;
    }

    body.rs-calculator-page .site-content {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    body.rs-calculator-page .rs-emi-input-panel,
    body.rs-calculator-page .rs-emi-chart-card,
    body.rs-calculator-page .rs-emi-table-card {
        padding: 15px !important;
        border-radius: 15px !important;
    }

    body.rs-calculator-page .rs-emi-header h2 {
        font-size: 29px !important;
    }

    body.rs-calculator-page .rs-emi-primary-result {
        padding: 20px !important;
        border-radius: 15px !important;
    }

    body.rs-calculator-page .rs-emi-primary-result strong {
        font-size: 34px !important;
    }

    body.rs-calculator-page .rs-sip-result-grid {
        grid-template-columns: 1fr !important;
    }

    body.rs-calculator-page .rs-sip-result-main {
        grid-column: auto !important;
    }
}

/* ---------------------------------------------------------
   7. Extra protection against theme form/table overflow
--------------------------------------------------------- */

@media (max-width: 768px) {
    .site-content input,
    .site-content select,
    .site-content textarea {
        max-width: 100%;
    }

    .site-content table {
        max-width: 100%;
    }
}
