/* ====== Dark theme — активируется классом body.dark-theme ====== */

/* Скрываем бесполезную бутстраповскую кнопку navbar-toggle (нет #navbar-collapse) —
   на мобиле она пересекалась с переключателем темы */
.navbar .navbar-toggle {
    display: none !important;
}

body.dark-theme {
    background-color: #161a20 !important;
    color: #d6d9de;
}

body.dark-theme div {
    color: inherit;
}

/* Базовый текст */
body.dark-theme,
body.dark-theme p,
body.dark-theme span,
body.dark-theme li,
body.dark-theme td,
body.dark-theme th,
body.dark-theme label,
body.dark-theme dt,
body.dark-theme dd {
    color: #d6d9de;
}

body.dark-theme h1,
body.dark-theme h2,
body.dark-theme h3,
body.dark-theme h4,
body.dark-theme h5,
body.dark-theme h6 {
    color: #f1f3f5 !important;
}

body.dark-theme .page-header,
body.dark-theme .page-header h1,
body.dark-theme .page-header h2 {
    color: #f1f3f5 !important;
    border-bottom-color: #2e3540 !important;
}

/* Заголовки виджетов и инфо-боксов на дашборде */
body.dark-theme .info-box .text,
body.dark-theme .info-box .number,
body.dark-theme .info-box-2 .text,
body.dark-theme .info-box-2 .number,
body.dark-theme .info-box .icon i,
body.dark-theme .info-box-2 .icon i {
    color: #f1f3f5 !important;
}

body.dark-theme a {
    color: #6db5ff;
}
body.dark-theme a:hover,
body.dark-theme a:focus {
    color: #9bcaff;
}

/* Синие кликабельные ссылки в таблицах — в светлой теме #1a73e8, не видны на тёмном фоне.
   Селектор для td специфичнее общего td-цвета (специфичность 0,3,4 против 0,2,4). */
body.dark-theme .table > tbody > tr > td.company-leads-link,
body.dark-theme td.company-leads-link,
body.dark-theme .company-leads-link,
body.dark-theme a[style*="color:#1a73e8"],
body.dark-theme a[style*="color: #1a73e8"] {
    color: #6db5ff !important;
}
body.dark-theme .table > tbody > tr > td.company-leads-link:hover,
body.dark-theme .company-leads-link:hover {
    color: #9bcaff !important;
}

/* UTM-плашка в таблице лидов (Vue scoped — пробиваем !important) */
body.dark-theme .utm-source-tag {
    background: #1a2433 !important;
    border-color: #2e3540 !important;
    color: #d6d9de !important;
}
body.dark-theme .utm-source-tag strong {
    color: #6db5ff !important;
}
body.dark-theme .utm-source-tag:hover {
    background: #1f2e42 !important;
    border-color: #1976d2 !important;
}

/* Поповер с UTM-метками */
body.dark-theme .utm-popover {
    background: #232932 !important;
    border-color: #2e3540 !important;
    color: #d6d9de !important;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5) !important;
}
body.dark-theme .utm-popover::before {
    background: #232932 !important;
    border-color: #2e3540 !important;
}
body.dark-theme .utm-popover-row + .utm-popover-row {
    border-top-color: #2e3540 !important;
}
body.dark-theme .utm-popover-key {
    color: #8a9099 !important;
}
body.dark-theme .utm-popover-value {
    color: #d6d9de !important;
}
body.dark-theme .utm-popover-value:hover {
    background: #2a3344 !important;
}
body.dark-theme .utm-popover-hint {
    color: #6c727d !important;
    border-top-color: #2e3540 !important;
}

/* Шапка */
body.dark-theme .navbar {
    background-color: #1f242c !important;
    color: #f1f3f5 !important;
    border-bottom: 1px solid #2a2f38;
}
body.dark-theme .navbar .navbar-brand,
body.dark-theme .navbar a,
body.dark-theme .navbar .nav > li > a {
    color: #f1f3f5 !important;
}
body.dark-theme .navbar .bars:after,
body.dark-theme .navbar .bars:before {
    background-color: #8a9099 !important;
}

