/* The Care Desk - phone layout (screens under 768px wide only)
   Desktop, tablet and printing are not affected. Keep this file last.
   Table labels come from js/mobile.js. */

/* The phone day list stays hidden until the phone rules below */
.cdm-days { display: none; }

@media screen and (max-width: 767.98px) {

    /* ---------- Top bar: one line ---------- */
    .app-layout header.navbar { flex-wrap: nowrap; gap: 8px; }
    .app-layout header.navbar > .d-flex:first-child { flex: 1 1 auto; min-width: 0; }
    .app-layout header.navbar h3 { min-width: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .app-layout header.navbar .btn-light { flex-wrap: nowrap; padding: 4px 8px; }
    .app-layout header.navbar .btn-light .text-start { max-width: 78px; }
    .app-layout header.navbar .btn-light .fw-bold { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .app-layout header.navbar .btn-light .small { display: none; }

    /* ---------- Page heading and button: wrap instead of squeezing ---------- */
    .app-layout .d-flex.justify-content-between.align-items-center.mb-3 { flex-wrap: wrap; gap: 10px; }

    /* ---------- Easier to tap ---------- */
    .app-layout .btn { min-height: 40px; }
    .app-layout .btn:has(> svg:only-child) { min-width: 40px; }
    .app-layout .btn-icon { min-width: 40px; }
    .app-layout .btn-list { gap: 10px; }
    .app-layout .nav-link { min-height: 40px; display: flex; align-items: center; }
    .app-layout .cdd-btn { display: inline-flex; align-items: center; min-height: 40px; }
    .app-layout .cdd-link { display: inline-flex; align-items: center; min-height: 36px; }
    .app-layout .cdd-dates button { min-height: 44px; }
    .modal .btn { min-height: 40px; }
    .modal .btn-close { min-width: 40px; min-height: 40px; }

    /* ---------- Stops iPhones zooming in when a box is tapped ---------- */
    .app-layout input:not([type=checkbox]):not([type=radio]),
    .app-layout select,
    .app-layout textarea,
    .modal input:not([type=checkbox]):not([type=radio]),
    .modal select,
    .modal textarea { font-size: 16px; }
    .app-layout .form-control,
    .app-layout .form-select,
    .modal .form-control,
    .modal .form-select { min-height: 40px; }

    /* ---------- Tables become one card per row ---------- */
    .cdm-cards, .cdm-cards tbody { display: block; width: 100%; }
    .cdm-cards thead { display: none; }
    .table-responsive:has(> .cdm-cards) { overflow-x: visible; }
    .cdm-cards tr { display: flex; flex-direction: column; margin: 10px 12px; border: 1px solid #e8eef5; border-radius: 14px; background: #fff; overflow: hidden; }
    .cdm-cards td {
        display: block;
        position: relative;
        width: auto !important;
        min-height: 38px;
        padding: 9px 12px 9px 40% !important;
        border: 0 !important;
        border-bottom: 1px solid #eef3f8 !important;
        text-align: right !important;
        white-space: normal !important;
        overflow-wrap: anywhere;
    }
    .cdm-cards td:last-child { border-bottom: 0 !important; }
    .cdm-cards td[data-label]:not([data-label=""])::before {
        content: attr(data-label);
        position: absolute;
        left: 12px;
        top: 9px;
        width: calc(40% - 18px);
        color: #5b6b80;
        font-size: 13px;
        font-weight: 500;
        text-align: left;
        text-transform: capitalize;
        overflow-wrap: normal;
    }

    /* A row with no heading, such as "No records found" */
    .cdm-cards td[colspan] { padding: 16px 12px !important; text-align: center !important; }
    .cdm-cards tr:has(> td[colspan]) { border: 0; }

    /* Action buttons sit along the bottom of the card */
    .cdm-cards td[data-label="Actions"],
    .cdm-cards td[data-label=""]:not([colspan]) {
        order: 99;
        padding: 10px 12px !important;
        background: #f6f9fd;
        text-align: left !important;
    }
    .cdm-cards td[data-label="Actions"]::before { display: none; }
    .cdm-cards td[data-label=""]:empty { display: none; }

    /* Rows with boxes to fill in: the label goes above the box */
    .cdm-cards td:has(input, select, textarea) { padding: 9px 12px !important; text-align: left !important; }
    .cdm-cards td[data-label]:not([data-label=""]):has(input, select, textarea)::before { position: static; display: block; width: auto; margin-bottom: 4px; }
    .modal .cdm-cards tr { margin: 10px 0; }
    .cdm-cards td:has(input, select, textarea) .form-control,
    .cdm-cards td:has(input, select, textarea) .form-select { width: 100%; }

    /* ---------- Appointments: day list instead of the month calendar ---------- */
    .cd-calendar-card { display: none !important; }
    .cdm-days { display: block; }

    /* Heading first, then the day list, then the rest of the page */
    :has(> .mt-4 > .cdm-days) { display: flex; flex-direction: column; }
    :has(> .mt-4 > .cdm-days) > .d-flex.justify-content-between.mb-3 { order: -2; }
    .mt-4:has(> .cdm-days) { order: -1; margin: 0 0 16px !important; }

    /* The 4 count boxes: two across */
    .row:has(> .col-md-3 .subheader) { row-gap: 10px; }
    .row:has(> .col-md-3 .subheader) > .col-md-3 { flex: 0 0 50%; width: 50%; }

    .cdm-days .cdm-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
    .cdm-days h3 { margin: 0; font-size: 17px; font-weight: 600; color: #14233a; }
    .cdm-week { display: flex; gap: 8px; }
    .cdm-week button { width: 40px; height: 40px; border: 1px solid #bcd4ee; border-radius: 50%; background: #fff; color: #1c5cab; font-size: 18px; line-height: 1; }
    .cdm-days .cdd-dates { display: flex; justify-content: space-between; gap: 4px; margin: 12px 0 10px; }
    .cdm-days .cdd-dates button { flex: 1 1 0; padding: 7px 0; border: 0; border-radius: 14px; background: none; color: #14233a; }
    .cdm-days .cdd-dates small { display: block; font-size: 12.5px; color: #5b6b80; }
    .cdm-days .cdd-dates b { font-size: 18px; font-weight: 600; }
    .cdm-days .cdd-dates .today b { color: #1c5cab; }
    .cdm-days .cdd-dates .on { background: #e4f0fd; box-shadow: inset 0 0 0 2px #2a78d6; }
    .cdm-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; padding: 11px; border-radius: 14px; background: #f6f9fd; color: inherit; text-decoration: none; }
    .cdm-row:hover { color: inherit; text-decoration: none; background: #eaf2fb; }
    .cdm-time { flex: 0 0 52px; font-size: 14.5px; font-weight: 600; color: #14233a; }
    .cdm-row b { display: block; font-size: 15px; font-weight: 600; color: #14233a; }
    .cdm-row small { display: block; font-size: 13px; color: #5b6b80; }
    .cdm-empty { margin: 16px 0 4px; color: #5b6b80; }
}
