/* Site-wide responsive rules, loaded on every dashboard page.
   Pages add their own styles after this file, so rules that must win use !important. */

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

img:not([height]) {
    height: auto;
}

html {
    -webkit-text-size-adjust: 100%;
}

/* Long emails, links and references wrap instead of widening the page. */
body {
    overflow-wrap: break-word;
}

/* ---- Tablets and phones ---- */
@media (max-width: 800px) {
    /* Client menu: brand and account on the first row, every link visible below. */
    .topbar {
        flex-wrap: wrap !important;
        height: auto !important;
    }

    .topbar .top-right {
        margin-left: auto;
        flex-wrap: wrap;
    }

    .client-nav {
        order: 3;
        flex: 0 0 100%;
        width: 100%;
        display: flex !important;
        flex-wrap: wrap !important;
        overflow: visible !important;
        gap: 4px !important;
        margin-left: 0 !important;
    }

    .client-nav .nav-link {
        flex: 1 1 30%;
        justify-content: center;
        min-height: 40px;
        padding: 8px 6px !important;
        font-size: 13px !important;
        white-space: nowrap;
    }

    /* Sales menu: same pattern. */
    .sales-topbar {
        flex-wrap: wrap !important;
        height: auto !important;
        min-height: 0 !important;
        padding: 10px 14px !important;
        row-gap: 8px;
    }

    .sales-nav {
        order: 3;
        flex: 0 0 100%;
        width: 100% !important;
        display: flex !important;
        flex-wrap: wrap !important;
        overflow: visible !important;
        gap: 4px !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .sales-nav-link {
        flex: 1 1 30%;
        justify-content: center;
        min-height: 40px;
        height: auto !important;
        padding: 8px 6px !important;
        font-size: 13px !important;
        white-space: nowrap;
    }
}

/* ---- Phones ---- */
@media (max-width: 767.98px) {
    /* Below 16px, iPhones zoom the whole page when a field is tapped. */
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
    select,
    textarea {
        font-size: 16px !important;
        max-width: 100%;
    }

    /* Comfortable to tap. */
    .btn {
        min-height: 40px;
    }

    .btn.btn-sm {
        min-height: 36px;
    }

    .modal-dialog {
        margin: 8px;
    }

    /* Status text and phone numbers wrap on the narrowest phones. */
    .contact-status,
    .lead-phone {
        white-space: normal !important;
    }

    .profile-header {
        flex-wrap: wrap;
    }

    /* Header rows of buttons wrap instead of spilling. */
    .clients-page-actions,
    .page-actions,
    .header-actions {
        flex-wrap: wrap;
        gap: 8px;
    }
}

/* ---- Phones: tables become cards (labels come from rma-responsive.js) ---- */
@media (max-width: 640px) {
    table.rma-stack {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        border: 0 !important;
        background: transparent !important;
    }

    table.rma-stack > caption {
        display: block;
    }

    table.rma-stack > thead {
        position: absolute !important;
        width: 1px !important;
        height: 1px !important;
        overflow: hidden !important;
        clip: rect(0 0 0 0) !important;
    }

    table.rma-stack > tbody,
    table.rma-stack > tfoot {
        display: block !important;
        width: 100% !important;
    }

    table.rma-stack > tbody > tr,
    table.rma-stack > tfoot > tr {
        display: block !important;
        width: 100% !important;
        margin: 0 0 10px !important;
        padding: 4px 12px !important;
        border: 1px solid #e4e7ec !important;
        border-radius: 10px !important;
        background: #fff !important;
    }

    table.rma-stack > tbody > tr > td,
    table.rma-stack > tbody > tr > th,
    table.rma-stack > tfoot > tr > td,
    table.rma-stack > tfoot > tr > th {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        padding: 8px 0 !important;
        border: 0 !important;
        border-bottom: 1px solid #f2f4f7 !important;
        text-align: left !important;
        white-space: normal !important;
    }

    table.rma-stack > tbody > tr > td:last-child,
    table.rma-stack > tfoot > tr > td:last-child {
        border-bottom: 0 !important;
    }

    table.rma-stack td[data-rma-label]::before,
    table.rma-stack th[data-rma-label]::before {
        content: attr(data-rma-label);
        display: block;
        margin-bottom: 2px;
        color: #667085;
        font-size: 12px;
        font-weight: 700;
    }

    /* Boxes that only existed to scroll the table sideways. */
    .rma-stack-wrap {
        overflow-x: visible !important;
    }

    /* Empty-state rows ("No records") stay centred, without a label. */
    table.rma-stack td[colspan] {
        text-align: center !important;
        border-bottom: 0 !important;
    }
}

/* ---- Small phones ---- */
@media (max-width: 360px) {
    .contact-status {
        max-width: 100%;
        padding: 3px 7px !important;
        font-size: 11px !important;
    }

    .lead-phone {
        font-size: 12px !important;
    }

    .sales-table-panel,
    .crm-panel {
        min-width: 0;
        max-width: 100%;
    }

    .client-nav .nav-link,
    .sales-nav-link {
        flex-basis: 45%;
    }
}

/* Notification sound on/off, added to the header by rma-notify-tone.js. */
.rma-tone-toggle {
    flex: none;
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid #dee2e6;
    border-radius: 50%;
    background: #fff;
    color: #252424;
    font-size: 16px;
    cursor: pointer;
}

.rma-tone-toggle:hover {
    border-color: #EB595F;
    color: #EB595F;
}

/* Unread count on the Messages menu, added by rma-notify-tone.js. */
.rma-messages-badge {
    display: inline-block;
    min-width: 18px;
    height: 18px;
    margin-left: 5px;
    padding: 0 5px;
    border-radius: 9px;
    background: #EB595F;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    vertical-align: middle;
}

.rma-messages-badge[hidden] {
    display: none;
}

.navbar-toggler.rma-has-unread {
    position: relative;
}

.navbar-toggler.rma-has-unread::after {
    content: "";
    position: absolute;
    top: 4px;
    right: 4px;
    width: 10px;
    height: 10px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #EB595F;
}

/* Client header: 3-bar menu on phones and tablets, added by rma-responsive.js. */
.rma-client-menu-toggle {
    display: none;
}

@media (max-width: 1050px) {
    .topbar.rma-has-menu {
        flex-wrap: wrap !important;
        height: auto !important;
        row-gap: 10px;
    }

    .topbar.rma-has-menu .top-right {
        display: contents;
    }

    .topbar.rma-has-menu .client-bell {
        order: 1;
        margin-left: auto;
    }

    .topbar.rma-has-menu .rma-client-menu-toggle {
        order: 2;
        flex: none;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        border: 1px solid #dee2e6;
        border-radius: 8px;
        background: #fff;
        color: #252424;
        font-size: 24px;
        cursor: pointer;
    }

    .topbar.rma-has-menu .rma-client-menu-toggle:focus-visible {
        outline: 2px solid #EB595F;
        outline-offset: 2px;
    }

    .topbar.rma-has-menu:not(.rma-menu-open) .client-nav,
    .topbar.rma-has-menu:not(.rma-menu-open) .rma-tone-toggle,
    .topbar.rma-has-menu:not(.rma-menu-open) .role-badge,
    .topbar.rma-has-menu:not(.rma-menu-open) .logout {
        display: none !important;
    }

    .topbar.rma-has-menu.rma-menu-open .client-nav {
        display: flex !important;
    }

    .topbar.rma-has-menu .client-nav {
        order: 3;
        flex: 0 0 100%;
        width: 100%;
        margin-left: 0 !important;
        flex-direction: column;
        align-items: stretch !important;
        flex-wrap: nowrap !important;
        overflow: visible !important;
    }

    .topbar.rma-has-menu .client-nav .nav-link {
        flex: none;
        width: 100%;
        justify-content: flex-start;
        text-align: left;
        min-height: 44px;
        padding: 10px 12px !important;
        font-size: 15px !important;
    }

    .topbar.rma-has-menu .rma-tone-toggle { order: 4; }
    .topbar.rma-has-menu .role-badge { order: 5; }

    .topbar.rma-has-menu .logout {
        order: 6;
        margin-left: auto;
    }
}
