/* CRM 0.9.112 — responsywność + automatycznie wysuwany sidebar na mniejszych ekranach. */

/* Elementy elastyczne nie mogą wymuszać szerokości większej niż obszar roboczy. */
.app-main,
.container,
.page-head,
.page-head > *,
.sales-workspace,
.sales-toolbar,
.hub-table-wrap {
    min-width: 0;
}

/* Akcje w nagłówku strony nie mogą łamać tekstu w połowie przycisku. */
.page-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
    flex: 0 0 auto;
}
.page-actions .btn,
.page-head > .btn,
.sales-toolbar .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    flex: 0 0 auto;
}
.page-head > div:first-child {
    min-width: 0;
}
.page-subtitle {
    overflow-wrap: anywhere;
}

/* Tabela Sprzedaży przewija się wewnątrz karty zamiast rozszerzać całą stronę. */
.hub-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-gutter: stable;
}
.sales-table td:nth-child(2),
.sales-table td:nth-child(3) {
    overflow-wrap: anywhere;
}

/*
 * Na ekranach do 1700 CSS px sidebar nie zabiera stale szerokości roboczej.
 * Przy myszy wysuwa się automatycznie po najechaniu na lewą krawędź ekranu.
 * Przycisk ☰ pozostaje jako alternatywa oraz obsługa urządzeń dotykowych.
 */

/* Niewielka strefa przy lewej krawędzi uruchamia sidebar bez kliknięcia. */
.sidebar-hover-zone {
    display: none;
}

@media (max-width: 1700px) {
    .sidebar-hover-zone {
        position: fixed;
        z-index: 39;
        left: 0;
        top: 58px;
        bottom: 0;
        width: 12px;
        display: block;
        background: transparent;
    }
    .sidebar-hover-zone::after {
        content: "";
        position: absolute;
        left: 0;
        top: 42%;
        width: 3px;
        height: 72px;
        border-radius: 0 4px 4px 0;
        background: rgba(11,92,91,.18);
        transition: background .15s ease, width .15s ease;
    }
    .sidebar-hover-zone:hover::after {
        width: 5px;
        background: rgba(11,92,91,.55);
    }
    .sidebar {
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: none;
    }
    .sidebar-open .sidebar,
    .sidebar-hover-open .sidebar {
        transform: translateX(0);
        box-shadow: 10px 0 35px #0003;
    }
    .app-main {
        margin-left: 0;
    }
    .sidebar-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
    }
    .topbar {
        gap: 8px;
        padding-left: 12px;
        padding-right: 12px;
    }
    .topbar-title {
        display: none;
    }
    .role-preview-switch {
        margin-left: 0;
        min-width: 0;
    }
    .role-preview-label {
        display: none;
    }
    .userbox strong {
        display: none;
    }
    .container {
        padding: 18px 20px 36px;
    }

    .page-head {
        flex-wrap: wrap;
        gap: 12px;
        align-items: flex-start;
    }
    .page-head > div:first-child {
        flex: 1 1 560px;
    }
    .page-actions {
        margin-left: auto;
    }

    /* Kontrolowany układ filtrów zamiast przypadkowego zawijania flexa. */
    .sales-toolbar {
        display: grid;
        grid-template-columns: minmax(260px, 1.5fr) repeat(4, minmax(140px, 1fr));
        gap: 10px;
        align-items: end;
    }
    .sales-toolbar .search-box,
    .sales-toolbar .filter-field {
        width: auto;
        min-width: 0;
        max-width: none;
        flex: none;
    }
    .sales-toolbar .search-box {
        min-width: 0;
    }
    .sales-toolbar .filter-submit,
    .sales-toolbar > .btn.ghost {
        width: auto;
        justify-self: start;
    }

    /* Checkboxy są obecnie techniczne/nieaktywne — na mniejszej szerokości nie zabierają miejsca. */
    .sales-table .check-col {
        display: none;
    }
    .hub-table.sales-table {
        min-width: 1020px;
    }
    .sales-table th,
    .sales-table td {
        padding-left: 8px;
        padding-right: 8px;
    }
    .person-cell {
        min-width: 150px;
    }
    .status-cell {
        min-width: 165px;
    }
}


@media (max-width: 1700px) and (hover: hover) and (pointer: fine) {
    /* Na komputerze menu otwiera się z lewej krawędzi — przycisk nie zabiera miejsca w topbarze. */
    .sidebar-toggle { display: none; }
}

@media (max-width: 1700px) and (hover: none), (max-width: 1700px) and (pointer: coarse) {
    .sidebar-hover-zone { display: none; }
}

@media (max-width: 1120px) {
    .page-head .page-actions {
        width: 100%;
        margin-left: 0;
        justify-content: flex-start;
    }
    .sales-toolbar {
        grid-template-columns: minmax(250px, 1.5fr) repeat(2, minmax(155px, 1fr));
    }
    .hub-table.sales-table {
        min-width: 960px;
    }
    .sales-meta-row {
        flex-wrap: wrap;
        align-items: flex-start;
    }
}

@media (max-width: 860px) {
    .container {
        padding: 14px;
    }
    .sales-toolbar {
        grid-template-columns: 1fr 1fr;
    }
    .sales-toolbar .search-box {
        grid-column: 1 / -1;
    }
    .sales-toolbar .filter-submit,
    .sales-toolbar > .btn.ghost {
        justify-self: stretch;
        width: 100%;
    }
    .sales-meta-row {
        display: block;
    }
    .sales-meta-row > span {
        display: block;
    }
    .sales-meta-row > span + span {
        margin-top: 4px;
    }
    .pagination-row {
        justify-content: flex-start;
        overflow-x: auto;
    }
    .role-preview-switch {
        max-width: 54vw;
        overflow-x: auto;
    }
}

@media (max-width: 640px) {
    .sales-toolbar {
        grid-template-columns: 1fr;
    }
    .sales-toolbar .search-box {
        grid-column: auto;
    }
    .page-actions {
        width: 100%;
        justify-content: stretch;
    }
    .page-actions .btn {
        flex: 1 1 auto;
    }
    .topbar .userbox .secondary {
        display: none;
    }
    .hub-table.sales-table {
        min-width: 900px;
    }
}
