/* =====================================================================
   WOWASCO Billing MIS — responsive layer for phones and tablets.
   Loaded after style.min.css and wowasco-enhancements.css.
   Desktop (>= 992px) is left exactly as it was.
   ===================================================================== */

/* Cell-content wrapper added by wowasco-responsive.js: no effect on desktop. */
.wr-val { display: contents; }

/* ---------- Everything: never wider than the screen ---------- */
img, video, canvas, svg { max-width: 100%; }
.main-app, .card, .card-body { min-width: 0; }
.apexcharts-canvas { max-width: 100% !important; }

/* =====================================================================
   Tablets and small laptops (< 992px)
   ===================================================================== */
@media (max-width: 991.98px) {
    /* Tables scroll sideways instead of squeezing columns into single letters. */
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    .table { table-layout: auto; }
    .table th, .table td { word-break: normal !important; }

    /* Page titles + action buttons wrap instead of overflowing. */
    .main-app > .d-flex,
    .main-app .card-header.d-flex,
    .main-app .d-flex.justify-content-between {
        flex-wrap: wrap;
        gap: .5rem;
    }

    /* Filter bars: inline fixed widths (e.g. style="width:210px") shrink to fit. */
    .main-app form .form-control[style*="width"],
    .main-app form .form-select[style*="width"],
    .main-app form input[style*="width"],
    .main-app form select[style*="width"] {
        max-width: 100%;
    }
    .main-app form.d-flex,
    .main-app form .d-flex { flex-wrap: wrap; }

    /* Button groups / toolbars wrap onto the next line. */
    .btn-toolbar, .btn-group:not(.dropdown):not([role="group"]) { flex-wrap: wrap; }

    /* Customer portal top navigation: comfortable touch targets. */
    .navbar .nav-link { padding-top: .6rem; padding-bottom: .6rem; }
}

/* Tablets (768px – 991px): keep the table layout, one line per cell, scroll sideways. */
@media (min-width: 768px) and (max-width: 991.98px) {
    .main-app .table th, .main-app .table td { white-space: nowrap !important; }
    .main-app .table td .text-wrap, .main-app .table td small { white-space: normal; }
}

/* =====================================================================
   Phones (< 768px)
   ===================================================================== */
