/**
 * Phone app shell. Every rule is limited to max-width 768px
 * except the default hidden tab bar and print reset.
 * Desktop (769px and up) is unchanged.
 */

.mobile-app-tabbar {
    display: none;
}

@media (max-width: 768px) {
    html {
        overflow-x: clip;
    }

    body:has(.mobile-app-tabbar) {
        padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
    }

    .mobile-app-tabbar {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1080;
        margin: 0;
        padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px));
        background: #fff;
        border-top: 1px solid #e7eaf0;
        box-shadow: 0 -6px 24px rgba(15, 23, 42, 0.08);
        gap: 2px;
    }

    .mobile-app-tab {
        flex: 1 1 0;
        min-width: 0;
        min-height: 52px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 4px 2px;
        border: 0;
        border-radius: 12px;
        background: transparent;
        color: #64748b;
        font: inherit;
        font-size: 0.68rem;
        font-weight: 600;
        line-height: 1.15;
        text-decoration: none;
        text-align: center;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-app-tab i {
        font-size: 1.05rem;
        line-height: 1;
    }

    .mobile-app-tab span {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-app-tab.is-current,
    .mobile-app-tab[aria-current="page"] {
        color: #ff6a00;
        background: #fff1e6;
    }

    .navbar {
        padding-top: env(safe-area-inset-top, 0px) !important;
        padding-bottom: 0 !important;
    }

    .page-header,
    .form-actions,
    .search-form,
    .crm-filter-bar {
        flex-wrap: wrap;
        max-width: 100%;
    }

    .search-row {
        grid-template-columns: 1fr !important;
    }

    .page-header .btn,
    .form-actions .btn,
    .search-form .btn {
        white-space: normal;
    }

    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="submit"]):not([type="button"]):not([type="hidden"]),
    select,
    textarea {
        font-size: 16px;
        max-width: 100%;
    }

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

    .kavach-2d-svg-embed,
    .design-canvas-editor,
    .job-card-drawing,
    .glass-job-card {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Undo the 920px table scroll and stack each row as a card.
       Selectors match responsive-fix-layer.css so later !important wins. */
    .section:not(.no-table-scroll),
    .table-container {
        overflow-x: visible !important;
        max-width: 100%;
    }

    .section:not(.no-table-scroll) .data-table,
    .table-container .data-table {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        overflow: visible !important;
        border: 0 !important;
        background: transparent !important;
    }

    .section:not(.no-table-scroll) .data-table thead,
    .table-container .data-table thead {
        display: none !important;
    }

    .section:not(.no-table-scroll) .data-table tbody,
    .table-container .data-table tbody,
    .section:not(.no-table-scroll) .data-table tr,
    .table-container .data-table tr {
        display: block !important;
        width: 100% !important;
    }

    .section:not(.no-table-scroll) .data-table tbody tr,
    .table-container .data-table tbody tr {
        margin: 0 0 12px !important;
        padding: 4px 0 8px !important;
        border: 1px solid #e7eaf0 !important;
        border-radius: 14px !important;
        background: #fff !important;
        box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05) !important;
        overflow: visible !important;
    }

    .section:not(.no-table-scroll) .data-table th,
    .section:not(.no-table-scroll) .data-table td,
    .table-container .data-table th,
    .table-container .data-table td {
        display: block !important;
        position: relative !important;
        width: auto !important;
        min-width: 0 !important;
        max-width: 100% !important;
        padding: 8px 14px 8px 46% !important;
        border: 0 !important;
        text-align: left !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        word-break: break-word;
    }

    .section:not(.no-table-scroll) .data-table tbody td:last-child,
    .table-container .data-table tbody td:last-child {
        white-space: normal !important;
    }

    .section:not(.no-table-scroll) .data-table td::before,
    .table-container .data-table td::before {
        content: attr(data-label) !important;
        display: block !important;
        position: absolute !important;
        left: 14px !important;
        top: 8px !important;
        width: 40% !important;
        padding: 0 !important;
        color: #64748b !important;
        font-size: 0.72rem !important;
        font-weight: 700 !important;
        line-height: 1.3 !important;
        text-align: left !important;
        white-space: normal !important;
    }

    .section:not(.no-table-scroll) .data-table td[colspan],
    .table-container .data-table td[colspan],
    .section:not(.no-table-scroll) .data-table td[data-label=""],
    .table-container .data-table td[data-label=""],
    .section:not(.no-table-scroll) .data-table td:not([data-label]),
    .table-container .data-table td:not([data-label]) {
        padding-left: 14px !important;
        text-align: center !important;
    }

    .section:not(.no-table-scroll) .data-table td[colspan]::before,
    .table-container .data-table td[colspan]::before,
    .section:not(.no-table-scroll) .data-table td[data-label=""]::before,
    .table-container .data-table td[data-label=""]::before,
    .section:not(.no-table-scroll) .data-table td:not([data-label])::before,
    .table-container .data-table td:not([data-label])::before {
        content: none !important;
        display: none !important;
    }

    .section:not(.no-table-scroll) .data-table td[data-label="Actions"],
    .table-container .data-table td[data-label="Actions"],
    .section:not(.no-table-scroll) .data-table td[data-label="Action"],
    .table-container .data-table td[data-label="Action"] {
        display: flex !important;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
        padding: 10px 14px 12px !important;
    }

    .section:not(.no-table-scroll) .data-table td[data-label="Actions"]::before,
    .table-container .data-table td[data-label="Actions"]::before,
    .section:not(.no-table-scroll) .data-table td[data-label="Action"]::before,
    .table-container .data-table td[data-label="Action"]::before {
        position: static !important;
        width: 100% !important;
        margin-bottom: 2px;
    }

    .section:not(.no-table-scroll) .data-table td .btn,
    .section:not(.no-table-scroll) .data-table td a.btn,
    .section:not(.no-table-scroll) .data-table td .btn-sm,
    .section:not(.no-table-scroll) .data-table td a.btn-sm,
    .table-container .data-table td .btn,
    .table-container .data-table td a.btn,
    .table-container .data-table td .btn-sm,
    .table-container .data-table td a.btn-sm {
        white-space: normal !important;
        min-height: 40px;
    }

    .modal,
    .confirm-modal {
        padding: calc(8px + env(safe-area-inset-top, 0px)) 8px calc(8px + env(safe-area-inset-bottom, 0px)) !important;
        align-items: flex-end;
    }

    .modal-content,
    .confirm-modal-content,
    .swal2-popup {
        width: 100% !important;
        max-width: 100% !important;
        max-height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) !important;
        margin: 0 !important;
        overflow-y: auto !important;
        box-sizing: border-box;
    }

    .profile-form .form-grid {
        grid-template-columns: 1fr !important;
    }

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

    .info-table td:first-child {
        width: 100% !important;
        padding-bottom: 0 !important;
    }

    body:has(.mobile-app-tabbar) .kx-float-contact {
        left: 0.65rem !important;
        bottom: calc(78px + env(safe-area-inset-bottom, 0px)) !important;
        z-index: 1070;
    }

    body:has(.mobile-app-tabbar) #kavach-chat-root {
        bottom: calc(78px + env(safe-area-inset-bottom, 0px)) !important;
    }

    body:has(.mobile-app-tabbar) .rq-sticky-bar {
        bottom: calc(68px + env(safe-area-inset-bottom, 0px));
        z-index: 1085;
    }

    body.request-quote-page:has(.mobile-app-tabbar) .contact-shell {
        padding-bottom: calc(10.5rem + env(safe-area-inset-bottom, 0px));
    }

    .contact-shell {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .rq-topbar-actions,
    .contact-topbar {
        flex-wrap: wrap;
        max-width: 100%;
    }

    body.quotation-builder {
        padding: 0 !important;
        overflow-x: clip;
    }

    body.quotation-builder .container,
    body.quotation-builder .container-fluid {
        width: 100%;
        max-width: 100%;
        border-radius: 0;
        box-shadow: none;
        padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
    }

    body.quotation-builder .main-content {
        padding: 16px 14px 24px;
    }

    body.quotation-builder .home-button {
        position: static !important;
        display: inline-flex;
        margin: 12px;
    }

    body.quotation-builder .left-sidebar-drawer {
        width: 100% !important;
        max-width: none !important;
        left: -100% !important;
        right: auto !important;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    body.quotation-builder .left-sidebar-drawer.open {
        left: 0 !important;
    }

    body.quotation-builder .selection-summary-drawer {
        width: 100% !important;
        max-width: none !important;
        right: -100% !important;
        left: auto !important;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    body.quotation-builder .selection-summary-drawer.open {
        right: 0 !important;
    }

    body.quotation-builder .left-drawer-toggle-button,
    body.quotation-builder .drawer-toggle-button {
        position: fixed !important;
        top: auto !important;
        bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
        width: 52px !important;
        height: 52px !important;
        border-radius: 16px !important;
        z-index: 1005 !important;
    }

    body.quotation-builder .left-drawer-toggle-button {
        left: 12px !important;
        right: auto !important;
    }

    body.quotation-builder .drawer-toggle-button {
        right: 12px !important;
        left: auto !important;
    }

    body.quotation-builder .left-drawer-toggle-button.drawer-open,
    body.quotation-builder .drawer-toggle-button.drawer-open {
        visibility: hidden;
    }

    body.quotation-builder .modal-content,
    body.quotation-builder #quotationModal .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        max-height: 100dvh !important;
        border-radius: 16px 16px 0 0 !important;
    }

    body.quotation-builder .color-palette {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    body.quotation-builder .size-row {
        grid-template-columns: 1fr !important;
    }
}

@media print {
    .mobile-app-tabbar {
        display: none !important;
    }

    body:has(.mobile-app-tabbar) {
        padding-bottom: 0 !important;
    }
}
