/* =========================================================
   PHASE 15D - PROFESSIONAL TABLET EXPERIENCE
   Applies only to tablet and small laptop widths. Phone rules
   remain below 768px and full desktop rules resume above 1180px.
   ========================================================= */

@media (min-width: 768px) and (max-width: 1180px) {
    /* Use an overlay drawer instead of permanently reserving sidebar width. */
    .app-sidebar {
        display: none !important;
    }

    .app-main {
        margin-left: 0 !important;
    }

    #desktopSidebarToggle {
        display: none !important;
    }

    #mobileNavigationToggle {
        display: inline-flex !important;
    }

    .mobile-nav-drawer.is-mounted,
    .mobile-nav-backdrop.is-mounted {
        display: block !important;
    }

    .app-topbar {
        min-height: 68px;
        padding-inline: 1rem;
    }

    .topbar-page-context {
        max-width: min(34vw, 19rem);
    }

    .topbar-section-label {
        display: block;
    }

    .app-page {
        padding: 1.25rem;
    }

    .bm-page-container {
        width: 100%;
        max-width: none;
        padding-inline: 0;
    }

    /* Tablet operational records: compact multi-column cards. */
    .table-responsive:has(> .bm-operational-list) {
        overflow-x: clip;
    }

    .bm-operational-list {
        width: 100% !important;
        min-width: 0 !important;
        background: transparent;
    }

    .bm-operational-list thead {
        display: none;
    }

    .bm-operational-list tbody {
        display: grid;
        gap: .85rem;
        padding: .85rem;
        background: var(--bm-surface-soft, #f7f9fc);
    }

    .bm-operational-list tbody tr {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        overflow: hidden;
        border: 1px solid var(--bm-border, #dfe5ef);
        border-radius: 1rem;
        background: #fff;
        box-shadow: 0 .3rem .9rem rgba(15, 23, 42, .05);
    }

    .bm-operational-list td {
        display: block;
        min-width: 0 !important;
        width: auto !important;
        padding: .75rem .85rem !important;
        border: 0;
        border-right: 1px solid var(--bm-border-light, #edf1f6);
        border-bottom: 1px solid var(--bm-border-light, #edf1f6);
        text-align: left !important;
        overflow-wrap: anywhere;
    }

    .bm-operational-list td::before {
        display: block;
        margin-bottom: .28rem;
        color: var(--bm-muted, #667085);
        content: attr(data-label);
        font-size: .68rem;
        font-weight: 800;
        letter-spacing: .055em;
        text-transform: uppercase;
    }

    .bm-operational-list td:first-child {
        grid-column: 1 / -1;
        padding: .85rem 1rem !important;
        border-right: 0;
        background: linear-gradient(180deg, #fff 0%, #fbfcff 100%);
    }

    .bm-operational-list td:first-child::before,
    .bm-operational-list td.bm-table-actions-cell::before {
        display: none;
    }

    .bm-operational-list td:first-child .bm-table-primary,
    .bm-operational-list td:first-child .customer-record-link,
    .bm-operational-list td:first-child .employee-record-link {
        font-size: 1.05rem;
        font-weight: 800;
    }

    .bm-operational-list td.bm-table-actions-cell {
        grid-column: 1 / -1;
        border-right: 0;
        background: #fbfcff;
    }

    .bm-operational-list .bm-table-actions {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: .55rem;
        width: 100%;
    }

    .bm-operational-list .bm-table-actions form,
    .bm-operational-list .bm-table-actions .btn,
    .bm-operational-list .bm-table-actions .ops-action-btn {
        width: 100% !important;
        min-width: 0 !important;
    }

    .bm-operational-list .bm-table-actions .btn,
    .bm-operational-list .bm-table-actions .ops-action-btn {
        display: inline-flex !important;
        min-height: var(--bm-grid-action-size-tablet);
        height: auto !important;
        align-items: center;
        justify-content: center;
        gap: .4rem;
        padding: .6rem .75rem !important;
        white-space: normal !important;
    }

    .bm-operational-list .bm-table-actions .visually-hidden {
        display: inline !important;
        position: static !important;
        width: auto !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        clip: auto !important;
        white-space: normal !important;
    }

    /* Dashboard cards and list widgets use available tablet width. */
    .dashboard-page .row > [class*="col-xl-"],
    .dashboard-page .row > [class*="col-lg-"] {
        flex: 0 0 50%;
        width: 50%;
    }

    .dashboard-page .widget-card,
    .dashboard-page .dashboard-stat-card {
        min-width: 0;
    }

    .bm-dashboard-mobile-list,
    .bm-dashboard-mobile-list tbody,
    .bm-dashboard-mobile-list tr,
    .bm-dashboard-mobile-list td {
        min-width: 0;
    }

    /* Filters should wrap intentionally instead of compressing controls. */
    .bm-toolbar,
    .invoice-filter-row,
    .report-filter-grid,
    .operations-filter-grid,
    .bm-filter-grid {
        gap: .75rem !important;
    }

    .invoice-filter-row-primary,
    .invoice-filter-row-secondary {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .invoice-filter-search,
    .invoice-customer-filter,
    .invoice-filter-actions {
        grid-column: 1 / -1;
        width: 100%;
    }

    .invoice-filter-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .6rem;
    }

    .invoice-filter-actions .btn,
    .bm-schedule-filter-actions .btn,
    .report-actions .btn {
        min-height: var(--bm-grid-action-size-tablet);
    }

    .report-summary-grid,
    .configuration-summary-grid,
    .business-settings-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .modal-dialog:not(.modal-fullscreen) {
        max-width: min(82vw, 860px);
        margin-inline: auto;
    }

    /* Keep calendar productive on tablets rather than forcing phone agenda. */
    .bm-calendar-shell .fc-header-toolbar {
        align-items: center;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .bm-calendar-shell .fc-toolbar-chunk {
        flex: 1 1 auto;
    }
}

@media (min-width: 768px) and (max-width: 899.98px) {
    .bm-operational-list tbody tr {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .bm-operational-list .bm-table-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-page .row > [class*="col-xl-"],
    .dashboard-page .row > [class*="col-lg-"] {
        flex: 0 0 100%;
        width: 100%;
    }
}

@media (min-width: 1180.01px) {
    /* Explicit desktop guardrails. */
    .app-sidebar {
        display: block;
    }

    .app-main {
        margin-left: var(--bm-sidebar-width);
    }
}

/* Appointment list refinement for smaller tablets such as iPad Mini/Air. */
@media (min-width: 768px) and (max-width: 899.98px) {
    .appointment-operational-list tbody {
        gap: 1rem;
        padding: 1rem;
    }

    .appointment-operational-list tbody tr {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .appointment-operational-list td:first-child {
        grid-column: 1;
        border-right: 1px solid var(--bm-border-light, #edf1f6);
        background: #fff;
    }

    .appointment-operational-list td:first-child::before {
        display: block;
    }

    .appointment-operational-list td:nth-child(2) {
        grid-column: 2;
        background: linear-gradient(180deg, #fff 0%, #fbfcff 100%);
    }

    .appointment-operational-list td:nth-child(3),
    .appointment-operational-list td:nth-child(4) {
        grid-column: span 1;
    }

    .appointment-operational-list td:nth-child(5) {
        grid-column: 1 / -1;
        border-right: 0;
    }

    .appointment-operational-list .bm-schedule-date {
        align-items: center;
        gap: .7rem;
    }

    .appointment-operational-list .bm-schedule-date-day {
        min-width: 2.6rem;
        min-height: 2.6rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: .8rem;
    }

    .appointment-operational-list .appointment-cell-with-icon {
        align-items: center;
        min-height: 2.75rem;
    }

    .appointment-operational-list td.bm-table-actions-cell {
        padding-top: .65rem !important;
        padding-bottom: .65rem !important;
    }

    .appointment-operational-list .bm-table-actions {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 900px) and (max-width: 1180px) {
    .appointment-operational-list tbody tr {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .appointment-operational-list td:first-child {
        grid-column: 1;
        border-right: 1px solid var(--bm-border-light, #edf1f6);
        background: #fff;
    }

    .appointment-operational-list td:first-child::before {
        display: block;
    }

    .appointment-operational-list td:nth-child(2) {
        grid-column: span 2;
        background: linear-gradient(180deg, #fff 0%, #fbfcff 100%);
    }

    .appointment-operational-list td:nth-child(5) {
        grid-column: span 1;
    }
}
