/**
 * SPEC-CRM-006 — Optimización responsive mobile (Portal CRM)
 */

/* —— Fase A: header global mobile —— */
@media (max-width: 767px) {
    .mobile-menu .mobile-menu-bar {
        height: 48px;
        min-height: 48px;
        padding-top: 0.25rem;
        padding-bottom: 0.25rem;
    }

    .mobile-menu #logoMobile svg {
        height: 36px;
        max-height: 36px;
        width: auto;
    }

    .mobile-menu #divProfile img {
        width: 2rem;
        height: 2rem;
    }

    .mobile-menu #divProfile .text-white {
        font-size: 0.8125rem;
        max-width: 42vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #mobile-menu-toggler {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* —— Fase B: listados — filtros mobile —— */
@media (max-width: 767px) {
    .crm-clients-list-toolbar {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.5rem;
        width: 100%;
    }

    .crm-clients-list-toolbar > .flex:first-child {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        gap: 0.5rem;
    }

    .crm-clients-list-toolbar > .flex:first-child .btn-primary.shadow-md {
        width: 100%;
        margin-right: 0 !important;
        min-height: 44px;
    }

    .crm-clients-list-toolbar > .col-span-2:empty {
        display: none;
    }

    .crm-clients-list-toolbar .crm-clients-filter-cell,
    .crm-clients-list-toolbar .crm-clients-search-cell,
    .crm-clients-list-toolbar .crm-clients-count-cell,
    .crm-clients-list-toolbar .crm-clients-extra-cell {
        grid-column: 1 / -1 !important;
        width: 100%;
        max-width: 100%;
    }

    .crm-clients-list-toolbar .form-select,
    .crm-clients-list-toolbar .form-control {
        width: 100%;
        min-height: 44px;
        font-size: 16px;
    }

    .crm-clients-list-toolbar .crm-clients-count-cell h1 {
        text-align: left;
        font-size: 1rem;
        margin: 0.25rem 0;
    }

    .crm-productors-list-toolbar {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .crm-productors-list-toolbar > * {
        width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        text-align: left;
    }

    .crm-productors-list-toolbar .form-select {
        min-height: 44px;
        font-size: 16px;
        width: 100%;
    }

    .crm-productors-list-toolbar .btn-primary {
        width: 100%;
        min-height: 44px;
    }
}

/* —— Fase C: Cliente 360 —— */
.crm-cp-back-list {
    display: none;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #475569;
    text-decoration: none;
    margin-bottom: 0.5rem;
    min-height: 44px;
    padding: 0.25rem 0;
}

.crm-cp-back-list:hover {
    color: #c62828;
}

@media (max-width: 768px) {
    .crm-cp-back-list {
        display: inline-flex;
    }
}

/* —— Fase D: NP mobile close + documento —— */
.np-mobile-icon-close {
    flex-shrink: 0;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e2e8f0;
    border-radius: 0.375rem;
    background: #fff;
    color: #334155;
    cursor: pointer;
}

.np-mobile-icon-close:hover {
    background: #f8fafc;
}

.np-mobile-icon-close:focus-visible {
    outline: 2px solid #c62828;
    outline-offset: 2px;
}

.np-preview-header-mobile,
.np-editor-header-mobile {
    padding: 0.125rem 0;
}

.np-mobile-header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
}

.np-mobile-header-title {
    flex: 1;
    min-width: 0;
}

.np-mobile-header-top .np-mobile-icon-close {
    flex-shrink: 0;
    margin-top: 0;
}

.np-editor-header-mobile .np-mobile-header-meta,
.np-preview-header-mobile .np-mobile-header-meta {
    word-break: break-word;
    overflow-wrap: anywhere;
}

