/* =======================================================================
   Bitrix24 Dashboard — оформление
   ======================================================================= */

:root {
    --bg: #f4f6fa;
    --panel: #ffffff;
    --border: #e2e7f0;
    --text: #1f2733;
    --muted: #7c8798;
    --accent: #2f6fed;
    --accent-soft: #e8f0ff;
    --success: #1f9d61;
    --danger: #d64545;
    --warning: #b7791f;
    --sidebar-bg: #131b2c;
    --sidebar-text: #aebbd2;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .05);
    --sidebar-width: 260px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

code {
    background: #eef1f7;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 12px;
    font-family: Consolas, Menlo, monospace;
}

/* ------------------------------- Каркас ------------------------------- */

.app {
    display: flex;
    min-height: 100vh;
}

.app__main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-width);
}

.content {
    flex: 1;
    padding: 20px 24px 8px;
}

.footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 24px 20px;
    color: var(--muted);
    font-size: 12px;
}

/* ------------------------------- Меню -------------------------------- */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 30;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 18px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}

.sidebar__logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, #2f6fed, #6f4ff2);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: .5px;
}

.sidebar__title {
    color: #fff;
    font-weight: 600;
    font-size: 14px;
}

.sidebar__subtitle {
    font-size: 11px;
    color: var(--sidebar-text);
}

.menu {
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    overflow-y: auto;
}

.menu__item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-weight: 500;
}

.menu__item:hover {
    background: rgba(255, 255, 255, .06);
    color: #fff;
    text-decoration: none;
}

.menu__item.is-active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 6px 16px rgba(47, 111, 237, .35);
}

.menu__icon {
    display: inline-flex;
    width: 18px;
    height: 18px;
}

.sidebar__footer {
    padding: 14px 18px 18px;
    border-top: 1px solid rgba(255, 255, 255, .07);
    font-size: 12px;
}

.sidebar__block-title {
    text-transform: uppercase;
    letter-spacing: .06em;
    font-size: 10px;
    color: #6f7d97;
    margin-bottom: 8px;
}

.sidebar__list {
    list-style: none;
    margin: 0 0 12px;
    padding: 0;
}

.sidebar__list li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    color: var(--sidebar-text);
}

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    flex: none;
}

.sidebar__mode {
    color: #6f7d97;
}

.sidebar__mode b {
    color: #dfe6f3;
    font-weight: 500;
}

/* ------------------------------ Топбар ------------------------------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px 24px 14px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.topbar__title h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 650;
}

.topbar__subtitle {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.topbar__status {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--muted);
}

.burger {
    display: none;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: var(--radius-sm);
    width: 36px;
    height: 36px;
    font-size: 16px;
    cursor: pointer;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.badge--live {
    background: #e6f7ef;
    color: var(--success);
}

.badge--mock {
    background: #fff5e5;
    color: var(--warning);
}

/* ------------------------------ Сообщения ---------------------------- */

.alert {
    margin: 16px 24px 0;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    line-height: 1.45;
}

.alert--warning {
    background: #fff8e8;
    border: 1px solid #f2dfb2;
    color: #6b5406;
}

.alert--error {
    background: #fdecec;
    border: 1px solid #f5c2c2;
    color: #8c1c1c;
    margin: 0 0 12px;
}

.alert__details {
    display: block;
    color: #8a7a4a;
    font-size: 12px;
    margin-top: 4px;
}

/* ------------------------------- Фильтры ----------------------------- */

.filters {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}

.filters__form {
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.filters__row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
}

.filters__row--selects {
    align-items: center;
    gap: 10px;
}

.filters__actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.filters__inline {
    display: flex;
    align-items: center;
    gap: 6px;
}

.filters__dash {
    color: var(--muted);
}