/* Сайдбар */
body.dark-theme .sidebar {
    background-color: #1f242c !important;
    color: #f1f3f5 !important;
}
body.dark-theme .sidebar .user-info,
body.dark-theme .sidebar .user-info::before,
body.dark-theme .sidebar .user-info::after {
    background: #1a1f26 !important;
    background-image: none !important;
    border-bottom: 1px solid #2a2f38;
}
body.dark-theme .sidebar .user-info .info-container,
body.dark-theme .sidebar .user-info .name,
body.dark-theme .sidebar .user-info .email,
body.dark-theme .sidebar .user-info a {
    color: #f1f3f5 !important;
}
body.dark-theme .sidebar .menu,
body.dark-theme .sidebar .menu .list {
    background-color: #1f242c !important;
}
body.dark-theme .sidebar .menu .list a {
    color: #e6e8eb !important;
    text-shadow: none !important;
}
body.dark-theme .sidebar .menu .list a i.material-icons,
body.dark-theme .sidebar .menu .list a span {
    color: #e6e8eb !important;
}
body.dark-theme .sidebar .menu .list a:hover {
    background-color: #2a2f38 !important;
    color: #ffffff !important;
}
body.dark-theme .sidebar .menu .list a:hover i.material-icons,
body.dark-theme .sidebar .menu .list a:hover span {
    color: #ffffff !important;
}
body.dark-theme .sidebar .menu .list a.toggled,
body.dark-theme .sidebar .menu .list li.active > a {
    background-color: #2a2f38 !important;
    color: #ffffff !important;
}
body.dark-theme .sidebar .menu .list .header {
    background-color: #161a20 !important;
    color: #8a9099 !important;
}
body.dark-theme .sidebar .menu .list .ml-menu {
    background-color: #1a1f26 !important;
}
body.dark-theme .sidebar .legal {
    background-color: #1a1f26 !important;
    color: #6c727d !important;
    border-top: 1px solid #2a2f38 !important;
}
body.dark-theme .sidebar .legal a,
body.dark-theme .sidebar .legal .copyright,
body.dark-theme .sidebar .legal .version {
    color: #8a9099 !important;
}

/* Карточки */
body.dark-theme .card {
    background-color: #232932 !important;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45) !important;
    color: #d6d9de;
}
body.dark-theme .card .header {
    border-bottom: 1px solid #2e3540 !important;
}
body.dark-theme .card .header h2,
body.dark-theme .card .header h3,
body.dark-theme .card .header > * {
    color: #f1f3f5 !important;
}
body.dark-theme .card .body {
    color: #d6d9de;
}

/* Таблицы */
body.dark-theme .table {
    color: #d6d9de !important;
    background-color: #232932 !important;
}
body.dark-theme .table > thead > tr > th,
body.dark-theme .table > tbody > tr > th,
body.dark-theme .table > tfoot > tr > th,
body.dark-theme .table > thead > tr > td,
body.dark-theme .table > tbody > tr > td,
body.dark-theme .table > tfoot > tr > td {
    border-color: #2e3540 !important;
    color: #d6d9de !important;
}
body.dark-theme .table > thead > tr > th {
    background-color: #1f242c !important;
    color: #f1f3f5 !important;
    border-bottom: 2px solid #2e3540 !important;
}
body.dark-theme .table-striped > tbody > tr:nth-of-type(odd) {
    background-color: #262c36 !important;
}
body.dark-theme .table-hover > tbody > tr:hover {
    background-color: #2c333d !important;
}
body.dark-theme .table-bordered,
body.dark-theme .table-bordered > thead > tr > th,
body.dark-theme .table-bordered > tbody > tr > td {
    border-color: #2e3540 !important;
}

/* DataTable / Vuetable */
body.dark-theme .dataTables_wrapper,
body.dark-theme .dataTables_info,
body.dark-theme .dataTables_paginate,
body.dark-theme .dataTables_filter,
body.dark-theme .dataTables_length {
    color: #d6d9de !important;
}
body.dark-theme .dataTables_paginate .paginate_button {
    color: #d6d9de !important;
    background: transparent !important;
    border-color: #2e3540 !important;
}
body.dark-theme .dataTables_paginate .paginate_button:hover {
    background: #2a2f38 !important;
    color: #ffffff !important;
}
body.dark-theme .dataTables_paginate .paginate_button.current {
    background: #1976d2 !important;
    color: #ffffff !important;
    border-color: #1976d2 !important;
}

