/*
 * Layout fixes for every screen, loaded after app.css.
 * Only arranges existing elements (no colours, no behaviour), so every
 * page keeps its look and simply stops overlapping or overflowing on
 * phones, tablets and small laptops.
 */

/* Tapping twice quickly no longer zooms the page (pinch zoom still works). */
html {
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
}

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

/* ================= Table toolbar: Show N entries | export buttons | search
   The app puts "Show N entries" in a 1/12-wide column, so from tablet width
   up its text ran over the export buttons. One row that wraps instead. */
.dataTables_wrapper > .row.margin-bottom-20 {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    margin-left: 0;
    margin-right: 0;
}
.dataTables_wrapper > .row.margin-bottom-20::before,
.dataTables_wrapper > .row.margin-bottom-20::after {
    display: none;
}
.dataTables_wrapper > .row.margin-bottom-20 > [class*="col-"] {
    float: none;
    width: auto;
    min-width: 0;
    padding-left: 0;
    padding-right: 0;
    flex: 0 0 auto;
}
/* export buttons take the middle and wrap; search keeps to the right */
.dataTables_wrapper > .row.margin-bottom-20 > [class*="col-"]:nth-child(2) {
    flex: 1 1 300px;
}
.dataTables_wrapper > .row.margin-bottom-20 > [class*="col-"]:nth-child(3) {
    margin-left: auto;
}
.dataTables_wrapper .dataTables_length label,
.dataTables_wrapper .dataTables_filter label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    white-space: nowrap;
}
.dataTables_wrapper .dataTables_length select {
    width: auto !important;
    margin: 0;
}
.dataTables_wrapper .dataTables_filter input {
    margin: 0;
}
.dataTables_wrapper .dt-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    float: none;
}
.dataTables_wrapper .dt-buttons > .btn,
.dataTables_wrapper .dt-buttons > .dt-button {
    float: none;
    margin: 0 !important;
}

/* footer: entry count and page numbers wrap instead of overflowing */
.dataTables_wrapper .dataTables_paginate .pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    justify-content: flex-end;
}
.dataTables_wrapper .dataTables_paginate .pagination > li > a,
.dataTables_wrapper .dataTables_paginate .pagination > li > span {
    float: none;
}

/* Date/time pickers: every card has a sideways-scroll box (for wide
   tables) that also cut off any calendar opening inside it, leaving only
   a thin strip over the field. While a calendar is open the box lets it
   show in full. */
.tw-overflow-x-auto:has(.bootstrap-datetimepicker-widget),
.table-responsive:has(.bootstrap-datetimepicker-widget),
.box-body:has(.bootstrap-datetimepicker-widget) {
    overflow: visible;
}
.bootstrap-datetimepicker-widget.dropdown-menu {
    z-index: 1060;
}

/* wide tables scroll inside their card, smoothly on touch screens */
.table-responsive,
.dataTables_scrollBody,
.dataTables_wrapper {
    -webkit-overflow-scrolling: touch;
}

/* ================= Till (POS) screen */
/* the location dropdown shares a third of the header with the date and
   was squeezed to a single letter on tablets */
.pos-header #select_location_id {
    min-width: 150px;
}
.pos-header .tw-flex.tw-items-center.tw-gap-2 {
    flex-wrap: wrap;
}
@media (min-width: 768px) and (max-width: 1199px) {
    .pos-header > .tw-flex {
        flex-wrap: wrap;
        gap: 8px;
    }
    .pos-header > .tw-flex > div {
        width: auto;
        flex: 1 1 auto;
    }

    /* bottom bar: Cash, Cancel and the total sat in a narrow sideways-
       scrolling strip, hidden off to the right; let the buttons wrap */
    .pos-form-actions > .tw-flex {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }
    .pos-form-actions .tw-overflow-x-auto {
        flex-wrap: wrap;
        justify-content: center;
        row-gap: 8px;
        overflow-x: visible;
    }
    .pos-form-actions .top-scrollbar {
        display: none;
    }
    /* room under the cart so its totals can scroll clear of the taller bar */
    body.lockscreen section.content {
        padding-bottom: 230px !important;
    }
}

/* ================= Tablets and phones */
@media (max-width: 991px) {
    /* page header: title, subtitle and any buttons wrap */
    .content-header {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        gap: 4px 10px;
    }
    .content-header > h1 {
        margin: 0;
    }
    .content-header > h1 small {
        display: inline-block;
        padding-left: 0;
    }
}

/* Small phones: cards drop their side padding, so Bootstrap rows (which
   reach 15px past each side) stuck out of every card. That gave each card
   a pointless sideways scroll and an empty scroll strip above it. Give
   the card back the 15px the rows expect. */
@media (max-width: 639px) {
    .tw-overflow-x-auto > .tw-py-2.tw-align-middle {
        padding-left: 15px;
        padding-right: 15px;
    }
}

/* ================= Phones */
@media (max-width: 767px) {
    /* table toolbar stacks: entries, buttons, then a full-width search */
    .dataTables_wrapper > .row.margin-bottom-20 > [class*="col-"] {
        flex: 1 1 100%;
        margin-left: 0;
        text-align: center;
    }
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_filter label {
        display: flex;
        width: 100%;
    }
    .dataTables_wrapper .dataTables_filter input {
        flex: 1;
        width: auto !important;
    }
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        text-align: center;
        float: none;
    }
    .dataTables_wrapper .dataTables_paginate .pagination {
        justify-content: center;
    }

    /* 16px text stops iPhones zooming in whenever a field is tapped */
    input.form-control,
    select.form-control,
    textarea.form-control,
    .select2-container .select2-selection,
    .select2-container .select2-search__field {
        font-size: 16px;
    }

    /* pop-up windows use the whole width of the phone */
    .modal-dialog,
    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl {
        width: auto;
        margin: 8px;
    }
    .modal-body {
        overflow-x: auto;
    }
    .modal-footer {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 6px;
    }
    .modal-footer .btn + .btn {
        margin-left: 0;
    }

    /* groups of buttons wrap instead of running off the screen */
    .box-tools,
    .btn-group:not(.dropdown):not(.bootstrap-select) {
        flex-wrap: wrap;
    }
    .box-header .box-tools {
        position: static;
        margin-top: 8px;
    }

    /* input + add button pairs keep both parts visible */
    .input-group {
        width: 100%;
    }
}
