/* Centlec website: phone and tablet layout fixes shared by every page.
   Loaded last in each page's head so it can correct the page styles. Every rule is inside a max-width media query,
   so the desktop layout does not change. */

/* Tablets and phones (below 992px) */
@media (max-width: 991.98px) {
    /* Pictures, videos and embedded maps never wider than the screen */
    img, video, iframe, embed, object, canvas {
        max-width: 100%;
    }

    /* Wide tables scroll sideways inside their card instead of pushing the page wider */
    .table-responsive,
    .dataTables_wrapper,
    .dataTables_scrollBody {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Map search box on the coordinates pages fits the map */
    #searchBox {
        width: auto;
        left: 15px;
        right: 15px;
        max-width: calc(100% - 30px);
    }
}

/* Form tables (application forms with input fields) scroll sideways inside their own box (centlec-tables.js adds the box) */
.cl-table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* List tables below 900px: each row is a card with the column name above each value, the same as the public pages
   (Bids, Tariffs, Power Interruptions). centlec-tables.js adds the class cl-stack and the column names. */
@media (max-width: 900px) {
    table.cl-stack {
        min-width: 0 !important;
        width: 100% !important;
        border-collapse: collapse;
    }

    table.cl-stack thead,
    .cl-stack-scroll .dataTables_scrollHead {
        display: none !important;
    }

    .cl-stack-scroll .dataTables_scrollBody {
        overflow: visible !important;
        height: auto !important;
        max-height: none !important;
    }

    table.cl-stack,
    table.cl-stack tbody,
    table.cl-stack tr,
    table.cl-stack td {
        display: block;
        width: 100% !important;
    }

    table.cl-stack tbody tr {
        border-bottom: 1px solid rgba(0, 0, 0, 0.06);
        padding: 14px 16px 12px;
        background: #fff;
    }

    table.cl-stack tbody tr:hover {
        background: #fff;
    }

    table.cl-stack tbody td {
        border: none !important;
        padding: 5px 0 !important;
        text-align: left !important;
        white-space: normal !important;
        height: auto !important;
    }

    table.cl-stack tbody td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: 0.6rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: #6c757d;
        margin-bottom: 2px;
    }

    table.cl-stack tbody td.cl-full-row {
        text-align: center !important;
        padding: 16px 0 !important;
    }

    table.cl-stack tbody td.cl-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: flex-start;
        margin-top: 4px;
    }

    table.cl-stack tbody td.cl-actions > * {
        margin: 0 !important;
    }
}

/* Phones and small tablets (below 768px) */
@media (max-width: 767.98px) {
    /* Nothing makes the page scroll sideways (clip does not break sticky headers) */
    body {
        overflow-x: hidden;
        overflow-x: clip;
    }

    /* Columns may shrink below their content, so long words and links wrap instead of overflowing */
    .row > [class*="col"] {
        min-width: 0;
    }

    h1, h2, h3, h4, h5, h6, p, li, dd, dt, label, legend, blockquote,
    .card-title, .card-text, .modal-title, .modal-body {
        overflow-wrap: break-word;
        word-wrap: break-word;
    }

    a[href^="mailto:"] {
        overflow-wrap: anywhere;
    }

    pre, code {
        white-space: pre-wrap;
        word-break: break-word;
    }

    /* Form fields and buttons stay inside the screen; long button text wraps */
    input, select, textarea, .form-control, .custom-select {
        max-width: 100%;
    }

    .btn {
        white-space: normal;
    }

    /* Pop-up windows: buttons wrap neatly instead of running off the edge */
    .modal-footer {
        flex-wrap: wrap;
        gap: 8px;
    }

    .modal-footer > * {
        margin-left: 0;
        margin-right: 0;
    }

    /* CMS pages: toolbar labels and Publish now / Schedule tabs wrap on small screens */
    .toolbar-wrapper .toolbar-control label {
        white-space: normal;
    }

    .publish-mode-tabs {
        flex-wrap: wrap;
    }

    .publish-mode-tabs .publish-mode-tab {
        white-space: normal;
        min-width: 120px;
    }

    .doc-preview .doc-preview-info,
    .lead-image-preview .preview-info {
        min-width: 0;
    }

    /* DataTables controls (show entries, search, paging) stacked and centred */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none;
        text-align: center;
        margin-bottom: 8px;
    }

    .dataTables_wrapper .dataTables_filter input {
        margin-left: 0;
        width: 100%;
        max-width: 280px;
    }

    .dataTables_wrapper .dataTables_paginate .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* Small phones (below 576px) */
@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0.5rem auto;
        max-width: calc(100% - 1rem);
    }

    .modal-body {
        padding: 16px;
    }

    .modal-footer > .btn {
        flex: 1 1 auto;
    }
}