/* Формы */
body.dark-theme .form-control,
body.dark-theme input.form-control,
body.dark-theme textarea.form-control,
body.dark-theme select.form-control {
    background-color: #1a1f26 !important;
    color: #f1f3f5 !important;
    border-color: #2e3540 !important;
}
body.dark-theme .form-control:focus {
    background-color: #1a1f26 !important;
    border-color: #1976d2 !important;
    box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.25);
}
body.dark-theme .form-control::placeholder {
    color: #7a8089 !important;
}
body.dark-theme .form-line {
    border-bottom: 1px solid #2e3540 !important;
}
body.dark-theme .form-line.focused {
    border-bottom: 2px solid #1976d2 !important;
}
body.dark-theme .form-line .form-label {
    color: #8a9099 !important;
}
body.dark-theme .input-group-addon {
    background-color: #2a2f38 !important;
    border-color: #2e3540 !important;
    color: #d6d9de !important;
}

/* Reset для финансовой страницы — переопределяем затемнение из my-styles */
body.dark-theme #counterparty-panel .form-control {
    background-color: #1a1f26 !important;
    border-color: #2e3540 !important;
}
body.dark-theme #counterparty-panel .form-control:focus {
    background-color: #1a1f26 !important;
    border-color: #1976d2 !important;
}

/* Кнопки */
body.dark-theme .btn-default {
    background-color: #2a2f38 !important;
    color: #f1f3f5 !important;
    border-color: #3a414c !important;
}
body.dark-theme .btn-default:hover,
body.dark-theme .btn-default:focus {
    background-color: #353c46 !important;
    color: #ffffff !important;
}
body.dark-theme .btn-link {
    color: #6db5ff !important;
}