@media (max-width: 767.98px) {
    .main-app { padding-left: .75rem !important; padding-right: .75rem !important; }
    .main-title { font-size: 1.15rem; }
    .card-one { padding: .75rem !important; }
    .card-body { padding: .75rem; }

    /* Filter / search fields take the full width. */
    .main-app form .form-control[style*="width"],
    .main-app form .form-select[style*="width"],
    .main-app form input[style*="width"],
    .main-app form select[style*="width"] {
        width: 100% !important;
    }
    .wowasco-table-tools { justify-content: stretch !important; }
    .wowasco-table-search { width: 100% !important; }

    /* Bigger touch targets. */
    .btn { min-height: 2.25rem; }
    .btn-sm { min-height: 2rem; }
    .form-control, .form-select { font-size: 16px; } /* stops iPhone zooming into fields */

    /* Modals use (almost) the full screen. */
    .modal-dialog { margin: .5rem; max-width: calc(100vw - 1rem); }
    .modal-body { padding: .85rem; }
    .modal-footer { flex-wrap: wrap; gap: .4rem; }
    .modal-footer .btn { flex: 1 1 auto; }

    /* SweetAlert pop-ups fit the screen. */
    .swal2-popup { width: calc(100vw - 2rem) !important; font-size: .9rem !important; }

    /* ---------- Data tables become stacked "cards" ----------
       wowasco-responsive.js adds .wr-stack to list tables and a
       data-label (the column heading) to every cell. */
    table.wr-stack { border: 0; width: 100% !important; table-layout: auto !important; }
    table.wr-stack thead { display: none; }
    table.wr-stack tbody tr {
        display: block;
        margin: 0 0 .75rem;
        border: 1px solid #e4e7ec;
        border-radius: .6rem;
        background: #fff;
        box-shadow: 0 1px 2px rgba(16, 24, 40, .05);
        overflow: hidden;
    }
    table.wr-stack tbody tr.table-warning,
    table.wr-stack tbody tr.ra-flagged { border-color: #f5c46b; }
    table.wr-stack tbody td {
        display: grid;
        grid-template-columns: 42% minmax(0, 1fr);
        column-gap: .75rem;
        align-items: start;
        width: 100% !important;
        padding: .45rem .75rem !important;
        border: 0;
        border-bottom: 1px solid #f2f4f7;
        text-align: right !important;
        font-size: .85rem !important;
        white-space: normal !important;
        word-break: normal !important;
        overflow-wrap: anywhere;
    }
    table.wr-stack tbody td:last-child { border-bottom: 0; }
    table.wr-stack tbody td::before {
        content: attr(data-label);
        text-align: left;
        white-space: normal;
        font-weight: 600;
        color: #475467;
        font-size: .78rem;
    }
    table.wr-stack tbody td[data-label=""]::before { content: none; }
    table.wr-stack tbody td[data-label=""] { grid-template-columns: minmax(0, 1fr); text-align: left !important; }
    table.wr-stack tbody td .wr-val { display: block; min-width: 0; }
    /* "No records" rows that span all columns. */
    table.wr-stack tbody td[colspan] { display: block; text-align: center !important; }
    table.wr-stack tbody td[colspan]::before { content: none; }
    /* Action cells: buttons line up on the right and wrap. */
    table.wr-stack tbody td .btn,
    table.wr-stack tbody td .btn-group { margin: .1rem 0 .1rem .25rem; }
    table.wr-stack tbody td > .d-flex { justify-content: flex-end; flex-wrap: wrap; }
    table.wr-stack tfoot { display: block; }
    table.wr-stack tfoot tr, table.wr-stack tfoot td { display: block; width: 100%; }

    /* Sticky toolbars would sit under the fixed top bar on phones. */
    .ra-bulkbar, .sticky-top { position: static !important; }

    /* Pagination controls centre on phones. */
    .pagination { flex-wrap: wrap; justify-content: center; }
}

/* Very small phones (< 400px) */
@media (max-width: 399.98px) {
    table.wr-stack tbody td { grid-template-columns: 45% minmax(0, 1fr); }
    .card-sign { width: calc(100vw - 1.5rem) !important; }
}

/* =====================================================================
   Footer (partials/footer.php) — one tidy bar at the bottom of the page.
   ===================================================================== */
.main-footer.wr-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .5rem 1.5rem;
    margin-top: auto;
    padding: 1rem 0 .5rem;
    border-top: 1px solid #e4e7ec;
    font-size: .8rem;
    color: #667085;
}
.main.main-app > .main-footer.wr-footer { margin-top: auto !important; }
/* Leave a comfortable gap between the last card and the footer. */
.main.main-app > *:has(+ .wr-footer) { margin-bottom: 2.5rem; }
.wr-footer strong { font-weight: 600; color: #344054; }
.wr-footer span { display: inline; margin: 0 !important; }
.wr-footer .wr-footer-version { display: inline-block; }
.wr-footer-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; }
.wr-footer-version {
    padding: .15rem .55rem;
    border-radius: 999px;
    background: #eef2ff;
    color: #3b5bdb;
    font-weight: 600;
    font-size: .72rem;
}
/* A footer accidentally placed after .main-app still lines up with the content. */
body > .main-footer.wr-footer { padding-left: 1rem; padding-right: 1rem; }
@media (min-width: 992px)  { body > .main-footer.wr-footer { margin-left: 240px; padding-left: 1.5rem; padding-right: 1.5rem; } }
@media (min-width: 1400px) { body > .main-footer.wr-footer { margin-left: 250px; } }
.sidebar-hide body > .main-footer.wr-footer, body.sidebar-hide > .main-footer.wr-footer { margin-left: 0; }
@media (max-width: 575.98px) {
    .main-footer.wr-footer { flex-direction: column; justify-content: center; text-align: center; gap: .4rem; }
    .wr-footer-meta { justify-content: center; }
}

/* =====================================================================
   Card polish for form / settings pages (opt-in: .wr-page on .main-app)
   ===================================================================== */
.wr-page .card-one { border: 1px solid #eaecf0; box-shadow: 0 1px 3px rgba(16, 24, 40, .06); border-radius: .6rem; }
.wr-page .card-one.h-auto { height: auto; }
.wr-page .card-one > .card-header {
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
    padding: .85rem 1.1rem; background: #fcfcfd; border-bottom: 1px solid #eaecf0;
    border-radius: .6rem .6rem 0 0;
}
.wr-page .card-one > .card-header .card-title { font-weight: 600; font-size: .95rem; display: flex; align-items: center; gap: .45rem; }
.wr-page .card-one > .card-header .card-title > i {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: .5rem; background: #eef2ff; color: #3b5bdb; font-size: 1rem; margin: 0 !important;
}
.wr-page .card-one > .card-body { padding: 1.1rem; }
.wr-page .wr-section-label {
    font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: #667085;
    margin: 1.25rem 0 .75rem; padding-top: 1rem; border-top: 1px dashed #eaecf0;
}
.wr-page .wr-stat { border: 1px solid #eaecf0; border-radius: .6rem; padding: .75rem 1rem; background: #fcfcfd; height: 100%; }
.wr-page .wr-stat small { color: #667085; font-weight: 500; }
@media (max-width: 767.98px) {
    .wr-page .card-one { padding: 0 !important; }
    .wr-page .card-one > .card-header { padding: .75rem; }
    .wr-page .card-one > .card-body { padding: .75rem; }
}
