.sales_pipeline_page {
    --sales-board-gap: 14px;
    --sales-column-width: 310px;

    width: 100%;
    min-width: 0;

    color: var(--color-text);
}

.sales_pipeline_header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;

    gap: 24px;
    margin-bottom: 20px;
}

.sales_pipeline_heading {
    display: flex;
    align-items: flex-end;

    min-width: 0;
    gap: 28px;
}

.sales_pipeline_heading h1 {
    margin: 0;

    color: var(--color-text-strong);

    font-size: 26px;
    line-height: 1.2;
}

.sales_pipeline_heading p {
    margin: 6px 0 0;

    color: var(--color-text-soft);

    font-size: 14px;
}

.sales_pipeline_view_tabs {
    display: inline-flex;
    padding: 4px;
    border: 1px solid var(--color-border);
    border-radius: 11px;
    background: var(--color-surface);
}

.sales_pipeline_view_tabs button {
    min-height: 34px;
    padding: 0 15px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--color-text-soft);
    font-weight: 700;
    cursor: pointer;
}

.sales_pipeline_view_tabs button.active {
    background: var(--color-primary);
    color: var(--color-text-white);
}

.sales_pipeline_history[hidden] { display: none !important; }
.sales_pipeline_history { display: grid; gap: 10px; }
.sales_history_row {
    display: grid;
    grid-template-columns: minmax(90px, .7fr) minmax(180px, 1.5fr) minmax(150px, 1.2fr) minmax(135px, 1fr) minmax(125px, .9fr) minmax(125px, .9fr);
    align-items: center;
    gap: 14px;
    padding: 15px 17px;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: var(--color-surface);
    color: var(--color-text);
}
.sales_history_row:not(.sales_history_header) { cursor: pointer; }
.sales_history_row:not(.sales_history_header):hover { border-color: var(--color-primary); }
.sales_history_header { color: var(--color-text-soft); font-size: 12px; font-weight: 700; }
.sales_history_title { color: var(--color-text-strong); font-weight: 700; }
.sales_history_meta { color: var(--color-text-soft); font-size: 12px; }
.sales_history_pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 10px;
}
.sales_history_pagination button {
    min-height: 36px;
    padding: 0 15px;
    border: 1px solid var(--color-border);
    border-radius: 9px;
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
}
.sales_history_pagination button:disabled { opacity: .45; cursor: default; }

@media (max-width: 900px) {
    .sales_pipeline_heading { align-items: flex-start; flex-direction: column; gap: 12px; }
    .sales_history_header { display: none; }
    .sales_history_row { grid-template-columns: 1fr 1fr; }
    .sales_history_title { grid-column: 1 / -1; }
}

.sales_pipeline_create {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-height: 44px;
    padding: 0 18px;

    border: 0;
    border-radius: 11px;

    background: var(--color-primary);
    color: var(--color-text-white);

    font-size: 14px;
    font-weight: 700;

    cursor: pointer;

    transition:
        transform 0.15s ease,
        filter 0.15s ease;
}

.sales_pipeline_create[hidden] {
    display: none !important;
}

.sales_pipeline_create span {
    margin-right: 7px;

    font-size: 20px;
    line-height: 1;
}

.sales_pipeline_create:hover {
    filter: brightness(0.94);
}

.sales_pipeline_create:active {
    transform: translateY(1px);
}

.sales_pipeline_toolbar {
    display: grid;
    grid-template-columns:
        minmax(230px, 640px)
        minmax(170px, 230px);
    align-items: center;

    gap: 10px;
    margin-bottom: 14px;
}

.sales_pipeline_search {
    position: relative;

    width: min(100%, 640px);
    min-width: 0;
}

.sales_pipeline_search_icon {
    position: absolute;
    top: 50%;
    left: 13px;

    color: var(--color-text-muted);

    font-size: 20px;

    pointer-events: none;

    transform: translateY(-50%);
}