/* Дропдауны */
body.dark-theme .dropdown-menu {
    background-color: #232932 !important;
    border: 1px solid #2e3540 !important;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}
body.dark-theme .dropdown-menu > li > a {
    color: #d6d9de !important;
}
body.dark-theme .dropdown-menu > li > a:hover,
body.dark-theme .dropdown-menu > li > a:focus {
    background-color: #2a2f38 !important;
    color: #ffffff !important;
}
body.dark-theme .dropdown-menu .divider {
    background-color: #2e3540 !important;
}

/* Модалки */
body.dark-theme .modal-content {
    background-color: #232932 !important;
    border: 1px solid #2e3540 !important;
    color: #d6d9de;
}
body.dark-theme .modal-header,
body.dark-theme .modal-footer {
    border-color: #2e3540 !important;
}
body.dark-theme .modal-title {
    color: #f1f3f5 !important;
}
body.dark-theme .close {
    color: #f1f3f5 !important;
    text-shadow: none !important;
    opacity: 0.7;
}

/* Алерты — оставляем цветными, делаем тёмный фон */
body.dark-theme .alert {
    border: none !important;
}
body.dark-theme .alert-success {
    background-color: rgba(76, 175, 80, 0.18) !important;
    color: #a6e3a8 !important;
}
body.dark-theme .alert-info {
    background-color: rgba(3, 169, 244, 0.18) !important;
    color: #8cd5ff !important;
}
body.dark-theme .alert-warning {
    background-color: rgba(255, 152, 0, 0.18) !important;
    color: #ffd183 !important;
}
body.dark-theme .alert-danger {
    background-color: rgba(244, 67, 54, 0.18) !important;
    color: #ff9b95 !important;
}

/* Бэйджи и label-status */
body.dark-theme .label,
body.dark-theme .badge {
    color: #ffffff;
}

/* Бутстрап select / селекты */
body.dark-theme .bootstrap-select > .btn,
body.dark-theme .bootstrap-select .dropdown-toggle {
    background-color: #1a1f26 !important;
    color: #f1f3f5 !important;
    border-color: #2e3540 !important;
}
body.dark-theme .bootstrap-select .dropdown-menu li a {
    color: #d6d9de !important;
}
body.dark-theme .bootstrap-select .dropdown-menu li.selected a,
body.dark-theme .bootstrap-select .dropdown-menu li.active a {
    background-color: #2a2f38 !important;
    color: #ffffff !important;
}

/* Page loader / overlay фоны */
body.dark-theme .page-loader-wrapper {
    background-color: #161a20 !important;
}
body.dark-theme .page-loader-wrapper p {
    color: #f1f3f5 !important;
}
body.dark-theme .overlay {
    background-color: rgba(0, 0, 0, 0.65) !important;
}

/* Loading спиннер — overlay тоже тёмный */
body.dark-theme .loading:before {
    background-color: rgba(0, 0, 0, 0.5) !important;
}

/* Панели Bootstrap */
body.dark-theme .panel {
    background-color: #232932 !important;
    border-color: #2e3540 !important;
}
body.dark-theme .panel-default > .panel-heading {
    background-color: #1f242c !important;
    color: #f1f3f5 !important;
    border-color: #2e3540 !important;
}

/* Списки / списковые группы */
body.dark-theme .list-group-item {
    background-color: #232932 !important;
    border-color: #2e3540 !important;
    color: #d6d9de !important;
}

/* Tabs */
body.dark-theme .nav-tabs {
    border-bottom: 1px solid #2e3540 !important;
}
body.dark-theme .nav-tabs > li > a {
    color: #c6cad0 !important;
    border: 1px solid transparent !important;
}
body.dark-theme .nav-tabs > li > a:hover {
    background-color: #2a2f38 !important;
    border-color: #2e3540 #2e3540 #2e3540 !important;
}
body.dark-theme .nav-tabs > li.active > a,
body.dark-theme .nav-tabs > li.active > a:hover,
body.dark-theme .nav-tabs > li.active > a:focus {
    background-color: #232932 !important;
    color: #ffffff !important;
    border-color: #2e3540 #2e3540 transparent !important;
}

/* Чекбоксы / радио — упрощённый стиль */
body.dark-theme [type="checkbox"] + label,
body.dark-theme [type="radio"] + label {
    color: #d6d9de;
}

/* hr */
body.dark-theme hr {
    border-color: #2e3540 !important;
}

/* Pre / code */
body.dark-theme pre,
body.dark-theme code {
    background-color: #1a1f26 !important;
    color: #d6d9de !important;
    border-color: #2e3540 !important;
}

/* Datepicker */
body.dark-theme .vdp-datepicker__calendar {
    background-color: #232932 !important;
    border-color: #2e3540 !important;
    color: #d6d9de !important;
}
body.dark-theme .vdp-datepicker__calendar header .next:after {
    border-left-color: #d6d9de !important;
}
body.dark-theme .vdp-datepicker__calendar header .prev:after {
    border-right-color: #d6d9de !important;
}
body.dark-theme .vdp-datepicker__calendar .cell:not(.blank):not(.disabled):hover {
    background-color: #2a2f38 !important;
    border-color: #2a2f38 !important;
}
body.dark-theme .vdp-datepicker__calendar .cell.selected {
    background-color: #1976d2 !important;
    color: #ffffff !important;
}

/* Кастомные сообщения */
body.dark-theme .message {
    background-color: rgba(3, 169, 244, 0.18) !important;
    color: #8cd5ff !important;
}
body.dark-theme .message_success {
    background-color: rgba(76, 175, 80, 0.22) !important;
    color: #a6e3a8 !important;
}
body.dark-theme .message_error {
    background-color: rgba(255, 87, 34, 0.22) !important;
    color: #ffac8f !important;
}

/* Цвета карточек CRM (зелёный/красный фон для удалённых строк остаётся, но осветляем) */
body.dark-theme .table_proxy-leads-report-table.table-striped > tbody > tr.deleted {
    background-color: rgba(244, 67, 54, 0.18) !important;
}
body.dark-theme .company__report-table > tbody > tr.company_report-table-disable-row {
    background-color: rgba(230, 66, 54, 0.18) !important;
}

/* Иконки ✎ в комментах */
body.dark-theme .table_company-comment-cell:after,
body.dark-theme .pl-report_table-admin-comment-cell:after {
    color: #6c727d !important;
}
body.dark-theme .table_company-comment-cell:hover:after,
body.dark-theme .pl-report_table-admin-comment-cell:hover:after {
    color: #ffffff !important;
}

/* ====== Кнопка переключения темы ====== */

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    margin: 5px 6px 0 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
    float: right;
}
.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.22);
    transform: rotate(15deg);
}
.theme-toggle:focus {
    outline: none;
}
.theme-toggle .material-icons {
    font-size: 22px;
    line-height: 1;
}
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: inline-block; }

body.dark-theme .theme-toggle {
    background: rgba(255, 255, 255, 0.08);
    color: #ffd76b;
}
body.dark-theme .theme-toggle:hover {
    background: rgba(255, 255, 255, 0.16);
}
body.dark-theme .theme-toggle .icon-sun { display: inline-block; }
body.dark-theme .theme-toggle .icon-moon { display: none; }

@media (max-width: 768px) {
    .theme-toggle {
        width: 34px;
        height: 34px;
        margin: 7px 4px 0 0;
    }
    .theme-toggle .material-icons {
        font-size: 20px;
    }
}

/* Гостевая шапка (логин) — кнопка темнее */
body:not(.dark-theme) .guest-top-bar .theme-toggle,
body:not(.dark-theme) .navbar .theme-toggle {
    background: rgba(255, 255, 255, 0.18);
}
