/*
 * Responsive layer for the operator/admin panel.
 *
 * Plain CSS on purpose (loaded with asset(), not through Vite), so it can be
 * deployed by uploading the file — no npm build needed.
 *
 * Breakpoints (Bootstrap 5):
 *   < 768px      phone   — one screen at a time, bottom tab bar
 *   768–1199px   tablet  — side menu becomes a drawer, messages in 2 columns
 *   >= 1200px    desktop — unchanged 3-column layout
 */

:root {
    --app-navbar-h: 56px;
    --app-tabbar-h: 60px;
    --app-safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===================== App shell ===================== */

/* Side menu: a normal column on desktop, a drawer (offcanvas-xl) below. */
@media (min-width: 1200px) {
    .app-sidebar {
        width: 260px;
        flex-shrink: 0;
    }
}

@media (max-width: 1199.98px) {
    .app-sidebar.offcanvas-xl {
        --bs-offcanvas-width: 300px;
    }

    .app-sidebar .offcanvas-body {
        padding: 0;
    }

    .app-sidebar .card {
        box-shadow: none !important;
        border-radius: 0 !important;
        min-height: 100%;
    }

    .app-sidebar .nav-link {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

.app-menu-btn {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    line-height: 1;
}

/* Bottom tab bar — phones only (the markup carries d-md-none). */
.app-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1030;
    display: grid;
    grid-auto-columns: minmax(0, 1fr);
    grid-auto-flow: column;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    padding: 4px 4px calc(4px + var(--app-safe-bottom));
}

.app-tabbar a {
    position: relative;
    min-height: 52px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: #5c636a;
    font-size: 12px;
    text-decoration: none;
}

.app-tabbar a .bi {
    font-size: 22px;
    line-height: 1;
}

.app-tabbar a.active {
    color: #0b5ed7;
    font-weight: 700;
}

.app-tabbar .badge {
    position: absolute;
    top: 2px;
    left: 54%;
    font-size: 10px;
}

@media (max-width: 767.98px) {
    .app-navbar {
        height: var(--app-navbar-h);
        padding-top: 4px;
        padding-bottom: 4px;
    }

    .app-navbar .navbar-brand img {
        height: 36px;
    }

    /* Room for the fixed tab bar. */
    body.has-tabbar .app-main {
        padding-bottom: calc(var(--app-tabbar-h) + var(--app-safe-bottom) + 16px) !important;
    }

    .app-main {
        padding: 12px 12px 16px !important;
    }

    /* iOS zooms into any field with a font smaller than 16px. */
    .app-main input.form-control,
    .app-main select.form-select,
    .app-main textarea.form-control {
        font-size: 16px;
    }

    .app-main .btn {
        min-height: 40px;
    }
}

/* ===================== Tables -> cards on phones ===================== */
/* Add class "table-mobile-cards" to a table; panel-responsive.js copies each
   column header into data-label on its cells. */
@media (max-width: 767.98px) {
    table.table-mobile-cards thead {
        display: none;
    }

    table.table-mobile-cards,
    table.table-mobile-cards tbody,
    table.table-mobile-cards tr,
    table.table-mobile-cards td {
        display: block;
        width: 100%;
    }

    table.table-mobile-cards tr {
        padding: 10px 14px;
        border-bottom: 1px solid #e5e7eb;
    }

    table.table-mobile-cards td {
        border: 0 !important;
        padding: 3px 0 !important;
        text-align: left !important;
    }

    table.table-mobile-cards td[data-label]:not([data-label=""])::before {
        content: attr(data-label);
        display: block;
        font-size: 12px;
        color: #5c636a;
    }

    /* First cell = the row's title, last cell = its actions. */
    table.table-mobile-cards td:first-child::before {
        display: none !important;
    }

    table.table-mobile-cards td:first-child {
        font-weight: 600;
        font-size: 16px;
    }

    table.table-mobile-cards td:last-child {
        padding-top: 8px !important;
    }

    table.table-mobile-cards td:last-child::before {
        display: none !important;
    }

    /* Short cells that sit side by side in the card (avatar + name,
       role + status badges); add to a <td> in the template. */
    table.table-mobile-cards td.mc-inline {
        display: inline-block;
        width: auto;
        vertical-align: middle;
        margin-right: 8px;
    }

    table.table-mobile-cards td.mc-title {
        font-weight: 600;
        font-size: 16px;
    }

    table.table-mobile-cards td:last-child .btn {
        min-width: 44px;
        min-height: 40px;
    }
}

/* ===================== Dashboard ===================== */
.chart-box {
    position: relative;
    height: 240px;
}

@media (max-width: 767.98px) {
    .chart-box {
        height: 200px;
    }
}

/* ===================== Messages ===================== */
@media (min-width: 768px) {
    .messenger {
        height: 80vh;
    }
}

@media (min-width: 1200px) {
    .messenger-info {
        width: 320px;
        flex-shrink: 0;
        height: 100%;
    }
}

/* Tablet: list + conversation, customer info as a drawer from the right. */
@media (min-width: 768px) and (max-width: 1199.98px) {
    .messenger-list {
        width: 300px !important;
    }

    .messenger-info.offcanvas-xl {
        --bs-offcanvas-width: 360px;
    }
}

@media (max-width: 1199.98px) {
    .messenger-info .messenger-info-close {
        display: inline-flex;
    }
}

.messenger-info-close {
    display: none;
}

/* Phone: one pane at a time, filling the screen between navbar and tab bar. */
@media (max-width: 767.98px) {
    .messenger-card {
        position: fixed;
        top: var(--app-navbar-h);
        left: 0;
        right: 0;
        bottom: calc(var(--app-tabbar-h) + var(--app-safe-bottom));
        z-index: 1020;
        border-radius: 0 !important;
        box-shadow: none !important;
    }

    body.messenger-chat-open .messenger-card {
        bottom: 0;
    }

    body.messenger-chat-open .app-tabbar {
        display: none !important;
    }

    .messenger-card .card-body,
    .messenger {
        height: 100%;
    }

    .messenger-list {
        width: 100% !important;
        border: 0 !important;
    }

    .messenger-chat {
        display: none !important;
    }

    .messenger.is-chat-open .messenger-list {
        display: none !important;
    }

    .messenger.is-chat-open .messenger-chat {
        display: flex !important;
        width: 100%;
    }

    .messenger .chat-item {
        padding: 14px 16px !important;
    }

    .messenger .chat-item p {
        max-width: none !important;
    }

    .messenger .chat-tab-btn {
        min-height: 44px;
    }

    #operator-send-form {
        padding-bottom: var(--app-safe-bottom);
    }

    #operator-message-input {
        font-size: 16px;
        border-radius: 22px;
    }

    .messenger .msg-row {
        max-width: 92%;
    }

    .messenger .msg-bubble {
        font-size: 15px;
    }

    /* Customer info: bottom sheet instead of a side drawer. */
    .messenger-info.offcanvas-xl.offcanvas-end {
        top: auto;
        left: 0;
        right: 0;
        width: 100% !important;
        height: 88vh;
        max-height: 88dvh;
        border-left: 0;
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
    }

    .messenger-info.offcanvas-xl.offcanvas-end.showing,
    .messenger-info.offcanvas-xl.offcanvas-end.show:not(.hiding) {
        transform: none;
    }

    .messenger-info #notes-panel-body {
        padding-bottom: calc(16px + var(--app-safe-bottom)) !important;
    }
}

.chat-header .chat-header-btn {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    padding: 0;
}

.chat-actions-menu .dropdown-item {
    min-height: 48px;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ===================== Push notifications offer ===================== */
.push-offer {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 1045;
    width: min(360px, calc(100vw - 32px));
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px 16px;
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

.push-offer.d-none {
    display: none !important;
}

@media (max-width: 767.98px) {
    .push-offer {
        left: 12px;
        right: 12px;
        width: auto;
        bottom: calc(var(--app-tabbar-h) + var(--app-safe-bottom) + 12px);
    }
}
