@media (max-width: 1100px) {
    .detail-modal { width: calc(100vw - 24px); top: 66px; }
    .detail-tab { font-size: 1rem; }
    .detail-tabs {
        grid-template-columns: repeat(5, minmax(120px, 1fr));
        overflow-x: auto;
        padding: 0 10px;
    }
    .detail-tab { white-space: nowrap; }
    .tab-panel { padding: 20px 14px 22px; }
    .detail-grid { grid-template-columns: 1fr; }
    .detail-fields { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .d-field.wide, .d-field.half { grid-column: span 2; }
    .modal-table-wrap, .assign-wrap { margin-left: 10px; margin-right: 10px; }
    .integration-panel-wrap { margin-left: 10px; margin-right: 10px; grid-template-columns: 1fr; }
    .track-step b { font-size: 1rem; }
    .track-step span { font-size: .92rem; }
    .public-link-row { min-width: 0; width: 100%; }
}

@media (max-width: 1080px) {
    .dashboard-shell { grid-template-columns: 1fr; }
    body.sidebar-hidden .dashboard-shell { grid-template-columns: 1fr; }
    .dash-sidebar {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        width: min(86vw, 320px);
        max-width: 320px;
        height: 100vh;
        z-index: 1200;
        transform: translateX(-104%);
        box-shadow: 0 20px 36px rgba(0, 0, 0, 0.22);
        border-right: 1px solid #d1d1d4;
    }
    body.sidebar-mobile-open .dash-sidebar { transform: translateX(0); }
    .mobile-sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(7, 16, 34, 0.48);
        z-index: 1190;
    }
    body.sidebar-mobile-open .mobile-sidebar-backdrop { display: block; }
    .mobile-sidebar-toggle { display: inline-flex; }

    body.sidebar-hidden .brand-strip { padding: 0 16px 0 22px; justify-content: space-between; }
    body.sidebar-hidden .brand-label { width: auto; opacity: 1; overflow: visible; }
    body.sidebar-hidden .menu-group { padding: 18px 18px 8px; }
    body.sidebar-hidden .menu-item { justify-content: flex-start; gap: 10px; padding: 10px 8px; }
    body.sidebar-hidden .menu-item .menu-text,
    body.sidebar-hidden .help-text { display: inline; }
    body.sidebar-hidden .menu-subgroup { display: none; margin: 2px 0 10px 32px; }
    body.sidebar-hidden .menu-subgroup.open { display: grid; }
    body.sidebar-hidden .menu-icon { width: 22px; font-size: 1.1rem; }
    body.sidebar-hidden .help-link { justify-content: flex-start; padding: 18px; }

    body.sidebar-mobile-open { overflow: hidden; }
    .topbar-title { display: none; }
    .inicio-grid { grid-template-columns: 1fr; }
    .status-layout { grid-template-columns: 1fr; }
    .home-quick-links { grid-template-columns: 1fr; }
    .integration-grid { grid-template-columns: 1fr; }
    .goal-card { min-height: 280px; }
    .goal-arc { margin-bottom: 30px; }
    .goal-metric .n { font-size: 2.4rem; }
    .goal-metric .t { max-width: 170px; }
    .toolbar, .title-search, .welcome-row { flex-direction: column; align-items: flex-start; }
    .welcome-head { display: block; }
    .welcome-title { font-size: 1.55rem; }
    .welcome-sub { font-size: 1rem; }
    .page-title,
    .billing-title,
    .section-title,
    .settings-title,
    .scan-title { font-size: 1.65rem; }
    .search-pill { width: 100%; min-width: 0; max-width: 100%; }
    .form-grid { grid-template-columns: 1fr; }
    .form-col-full { grid-column: span 1; }
    .cost-filters { grid-template-columns: 1fr; }
    .cost-summary { grid-template-columns: 1fr; }
    .bill-row { grid-template-columns: 1fr; gap: 6px; }
    .settings-form { grid-template-columns: 1fr; gap: 26px; max-width: 100%; }
    .settings-logo-field { margin-top: 0; }
    .settings-form-account { gap: 14px; }
    .settings-actions { justify-content: flex-start; }
    .settings-form-account .settings-logo-field input[type="file"] { max-width: 100%; }
    .users-admin-grid { grid-template-columns: 1fr; height: auto; min-height: 0; }
    .warehouse-admin-grid { grid-template-columns: 1fr; }
    .warehouse-form { grid-template-columns: 1fr; }
    .warehouse-card { min-height: auto; }
    .camera-module-wrap { height: auto; }
    .camera-frame { width: min(320px, 86vw); }
}

