/*
 * IrisDesk 1.5.0 — Etap 35I
 * Warstwa mobilna. Reguły są celowo ładowane po pozostałych arkuszach,
 * aby nie zmieniać układu desktopowego.
 */

.mobile-bottom-nav,
.mobile-filter-toggle {
    display: none;
}

@media (max-width: 991.98px) {
    .irisdesk-navbar .navbar-collapse {
        max-height: calc(100dvh - 58px);
        overflow-y: auto;
        padding: .5rem 0 1rem;
    }

    .irisdesk-navbar .navbar-nav {
        gap: .15rem;
    }

    .irisdesk-navbar .nav-link {
        min-height: 44px;
        padding: .65rem .75rem;
        border-radius: .65rem;
    }

    .irisdesk-navbar .nav-link:active {
        background: rgba(255, 255, 255, .12);
    }

    .global-base-status-sidebar,
    .global-base-status-show {
        display: none !important;
    }

    .global-base-status-layout,
    .global-base-status-content {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
    }

    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 767.98px) {
    :root {
        --mobile-bottom-nav-height: 66px;
    }

    html {
        scroll-padding-top: 68px;
    }

    body {
        padding-bottom: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom));
        overflow-x: hidden;
    }

    main.container-fluid {
        padding: .75rem .625rem 1rem !important;
    }

    .irisdesk-navbar {
        min-height: 54px;
    }

    .irisdesk-navbar .navbar-brand {
        max-width: calc(100vw - 76px);
        overflow: hidden;
        font-size: 1rem;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .irisdesk-navbar .navbar-text,
    .irisdesk-navbar form[action$="/logout"] {
        margin: .5rem .75rem 0 !important;
    }

    .mobile-bottom-nav {
        position: fixed;
        z-index: 1045;
        right: 0;
        bottom: 0;
        left: 0;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        min-height: var(--mobile-bottom-nav-height);
        padding: .35rem .2rem calc(.3rem + env(safe-area-inset-bottom));
        border-top: 1px solid rgba(15, 23, 42, .13);
        background: rgba(255, 255, 255, .96);
        box-shadow: 0 -.45rem 1.25rem rgba(15, 23, 42, .09);
        backdrop-filter: blur(12px);
    }

    .mobile-bottom-nav > a {
        position: relative;
        display: flex;
        min-width: 0;
        min-height: 52px;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        gap: .12rem;
        border-radius: .65rem;
        color: #64748b;
        font-size: .61rem;
        font-weight: 700;
        line-height: 1.05;
        text-align: center;
        text-decoration: none;
    }

    .mobile-bottom-nav > a.is-active {
        background: #eef4ff;
        color: #174ea6;
    }

    .mobile-bottom-nav-icon {
        font-size: 1.18rem;
        line-height: 1;
    }

    .mobile-bottom-nav-badge {
        position: absolute;
        top: .08rem;
        left: calc(50% + .45rem);
        display: inline-flex;
        min-width: 1.1rem;
        height: 1.1rem;
        align-items: center;
        justify-content: center;
        padding: 0 .25rem;
        border: 2px solid #fff;
        border-radius: 999px;
        background: #dc2445;
        color: #fff;
        font-size: .57rem;
        line-height: 1;
    }

    .mobile-bottom-nav-badge[hidden] {
        display: none !important;
    }

    h1,
    .h1 {
        font-size: 1.45rem;
    }

    h2,
    .h2 {
        font-size: 1.25rem;
    }

    .card {
        border-radius: .8rem;
    }

    .card-header,
    .card-body,
    .card-footer {
        padding: .85rem;
    }

    .alert {
        padding: .75rem;
    }

    .btn,
    .form-control,
    .form-select,
    .input-group-text {
        min-height: 44px;
    }

    .btn-sm,
    .form-control-sm,
    .form-select-sm {
        min-height: 38px;
    }

    textarea.form-control {
        font-size: 16px;
    }

    input.form-control,
    select.form-select {
        font-size: 16px;
    }

    .pagination {
        flex-wrap: wrap;
    }

    /* Przewijane zakładki i szybkie filtry. */
    .nav-tabs,
    .nav-pills,
    .message-stat-strip,
    .order-kpi-strip,
    .order-queue-strip,
    .order-courier-strip,
    .production-tabs,
    .production-courier-filters {
        max-width: 100%;
        overflow-x: auto;
        overscroll-behavior-inline: contain;
        scrollbar-width: none;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
    }

    .nav-tabs::-webkit-scrollbar,
    .nav-pills::-webkit-scrollbar,
    .message-stat-strip::-webkit-scrollbar,
    .order-kpi-strip::-webkit-scrollbar,
    .order-queue-strip::-webkit-scrollbar,
    .order-courier-strip::-webkit-scrollbar,
    .production-tabs::-webkit-scrollbar,
    .production-courier-filters::-webkit-scrollbar {
        display: none;
    }

    .nav-tabs > *,
    .nav-pills > *,
    .message-stat,
    .order-kpi-item,
    .order-queue-chip,
    .order-courier-chip,
    .production-tab,
    .production-courier-filter {
        scroll-snap-align: start;
    }

    /* Filtry skrzynki — na telefonie domyślnie jako zwijany panel. */
    .mobile-filter-toggle {
        display: flex;
        width: 100%;
        align-items: center;
        justify-content: space-between;
        margin-bottom: .65rem;
    }

    .message-filter-card.mobile-filter-collapsed {
        display: none;
    }

    .message-filter-card {
        margin-bottom: .75rem;
    }

    /* Lista rozmów. */
    .message-conversation-row {
        padding: .8rem !important;
    }

    .message-conversation-link {
        gap: .65rem !important;
    }

    .message-avatar {
        width: 38px !important;
        height: 38px !important;
        flex-basis: 38px !important;
    }

    .message-conversation-actions {
        width: 100%;
        justify-content: flex-end;
        padding-left: 3rem;
    }

    /* Rozmowa i odpowiedź. */
    .message-thread-header .card-body > .d-flex {
        flex-direction: column;
    }

    .message-thread-header .h4 {
        max-width: calc(100vw - 5rem);
        font-size: 1.08rem;
    }

    .conversation-card {
        overflow: visible;
    }

    .conversation-messages {
        height: auto !important;
        min-height: 42dvh !important;
        max-height: 58dvh;
        padding: .75rem !important;
        overscroll-behavior: contain;
    }

    .message-bubble {
        max-width: 96% !important;
        padding: .75rem !important;
    }

    .conversation-card .card-footer {
        position: relative !important;
        bottom: auto !important;
        padding: .75rem !important;
        box-shadow: none !important;
    }

    .ai-reply-assistant {
        padding: .75rem;
    }

    .ai-reply-assistant-header {
        align-items: stretch;
        flex-direction: column;
    }

    .ai-reply-toolbar {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
        gap: .45rem;
    }

    .ai-reply-toolbar .btn {
        width: 100%;
        white-space: normal;
    }

    .pending-attachment-list {
        max-width: 100%;
    }

    #attachmentLabel {
        display: block;
        margin: .4rem 0 0 !important;
    }

    form[action$="/conversations/send"] > .d-flex {
        align-items: stretch !important;
        flex-direction: column;
    }

    form[action$="/conversations/send"] > .d-flex > div,
    form[action$="/conversations/send"] > .d-flex > button {
        width: 100%;
    }

    /* Zamówienia jako karty zamiast tabeli szerszej niż ekran. */
    .order-list-table-wrap {
        overflow: visible !important;
    }

    .order-baselike-table {
        display: block;
        min-width: 0 !important;
        border: 0;
        background: transparent;
    }

    .order-baselike-table thead {
        display: none;
    }

    .order-baselike-table tbody {
        display: grid;
        gap: .75rem;
    }

    .order-baselike-table tbody > tr {
        position: relative;
        display: grid;
        min-width: 0;
        overflow: hidden;
        border: 1px solid var(--bs-border-color);
        border-radius: .8rem;
        background: var(--bs-body-bg);
        box-shadow: 0 .15rem .55rem rgba(15, 23, 42, .05);
    }

    .order-baselike-table tbody > tr > td {
        display: block;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        padding: .72rem .8rem !important;
        border: 0;
        border-bottom: 1px solid var(--bs-border-color-translucent);
        text-align: left !important;
    }

    .order-baselike-table tbody > tr > td:last-child {
        border-bottom: 0;
    }

    .order-baselike-table tbody > tr > td::before,
    .mobile-card-table tbody > tr > td::before {
        display: block;
        margin-bottom: .28rem;
        color: var(--bs-secondary-color);
        content: attr(data-mobile-label);
        font-size: .64rem;
        font-weight: 800;
        letter-spacing: .045em;
        text-transform: uppercase;
    }

    .order-baselike-table .order-select-column,
    .order-baselike-table td:first-child {
        position: absolute;
        z-index: 2;
        top: .55rem;
        right: .6rem;
        width: 36px !important;
        padding: .3rem !important;
        border: 0;
    }

    .order-baselike-table td:first-child::before {
        display: none;
    }

    .order-baselike-table .order-main-cell {
        padding-right: 3.5rem !important;
        background: var(--bs-tertiary-bg);
    }

    .order-baselike-table .order-products-list {
        max-height: none;
    }

    /* Proste tabele administracyjne i reguły AI jako karty. */
    .mobile-card-table,
    .mobile-card-table tbody,
    .mobile-card-table tbody > tr,
    .mobile-card-table tbody > tr > td {
        display: block;
        width: 100%;
    }

    .mobile-card-table thead {
        display: none;
    }

    .mobile-card-table tbody {
        padding: .65rem;
    }

    .mobile-card-table tbody > tr {
        margin-bottom: .7rem;
        overflow: hidden;
        border: 1px solid var(--bs-border-color);
        border-radius: .7rem;
        background: var(--bs-body-bg);
    }

    .mobile-card-table tbody > tr:last-child {
        margin-bottom: 0;
    }

    .mobile-card-table tbody > tr > td {
        padding: .65rem .75rem;
        border: 0;
        border-bottom: 1px solid var(--bs-border-color-translucent);
        text-align: left !important;
    }

    .mobile-card-table tbody > tr > td:last-child {
        border-bottom: 0;
    }

    .mobile-card-table tbody > tr > td[colspan]::before {
        display: none;
    }

    .mobile-card-table form,
    .mobile-card-table .btn {
        width: 100%;
    }

    /* Produkcja. */
    .production-header-actions {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
    }

    .production-header-actions .btn {
        width: 100%;
        white-space: normal;
    }

    .production-toolbar {
        gap: .65rem !important;
    }

    .production-search .btn {
        flex: 1;
    }

    .production-package {
        border-radius: .8rem !important;
    }

    .production-package-head,
    .production-package-notes {
        padding: .8rem !important;
    }

    .production-order-customer {
        white-space: normal !important;
    }

    .production-item {
        padding: .75rem !important;
    }

    /* Pełnoekranowe modale: rozmowy, ustawienia i podglądy. */
    .modal-dialog {
        width: 100%;
        max-width: none;
        height: 100%;
        min-height: 100%;
        margin: 0;
    }

    .modal-content {
        min-height: 100%;
        border: 0;
        border-radius: 0;
    }

    .modal-header {
        position: sticky;
        z-index: 3;
        top: 0;
        padding: .75rem;
        background: var(--bs-body-bg);
    }

    .modal-body {
        padding: .75rem;
    }

    .modal-footer {
        position: sticky;
        z-index: 3;
        bottom: 0;
        padding: .65rem .75rem calc(.65rem + env(safe-area-inset-bottom));
        background: var(--bs-body-bg);
    }

    .production-communication-history {
        height: min(40dvh, 320px) !important;
    }

    .production-communication-history-grid {
        gap: .65rem !important;
    }

    .production-compose {
        padding: .7rem !important;
    }

    .production-compose-tabs {
        overflow-x: auto;
    }

    .production-compose-form .d-flex.justify-content-between {
        align-items: stretch !important;
        flex-direction: column;
    }

    .production-compose-form .d-flex.justify-content-between .btn,
    .production-compose-form .d-flex.justify-content-between > div {
        width: 100%;
    }

    /* Reguły oraz nauka AI. */
    .ai-rule-product {
        width: 100%;
    }

    .ai-rule-product + .d-flex,
    article > .d-flex.justify-content-between > .d-flex {
        width: 100%;
    }

    .ai-rule-product + .d-flex form,
    .ai-rule-product + .d-flex .btn {
        flex: 1;
    }

    /* Nie pozwalaj długim identyfikatorom i adresom rozszerzać strony. */
    code,
    pre,
    .font-monospace,
    .text-break,
    a,
    td,
    th {
        overflow-wrap: anywhere;
    }

    .input-group {
        flex-wrap: wrap;
    }

    .input-group > .form-control,
    .input-group > .form-select {
        min-width: 0;
    }
}

@media (max-width: 399.98px) {
    .mobile-bottom-nav > a {
        font-size: .56rem;
    }

    .mobile-bottom-nav-icon {
        font-size: 1.05rem;
    }

    .production-header-actions,
    .ai-reply-toolbar {
        grid-template-columns: 1fr;
    }
}
