/* ===== Палитра ===== */
:root {
    --dark: #595959;
    --gray: #6d746f;
    --sage: #808f85;
    --green: #91c499;
    --cream: #f2e9dc;

    --bg: var(--cream);
    --bg-card: #ffffff;
    --bg-card-hover: #f7f5f0;
    --bg-input: #ffffff;
    --text-primary: var(--dark);
    --text-secondary: var(--gray);
    --text-muted: #a0a8a3;
    --border-color: #d5d9d4;
    --border-accent: var(--sage);
    --shadow-sm: 0 1px 3px rgba(89, 89, 89, 0.08);
    --shadow-md: 0 2px 8px rgba(89, 89, 89, 0.1);
    --shadow-lg: 0 4px 16px rgba(89, 89, 89, 0.12);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --transition: all 0.2s ease;
    --font-sans: 'Segoe UI', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

/* ===== Reset & Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

/* ===== Navbar ===== */
.navbar-crm {
    background: #ffffff !important;
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
}

.navbar-crm .navbar-brand {
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--dark) !important;
}

.navbar-crm .navbar-brand::before {
    content: '◆ ';
    color: var(--green);
}

.navbar-crm .nav-link {
    color: var(--gray) !important;
    font-weight: 500;
    padding: 0.4rem 0.85rem !important;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    font-size: 0.9rem;
}

.navbar-crm .nav-link:hover {
    color: var(--dark) !important;
    background: var(--cream);
}

.navbar-crm .navbar-text {
    color: var(--gray) !important;
    font-weight: 500;
}

.navbar-crm .nav-link[href*="logout"] {
    color: #c0392b !important;
}

/* ===== Main ===== */
.main-container {
    padding: 1.5rem 0;
}

/* ===== Page Header ===== */
.page-header { margin-bottom: 1.5rem; }

.page-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--dark);
    margin-bottom: 0.15rem;
}

.page-header .page-subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ===== Cards ===== */
.card-crm {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    overflow: hidden;
}

.card-crm:hover {
    box-shadow: var(--shadow-md);
}

.card-crm .card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--dark);
}

.card-crm .card-body { padding: 1.25rem; }

/* ===== Stats ===== */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 3px; height: 100%;
}
.stat-card.primary::before { background: var(--green); }
.stat-card.secondary::before { background: var(--sage); }
.stat-card.accent::before { background: #91c499; }
.stat-card.orange::before { background: var(--gray); }

.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-card .stat-icon {
    width: 40px; height: 40px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 0.75rem;
    font-size: 1.2rem;
    background: var(--cream);
}

.stat-card .stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 0.2rem;
}

.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--dark);
    line-height: 1.2;
}

/* ===== Tables ===== */
.table-crm {
    width: 100%;
    border-collapse: separate; /* sticky + collapse=separate required */
    border-spacing: 0;
    color: var(--text-primary);
    font-size: 0.9rem;
}

/* Горизонтальный + вертикальный скролл: шапка едет вместе с тобой */
.table-crm-scroll {
    overflow: auto;
    max-height: min(72vh, calc(100vh - 160px));
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    position: relative;
    overscroll-behavior: contain;
}

.table-crm thead th {
    background: var(--cream);
    border: none;
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--gray);
    border-bottom: 1px solid var(--border-color);
    /* sticky header: при скролле вниз остаётся видимым */
    position: sticky;
    top: 0;
    z-index: 6;
    box-shadow: 0 1px 0 var(--border-color);
    white-space: nowrap;
}

.table-crm tbody tr { transition: var(--transition); }
.table-crm tbody tr:hover { background: var(--cream); }