@media (max-width: 640px) {
    .toolbar {
        gap: 10px;
        margin-top: 6px;
    }
    .title-search {
        width: 100%;
        gap: 10px;
    }
    .title-search .page-title {
        margin-bottom: 2px;
        line-height: 1.15;
    }
    .search-pill {
        width: 100%;
        flex: 1 1 auto;
        max-width: none;
        height: 46px;
        padding: 0 14px;
        border-radius: 14px;
        background: #ffffff;
        border-color: #c4cfdf;
    }
    .search-pill input {
        font-size: 16px;
    }
    .filter-btn {
        width: 100%;
        text-align: center;
    }
    .ship-pagination {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .ship-pagination-controls {
        justify-self: stretch;
        width: 100%;
        gap: 8px;
        overflow-x: auto;
        overflow-y: hidden;
        padding-bottom: 2px;
        -webkit-overflow-scrolling: touch;
    }
    .ship-page-list {
        flex: 0 0 auto;
        gap: 4px;
    }
    .ship-page-btn,
    .ship-page-number {
        flex: 0 0 auto;
        white-space: nowrap;
        padding: 7px 9px;
        font-size: .8rem;
    }
    .ship-pagination-summary-inline,
    .ship-pagination-summary {
        text-align: left;
        white-space: normal;
        font-size: .82rem;
        line-height: 1.3;
    }

    /* ── Envios: table → card list ── */
    .card-soft.table-wrap {
        background: transparent;
        border: none;
        box-shadow: none;
        border-radius: 0;
        padding: 0;
        overflow: visible;
    }
    .ship-table {
        display: block;
        min-width: 0;
    }
    .ship-table thead {
        display: none;
    }
    .ship-table tbody {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    .ship-table tbody tr {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px 14px;
        background: #ffffff;
        border-radius: 14px;
        padding: 14px 16px;
        border: 1px solid #e0e3ec;
        box-shadow: 0 1px 6px rgba(0, 0, 0, .07);
        cursor: pointer;
    }
    .ship-table tbody tr + tr {
        border-top: none;
    }
    .ship-table td {
        display: flex;
        flex-direction: column;
        padding: 0;
        border: none;
        font-size: .9rem;
        word-break: break-word;
        overflow: hidden;
        min-width: 0;
    }
    .ship-table td[data-label]::before {
        content: attr(data-label);
        font-size: .71rem;
        font-weight: 700;
        color: #8896ae;
        text-transform: uppercase;
        letter-spacing: .04em;
        margin-bottom: 2px;
    }
    /* Referencia — highlighted, no redundant label */
    .ship-table td:nth-child(2) {
        font-size: 1rem;
        font-weight: 700;
        color: #0c4fa7;
    }
    /* Hide secondary columns (visible in modal detail) */
    .ship-table td:nth-child(3),
    .ship-table td:nth-child(4),
    .ship-table td:nth-child(7),
    .ship-table td:nth-child(8) {
        display: none;
    }
    /* Estado — spans full width, badge inline */
    .ship-table td:nth-child(11) {
        grid-column: span 2;
        flex-direction: row;
        align-items: center;
        gap: 10px;
        padding-top: 4px;
        border-top: 1px solid #f0f0f4;
    }
    .ship-table td:nth-child(11)::before {
        display: none;
    }
    /* Empty state colspan cell */
    .ship-table td[colspan] {
        grid-column: span 2;
        text-align: center;
        padding: 20px 0;
    }

    /* ── Envios: detail modal full-screen ── */
    .screen-dimmer {
        display: none !important;
    }
    .detail-modal {
        top: 0;
        left: 0 !important;
        right: 0;
        bottom: 0;
        transform: none !important;
        width: 100% !important;
        max-height: 100%;
        height: 100%;
        border-radius: 0;
        border: none;
        box-shadow: none;
    }

    /* ── Tabs: horizontal scrollable strip ── */
    .detail-tabs {
        display: flex !important;
        grid-template-columns: unset !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        scrollbar-width: none;
        padding: 0;
        border-bottom: 2px solid #c6c6cb;
    }
    .detail-tabs::-webkit-scrollbar {
        display: none;
    }
    .detail-tab {
        flex: 0 0 auto;
        scroll-snap-align: start;
        padding: 12px 16px 8px;
        font-size: .88rem;
        white-space: nowrap;
        border-bottom-width: 3px;
    }

    /* ── Tab panels ── */
    .tab-panel {
        padding: 14px 12px 18px;
        min-height: 0;
    }

    /* ── Detail tab: single column fields ── */
    .detail-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }
    .detail-fields {
        grid-template-columns: 1fr 1fr;
    }
    .d-field.wide {
        grid-column: span 2;
    }
    .d-field.half {
        grid-column: span 1;
    }
    .qr-box-wrap {
        margin-top: 0;
    }

    /* ── Tables inside modal ── */
    .modal-table-wrap,
    .assign-wrap {
        margin-left: 0;
        margin-right: 0;
    }
    .modal-table thead th,
    .modal-table tbody td {
        font-size: .85rem;
        padding: 10px 10px;
    }

    /* ── Tracking tab ── */
    .track-flow {
        margin: 30px 0 10px;
    }
    .track-steps {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
    .track-line {
        display: none;
    }
    .track-step b {
        font-size: .9rem;
    }
    .track-step span {
        font-size: .82rem;
    }
    .public-link-wrap {
        margin-top: 30px;
    }
    .public-link-row {
        min-width: 0;
        width: 100%;
    }

    /* ── Integration tab ── */
    .integration-panel-wrap {
        margin: 0;
        grid-template-columns: 1fr;
    }

    /* ── Footer ── */
    .detail-footer {
        padding: 10px 12px;
        gap: 8px;
    }
    .modal-close-btn {
        flex: 1;
        text-align: center;
    }
}