.sales_pipeline_search input {
    width: 100%;
    min-height: 42px;
    padding: 0 14px 0 39px;

    box-sizing: border-box;

    border: 1px solid var(--color-border);
    border-radius: 10px;

    background: var(--color-surface);
    color: var(--color-text);

    font-size: 14px;
}

.sales_pipeline_stage_filter {
    width: 100%;
    min-height: 42px;
    padding: 0 12px;

    box-sizing: border-box;

    border: 1px solid var(--color-border);
    border-radius: 10px;

    background: var(--color-surface);
    color: var(--color-text);

    font: inherit;
    font-size: 14px;
}

.sales_pipeline_search input:focus,
.sales_pipeline_stage_filter:focus {
    border-color: var(--color-primary);
    outline: none;

    box-shadow: 0 0 0 3px
        color-mix(
            in srgb,
            var(--color-primary) 16%,
            transparent
        );
}

.sales_pipeline_summary {
    display: flex;
    align-items: center;

    min-height: 52px;
    padding: 9px 14px;
    gap: 26px;
    margin-bottom: 14px;

    box-sizing: border-box;

    border: 1px solid var(--color-border-subtle);
    border-radius: 12px;

    background: var(--color-surface);
}

.sales_pipeline_summary > div {
    display: flex;
    flex-direction: column;

    gap: 3px;
}

.sales_pipeline_summary span {
    color: var(--color-text-soft);

    font-size: 11px;
}

.sales_pipeline_summary strong {
    color: var(--color-text-strong);

    font-size: 15px;
}

.sales_pipeline_sync {
    flex-direction: row !important;
    align-items: center;

    gap: 7px !important;
    margin-left: auto;
}

.sales_pipeline_sync_dot {
    width: 7px;
    height: 7px;

    border-radius: 50%;

    background: #22c55e;

    box-shadow: 0 0 0 4px
        color-mix(
            in srgb,
            #22c55e 14%,
            transparent
        );
}

.sales_pipeline_loading,
.sales_pipeline_error,
.sales_pipeline_empty {
    display: flex;
    align-items: center;
    justify-content: center;

    min-height: 160px;
    gap: 10px;

    border: 1px dashed var(--color-border);
    border-radius: 14px;

    background: var(--color-surface-muted);
    color: var(--color-text-soft);
}
.sales_pipeline_loading[hidden],
.sales_pipeline_error[hidden],
.sales_pipeline_empty[hidden] {
    display: none !important;
}

.sales_pipeline_loader {
    width: 21px;
    height: 21px;

    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;

    animation: sales-pipeline-spin 0.8s linear infinite;
}

@keyframes sales-pipeline-spin {
    to {
        transform: rotate(360deg);
    }
}

.sales_pipeline_error,
.sales_pipeline_empty {
    flex-direction: column;

    padding: 30px;

    text-align: center;
}

.sales_pipeline_error strong,
.sales_pipeline_empty strong {
    color: var(--color-text-strong);

    font-size: 16px;
}

.sales_pipeline_error button {
    min-height: 38px;
    padding: 0 14px;

    border: 0;
    border-radius: 9px;

    background: var(--color-primary);
    color: var(--color-text-white);

    font-weight: 600;

    cursor: pointer;
}

.sales_pipeline_empty > div {
    font-size: 32px;
}

.sales_pipeline_board_scroll {
    width: 100%;
    min-width: 0;

    overflow-x: auto;
    overflow-y: hidden;

    scrollbar-width: thin;
    scrollbar-color:
        var(--color-border)
        transparent;
    overscroll-behavior-x: contain;
    scrollbar-gutter: stable;
}

.sales_pipeline_board {
    display: flex;
    align-items: stretch;

    width: max-content;
    min-width: 100%;
    min-height: calc(100dvh - 330px);

    gap: var(--sales-board-gap);
    padding-bottom: 12px;
}

.sales_pipeline_column {
    display: flex;
    flex-direction: column;

    width: var(--sales-column-width);
    min-width: var(--sales-column-width);

    border: 1px solid var(--color-border-subtle);
    border-top: 3px solid var(--pipeline-stage-color);
    border-radius: 13px;

    background: var(--color-surface-muted);

    overflow: hidden;
}