@media (max-width: 1023px) {
    .np-preview-modal .modal-header.np-preview-header {
        padding: 0.5rem 0.75rem;
    }

    .np-preview-modal .np-preview-body {
        flex-direction: column;
        padding: 0;
        max-width: 100%;
        overflow-x: hidden;
    }

    .np-preview-modal .np-preview-document-host {
        max-height: none;
        padding: 0 0.5rem 5.5rem;
        text-align: left;
    }

    .np-preview-modal .np-preview-document-frame {
        display: block;
        width: 100%;
        max-width: 100%;
        border: none;
        text-align: left;
    }

    .np-preview-modal .np-preview-document-scroller {
        overflow-x: hidden;
    }

    .np-preview-modal .np-preview-document-frame .receipt-content {
        width: 100% !important;
        max-width: 100%;
        box-sizing: border-box;
        font-size: 11px;
        line-height: 1.35;
    }

    .np-preview-modal .np-preview-document-frame .receipt-content main {
        margin: 0;
        padding: 0.5rem 0.25rem 1rem;
    }

    .np-preview-modal .np-preview-document-frame .receipt-content .businessName,
    .np-preview-modal .np-preview-document-frame .receipt-content .cc {
        float: none;
        width: 100%;
        max-width: 100%;
        text-align: left;
        display: block;
        margin-bottom: 0.35rem;
    }

    .np-preview-modal .np-preview-document-frame .receipt-content .uppercase {
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    .np-preview-modal .np-preview-document-frame .receipt-content .contact_label {
        float: none;
        width: auto;
        display: block;
        margin-top: 0.5rem;
    }

    .np-preview-modal .np-preview-document-frame .receipt-content .contact_details {
        margin-left: 0;
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    .np-preview-modal .np-preview-document-frame .receipt-content .cargo-details {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .np-preview-modal .np-preview-document-frame .receipt-content .departure_date,
    .np-preview-modal .np-preview-document-frame .receipt-content .cargo {
        float: none;
        width: 100%;
        max-width: 100%;
    }

    .np-preview-modal .np-preview-document-frame .receipt-content .items-table {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        font-size: 9px;
        line-height: 1.3;
    }

    .np-preview-modal .np-preview-document-frame .receipt-content .items-table td {
        white-space: normal;
        word-break: break-word;
        vertical-align: top;
    }

    .np-preview-modal .np-preview-document-frame .receipt-content .items-table thead td {
        white-space: normal;
    }

    .np-preview-modal .np-preview-document-frame .receipt-content .total-details div {
        float: none;
        display: inline-block;
        margin-top: 0.5rem;
    }

    .np-preview-modal .np-preview-document-frame .receipt-content .items-table img {
        float: none;
        display: inline-block;
        vertical-align: middle;
        margin-right: 4px;
    }
}

/* —— Fase E: comentario sucursal + dictado —— */
.crm-branch-comment-field {
    min-width: 0;
    width: 100%;
}

.crm-branch-comment-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

@media (min-width: 768px) {
    .crm-branch-comment-row {
        flex-direction: row;
        align-items: flex-start;
    }

    .crm-branch-comment-field-wrap {
        flex: 1;
    }

    .crm-branch-comment-actions {
        flex-shrink: 0;
        padding-top: 1.75rem;
    }
}

.crm-branch-comment-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.crm-branch-comment-input-row textarea {
    flex: 1;
    min-width: 0;
    min-height: 100px;
}

.crm-branch-speech-btn {
    min-width: 44px;
    min-height: 44px;
    flex-shrink: 0;
}

.crm-branch-speech-btn[hidden] {
    display: none !important;
}

.crm-branch-speech-btn.is-listening {
    color: #fff;
    border-color: #b91c1c;
    background: #dc2626;
}

.crm-branch-speech-help {
    font-size: 0.75rem;
    color: #64748b;
    margin-top: 6px;
    line-height: 1.35;
}

.crm-branch-speech-state {
    font-size: 0.875rem;
    font-weight: 500;
    color: #b91c1c;
    margin-top: 4px;
    min-height: 1.25rem;
}

.crm-branch-speech-error {
    font-size: 0.8125rem;
    color: #b91c1c;
    margin-top: 4px;
}

/* —— Fases F + G: tablas y controles táctiles —— */
@media (max-width: 767px) {
    .crm-client-list-card .crm-client-list-head,
    .crm-client-list-card .crm-client-list-subhead {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.35rem;
    }

    .crm-client-list-card .crm-client-list-actions {
        width: 100%;
        text-align: left !important;
    }

    .crm-client-list-card .btn {
        min-height: 44px;
    }

    .crm-responsive-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    .crm-responsive-table-wrap .hide-on-mobile {
        display: none !important;
    }

    .crm-touch-target,
    .np-preview-tab,
    .crm-cp-tabs button {
        min-height: 44px;
    }
}