.table-crm tbody td {
    padding: 0.7rem 1rem;
    border: none;
    border-bottom: 1px solid #e8e6e0;
    vertical-align: middle;
    background: var(--bg-card, #fff);
}

/* Липкие колонки: № + имя менеджера (скролл вправо — имя остаётся) */
.table-crm.table-crm-sticky-cols th:nth-child(1),
.table-crm.table-crm-sticky-cols td:nth-child(1) {
    position: sticky;
    left: 0;
    z-index: 3;
    background: var(--cream);
    min-width: 44px;
    box-shadow: 1px 0 0 var(--border-color);
}
.table-crm.table-crm-sticky-cols th:nth-child(2),
.table-crm.table-crm-sticky-cols td:nth-child(2) {
    position: sticky;
    left: 44px;
    z-index: 3;
    background: var(--bg-card, #fff);
    min-width: 140px;
    max-width: 220px;
    box-shadow: 2px 0 6px rgba(0,0,0,.06);
}
.table-crm.table-crm-sticky-cols thead th:nth-child(1),
.table-crm.table-crm-sticky-cols thead th:nth-child(2) {
    z-index: 8; /* выше body sticky cells */
    background: var(--cream);
}
.table-crm.table-crm-sticky-cols tbody tr:hover td:nth-child(1),
.table-crm.table-crm-sticky-cols tbody tr:hover td:nth-child(2) {
    background: var(--cream);
}

/* Вариант: только 1-я колонка (имя) липкая */
.table-crm.table-crm-sticky-name th:nth-child(1),
.table-crm.table-crm-sticky-name td:nth-child(1) {
    position: sticky;
    left: 0;
    z-index: 3;
    background: var(--bg-card, #fff);
    min-width: 120px;
    box-shadow: 2px 0 6px rgba(0,0,0,.06);
}
.table-crm.table-crm-sticky-name thead th:nth-child(1) {
    z-index: 8;
    background: var(--cream);
}

/* Фильтры/период сверху — едут вместе со скроллом страницы */
.crm-sticky-toolbar {
    position: sticky;
    top: 56px;
    z-index: 20;
    background: var(--bg-page, var(--bg-card, #f7f6f2));
    padding: 0.35rem 0;
    margin-bottom: 0.5rem;
}
.crm-sticky-toolbar .card-crm {
    margin-bottom: 0 !important;
    box-shadow: 0 4px 14px rgba(0,0,0,.06);
}

/* ===== Buttons ===== */
.btn-crm {
    padding: 0.4rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.85rem;
    transition: var(--transition);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.btn-crm-primary { background: var(--green); color: #fff; }
.btn-crm-primary:hover { background: #7db88a; color: #fff; }

.btn-crm-success { background: var(--sage); color: #fff; }
.btn-crm-success:hover { background: #6f7d74; color: #fff; }

.btn-crm-danger { background: #e74c3c; color: #fff; }
.btn-crm-danger:hover { background: #c0392b; color: #fff; }

.btn-crm-warning { background: var(--cream); color: var(--dark); border: 1px solid var(--border-color); }
.btn-crm-warning:hover { background: #e5dccf; color: var(--dark); }

.btn-crm-info { background: transparent; color: var(--gray); border: 1px solid var(--border-color); }
.btn-crm-info:hover { background: var(--cream); color: var(--dark); }

.btn-crm-outline { background: transparent; border: 1px solid var(--border-color); color: var(--gray); }
.btn-crm-outline:hover { border-color: var(--sage); color: var(--dark); background: var(--cream); }

.btn-crm-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }

/* ===== Badges ===== */
.badge-crm {
    padding: 0.3em 0.65em;
    font-size: 0.72rem;
    font-weight: 500;
    border-radius: 50px;
}

.badge-new { background: #dbeafe; color: #1e40af; }  /* синий — Знакомство */
.badge-progress { background: #fef3c7; color: #92400e; }  /* желтый — В работе */
.badge-ready { background: #d1fae5; color: #065f46; }  /* зеленый — Готов к передаче */
.badge-work { background: #e0e7e2; color: var(--gray); }
.badge-closed { background: #e8e8e8; color: var(--text-muted); }
.badge-fail { background: #fde8e8; color: #c0392b; }
.badge-noanswer { background: #e2e8f0; color: #475569; }
.badge-prank { background: #f3e8ff; color: #7e22ce; }
.badge-skip { background: #e0f2fe; color: #0369a1; }

/* ===== Forms ===== */
.form-crm .form-group { margin-bottom: 1rem; }

.form-crm label {
    display: block;
    margin-bottom: 0.3rem;
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--gray);
}

.form-crm .form-control,
.auth-form .form-control {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--dark);
    padding: 0.55rem 0.85rem;
    font-size: 0.9rem;
    transition: var(--transition);
    width: 100%;
}

.form-crm .form-control:focus,
.auth-form .form-control:focus {
    border-color: var(--sage);
    box-shadow: 0 0 0 2px rgba(128, 143, 133, 0.15);
    outline: none;
}

.form-crm .form-control::placeholder { color: var(--text-muted); }

.form-crm select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236d746f' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.8rem center;
    padding-right: 2rem;
}

/* ===== Auth ===== */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 70px);
    padding: 2rem;
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    animation: fadeInUp 0.4s ease;
}

.auth-header { text-align: center; margin-bottom: 1.5rem; }

.auth-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px; height: 64px;
    border-radius: 50%;
    background: var(--cream);
    color: var(--sage);
    margin-bottom: 1rem;
}

.auth-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--dark);
    margin-bottom: 0.3rem;
}

.auth-subtitle { color: var(--text-muted); font-size: 0.9rem; }

.auth-form .form-group { margin-bottom: 1.1rem; }
.auth-form label { display: block; margin-bottom: 0.3rem; font-weight: 500; font-size: 0.85rem; color: var(--gray); }

.btn-auth {
    width: 100%;
    padding: 0.7rem;
    background: var(--green);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 0.3rem;
}

.btn-auth:hover { background: #7db88a; }

.auth-footer {
    text-align: center;
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.85rem;
}

.auth-footer a { color: var(--sage); text-decoration: none; font-weight: 600; }
.auth-footer a:hover { color: var(--green); }

/* ===== Alerts ===== */
.alert-crm {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

.alert-crm.alert-success { border-color: var(--green); background: #e3f0e5; color: #4a7a55; }
.alert-crm.alert-warning { border-color: #e8d5a0; background: #fdf8ed; color: #8a7a40; }
.alert-crm.alert-error, .alert-crm.alert-danger { border-color: #e8b0a0; background: #fdf0ed; color: #8a3a2b; }
.alert-crm.alert-info { border-color: var(--sage); background: #eef2ef; color: var(--gray); }

/* ===== Quick Add ===== */
.quick-add-card {
    background: #f7faf7;
    border: 1px solid var(--green);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

/* ===== Detail Table ===== */
.detail-table { width: 100%; }
.detail-table tr { border-bottom: 1px solid #e8e6e0; }
.detail-table tr:last-child { border-bottom: none; }

.detail-table th {
    padding: 0.65rem 1rem;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--gray);
    width: 35%;
    background: var(--cream);
}

.detail-table td {
    padding: 0.65rem 1rem;
    color: var(--dark);
    width: 65%;
}

/* ===== Tabs ===== */
.nav-tabs-crm {
    border-bottom: 1px solid var(--border-color);
    gap: 0.2rem;
}

.nav-tabs-crm .nav-link {
    border: none;
    color: var(--gray);
    font-weight: 500;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    transition: var(--transition);
    font-size: 0.9rem;
}

.nav-tabs-crm .nav-link:hover { color: var(--dark); background: var(--cream); }
.nav-tabs-crm .nav-link.active { color: var(--dark); background: #eef2ef; }
.nav-tabs-crm .nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -1px; left: 0;
    width: 100%; height: 2px;
    background: var(--green);
}

/* ===== File List ===== */
.file-list .list-group-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm) !important;
    margin-bottom: 0.4rem;
    color: var(--dark);
    padding: 0.7rem 1rem;
}

/* ===== Modal ===== */
.modal-crm .modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.modal-crm .modal-header {
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
}

.modal-crm .modal-header .modal-title { font-weight: 600; color: var(--dark); }
.modal-crm .modal-body { padding: 1.25rem; }
.modal-crm .modal-footer { border-top: 1px solid var(--border-color); padding: 1rem 1.25rem; }

/* ===== Copy button ===== */
.btn-copy {
    background: var(--cream);
    border: 1px solid var(--border-color);
    color: var(--gray);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.85rem;
    font-weight: 500;
    transition: var(--transition);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
}

.btn-copy:hover { background: #e5dccf; color: var(--dark); }

/* ===== Action group ===== */
.action-group { display: flex; gap: 0.3rem; flex-wrap: wrap; }

/* ===== List group ===== */
.list-group-crm .list-group-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--dark);
}

/* ===== Auth form radio ===== */
.auth-form input[type="radio"] { appearance: none; width: 16px; height: 16px; border: 2px solid var(--border-color); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; vertical-align: middle; margin-right: 4px; position: relative; }
.auth-form input[type="radio"]:checked { border-color: var(--green); }
.auth-form input[type="radio"]:checked::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--green); position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
.auth-form ul, .auth-form li { list-style: none; padding: 0; margin: 0; }
.auth-form li { margin-bottom: 0.4rem; display: flex; align-items: center; gap: 0.4rem; color: var(--dark); padding: 0.4rem 0.6rem; border-radius: var(--radius-sm); cursor: pointer; }
.auth-form li:hover { background: var(--cream); }
.auth-form .errorlist { list-style: none; padding: 0; margin: 0.4rem 0 0; }
.auth-form .errorlist li { color: #c0392b; font-size: 0.8rem; padding: 0.15rem 0; background: transparent; }

/* ===== Animations ===== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in { animation: fadeInUp 0.4s ease; }
.animate-fade-in-delay-1 { animation: fadeInUp 0.4s ease 0.08s both; }
.animate-fade-in-delay-2 { animation: fadeInUp 0.4s ease 0.15s both; }
.animate-fade-in-delay-3 { animation: fadeInUp 0.4s ease 0.22s both; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--cream); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray); }

/* ===== Search ===== */
.search-box .input-group {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.search-box .input-group:focus-within { border-color: var(--sage); }
.search-box .form-control { background: transparent; border: none; color: var(--dark); padding: 0.6rem 1rem; }
.search-box .form-control:focus { box-shadow: none; }
.search-box .btn-search { background: transparent; border: none; color: var(--gray); padding: 0.6rem 1rem; }

/* ===== Empty state ===== */
.empty-state { text-align: center; padding: 2rem; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; opacity: 0.6; }

/* ===== Kanban ===== */
.kanban-board { display: flex; gap: 1rem; overflow-x: auto; padding-bottom: 1rem; min-height: 65vh; }
.kanban-column { flex: 1; min-width: 240px; max-width: 300px; background: #f7f5f0; border: 1px solid var(--border-color); border-radius: var(--radius-lg); display: flex; flex-direction: column; }
.kanban-column-header { padding: 0.85rem 1rem; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.kanban-column-title { font-weight: 600; font-size: 0.85rem; display: flex; align-items: center; gap: 0.4rem; }
.kanban-count { background: var(--cream); padding: 0.15rem 0.5rem; border-radius: 20px; font-size: 0.75rem; color: var(--gray); }
.kanban-cards { padding: 0.6rem; flex: 1; min-height: 100px; }
.kanban-cards.drag-over { background: rgba(128, 143, 133, 0.08); border-radius: var(--radius-sm); }
.kanban-card { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 0.65rem; margin-bottom: 0.5rem; cursor: grab; transition: all 0.15s; }
.kanban-card:hover { box-shadow: var(--shadow-md); border-color: var(--sage); }
.kanban-card.dragging { opacity: 0.3; }
.kanban-card-top { margin-bottom: 0.3rem; }
.kanban-card-top strong { display: block; font-size: 0.9rem; }
.kanban-card-top small { color: var(--text-muted); font-size: 0.75rem; }
.kanban-card-body { display: flex; flex-direction: column; gap: 0.15rem; font-size: 0.75rem; color: var(--gray); margin-bottom: 0.4rem; }
.kanban-card-actions { display: flex; gap: 0.25rem; }
.kanban-card-actions .btn-crm-sm { padding: 0.15rem 0.4rem; font-size: 0.7rem; }
.kanban-empty { text-align: center; padding: 1.25rem; color: var(--text-muted); font-size: 0.8rem; }
.kanban-column .badge-crm { font-size: 0.65rem; }

/* ===== Expandable client rows ===== */
.client-list { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.75rem; }
.client-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: var(--transition);
}
.client-item.is-open { border-color: var(--sage); box-shadow: var(--shadow-md); }
.client-item-head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    cursor: pointer;
    user-select: none;
    background: #fff;
}
.client-item-head:hover { background: var(--cream); }
.client-num {
    min-width: 28px;
    height: 28px;
    padding: 0 0.35rem;
    border-radius: 8px;
    background: var(--cream);
    border: 1px solid var(--border-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--gray);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}
.client-arrow {
    width: 32px; height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--cream);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    color: var(--dark);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}
.client-item.is-open .client-arrow { transform: rotate(90deg); background: var(--green); color: #fff; border-color: var(--green); }
.client-item-meta { flex: 1; min-width: 0; }
.client-item-meta strong { display: block; font-size: 0.95rem; }
.client-item-meta small { color: var(--text-muted); font-size: 0.78rem; }
.client-item-body {
    display: none;
    padding: 0 1rem 1rem;
    border-top: 1px solid var(--border-color);
    background: #faf9f6;
}
.client-item.is-open .client-item-body { display: block; }
.client-form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem 1rem;
    padding-top: 1rem;
}
.client-form-grid .form-group { margin: 0; }
.client-form-grid .form-group label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--gray);
    margin-bottom: 0.25rem;
}
.client-form-grid .form-group.full { grid-column: 1 / -1; }
.client-form-grid .form-control {
    width: 100%;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    background: #fff;
}
.client-form-grid .form-control:focus {
    outline: none;
    border-color: var(--sage);
    box-shadow: 0 0 0 2px rgba(128, 143, 133, 0.15);
}
.client-form-actions {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    margin-top: 1.15rem;
    padding-top: 0.85rem;
    border-top: 1px dashed var(--border-color);
}
.client-form-actions .btn-row {
    display: flex;
    gap: 0.65rem;
    flex-wrap: wrap;
}
.btn-crm-lg {
    flex: 1;
    min-width: 140px;
    padding: 0.9rem 1.25rem;
    font-size: 1rem;
    font-weight: 700;
    border-radius: var(--radius-md);
    text-align: center;
    justify-content: center;
}
.btn-crm-lg.btn-transfer {
    background: var(--green);
    color: #fff;
    border: none;
}
.btn-crm-lg.btn-transfer:hover { background: #7db88a; color: #fff; }
.btn-crm-lg.btn-fail {
    background: #e74c3c;
    color: #fff;
    border: none;
}
.btn-crm-lg.btn-fail:hover { background: #c0392b; color: #fff; }
.btn-crm-lg.btn-noanswer {
    background: #64748b;
    color: #fff;
    border: none;
}
.btn-crm-lg.btn-noanswer:hover { background: #475569; color: #fff; }
.btn-crm-lg.btn-prank {
    background: #a855f7;
    color: #fff;
    border: none;
}
.btn-crm-lg.btn-prank:hover { background: #9333ea; color: #fff; }
.btn-crm-lg.btn-skip {
    background: #0ea5e9;
    color: #fff;
    border: none;
}
.btn-crm-lg.btn-skip:hover { background: #0284c7; color: #fff; }

/* Кнопки действий в шапке карточки клиента */
.client-head-actions {
    display: inline-flex;
    gap: 0.25rem;
    align-items: center;
}
.btn-head-action {
    border: 1px solid var(--border-color);
    background: var(--bg-card, #fff);
    border-radius: 8px;
    width: 2rem;
    height: 2rem;
    padding: 0;
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-head-action:hover { filter: brightness(0.95); transform: translateY(-1px); }
.btn-head-fail { border-color: #f5c6cb; background: #fde8e8; }
.btn-head-noanswer { border-color: #cbd5e1; background: #e2e8f0; }
.btn-head-prank { border-color: #e9d5ff; background: #f3e8ff; }
.btn-head-skip { border-color: #bae6fd; background: #e0f2fe; }
.btn-head-restore { border-color: #86efac; background: #dcfce7; }
.btn-head-action.is-current,
.btn-crm-lg.is-current {
    box-shadow: 0 0 0 2px var(--green, #10b981);
    font-weight: 700;
}
.btn-crm-lg.btn-restore {
    background: #16a34a;
    color: #fff;
    border: none;
}
.btn-crm-lg.btn-restore:hover { background: #15803d; color: #fff; }

/* Дашборд: кликабельные карточки и папки */
.stat-card-click { cursor: pointer; transition: box-shadow .15s, transform .15s; }
.stat-card-click:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-card-click.is-active { outline: 2px solid var(--green, #10b981); outline-offset: 1px; }
.dash-folder-list { max-height: 420px; overflow-y: auto; }
.dash-folder-item {
    width: 100%;
    text-align: left;
    border: 0;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    padding: 0.85rem 1rem;
    cursor: pointer;
    color: inherit;
}
.dash-folder-item:hover { background: rgba(16, 185, 129, 0.06); }
.dash-folder-main {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: baseline;
}
.dash-folder-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    margin-top: 0.25rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    align-items: center;
}
.dash-folder-comment {
    margin-top: 0.35rem;
    font-size: 0.82rem;
    color: var(--gray);
    white-space: pre-wrap;
    max-height: 3.2em;
    overflow: hidden;
}
.stats-row-wrap .stat-col { margin-bottom: 0.35rem; }

/* Кто передал / кто ведёт */
.client-mgr-chips {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: center;
    max-width: 220px;
}
.mgr-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    white-space: nowrap;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 1px solid var(--border-color);
    background: #f8fafc;
    color: var(--gray);
}
.mgr-chip.mgr-m1 { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.mgr-chip.mgr-m2 { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.mgr-chip.mgr-wait { background: #fff7ed; color: #c2410c; border-color: #fed7aa; }

.client-manager-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.5rem 0.75rem;
    padding: 0.75rem 0.85rem;
    margin: 0.75rem 0 0.25rem;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm, 8px);
}
.mgr-bar-item { min-width: 0; }
.mgr-bar-label {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-bottom: 0.15rem;
}
.mgr-bar-value {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--dark);
    word-break: break-word;
}
body.dark-theme .client-manager-bar {
    background: linear-gradient(180deg, #2a2a2a 0%, #222 100%);
}
body.dark-theme .mgr-chip.mgr-m1 { background: #1e3a5f; color: #93c5fd; border-color: #1e40af; }
body.dark-theme .mgr-chip.mgr-m2 { background: #064e3b; color: #6ee7b7; border-color: #065f46; }
body.dark-theme .mgr-chip.mgr-wait { background: #431407; color: #fdba74; border-color: #9a3412; }

.sidebar-job-title {
    display: block;
    font-size: 0.72rem !important;
    font-weight: 600;
    color: var(--green, #10b981) !important;
    margin-top: 0.05rem;
    line-height: 1.2;
}
.dash-period-card .form-control {
    background: var(--bg-input, #fff);
    border-color: var(--border-color);
    color: var(--dark);
}

/* ===== Реестр 2-го этапа (компактная таблица) ===== */
.sheet-wrap {
    overflow: auto;
    max-width: 100%;
    max-height: min(70vh, calc(100vh - 180px));
    -webkit-overflow-scrolling: touch;
}
.sheet-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.62rem;
    min-width: 780px;
    table-layout: fixed;
    background: #fff;
}
.sheet-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #e8f0fe;
    color: #1a73e8;
    font-weight: 700;
    text-transform: none;
    padding: 0.22rem 0.18rem;
    border: 1px solid #c5d4f0;
    white-space: nowrap;
    text-align: center;
    font-size: 0.58rem;
    line-height: 1.15;
}
.sheet-table tbody td {
    padding: 0.18rem 0.2rem;
    border: 1px solid #e0e0e0;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: #fff;
    color: #202124;
    line-height: 1.2;
}
.sheet-table tbody tr:hover td {
    background: #f8fbff;
}
.sheet-num { text-align: center; font-weight: 600; width: 28px; }
.sheet-center { text-align: center; }
.sheet-date { text-align: center; width: 62px; font-variant-numeric: tabular-nums; }
.sheet-fio { font-weight: 600; max-width: 110px !important; width: 110px; }
.sheet-user { color: #1a73e8; font-weight: 600; max-width: 90px !important; width: 90px; }
.sheet-comment { max-width: 110px !important; width: 110px; color: #5f6368; vertical-align: top; }
.comment-main { white-space: pre-wrap; word-break: break-word; }
.closer-under-comment {
    margin-top: 0.35rem;
    line-height: 1.25;
    font-size: 0.78rem;
}
.closer-sep {
    color: var(--text-muted, #94a3b8);
    letter-spacing: 0.02em;
    margin: 0.15rem 0;
    user-select: none;
}
.closer-label {
    text-transform: lowercase;
    color: var(--text-muted, #64748b);
    font-weight: 600;
    font-size: 0.72rem;
}
.closer-name {
    font-weight: 700;
    color: var(--primary, #2563eb);
    word-break: break-word;
}
.sheet-comment .closer-under-comment { font-size: 0.68rem; }
.sheet-comment .closer-name { font-size: 0.7rem; }
.sheet-phone { max-width: 78px !important; width: 78px; }
.sheet-cold { max-width: 72px !important; width: 72px; }
.sheet-m2 { max-width: 72px !important; width: 72px; }
.sheet-max { max-width: 48px !important; width: 48px; }
.sheet-itog {
    text-align: center;
    font-weight: 700;
    text-transform: lowercase;
    width: 58px;
}
.sheet-actions {
    white-space: nowrap;
    width: 88px;
    padding: 0.1rem !important;
}
.sheet-actions .btn-crm-sm {
    padding: 0.08rem 0.2rem;
    font-size: 0.62rem;
    margin: 0;
    line-height: 1;
}
/* Цвета итога как в таблице */
.sheet-itog-red .sheet-itog { background: #ea4335 !important; color: #fff !important; }
.sheet-itog-yellow .sheet-itog { background: #fbbc04 !important; color: #202124 !important; }
.sheet-itog-green .sheet-itog { background: #34a853 !important; color: #fff !important; }
.sheet-itog-purple .sheet-itog { background: #a855f7 !important; color: #fff !important; }
.sheet-itog-blue .sheet-itog { background: #4285f4 !important; color: #fff !important; }
.sheet-itog-orange .sheet-itog { background: #f39c12 !important; color: #fff !important; }

body.dark-theme .sheet-table { background: #1e1e1e; }
body.dark-theme .sheet-table thead th {
    background: #1e3a5f;
    color: #93c5fd;
    border-color: #334155;
}
body.dark-theme .sheet-table tbody td {
    background: #2a2a2a;
    color: #e5e5e5;
    border-color: #3a3a3a;
}
body.dark-theme .sheet-table tbody tr:hover td { background: #333; }

.btn-crm-lg.btn-save {
    background: var(--sage);
    color: #fff;
    border: none;
}
.btn-crm-lg.btn-save:hover { background: #6f7d74; color: #fff; }
/* ===== М1 топбар как на макете (пилюли + Excel) ===== */
.m1-topbar {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.15rem 0 0.25rem;
}
.m1-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    align-items: center;
}
.m1-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.48rem 0.95rem;
    border-radius: 999px;
    background: #f0ebe3;
    color: #3d3a35;
    text-decoration: none !important;
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid transparent;
    transition: 0.15s ease;
    line-height: 1.2;
}
.m1-pill:hover {
    background: #e6e0d6;
    color: #1a1a1a;
}
.m1-pill.is-on {
    background: #ebe4d8;
    box-shadow: 0 1px 0 rgba(0,0,0,.04), inset 0 0 0 1px rgba(0,0,0,.04);
    color: #1f1c18;
}
.m1-pill-ico {
    font-size: 0.95rem;
    line-height: 1;
}
.m1-pill-num {
    font-weight: 700;
    font-size: 0.88rem;
    opacity: 0.85;
    margin-left: 0.1rem;
}
.m1-pill-fail .m1-pill-num-fail,
.m1-pill-fail .m1-pill-ico {
    color: #c0392b;
}
.m1-pill-fail.is-on {
    background: #f8e9e7;
}
.m1-export-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.m1-btn-export {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.42rem 0.9rem;
    border-radius: 10px;
    background: #a8c5a8;
    color: #1a3d2e !important;
    font-weight: 700;
    font-size: 0.86rem;
    text-decoration: none !important;
    border: none;
    transition: 0.15s ease;
}
.m1-btn-export:hover {
    background: #93b693;
    color: #0f241a !important;
}
body.dark-theme .m1-pill {
    background: #2a2e2c;
    color: #e8e6e0;
}
body.dark-theme .m1-pill.is-on {
    background: #3a403c;
    color: #fff;
}
body.dark-theme .m1-btn-export {
    background: #3d6b4f;
    color: #e8f5e9 !important;
}
body.dark-theme .m1-pill-fail .m1-pill-num-fail,
body.dark-theme .m1-pill-fail .m1-pill-ico {
    color: #ff8a80;
}

.client-status-pills {
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;
    margin: 0.25rem 0 0.5rem;
}
.client-status-pills button {
    border: 1px solid var(--border-color, #d5d9d4);
    background: #fff;
    border-radius: 20px;
    padding: 0.42rem 0.8rem;
    font-size: 0.82rem;
    cursor: pointer;
    color: var(--dark, #222);
    line-height: 1.25;
}
.client-status-pills button:hover {
    border-color: var(--sage, #91c499);
    background: var(--cream, #f5f3ee);
}
.client-status-pills button.active {
    border-color: #1a3d2e;
    background: #1a3d2e;
    color: #fff;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(26,61,46,.22);
}
.client-status-pills button:disabled {
    opacity: 0.55;
    cursor: wait;
}
body.dark-theme .client-status-pills button {
    background: #2a2e2c;
    border-color: #3d4440;
    color: #eee;
}
body.dark-theme .client-status-pills button.active {
    background: #2d6a4f;
    border-color: #2d6a4f;
    color: #fff;
}
.field-hint { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.15rem; }
.field-req::after { content: ' *'; color: #e74c3c; }

@media (max-width: 768px) {
    .client-form-grid { grid-template-columns: 1fr; }
    .btn-crm-lg { min-width: 100%; }
}

/* ===== Responsive ===== */

/* ---------- Small desktop / планшеты (769-1024) ---------- */
@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar {
        width: 200px;
    }

    .main-content {
        margin-left: 200px;
    }

    .chart-body {
        padding: 0.85rem !important;
    }

    .client-form-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ---------- Мобильные (< 769px) ---------- */
@media (max-width: 768px) {

    /* --- Сайдбар --- */
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .top-bar {
        display: flex;
    }

    .sidebar-overlay.show {
        display: block;
    }

    .container-fluid.p-4 {
        padding: 0.75rem !important;
    }

    /* --- Стат-карточки --- */
    .stat-card {
        padding: 0.85rem;
    }
    .stat-card .stat-value {
        font-size: 1.25rem;
    }
    .stat-card .stat-icon {
        width: 34px;
        height: 34px;
        font-size: 1rem;
    }

    /* --- Страница --- */
    .page-header h2 {
        font-size: 1.15rem;
    }
    .page-header {
        margin-bottom: 0.75rem;
    }

    /* --- Форма клиента --- */
    .client-form-grid {
        grid-template-columns: 1fr;
    }

    .client-item-head {
        flex-wrap: wrap;
        gap: 0.4rem;
        padding: 0.65rem 0.75rem;
    }

    .client-item-head .client-arrow {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }

    .client-item-meta strong {
        font-size: 0.85rem;
    }

    .client-item-meta small {
        font-size: 0.72rem;
    }

    .client-item-body {
        padding: 0 0.75rem 0.75rem;
    }

    .client-form-grid .form-group label {
        font-size: 0.75rem;
    }

    .client-form-grid .form-control {
        font-size: 0.85rem;
        padding: 0.4rem 0.6rem;
    }

    .btn-crm-lg {
        min-width: 100%;
        padding: 0.7rem 1rem;
        font-size: 0.9rem;
    }

    .client-form-actions .btn-row {
        flex-direction: column;
    }

    .client-status-pills button {
        font-size: 0.72rem;
        padding: 0.25rem 0.55rem;
    }

    /* --- Быстрые ссылки дашборда --- */
    .quick-link-icon {
        font-size: 1.4rem;
    }
    .quick-links-row h6 {
        font-size: 0.78rem;
    }
    .quick-links-row .card-crm {
        padding: 0.65rem !important;
    }

    /* --- Чарты --- */
    .chart-body {
        min-height: 180px;
        padding: 0.75rem !important;
    }
    .chart-wrapper {
        height: 200px;
    }

    /* --- Детали дня --- */
    .day-stats-grid {
        grid-template-columns: 1fr;
    }

    /* --- Аутентификация --- */
    .auth-card {
        padding: 1.5rem;
    }

    /* --- Таблица (старый стиль, но сейчас используем client-list) --- */
    .detail-table th {
        width: 40%;
        font-size: 0.75rem;
        padding: 0.5rem 0.75rem;
    }
    .detail-table td {
        font-size: 0.82rem;
        padding: 0.5rem 0.75rem;
    }

    /* --- Фильтры --- */
    .card-crm .row.g-2 input,
    .card-crm .row.g-2 select {
        font-size: 0.82rem;
    }

    /* --- Адаптивная таблица (карточки), НО keep-head сохраняет шапку+scroll --- */
    .table-crm:not(.table-crm-keep-head) thead {
        display: none;
    }

    .table-crm:not(.table-crm-keep-head) tbody tr {
        display: block;
        padding: 0.65rem;
        border-bottom: 1px solid var(--border-color);
    }

    .table-crm:not(.table-crm-keep-head) tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.3rem 0;
        border: none;
        font-size: 0.8rem;
    }

    .table-crm:not(.table-crm-keep-head) tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--gray);
        font-size: 0.7rem;
        text-transform: uppercase;
        flex-shrink: 0;
        margin-right: 0.5rem;
    }

    .table-crm:not(.table-crm-keep-head) tbody td:last-child {
        border-bottom: none;
    }

    /* Менеджеры / рейтинги: шапка остаётся, таблица скроллится */
    .table-crm.table-crm-keep-head {
        min-width: 720px;
    }
    .table-crm-scroll {
        max-height: min(75vh, calc(100vh - 120px));
    }
    .crm-sticky-toolbar {
        top: 0;
    }

    /* --- Пагинация --- */
    .page-link {
        padding: 0.3rem 0.55rem;
        font-size: 0.78rem;
    }

    /* --- Настройки (темы) --- */
    .theme-option {
        max-width: 140px;
    }
    .theme-option-preview {
        height: 70px;
    }
}

/* ---------- Очень маленькие (< 420px) ---------- */
@media (max-width: 420px) {
    .stat-card {
        padding: 0.6rem;
    }
    .stat-card .stat-value {
        font-size: 1.05rem;
    }
    .stat-card .stat-icon {
        width: 28px;
        height: 28px;
        font-size: 0.85rem;
    }
    .top-bar-title {
        font-size: 0.78rem;
    }
    .top-bar {
        padding: 0.5rem 0.75rem;
    }
    .hamburger {
        font-size: 1.1rem;
    }
    .sidebar {
        width: 260px;
    }
}

/* ---------- Широкие экраны (≥ 1600) ---------- */
@media (min-width: 1600px) {
    .container-fluid.p-4 {
        max-width: 1400px;
        margin: 0 auto;
    }
}

/* ===================================================================
   ТЁМНАЯ ТЕМА
   (body.dark-theme + html[data-theme=dark] — чтобы не слетала при переходах)
   =================================================================== */
html[data-theme="dark"],
body.dark-theme,
html[data-theme="dark"] body {
    --dark: #f0f0f0;
    --gray: #c0c0c0;
    --sage: #bb86fc;
    --green: #bb86fc;
    --cream: #333333;

    --bg: #121212;
    --bg-card: #1e1e1e;
    --bg-card-hover: #2a2a2a;
    --bg-input: #2a2a2a;
    --text-primary: #f0f0f0;
    --text-secondary: #c0c0c0;
    --text-muted: #aaaaaa;
    --border-color: #444444;
    --border-accent: #bb86fc;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.6);
}

html[data-theme="dark"] body,
body.dark-theme {
    background: var(--bg);
    color: var(--text-primary);
}

body.dark-theme .navbar-crm {
    background: #1e1e1e !important;
    border-bottom-color: var(--border-color);
}

body.dark-theme .navbar-crm .nav-link {
    color: var(--gray) !important;
}

body.dark-theme .navbar-crm .nav-link:hover {
    color: var(--dark) !important;
    background: var(--cream);
}

body.dark-theme .navbar-crm .navbar-text {
    color: var(--gray) !important;
}

body.dark-theme .navbar-crm .navbar-brand {
    color: var(--dark) !important;
}

body.dark-theme .table-crm thead th {
    background: var(--cream);
    color: var(--text-secondary);
}

body.dark-theme .table-crm tbody tr:hover {
    background: var(--cream);
}

body.dark-theme .table-crm tbody td {
    border-bottom-color: var(--border-color);
    background: var(--bg-card, #1e2220);
}

body.dark-theme .table-crm.table-crm-sticky-cols th:nth-child(1),
body.dark-theme .table-crm.table-crm-sticky-cols td:nth-child(1),
body.dark-theme .table-crm.table-crm-sticky-cols thead th:nth-child(1),
body.dark-theme .table-crm.table-crm-sticky-cols thead th:nth-child(2),
body.dark-theme .table-crm.table-crm-sticky-name thead th:nth-child(1) {
    background: var(--cream);
}
body.dark-theme .table-crm.table-crm-sticky-cols td:nth-child(2),
body.dark-theme .table-crm.table-crm-sticky-name td:nth-child(1) {
    background: var(--bg-card, #1e2220);
}
body.dark-theme .crm-sticky-toolbar {
    background: var(--bg-page, #121512);
}

body.dark-theme .quick-add-card {
    background: var(--bg-card);
}

body.dark-theme .client-item-head {
    background: var(--bg-card);
    border-bottom: 1px solid transparent;
}

body.dark-theme .client-item-head:hover {
    background: var(--cream);
}

body.dark-theme .client-item-body {
    background: var(--bg-card);
}

body.dark-theme .client-form-grid .form-control {
    background: var(--bg-input);
    color: var(--dark);
    border-color: var(--border-color);
}

body.dark-theme .client-status-pills button {
    background: var(--bg-input);
    color: var(--gray);
    border-color: var(--border-color);
}

body.dark-theme .client-status-pills button.active {
    background: rgba(90, 158, 106, 0.2);
    color: var(--green);
    border-color: var(--green);
}

body.dark-theme .detail-table th {
    background: var(--cream);
    color: var(--text-secondary);
}

body.dark-theme .team-stat-box {
    background: var(--cream);
    border-color: var(--border-color);
}

body.dark-theme .stat-card .stat-icon {
    background: var(--cream);
}

body.dark-theme .kanban-column {
    background: var(--cream);
}

body.dark-theme .kanban-card {
    background: var(--bg-card);
}

body.dark-theme .file-list .list-group-item {
    background: var(--bg-card);
}

body.dark-theme::-webkit-scrollbar-track {
    background: var(--cream);
}

body.dark-theme::-webkit-scrollbar-thumb {
    background: var(--border-color);
}

body.dark-theme .auth-card {
    background: var(--bg-card);
}

body.dark-theme .auth-icon {
    background: var(--cream);
    color: var(--sage);
}

body.dark-theme .auth-form input[type="radio"] {
    border-color: var(--border-color);
}

body.dark-theme .auth-form li:hover {
    background: var(--cream);
}

body.dark-theme .auth-footer {
    border-top-color: var(--border-color);
}

body.dark-theme .btn-crm-warning {
    background: var(--cream);
    color: var(--dark);
    border-color: var(--border-color);
}

body.dark-theme .btn-crm-info {
    background: transparent;
    color: var(--gray);
    border-color: var(--border-color);
}

body.dark-theme .btn-crm-info:hover {
    background: var(--cream);
    color: var(--dark);
}

body.dark-theme .btn-crm-outline {
    background: transparent;
    border-color: var(--border-color);
    color: var(--gray);
}

body.dark-theme .btn-crm-outline:hover {
    border-color: var(--sage);
    color: var(--dark);
    background: var(--cream);
}

body.dark-theme .btn-copy {
    background: var(--cream);
    border-color: var(--border-color);
    color: var(--gray);
}

body.dark-theme .btn-copy:hover {
    background: #3d3d3d;
    color: var(--dark);
    border-color: var(--border-accent);
}

body.dark-theme .nav-tabs-crm .nav-link {
    color: var(--gray);
}

body.dark-theme .nav-tabs-crm .nav-link:hover {
    color: var(--dark);
    background: var(--cream);
}

body.dark-theme .nav-tabs-crm .nav-link.active {
    color: var(--dark);
    background: var(--bg-card);
}

body.dark-theme .empty-state {
    color: var(--text-muted);
}

body.dark-theme .page-header h2 {
    color: var(--dark);
}

body.dark-theme .day-stat-item {
    background: var(--cream);
    border-color: var(--border-color);
}

body.dark-theme .day-total-row {
    background: var(--cream);
    border-color: var(--border-color);
}

body.dark-theme .sidebar {
    background: #181818;
    border-right-color: var(--border-color);
}

body.dark-theme .sidebar-header {
    border-bottom-color: var(--border-color);
}

body.dark-theme .sidebar-link {
    color: #c8c8c8;
}

body.dark-theme .sidebar-link:hover {
    background: var(--cream);
    color: var(--dark);
}

body.dark-theme .sidebar-item.active .sidebar-link {
    background: rgba(187, 134, 252, 0.15);
    color: var(--green);
}

body.dark-theme .sidebar-footer {
    border-top-color: var(--border-color);
}

body.dark-theme .sidebar-user-info strong {
    color: #f0f0f0;
}

body.dark-theme .sidebar-user-avatar {
    background: var(--green);
}

body.dark-theme .sidebar-logout {
    color: var(--gray);
}

body.dark-theme .sidebar-logout:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

body.dark-theme .theme-switch .theme-slider {
    background: var(--bg-input);
}

body.dark-theme .theme-switch input:checked + .theme-slider {
    background: var(--green);
}

body.dark-theme .theme-switch .theme-slider .fa-sun {
    color: #f59e0b;
}

body.dark-theme .theme-switch .theme-slider .fa-moon {
    color: #818cf8;
}

body.dark-theme .sidebar-divider span {
    color: #888888;
}

body.dark-theme .quick-link-card {
    background: var(--bg-card);
    border-color: var(--border-color);
}

body.dark-theme .quick-link-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-accent);
}

body.dark-theme .quick-link-card h6 {
    color: var(--dark);
}

body.dark-theme .quick-link-card small {
    color: var(--text-muted);
}

body.dark-theme .card-crm {
    background: var(--bg-card);
    border-color: var(--border-color);
}

body.dark-theme .card-crm .card-header {
    color: #f0f0f0;
    border-bottom-color: var(--border-color);
}

body.dark-theme .alert-crm.alert-success {
    background: rgba(187, 134, 252, 0.15);
    border-color: var(--green);
    color: var(--green);
}

body.dark-theme .alert-crm.alert-warning {
    background: rgba(245, 158, 11, 0.15);
    border-color: #f59e0b;
    color: #fbbf24;
}

body.dark-theme .alert-crm.alert-error,
body.dark-theme .alert-crm.alert-danger {
    background: rgba(239, 68, 68, 0.15);
    border-color: #ef4444;
    color: #f87171;
}

body.dark-theme .alert-crm.alert-info {
    background: rgba(187, 134, 252, 0.1);
    border-color: var(--sage);
    color: var(--sage);
}

body.dark-theme .stat-card {
    background: var(--bg-card);
    border-color: var(--border-color);
}

body.dark-theme .client-form-grid .form-control:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 2px rgba(187, 134, 252, 0.2);
}

body.dark-theme .chart-body {
    background: var(--bg-card);
}

body.dark-theme .nav-tabs-crm .nav-link.active::after {
    background: var(--green);
}

body.dark-theme .stat-card .stat-value {
    color: #f0f0f0;
}

body.dark-theme .client-num {
    background: var(--bg-input);
    border-color: var(--border-color);
    color: #c0c0c0;
}

body.dark-theme .client-item-meta strong {
    color: #f0f0f0;
}

body.dark-theme .client-item-meta small {
    color: #999999;
}

body.dark-theme .client-form-grid .form-group label {
    color: #b0b0b0;
}

body.dark-theme .form-crm .form-control::placeholder {
    color: #777777;
}

body.dark-theme .page-header .page-subtitle {
    color: #888888;
}

body.dark-theme .dash-hint {
    color: #888888 !important;
}

body.dark-theme .detail-table td {
    color: #f0f0f0;
}

body.dark-theme .detail-table th {
    color: #b0b0b0;
}

body.dark-theme .table-crm tbody td {
    color: #e0e0e0;
}

body.dark-theme .badge-new { background: #1e3a5f; color: #93c5fd; }
body.dark-theme .badge-progress { background: #5c4a1e; color: #fcd34d; }
body.dark-theme .badge-ready { background: #1a3d2e; color: #6ee7b7; }
body.dark-theme .badge-work { background: #3a3a3a; color: #c0c0c0; }
body.dark-theme .badge-closed { background: #3a3a3a; color: #999999; }
body.dark-theme .badge-fail { background: #4a2020; color: #fca5a5; }
body.dark-theme .badge-noanswer { background: #334155; color: #cbd5e1; }
body.dark-theme .badge-prank { background: #3b0764; color: #e9d5ff; }
body.dark-theme .badge-skip { background: #0c4a6e; color: #bae6fd; }

body.dark-theme .list-group-crm .list-group-item {
    background: var(--bg-card);
    border-color: var(--border-color);
    color: var(--dark);
}

body.dark-theme .modal-crm .modal-content {
    background: var(--bg-card);
    border-color: var(--border-color);
}

body.dark-theme .modal-crm .modal-header {
    border-bottom-color: var(--border-color);
}

body.dark-theme .modal-crm .modal-header .modal-title {
    color: var(--dark);
}

body.dark-theme .modal-crm .modal-footer {
    border-top-color: var(--border-color);
}

body.dark-theme .form-crm label,
body.dark-theme .auth-form label {
    color: var(--text-secondary);
}

body.dark-theme .form-crm .form-control,
body.dark-theme .auth-form .form-control {
    background: var(--bg-input);
    border-color: var(--border-color);
    color: var(--dark);
}

body.dark-theme .form-crm .form-control:focus,
body.dark-theme .auth-form .form-control:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 2px rgba(187, 134, 252, 0.2);
}

body.dark-theme select.form-control {
    background-color: var(--bg-input);
    color: var(--dark);
}

/* Bootstrap .text-muted и другие вспомогательные классы */
body.dark-theme .text-muted {
    color: #aaaaaa !important;
}

body.dark-theme .text-secondary {
    color: #c0c0c0 !important;
}

body.dark-theme .text-body {
    color: #f0f0f0 !important;
}

body.dark-theme small.text-muted,
body.dark-theme .small.text-muted {
    color: #aaaaaa !important;
}

/* Чекбокс с подписью */
body.dark-theme .form-group label input[type="checkbox"] {
    accent-color: var(--green);
}

body.dark-theme .form-group label {
    color: #f0f0f0 !important;
}

/* ===================================================================
   БОКОВОЕ МЕНЮ
   =================================================================== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 250px;
    height: 100vh;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 1020;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--dark);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-brand:hover {
    color: var(--green);
}

.sidebar-brand i {
    color: var(--green);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0;
}

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-item {
    margin: 0.15rem 0.5rem;
}

.sidebar-item.active .sidebar-link {
    background: rgba(145, 196, 153, 0.15);
    color: var(--green);
    font-weight: 600;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.65rem 1rem;
    border-radius: 8px;
    color: var(--gray);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.sidebar-link:hover {
    background: var(--cream);
    color: var(--dark);
}

.sidebar-has-sub > .sidebar-sub-toggle {
    width: 100%;
    border: 0;
    background: transparent;
    cursor: pointer;
    text-align: left;
    font: inherit;
    color: inherit;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.sidebar-sub {
    list-style: none;
    margin: 0;
    padding: 0 0 0.35rem 1rem;
    display: none;
}
.sidebar-has-sub.open > .sidebar-sub { display: block; }
.sidebar-sub-link {
    display: block;
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    color: inherit;
    text-decoration: none;
    font-size: 0.88rem;
}
.sidebar-sub-item.active .sidebar-sub-link {
    font-weight: 600;
    background: rgba(145, 196, 153, 0.2);
}

.sidebar-link i {
    width: 20px;
    text-align: center;
    font-size: 0.95rem;
}

.sidebar-divider {
    padding: 0.75rem 1.25rem 0.25rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

/* Мессенджер — внизу сайдбара, над профилем */
.sidebar-messenger {
    border-top: 1px solid var(--border-color);
    padding: 0.4rem 0.5rem;
}
.sidebar-messenger-link {
    font-weight: 600;
    color: #229ED9 !important;
}
.sidebar-messenger-link:hover {
    background: rgba(34, 158, 217, 0.1) !important;
    color: #1a7fb0 !important;
}
.sidebar-messenger-link.active {
    background: rgba(34, 158, 217, 0.15) !important;
    color: #1a7fb0 !important;
}

.sidebar-footer {
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-bottom: 0.5rem;
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--green);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

.sidebar-user-info strong {
    display: block;
    font-size: 0.85rem;
    color: var(--dark);
    line-height: 1.2;
}

.sidebar-user-info small {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.sidebar-theme-toggle {
    display: flex;
    justify-content: center;
    margin-bottom: 0.5rem;
}

.sidebar-logout {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    color: #e74c3c;
    text-decoration: none;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.sidebar-logout:hover {
    background: rgba(231, 76, 60, 0.1);
    color: #c0392b;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1010;
}

.sidebar-overlay.show {
    display: block;
}

.main-content {
    margin-left: 250px;
    min-height: 100vh;
    background: var(--bg);
    transition: margin-left 0.3s ease;
}

.top-bar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.hamburger {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--dark);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
}

.hamburger:hover {
    background: var(--cream);
}

.top-bar-title {
    font-weight: 600;
    color: var(--dark);
    font-size: 0.95rem;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    width: 52px;
    height: 26px;
}

.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.theme-slider {
    position: absolute;
    inset: 0;
    background: var(--cream);
    border-radius: 26px;
    border: 1px solid var(--border-color);
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 6px;
}

.theme-slider i {
    font-size: 0.7rem;
    color: var(--text-muted);
    z-index: 1;
}

.theme-slider::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--green);
    transition: transform 0.3s;
    left: 2px;
    z-index: 2;
}

.theme-switch input:checked + .theme-slider::before {
    transform: translateX(26px);
}

.theme-switch-sm {
    width: 42px;
    height: 22px;
}

.theme-switch-sm .theme-slider::before {
    width: 16px;
    height: 16px;
}

.theme-switch-sm input:checked + .theme-slider::before {
    transform: translateX(20px);
}

.theme-switch-sm .theme-slider {
    padding: 0 4px;
}

.theme-switch-sm .theme-slider i {
    font-size: 0.6rem;
}

/* --- Pagination --- */
.page-link {
    border-radius: 8px !important;
    border: 1px solid var(--border-color);
    color: var(--gray);
    background: var(--bg-card);
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.page-link:hover {
    background: var(--cream);
    color: var(--dark);
    border-color: var(--sage);
}

.page-item.active .page-link {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}

.page-item.disabled .page-link {
    opacity: 0.4;
    pointer-events: none;
}

.form-label {
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--gray);
    margin-bottom: 0.3rem;
}

/* ===================================================================
   УЛУЧШЕНИЯ АДАПТИВНОСТИ ДАШБОРДА
   =================================================================== */

/* --- 5 стат-карточек в один ряд --- */
.stats-row-5 .stat-card {
    padding: 0.7rem 0.6rem;
}

.stats-row-5 .stat-icon {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
}

.stats-row-5 .stat-value {
    font-size: 1.2rem;
}

.stats-row-5 .stat-label {
    font-size: 0.65rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 768px) {
    .stats-row-5 .stat-col {
        flex: 0 0 33.333%;
        max-width: 33.333%;
    }
    .stats-row-5 .stat-card {
        padding: 0.6rem 0.5rem;
    }
    .stats-row-5 .stat-value {
        font-size: 1rem;
    }
    .stats-row-5 .stat-label {
        font-size: 0.6rem;
    }
    .stats-row-5 .stat-icon {
        width: 28px;
        height: 28px;
        font-size: 0.8rem;
    }
}

@media (max-width: 420px) {
    .stats-row-5 .stat-col {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

/* --- Чарты --- */
.chart-body {
    position: relative;
    min-height: 220px;
}

.chart-wrapper {
    position: relative;
    width: 100%;
    height: 250px;
}

.chart-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
}

@media (max-width: 576px) {
    .chart-wrapper {
        height: 200px;
    }
    .chart-body {
        min-height: 180px;
    }
}

/* --- Быстрые ссылки --- */
.quick-links-row .quick-link-card {
    transition: all 0.2s;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
}

.quick-links-row .quick-link-card:hover {
    border-color: var(--green);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.quick-link-icon {
    font-size: 1.6rem;
    margin-bottom: 0.4rem;
}

.quick-links-row h6 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 0.2rem;
}

@media (max-width: 576px) {
    .quick-link-icon {
        font-size: 1.3rem;
    }
    .quick-links-row h6 {
        font-size: 0.78rem;
    }
    .quick-links-row .card-crm {
        padding: 0.65rem !important;
    }
}

/* --- Подсказка на графике --- */
.dash-hint {
    font-size: 0.72rem;
    opacity: 0.7;
    font-style: italic;
}

/* --- Модальное окно детали дня --- */
.day-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.day-stat-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    background: var(--cream);
    padding: 0.7rem 0.85rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.day-stat-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.day-stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    line-height: 1.2;
}

.day-stat-value {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--dark);
    line-height: 1.2;
}

.day-total-row {
    text-align: center;
    padding: 0.6rem;
    background: var(--cream);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.85rem;
}

.day-total-row strong {
    font-size: 1.1rem;
    color: var(--dark);
    margin-left: 0.3rem;
}

.modal-crm .modal-content {
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
}

.modal-crm .modal-header {
    border-bottom: 1px solid var(--border-color);
    padding: 0.85rem 1.15rem;
}

.modal-crm .modal-header .modal-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--dark);
}

.modal-crm .modal-body {
    padding: 1.15rem;
}

.modal-crm .modal-footer {
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1.15rem;
}

.modal-crm .btn-close {
    filter: none;
}

body.dark-theme .day-stat-item {
    background: var(--cream);
    border-color: var(--border-color);
}

body.dark-theme .day-total-row {
    background: var(--cream);
    border-color: var(--border-color);
}

/* --- Адаптивная таблица клиентов (без keep-head) --- */
@media (max-width: 768px) {
    .table-crm:not(.table-crm-keep-head) thead {
        display: none;
    }

    .table-crm:not(.table-crm-keep-head) tbody tr {
        display: block;
        padding: 0.75rem;
        border-bottom: 1px solid var(--border-color);
    }

    .table-crm:not(.table-crm-keep-head) tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.35rem 0;
        border: none;
        font-size: 0.82rem;
    }

    .table-crm:not(.table-crm-keep-head) tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--gray);
        font-size: 0.75rem;
        text-transform: uppercase;
        margin-right: 0.5rem;
    }

    .table-crm:not(.table-crm-keep-head) tbody td:last-child {
        border-bottom: none;
    }
}

/* sheet-table: шапка + первая колонка липкие при скролле */
.sheet-table thead th {
    z-index: 5;
}
.sheet-table th:first-child,
.sheet-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #fff;
    box-shadow: 1px 0 0 #e0e0e0;
}
.sheet-table thead th:first-child {
    z-index: 7;
    background: #e8f0fe;
}
body.dark-theme .sheet-table th:first-child,
body.dark-theme .sheet-table td:first-child {
    background: var(--bg-card, #1e2220);
}
body.dark-theme .sheet-table thead th:first-child {
    background: #1a2a40;
}

/* --- Адаптация для очень маленьких экранов --- */
@media (max-width: 400px) {
    .stat-card {
        padding: 0.75rem;
    }
    .stat-card .stat-value {
        font-size: 1.1rem;
    }
    .stat-card .stat-icon {
        width: 32px;
        height: 32px;
        font-size: 0.95rem;
    }
    .navbar-brand {
        font-size: 1rem !important;
    }
    .top-bar-title {
        font-size: 0.82rem;
    }
    .day-stats-grid {
        grid-template-columns: 1fr;
    }
}

/* --- Адаптация фильтров на странице клиентов --- */
@media (max-width: 768px) {
    .card-crm .row.g-2 input,
    .card-crm .row.g-2 select {
        font-size: 0.82rem;
    }
}

/* --- Отзывчивый контейнер для очень широких экранов --- */
@media (min-width: 1600px) {
    .container-fluid.p-4 {
        max-width: 1400px;
        margin: 0 auto;
    }
}

/* --- Анимация появления --- */
@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal.fade .modal-dialog {
    animation: fadeSlideUp 0.25s ease;
}