.sales_pipeline_column_header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    min-height: 50px;
    padding: 0 13px;

    box-sizing: border-box;

    border-bottom: 1px solid var(--color-border-subtle);

    background: var(--color-surface);
}

.sales_pipeline_column_header > div {
    display: flex;
    align-items: center;

    min-width: 0;
    gap: 8px;
}

.sales_pipeline_column_header h2 {
    margin: 0;

    color: var(--color-text-strong);

    font-size: 14px;
    font-weight: 700;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sales_pipeline_column_dot {
    flex: 0 0 auto;

    width: 8px;
    height: 8px;

    border-radius: 50%;

    background: var(--pipeline-stage-color);
}

.sales_pipeline_column_count {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-width: 25px;
    height: 25px;
    padding: 0 7px;

    box-sizing: border-box;

    border-radius: 999px;

    background: var(--color-surface-secondary);
    color: var(--color-text-soft);

    font-size: 12px;
    font-weight: 700;
}

.sales_pipeline_column_body {
    display: flex;
    flex-direction: column;
    flex: 1;

    min-height: 140px;
    gap: 10px;
    padding: 10px;

    transition:
        background 0.15s ease,
        box-shadow 0.15s ease;
}

.sales_pipeline_column_body.drag_over {
    background:
        color-mix(
            in srgb,
            var(--pipeline-stage-color) 9%,
            var(--color-surface-muted)
        );

    box-shadow:
        inset 0 0 0 2px
        var(--pipeline-stage-color);
}

.sales_pipeline_column_empty {
    display: flex;
    align-items: center;
    justify-content: center;

    min-height: 90px;
    padding: 14px;

    border: 1px dashed var(--color-border);
    border-radius: 10px;

    color: var(--color-text-muted);

    font-size: 12px;
    text-align: center;
}

.sales_deal_card {
    position: relative;

    padding: 13px;

    border: 1px solid var(--color-border-subtle);
    border-left: 3px solid var(--deal-stage-color);
    border-radius: 11px;

    background: var(--color-surface);
    color: var(--color-text);

    cursor: pointer;

    box-shadow:
        0 2px 8px
        color-mix(
            in srgb,
            #000000 7%,
            transparent
        );

    transition:
        transform 0.15s ease,
        box-shadow 0.15s ease,
        opacity 0.15s ease;
}

.sales_deal_card:hover {
    transform: translateY(-2px);

    box-shadow:
        0 7px 18px
        color-mix(
            in srgb,
            #000000 11%,
            transparent
        );
}

.sales_deal_card:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.sales_deal_card.dragging,
.sales_deal_card.moving {
    opacity: 0.55;
}

.sales_deal_card_top,
.sales_deal_card_bottom,
.sales_deal_meta,
.sales_deal_delivery {
    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 10px;
}

.sales_deal_number {
    color: var(--color-text-soft);

    font-size: 11px;
    font-weight: 700;
}

.sales_deal_menu {
    width: 30px;
    height: 27px;
    padding: 0;

    border: 0;
    border-radius: 7px;

    background: transparent;
    color: var(--color-text-soft);

    font-size: 17px;
    letter-spacing: 1px;

    cursor: pointer;
}

.sales_deal_menu:hover {
    background: var(--color-surface-hover);
}

.sales_deal_title {
    margin: 9px 0 5px;

    color: var(--color-text-strong);

    font-size: 14px;
    line-height: 1.35;

    overflow-wrap: anywhere;
}

.sales_deal_customer {
    color: var(--color-text-slate);

    font-size: 13px;
    line-height: 1.35;

    overflow-wrap: anywhere;
}

.sales_deal_badges {
    display: flex;
    flex-wrap: wrap;

    gap: 5px;
    margin-top: 9px;
}

.sales_deal_badge {
    display: inline-flex;
    align-items: center;

    min-height: 22px;
    padding: 0 8px;

    border-radius: 999px;

    font-size: 10px;
    font-weight: 700;
}

.sales_deal_badge_call {
    background: #fef3c7;
    color: #92400e;
}

.sales_deal_badge_unassigned {
    background: #fee2e2;
    color: #991b1b;
}

.sales_deal_delivery {
    margin-top: 12px;
    padding: 9px 0;

    border-top: 1px solid var(--color-border-subtle);
    border-bottom: 1px solid var(--color-border-subtle);
}

.sales_deal_delivery > div {
    display: flex;
    flex-direction: column;

    min-width: 0;
    gap: 3px;
}

.sales_deal_delivery > div:last-child {
    align-items: flex-end;

    text-align: right;
}

.sales_deal_delivery span,
.sales_deal_meta {
    color: var(--color-text-soft);

    font-size: 10px;
}

.sales_deal_delivery strong {
    color: var(--color-text-strong);

    font-size: 12px;
}

.sales_deal_meta {
    margin-top: 9px;
}

.sales_deal_meta span {
    min-width: 0;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sales_deal_meta span:first-child {
    max-width: 56%;
}

.sales_deal_card_bottom {
    margin-top: 12px;

    color: var(--color-text-soft);

    font-size: 11px;
}

.sales_deal_card_bottom strong {
    color: var(--color-text-strong);

    font-size: 14px;
}

.sales_deal_stage_mobile {
    display: none;
}


:root[data-theme="dark"] .sales_deal_badge_call {
    background: #4a3813;
    color: #fde68a;
}

:root[data-theme="dark"] .sales_deal_badge_unassigned {
    background: #4c1d1d;
    color: #fecaca;
}


@media (max-width: 700px) {
    .sales_pipeline_page {
        --sales-board-gap: 12px;
        --sales-column-width: calc(100vw - 38px);
    }

    .sales_pipeline_header {
        align-items: stretch;
        flex-direction: column;

        gap: 14px;
        margin-bottom: 15px;
    }

    .sales_pipeline_heading {
        align-items: stretch;
        flex-direction: column;

        gap: 12px;
    }

    .sales_pipeline_heading h1 {
        font-size: 22px;
    }

    .sales_pipeline_create {
        width: 100%;
    }

    .sales_pipeline_search {
        width: 100%;
    }

    .sales_pipeline_toolbar {
        grid-template-columns: 1fr;
    }

    .sales_pipeline_summary {
        gap: 18px;

        overflow-x: auto;
    }

    .sales_pipeline_sync {
        min-width: max-content;
    }

    .sales_pipeline_board_scroll {
        margin-right: -10px;
        padding-right: 10px;

        scroll-snap-type: x mandatory;
    }

    .sales_pipeline_board {
        min-height: calc(100dvh - 390px);
    }

    .sales_pipeline_column {
        scroll-snap-align: start;
    }

    .sales_deal_card {
        cursor: default;
    }

    .sales_deal_stage_mobile {
        display: flex;
        flex-direction: column;

        gap: 5px;
        margin-top: 12px;
        padding-top: 10px;

        border-top: 1px solid var(--color-border-subtle);
    }

    .sales_deal_stage_mobile > span {
        color: var(--color-text-soft);

        font-size: 10px;
        font-weight: 600;
    }

    .sales_deal_stage_mobile select {
        width: 100%;
        min-height: 38px;
        padding: 0 10px;

        border: 1px solid var(--color-border);
        border-radius: 9px;

        background: var(--color-surface);
        color: var(--color-text);

        font-size: 13px;
    }
}


@media (max-width: 420px) {
    .sales_pipeline_page {
        --sales-column-width: calc(100vw - 28px);
    }

    .sales_pipeline_summary {
        padding: 9px 11px;
    }
}


@media (prefers-reduced-motion: reduce) {
    .sales_pipeline_loader {
        animation-duration: 1.8s;
    }

    .sales_deal_card,
    .sales_pipeline_create {
        transition: none;
    }
}


/* Mobile “all stages”: one vertical list, with the stage on each card. */
.sales_deal_card_stage_badge {
    display: none;
}

@media (max-width: 700px) {
    .sales_pipeline_board_scroll_flat {
        overflow: visible;
        margin-right: 0;
        padding-right: 0;
        scroll-snap-type: none;
        scrollbar-gutter: auto;
    }

    .sales_pipeline_board_flat {
        flex-direction: column;
        width: 100%;
        min-width: 0;
        min-height: 0;
        gap: 12px;
    }

    .sales_pipeline_board_flat > .sales_deal_card {
        flex: none;
        box-sizing: border-box;
        width: 100%;
        min-width: 0;
    }

    .sales_pipeline_board_flat .sales_deal_card_top {
        flex-wrap: wrap;
        gap: 8px;
    }

    .sales_pipeline_board_flat .sales_deal_card_stage_badge {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        max-width: 100%;
        min-width: 0;
        padding: 4px 8px;
        border-radius: 8px;
        background: var(--color-surface-secondary);
        color: var(--color-text);
        font-size: 12px;
        line-height: 1.4;
        overflow-wrap: anywhere;
    }

    .sales_pipeline_board_flat .sales_deal_card_stage_badge::before {
        content: "";
        flex: 0 0 7px;
        height: 7px;
        border-radius: 50%;
        background: var(--deal-stage-color);
    }
}


.sales_deal_contacts {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 12px;
    margin-top: 8px;
}

.sales_deal_contacts a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    max-width: 100%;
    color: var(--color-primary);
    font-size: 13px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.sales_deal_phone_link {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.sales_deal_map_link {
    padding: 6px 10px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface-secondary);
    text-decoration: none;
}

.sales_deal_contacts a:hover {
    text-decoration: underline;
}

.sales_deal_contacts a:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 3px;
}
/* Контейнер состава заказа внутри карточки Kanban. */
.sales_deal_products_section {
    padding: 10px 0;
    border-top: 1px solid var(--border-color, #e5e7eb);
}

/* Заголовок списка товаров и услуг. */
.sales_deal_products_title {
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 600;
    opacity: 0.7;
}

/* Вертикальный список позиций сделки. */
.sales_deal_products {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Строка товара: название слева, количество справа. */
.sales_deal_product {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    font-size: 13px;
}

/* Название товара с переносом длинных строк. */
.sales_deal_product_name {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

/* Количество товара и его единица измерения. */
.sales_deal_product_quantity {
    flex-shrink: 0;
    white-space: nowrap;
    font-weight: 600;
}

/* Сообщение для сделок без товаров. */
.sales_deal_products_empty {
    font-size: 12px;
    opacity: 0.6;
}
/* Компактный блок состава заказа в карточке Kanban. */
.sales_deal_products_section {
    padding: 6px 0;
    margin: 0;
    border-top: 1px solid var(--border-color, #e5e7eb);
}

/* Заголовок списка позиций. */
.sales_deal_products_title {
    margin: 0 0 5px;
    font-size: 11px;
    line-height: 1.3;
}

/* Убираем лишние промежутки между товарами. */
.sales_deal_products {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin: 0;
    padding: 0;
}

/* Компактная строка: название слева, количество справа. */
.sales_deal_product {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 0;
    margin: 0;
    min-height: 0;
    font-size: 11px;
    line-height: 1.35;
    border: 0;
    background: transparent;
}

/* Название товара переносится при необходимости. */
.sales_deal_product_name {
    flex: 1 1 0;
    min-width: 0;
    font-size: inherit;
    line-height: inherit;
    overflow-wrap: anywhere;
}

/* Количество справа, без переноса. */
.sales_deal_product_quantity {
    flex: 0 0 auto;
    white-space: nowrap;
    font-size: inherit;
    line-height: inherit;
    font-weight: 600;
}

/* На телефонах делаем список чуть крупнее для читаемости. */
@media (max-width: 768px) {
    .sales_deal_products_section {
        padding: 5px 0;
    }

    .sales_deal_product {
        padding: 3px 0;
        font-size: 12px;
        gap: 6px;
    }
}