.filters__hint {
    color: var(--muted);
    font-size: 12px;
    margin-left: auto;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.field__label {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

input[type="date"] {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 9px;
    font: inherit;
    color: var(--text);
    background: #fff;
}

input[type="date"]:focus {
    outline: 2px solid var(--accent-soft);
    border-color: var(--accent);
}

.presets {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.preset {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    border-radius: 999px;
    padding: 6px 12px;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

.preset:hover {
    border-color: var(--accent);
    color: var(--accent);
    text-decoration: none;
}

.preset.is-active {
    background: var(--accent-soft);
    border-color: #bcd2ff;
    color: var(--accent);
    font-weight: 600;
}

.btn {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

.btn--primary:hover {
    background: #245ecf;
    color: #fff;
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--muted);
    cursor: pointer;
}

.switch b {
    color: var(--text);
}

/* Выпадающие мультиселекты */

.ms {
    position: relative;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
}

.ms.is-open {
    border-color: var(--accent);
}

.ms__toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 190px;
    padding: 8px 12px;
    border: 0;
    background: none;
    font: inherit;
    font-size: 13px;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.ms__caret {
    margin-left: auto;
    color: var(--muted);
}

.ms__label {
    color: var(--muted);
    font-size: 12px;
}

.ms__value {
    color: var(--accent);
    font-weight: 600;
}

.ms__body {
    position: absolute;
    z-index: 20;
    top: calc(100% + 6px);
    left: 0;
    min-width: 260px;
    max-width: 380px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 10px;
}

.ms__body--scroll {
    max-height: 320px;
    overflow-y: auto;
}

.ms__group {
    margin-bottom: 8px;
}

.ms__group-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    margin: 6px 0 4px;
}

.ms__actions {
    display: flex;
    gap: 12px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
    padding-top: 8px;
}

.link {
    border: 0;
    background: none;
    padding: 0;
    color: var(--accent);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

.checkbox {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 4px 2px;
    font-size: 13px;
    cursor: pointer;
}

.checkbox input {
    margin-top: 2px;
}

/* ------------------------------- Карточки ---------------------------- */

.stats {
    position: relative;
}

.stats.is-loading {
    opacity: .55;
    pointer-events: none;
}

.stats.is-loading::after {
    content: "Обновление данных…";
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(19, 27, 44, .88);
    color: #fff;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 12px;
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 18px;
    overflow: hidden;
}

.card__head {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.card__head h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 650;
}

.card__body {
    padding: 14px 16px;
}

.hint {
    color: var(--muted);
    font-size: 12px;
}

.note {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.empty {
    color: var(--muted);
    font-size: 13px;
    margin: 6px 0;
}

.methods {
    margin: 0;
    padding-left: 18px;
    color: var(--muted);
    font-size: 13px;
}

.methods li {
    margin-bottom: 4px;
}

/* KPI */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.kpi-grid--compact {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.kpi-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 16px;
}

.kpi-card--accent {
    background: linear-gradient(135deg, #2f6fed, #6f4ff2);
    border-color: transparent;
    color: #fff;
}

.kpi-card--accent .kpi-card__label,
.kpi-card--accent .kpi-card__hint {
    color: rgba(255, 255, 255, .82);
}

.kpi-card--disabled {
    opacity: .7;
}

.kpi-card__label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}

.kpi-card__value {
    font-size: 24px;
    font-weight: 700;
    margin: 6px 0 4px;
}

.kpi-card__value small {
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
}

.kpi-card__hint {
    font-size: 12px;
    color: var(--muted);
}

/* Чипы (короткие показатели) */

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 18px;
}

.chip {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 12px;
    color: var(--muted);
    box-shadow: var(--shadow);
}

.chip b {
    display: block;
    font-size: 16px;
    color: var(--text);
}

/* ------------------------------- Таблицы ----------------------------- */

.table-wrap {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
}

.table {
    width: 100%;
    /* Таблица не сжимается: при большом числе колонок появляется горизонтальный скролл */
    min-width: max-content;
    border-collapse: collapse;
    font-size: 13px;
}

.table th,
.table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

.table thead th {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
    background: #fafbfe;
    position: sticky;
    top: 0;
}

.table tfoot th {
    background: #f7f9fd;
    font-weight: 600;
    border-top: 1px solid var(--border);
}

.table td.num,
.table th.num {
    text-align: right;
}

.table .strong {
    font-weight: 600;
}

.table .muted,
.muted {
    color: var(--muted);
}

.table .sub {
    display: block;
    font-size: 11px;
    color: var(--muted);
}

.table .bar-col {
    width: 140px;
}

.table--compact th,
.table--compact td {
    padding: 7px 9px;
}

/*
 * Таблицы списков (лиды, сделки): ячейки не переносятся по строкам, поэтому
 * при большом числе выбранных полей появляется горизонтальный скролл.
 */
.table--entity th,
.table--entity td {
    white-space: nowrap;
}

/* Сделки одного договора: цветная метка слева и граница начала группы */
.table--entity .row--contract-1 td:first-child {
    box-shadow: inset 4px 0 0 #6f8ff0;
}

.table--entity .row--contract-2 td:first-child {
    box-shadow: inset 4px 0 0 #f0a86f;
}

.table--entity .row--contract-first td {
    border-top: 2px solid #dbe2f0;
}

.table--managers .group-head {
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.muted-row td {
    color: var(--muted);
}

/* Полосы */

.bar {
    display: inline-block;
    vertical-align: middle;
    width: 100%;
    min-width: 60px;
    height: 6px;
    background: #eef1f7;
    border-radius: 999px;
    overflow: hidden;
    position: relative;
}

.bar__fill {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #2f6fed, #6f4ff2);
    border-radius: 999px;
}

.bar__caption {
    display: block;
    font-size: 11px;
    color: var(--muted);
    margin-top: 3px;
}

.share {
    display: flex;
    align-items: center;
    gap: 8px;
}

.share__value {
    min-width: 46px;
    font-variant-numeric: tabular-nums;
}

/* --------------------------- Срок перехода --------------------------- */

.conv-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.conv-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    background: #fbfcfe;
}

.conv-card--empty {
    background: #fff;
}

.conv-card__name {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
}

.conv-card__value {
    font-size: 22px;
    font-weight: 700;
}

.conv-card__value small {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
}

.conv-card__meta {
    font-size: 11px;
    color: var(--muted);
    margin-top: 3px;
}

/* --------------------------- Стадии сделок --------------------------- */

.stage-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    gap: 14px;
}

.stage-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #fff;
}

.stage-card__head {
    padding: 10px 12px;
    background: #fafbfe;
    border-bottom: 1px solid var(--border);
}

.stage-card__head h4 {
    margin: 0 0 4px;
    font-size: 14px;
}

.stage-card__totals {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 12px;
    color: var(--muted);
}

.stage-card__totals b {
    color: var(--text);
}

/* --------------------------------- Теги ------------------------------ */

.tag {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
}

.tag--ok {
    background: #e6f7ef;
    color: var(--success);
}

.tag--bad {
    background: #fdecec;
    color: var(--danger);
}

/* ------------------------------ Адаптив ------------------------------ */

@media (max-width: 1100px) {
    .stage-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .app__main {
        margin-left: 0;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: var(--shadow);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .burger {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .topbar {
        flex-wrap: wrap;
    }

    .topbar__status {
        width: 100%;
        margin-left: 0;
        justify-content: space-between;
    }

    .content {
        padding: 16px 14px 8px;
    }

    .filters__actions {
        margin-left: 0;
    }

    .filters__hint {
        margin-left: 0;
    }
}

/* ------------------- Служебные элементы Vue-приложения ---------------- */

.boot,
.loader {
    padding: 40px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
}

.loader {
    padding: 24px;
}

.spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    display: inline-block;
    animation: dc-spin .8s linear infinite;
}

@keyframes dc-spin {
    to {
        transform: rotate(360deg);
    }
}

.input {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    font: inherit;
    font-size: 13px;
    color: var(--text);
    background: #fff;
}

.input:focus {
    outline: 2px solid var(--accent-soft);
    border-color: var(--accent);
}

.input--search {
    margin-left: auto;
    min-width: 220px;
}

.btn--sm {
    padding: 6px 10px;
    font-size: 12px;
}

.btn:disabled {
    opacity: .6;
    cursor: default;
}

.tag--base {
    background: var(--accent-soft);
    color: var(--accent);
}

/* Полосы внутри числовых ячеек таблиц (менеджеры и т.п.) */
.table .num .bar {
    width: 70px;
    margin-left: 8px;
}

/* Таблицы внутри карточек воронок */
.stage-card .table th {
    position: static;
}

/* --- Разделы «Настройки» и «Отдел продаж» --------------------------------- */

.alert--success {
    background: #e9f7ef;
    border-color: #b7e2c9;
    color: #1c6b3f;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

.field--wide {
    grid-column: 1 / -1;
}

.actions {
    display: flex;
    gap: 10px;
    margin: 16px 0 0;
}

/* Поля ввода планов в таблицах */
.input--num {
    width: 130px;
    text-align: right;
}

/* Текущий месяц в плане продаж */
.row--current td {
    background: var(--accent-soft);
}

.table code,
.note code {
    background: #f2f4f7;
    border-radius: 4px;
    padding: 1px 4px;
    font-size: 12px;
}

/* Переключатель режимов раздела (например, «Отдел продаж») */
.tabs {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 16px 24px 0;
    flex-wrap: wrap;
}

.tabs__actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

/* Список чекбоксов полей в настройках */
.field-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px 14px;
}

/* Итоговая строка таблиц плана */
.table tfoot td {
    border-top: 2px solid var(--border);
    font-weight: 600;
}

/*
 * Раскрывающиеся списки не должны обрезаться карточкой:
 * раньше список воронок в настройках уходил за границу блока.
 */
.card,
.card__body {
    overflow: visible;
}

.ms {
    position: relative;
}

.ms.is-open {
    z-index: 40;
}

.ms__body {
    z-index: 41;
}

/* Поиск внутри выпадающего списка (поля сделок/лидов, сотрудники) */
.ms__search {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 6px 0 8px;
    background: #fff;
}

.ms__hint {
    margin-bottom: 6px;
    font-size: 11px;
    color: var(--muted);
}

.ms__empty {
    margin: 4px 0 8px;
    font-size: 12px;
    color: var(--muted);
}

.input--sm {
    width: 100%;
    padding: 5px 8px;
    font-size: 13px;
}

/* Выбор колонок по каждой воронке: название воронки + список полей */
.pipeline-fields {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 12px 18px;
    align-items: start;
}

.pipeline-fields + .pipeline-fields {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
}

.pipeline-fields__name {
    padding-top: 9px;
    font-size: 13px;
    font-weight: 600;
}

.pipeline-fields__count {
    display: block;
    margin-top: 2px;
    font-size: 11px;
    font-weight: 400;
    color: var(--muted);
}

@media (max-width: 720px) {
    .pipeline-fields {
        grid-template-columns: 1fr;
    }

    .pipeline-fields__name {
        padding-top: 0;
    }
}

/* --------------------------- Лента событий CRM ----------------------- */

.events {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 320px;
    overflow-y: auto;
}

.events__item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 2px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.events__item:last-child {
    border-bottom: 0;
}

.events__time {
    min-width: 62px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.events__entity {
    font-weight: 600;
}

.events__id {
    color: var(--muted);
}

.events__title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.events__code {
    color: var(--muted);
    font-size: 11px;
    font-family: Consolas, Menlo, monospace;
}
