/* ============================================
   SuperNova CRM - Design System & Styles
   ============================================ */

/* --- CSS Variables --- */
:root {
    --bg: #0f1923;
    --bg-card: #172a3a;
    --bg-sidebar: #0d1520;
    --bg-header: #0d1520;
    --blue: #4361ee;
    --blue-hover: #3651de;
    --green: #22c55e;
    --green-bg: rgba(34, 197, 94, 0.12);
    --yellow: #f59e0b;
    --yellow-bg: rgba(245, 158, 11, 0.12);
    --red: #ef4444;
    --red-bg: rgba(239, 68, 68, 0.12);
    --purple: #a855f7;
    --purple-bg: rgba(168, 85, 247, 0.12);
    --blue-bg: rgba(67, 97, 238, 0.12);
    --text: #e8e8e8;
    --text2: #8899aa;
    --text3: #5a6a7a;
    --border: #1e3348;
    --border-hover: #2a4a68;
    --radius-card: 12px;
    --radius-btn: 8px;
    --radius-input: 8px;
    --header-h: 56px;
    --sidebar-w: 220px;
    --sidebar-collapsed-w: 60px;
    --side-panel-w: 420px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --shadow: 0 2px 8px rgba(0,0,0,0.25);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --transition: 0.2s ease;
    --bg-hover: rgba(255,255,255,0.04);
    --bg-elevated: rgba(255,255,255,0.06);
    --bg-elevated-hover: rgba(255,255,255,0.1);
    --bg-thead: rgba(13, 21, 32, 0.95);
    --skeleton-mid: #1e3348;
    --spring: cubic-bezier(0.16, 1, 0.3, 1);
    /* Aliases (используются в index.html модалке поиска) */
    --bg-primary: var(--bg);
    --bg-secondary: var(--bg-card);
    --border-color: var(--border);
    --text-primary: var(--text);
    --text-secondary: var(--text2);
    color-scheme: dark;
}

/* --- Light Theme (голубовато-серый фон + белые карточки с тенями, по мотивам Bitrix24/Linear) --- */
html[data-theme="light"] {
    --bg: #e4ebf4;
    --bg-card: #ffffff;
    --bg-sidebar: #fafcfe;
    --bg-header: #fbfdff;
    --blue: #3b5bdb;
    --blue-hover: #2f4bc7;
    --text: #1c2b3a;
    --text2: #5a6b7d;
    --text3: #8fa0b3;
    --border: #d9e2ee;
    --border-hover: #aebfd4;
    --shadow: 0 1px 2px rgba(30, 54, 90, 0.06), 0 4px 14px -4px rgba(30, 54, 90, 0.10);
    --shadow-lg: 0 12px 40px -8px rgba(30, 54, 90, 0.25);
    --bg-hover: rgba(59, 91, 219, 0.055);
    --bg-elevated: rgba(43, 71, 138, 0.06);
    --bg-elevated-hover: rgba(43, 71, 138, 0.11);
    --bg-thead: #f2f6fb;
    --skeleton-mid: #dfe7f1;
    --green-bg: rgba(22, 163, 74, 0.1);
    --yellow-bg: rgba(217, 119, 6, 0.1);
    --red-bg: rgba(220, 38, 38, 0.08);
    --purple-bg: rgba(147, 51, 234, 0.08);
    --blue-bg: rgba(59, 91, 219, 0.08);
    --green: #16a34a;
    --yellow: #d97706;
    --red: #dc2626;
    --purple: #9333ea;
    color-scheme: light;
}
/* Светлая тема: голубоватый градиентный фон рабочей области */
html[data-theme="light"] body {
    background: #e4ebf4;
}
html[data-theme="light"] .main-content {
    background: linear-gradient(168deg, #eaf0f8 0%, #e1eaf4 45%, #e6edf6 100%);
}
/* Sidebar и header: лёгкий вертикальный градиент + тень отделяют от фона */
html[data-theme="light"] .sidebar {
    background: linear-gradient(180deg, #fdfeff 0%, #f6f9fd 100%);
    box-shadow: 1px 0 12px rgba(30, 54, 90, 0.06);
}
html[data-theme="light"] .header {
    background: rgba(252, 253, 255, 0.88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 1px 10px rgba(30, 54, 90, 0.07);
}
/* Карточки: едва заметный градиент + слоистая тень вместо плоского белого.
   [style*=…] покрывает inline-стили из JS-страниц; !important нужен, т.к. inline background сбрасывает background-image */
html[data-theme="light"] .stat-card,
html[data-theme="light"] .table-wrapper,
html[data-theme="light"] .funnel-pipeline,
html[data-theme="light"] .kanban-card,
html[data-theme="light"] [style*="background:var(--bg-card)"],
html[data-theme="light"] [style*="background: var(--bg-card)"] {
    background-image: linear-gradient(180deg, #ffffff 0%, #fafcfe 100%) !important;
    box-shadow: 0 1px 2px rgba(30, 54, 90, 0.05), 0 8px 24px -12px rgba(30, 54, 90, 0.18);
}
html[data-theme="light"] .stat-card:hover,
html[data-theme="light"] .kanban-card:hover {
    box-shadow: 0 2px 4px rgba(30, 54, 90, 0.07), 0 14px 34px -12px rgba(30, 54, 90, 0.28);
}
/* Модалки и боковые панели: выразительная тень */
html[data-theme="light"] .modal-content,
html[data-theme="light"] .side-panel {
    box-shadow: 0 24px 64px -12px rgba(30, 54, 90, 0.35);
}
/* Кнопки: primary с голубым свечением, secondary с мягкой тенью */
html[data-theme="light"] .btn-primary {
    box-shadow: 0 2px 8px rgba(59, 91, 219, 0.30);
}
html[data-theme="light"] .btn-primary:hover {
    box-shadow: 0 4px 12px rgba(59, 91, 219, 0.40);
}
html[data-theme="light"] .btn-secondary {
    box-shadow: 0 1px 2px rgba(30, 54, 90, 0.08);
}
/* Таблицы: голубоватая шапка, чуть заметная граница снизу */
html[data-theme="light"] thead th {
    background: var(--bg-thead);
    border-bottom: 1px solid #dce5f0;
}
/* Инпуты/селекты: внутренняя лёгкая тень, белый фон */
html[data-theme="light"] input,
html[data-theme="light"] select,
html[data-theme="light"] textarea {
    box-shadow: inset 0 1px 2px rgba(30, 54, 90, 0.05);
}
html[data-theme="light"] input:focus,
html[data-theme="light"] select:focus,
html[data-theme="light"] textarea:focus {
    box-shadow: inset 0 1px 2px rgba(30, 54, 90, 0.04), 0 0 0 3px rgba(59, 91, 219, 0.12);
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    touch-action: pan-x pan-y;
}

a {
    color: var(--blue);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

h1, h2, h3, h4 {
    font-weight: 600;
    line-height: 1.3;
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }

img {
    max-width: 100%;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text3);
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

/* --- Login Page --- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 48px 40px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    max-width: 400px;
    width: 90%;
    animation: fadeSlideIn 0.5s ease-out;
}

.login-logo img {
    margin-bottom: 16px;
    animation: float 3s ease-in-out infinite;
}

.login-logo h1 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.login-logo p {
    color: var(--text2);
    margin-bottom: 32px;
}

#telegram-login-widget {
    display: flex;
    justify-content: center;
}

/* --- Telegram "Open in browser" bar --- */
.tg-browser-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 32px;
    background: var(--blue);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.tg-browser-link {
    color: #fff !important;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
}
.tg-browser-bar ~ .header { top: 32px; }
.tg-browser-bar ~ .sidebar { top: calc(var(--header-h) + 32px); height: calc(100vh - var(--header-h) - 32px); }
.tg-browser-bar ~ .sidebar-overlay { top: calc(var(--header-h) + 32px); }
.tg-browser-bar ~ .content { margin-top: calc(var(--header-h) + 32px); height: calc(100vh - var(--header-h) - 32px); }

/* --- Header --- */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-h);
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    gap: 8px;
    z-index: 100;
    overflow: hidden;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-shrink: 0;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo-text {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-shrink: 0;
    justify-content: flex-end;
}

.user-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.3;
}

.user-name {
    font-weight: 600;
    font-size: 0.875rem;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text2);
    text-transform: capitalize;
}

.btn-logout {
    color: var(--text2);
    padding: 6px;
    border-radius: var(--radius-btn);
}
.btn-logout:hover {
    color: var(--red);
    background: var(--red-bg);
}

/* Burger */
.burger-btn {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-btn);
}
.burger-btn span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text);
    border-radius: 1px;
    transition: var(--transition);
}
.burger-btn:hover {
    background: var(--bg-hover);
}

/* Rates Widget */
.rates-widget {
    display: flex;
    gap: 16px;
    font-size: 0.825rem;
    color: var(--text2);
}

.rate-item {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.rate-label {
    color: var(--text3);
    font-weight: 500;
}

.rate-value {
    color: var(--text);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 90;
    transition: width var(--transition), transform var(--transition);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 12px 8px;
    gap: 2px;
}

.nav-section-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text3);
    padding: 16px 16px 6px;
    margin-top: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-btn);
    color: var(--text2);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: background var(--transition), color var(--transition), padding-left var(--transition);
    white-space: nowrap;
    overflow: hidden;
    position: relative;
}

.nav-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 3px;
    height: 0;
    background: var(--blue);
    transition: height 0.2s, top 0.2s;
    border-radius: 0 3px 3px 0;
}

.nav-item.active::before {
    height: 60%;
    top: 20%;
}

.nav-item:hover .nav-icon {
    transform: scale(1.15);
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text);
    text-decoration: none;
}

.nav-item.active {
    background: var(--blue-bg);
    color: var(--blue);
}

.nav-item.active .nav-icon {
    stroke: var(--blue);
}

.nav-icon {
    flex-shrink: 0;
    transition: transform 0.2s;
}

.nav-text {
    transition: opacity var(--transition);
}

.nav-item[style*="display: none"] {
    display: none !important;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 85;
}

/* --- Content Area --- */
.content {
    margin-left: var(--sidebar-w);
    margin-top: var(--header-h);
    padding: 24px;
    height: calc(100vh - var(--header-h));
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    transition: margin-left var(--transition);
}

.content > * {
    animation: fadeSlideIn 0.3s ease-out;
}

/* --- Sub-tabs --- */
.sub-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.sub-tab {
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text2);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.2s, border-color 0.3s, background 0.2s;
}
.sub-tab:hover:not(.active) {
    color: var(--text);
    background: rgba(67,97,238,0.05);
}
.sub-tab:hover { color: var(--text); }
.sub-tab.active {
    color: var(--blue);
    border-bottom-color: var(--blue);
}
/* sub-content: first child visible, rest hidden via inline style in JS */

/* --- Week/Month Navigation --- */
.week-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.week-nav-label {
    font-size: 14px;
    font-weight: 600;
    min-width: 180px;
    text-align: center;
}
.week-nav-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    color: var(--text);
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
}
.week-nav-btn:hover { border-color: var(--blue); }

/* --- Calendar Grid --- */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}
.calendar-header-cell {
    text-align: center;
    font-size: 11px;
    color: var(--text2);
    padding: 6px 0;
    text-transform: uppercase;
}
.calendar-cell {
    background: var(--bg-card);
    border-radius: 6px;
    min-height: 60px;
    padding: 6px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: border-color 0.2s;
}
.calendar-cell:hover { border-color: var(--border-hover); }
.calendar-cell.today { border-color: var(--blue); }
.calendar-cell.other-month { opacity: 0.3; }
.calendar-day { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.calendar-badge {
    background: var(--blue-bg);
    color: var(--blue);
    font-size: 10px;
    font-weight: 600;
    border-radius: 4px;
    padding: 1px 5px;
    display: inline-block;
}

/* --- Distribution Panels --- */
.distrib-panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.distrib-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 16px;
}
.distrib-panel h4 {
    margin: 0 0 12px;
    font-size: 14px;
    font-weight: 600;
}
.distrib-panel .field { margin-bottom: 10px; }
.distrib-panel .field label {
    display: block;
    font-size: 11px;
    color: var(--text2);
    margin-bottom: 4px;
}

/* --- Page Header --- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 {
    font-size: 1.5rem;
}

.page-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* --- Stat Cards Grid --- */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}
.stat-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.stat-card-label {
    font-size: 0.8rem;
    color: var(--text2);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.stat-card-sub {
    font-size: 0.8rem;
    color: var(--text2);
}

.stat-card-change {
    font-size: 0.8rem;
    font-weight: 600;
}
.stat-card-change.positive { color: var(--green); }
.stat-card-change.negative { color: var(--red); }

.stat-card.clickable {
    cursor: pointer;
}
.stat-card.clickable:hover {
    border-color: var(--blue);
    box-shadow: 0 8px 24px rgba(67,97,238,0.15);
}

/* --- Alert Cards --- */
.alert-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.alert-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: border-color var(--transition);
}
.alert-card:hover {
    border-color: var(--border-hover);
}

.alert-card-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.alert-card-text {
    flex: 1;
}

.alert-card-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.alert-card-desc {
    font-size: 0.8rem;
    color: var(--text2);
}

.alert-card.alert-warning {
    border-left: 3px solid var(--yellow);
}
.alert-card.alert-danger {
    border-left: 3px solid var(--red);
}
.alert-card.alert-info {
    border-left: 3px solid var(--blue);
}

/* --- Tables --- */
.table-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    overflow: hidden;
    margin-bottom: 24px;
}

.table-scroll {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

thead {
    position: sticky;
    top: 0;
    z-index: 5;
}

thead th {
    background: var(--bg-thead);
    padding: 12px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--text2);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    cursor: default;
    user-select: none;
}

thead th.sortable {
    cursor: pointer;
}
thead th.sortable:hover {
    color: var(--text);
}

thead th .sort-icon {
    display: inline-block;
    margin-left: 4px;
    opacity: 0.3;
    font-size: 0.7rem;
}
thead th.sort-asc .sort-icon,
thead th.sort-desc .sort-icon {
    opacity: 1;
    color: var(--blue);
}

tbody tr {
    border-bottom: 1px solid rgba(30, 51, 72, 0.5);
    transition: background 0.15s, box-shadow 0.15s;
}

tbody tr:hover {
    background: var(--bg-hover);
    box-shadow: inset 3px 0 0 var(--blue);
}

tbody tr.clickable {
    cursor: pointer;
}
tbody tr.clickable:hover {
    background: rgba(67, 97, 238, 0.06);
}

tbody td {
    padding: 10px 14px;
    vertical-align: middle;
    white-space: nowrap;
}

tbody td.wrap {
    white-space: normal;
    max-width: 250px;
}

.table-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text2);
}

/* Checkbox in table */
.row-checkbox {
    width: 16px;
    height: 16px;
    accent-color: var(--blue);
    cursor: pointer;
}

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    transition: transform 0.15s;
}

.badge:hover {
    transform: scale(1.05);
}

.badge-green {
    background: var(--green-bg);
    color: var(--green);
}
.badge-yellow {
    background: var(--yellow-bg);
    color: var(--yellow);
}
.badge-red {
    background: var(--red-bg);
    color: var(--red);
}
.badge-blue {
    background: var(--blue-bg);
    color: var(--blue);
}
.badge-purple {
    background: var(--purple-bg);
    color: var(--purple);
}
.badge-gray {
    background: rgba(136, 153, 170, 0.12);
    color: var(--text2);
}

/* --- Buttons --- */
button, .btn {
    font-family: var(--font);
    font-size: 0.85rem;
    cursor: pointer;
    border: none;
    outline: none;
    transition: all var(--transition);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-btn);
    font-weight: 500;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(67,97,238,0.3);
}

.btn:active {
    transform: translateY(1px);
    box-shadow: none;
}

.btn-primary {
    background: var(--blue);
    color: #fff;
}
.btn-primary:hover {
    background: var(--blue-hover);
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover {
    background: var(--bg-elevated-hover);
    border-color: var(--border-hover);
}

.btn-danger {
    background: var(--red);
    color: #fff;
}
.btn-danger:hover {
    background: #dc2626;
}

.btn-ghost {
    background: transparent;
    color: var(--text2);
    border: none;
}
.btn-ghost:hover {
    background: var(--bg-elevated);
    color: var(--text);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.78rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn.loading {
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
    position: relative;
}

.btn.loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    animation: btnShimmer 1.5s infinite;
}

.btn.loading::before {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 6px;
}

/* --- Inputs & Selects --- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.form-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text2);
}

input[type="text"],
input[type="search"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="email"],
input[type="tel"],
textarea,
select {
    font-family: var(--font);
    font-size: 0.85rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-input);
    padding: 8px 12px;
    outline: none;
    transition: border-color var(--transition);
    width: 100%;
}

/* Date/time picker styling for dark theme */
input[type="date"],
input[type="time"] {
    cursor: pointer;
    position: relative;
    min-height: 36px;
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
    filter: invert(0.7);
    cursor: pointer;
    padding: 4px;
    margin: 0;
}
/* Firefox */
input[type="date"]::-moz-calendar-picker-indicator,
input[type="time"]::-moz-calendar-picker-indicator {
    filter: invert(0.7);
}
/* Color scheme for dark mode picker popup */
input[type="date"],
input[type="time"] {
    color-scheme: dark;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(67,97,238,0.15);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input::placeholder, textarea::placeholder {
    color: var(--text3);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%238899aa' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* Inline edit */
.inline-edit {
    background: transparent;
    border: 1px solid transparent;
    padding: 4px 6px;
    border-radius: 4px;
    color: var(--text);
    width: 100%;
    min-width: 80px;
}
.inline-edit:hover {
    border-color: var(--border);
}
.inline-edit:focus {
    background: var(--bg);
    border-color: var(--blue);
}

/* --- Filters Bar --- */
.filters-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filters-bar input[type="search"],
.filters-bar input[type="text"] {
    max-width: 260px;
}

.filters-bar select {
    max-width: 180px;
}

.filter-count {
    font-size: 0.8rem;
    color: var(--text2);
    margin-left: auto;
}

/* --- Modals --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    animation: modalFadeIn 0.2s ease forwards;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-lg);
    max-width: 560px;
    width: 90%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.3s var(--spring) forwards;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.1rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text2);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    border-radius: 4px;
}
.modal-close:hover {
    color: var(--text);
    background: var(--bg-elevated);
}

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* --- Side Panel --- */
.side-panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 150;
    display: none;
    opacity: 0;
    transition: opacity var(--transition);
}
.side-panel-overlay.visible {
    display: block;
    opacity: 1;
}

.side-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--side-panel-w);
    max-width: 100vw;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    z-index: 160;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.35s var(--spring);
    box-shadow: var(--shadow-lg);
}
.side-panel.open {
    transform: translateX(0);
}

.side-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.side-panel-title {
    font-size: 1.05rem;
    font-weight: 600;
}

.side-panel-close {
    font-size: 1.5rem;
    color: var(--text2);
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
}
.side-panel-close:hover {
    color: var(--text);
}

.side-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    top: 72px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    padding: 12px 20px;
    font-size: 0.85rem;
    color: var(--text);
    box-shadow: var(--shadow);
    pointer-events: auto;
    min-width: 280px;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastIn 0.4s var(--spring) forwards;
    cursor: pointer;
}

.toast.toast-out {
    animation: toastOut 0.3s ease-in forwards;
}

.toast-close {
    flex-shrink: 0;
    margin-left: auto;
    font-size: 1.2rem;
    color: var(--text2);
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.15s;
}
.toast-close:hover {
    opacity: 1;
    color: var(--text);
}

.toast-message {
    white-space: pre-line; /* переносы \n в тексте тоста (например, номер карусели) */
}

.toast-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
}

.toast.toast-success {
    border-left: 3px solid var(--green);
}
.toast.toast-success .toast-icon {
    background: var(--green-bg);
    color: var(--green);
}

.toast.toast-error {
    border-left: 3px solid var(--red);
}
.toast.toast-error .toast-icon {
    background: var(--red-bg);
    color: var(--red);
}

.toast.toast-warning {
    border-left: 3px solid var(--yellow);
}
.toast.toast-warning .toast-icon {
    background: var(--yellow-bg);
    color: var(--yellow);
}

.toast.toast-info {
    border-left: 3px solid var(--blue);
}
.toast.toast-info .toast-icon {
    background: var(--blue-bg);
    color: var(--blue);
}

/* --- Funnel / Pipeline --- */
/* Funnel — compact pipeline */
.funnel-pipeline {
    display: flex;
    align-items: stretch;
    gap: 0;
    margin-bottom: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 12px 8px;
    overflow-x: auto;
}
.funnel-pipeline::-webkit-scrollbar { display: none; }

.funnel-stage {
    flex: 1;
    min-width: 0;
    padding: 0 10px;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
    border-radius: var(--radius-btn);
}
.funnel-stage:hover {
    background: var(--bg-hover);
}

.funnel-stage-top {
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin-bottom: 4px;
}
.funnel-stage-count {
    font-size: 1.1rem;
    font-weight: 800;
    line-height: 1;
}
.funnel-stage-pct {
    font-size: 0.68rem;
    color: var(--text3);
    font-weight: 600;
}

.funnel-stage-bar-bg {
    height: 4px;
    background: var(--bg-elevated);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 4px;
}
.funnel-stage-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.funnel-stage-label {
    font-size: 0.68rem;
    color: var(--text2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.funnel-stage-arrow {
    position: absolute;
    right: -5px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text3);
    font-size: 1rem;
    opacity: 0.3;
    pointer-events: none;
    z-index: 1;
}

/* Legacy funnel classes (keep for backwards compat) */
.funnel-container { display: flex; gap: 2px; margin-bottom: 24px; border-radius: var(--radius-card); overflow: hidden; }
.funnel-bar { flex: 1; padding: 16px 12px; text-align: center; min-width: 80px; cursor: pointer; }
.funnel-bar-count { font-size: 1.5rem; font-weight: 700; }
.funnel-bar-label { font-size: 0.72rem; margin-top: 4px; opacity: 0.85; }
.funnel-bar-pct { font-size: 0.7rem; opacity: 0.6; margin-top: 2px; }

/* --- Progress Bars --- */
.progress-bar {
    height: 6px;
    background: var(--bg-elevated);
    border-radius: 3px;
    overflow: hidden;
    width: 100%;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.8s var(--spring);
}

.progress-bar-fill.green { background: var(--green); }
.progress-bar-fill.blue { background: var(--blue); }
.progress-bar-fill.yellow { background: var(--yellow); }
.progress-bar-fill.red { background: var(--red); }

.progress-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.progress-label {
    font-size: 0.8rem;
    color: var(--text2);
    min-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.progress-value {
    font-size: 0.8rem;
    font-weight: 600;
    min-width: 50px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* --- Manager Progress (Recovery) — compact cards --- */
.manager-progress-grid {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.mgr-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    padding: 10px 14px;
    text-align: center;
    min-width: 80px;
}
.mgr-card-name {
    font-size: 0.72rem;
    color: var(--text2);
    margin-bottom: 2px;
    white-space: nowrap;
}
.mgr-card-stat {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}
.mgr-card-sep {
    opacity: 0.35;
    font-weight: 400;
}
.mgr-card-pct {
    font-size: 0.7rem;
    font-weight: 600;
}

/* Legacy manager-progress */
.manager-progress {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 20px;
    margin-bottom: 24px;
}
.manager-progress h3 { margin-bottom: 16px; }

/* --- Invoice Timeline --- */
.inv-timeline {
    position: relative;
    padding: 4px 0;
}
.inv-tl-step {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    position: relative;
    padding-bottom: 4px;
}
.inv-tl-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text3);
    flex-shrink: 0;
    z-index: 1;
}
.inv-tl-step.done .inv-tl-dot {
    color: #fff;
    font-size: 0.75rem;
}
.inv-tl-line {
    position: absolute;
    left: 13px;
    top: 28px;
    width: 2px;
    height: calc(100% - 24px);
    background: var(--border);
}
.inv-tl-step.done .inv-tl-line {
    opacity: 0.6;
}
.inv-tl-content {
    flex: 1;
    padding: 4px 0 12px;
}
.inv-tl-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
}
.inv-tl-step:not(.done) .inv-tl-label {
    color: var(--text3);
}
.inv-tl-date {
    font-size: 0.72rem;
    color: var(--text3);
    margin-top: 1px;
}
.inv-tl-step.done .inv-tl-date {
    color: var(--text2);
}

/* --- Loading / Skeleton --- */
.skeleton {
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--skeleton-mid) 50%, var(--bg-card) 75%);
    background-size: 200px 100%;
    animation: skeletonPulse 1.5s ease-in-out infinite;
    border-radius: var(--radius-card);
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    width: 80%;
}

.skeleton-title {
    height: 20px;
    width: 40%;
    margin-bottom: 12px;
}

.skeleton-card {
    height: 100px;
    border-radius: var(--radius-card);
}

.skeleton-row {
    height: 44px;
    margin-bottom: 2px;
}

.spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.spinner::after {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* --- Empty State --- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text2);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-text {
    font-size: 1rem;
    font-weight: 500;
}

.empty-sub {
    font-size: 0.85rem;
    color: var(--text3);
    margin-top: 4px;
}

/* --- Period Selector --- */
.period-selector {
    display: inline-flex;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    overflow: hidden;
}

.period-btn {
    padding: 6px 14px;
    font-size: 0.8rem;
    background: transparent;
    color: var(--text2);
    border: none;
    cursor: pointer;
    font-family: var(--font);
    font-weight: 500;
    transition: all var(--transition);
}
.period-btn:hover:not(.active) {
    background: rgba(67,97,238,0.1);
    color: var(--blue);
}
.period-btn:hover {
    color: var(--text);
}
.period-btn.active {
    background: var(--blue);
    color: #fff;
    box-shadow: 0 2px 8px rgba(67,97,238,0.4);
}

/* --- Bulk Actions --- */
.bulk-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--blue-bg);
    border: 1px solid var(--blue);
    border-radius: var(--radius-btn);
    padding: 8px 16px;
    margin-bottom: 12px;
    font-size: 0.85rem;
    animation: fadeIn 0.2s ease;
}

.bulk-bar .bulk-count {
    font-weight: 600;
    color: var(--blue);
}

/* --- Pagination --- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 16px;
}

.pagination button {
    min-width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text2);
    font-size: 0.8rem;
    font-family: var(--font);
    cursor: pointer;
}
.pagination button:hover {
    background: var(--bg-hover);
    color: var(--text);
}
.pagination button.active {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
}
.pagination button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.pagination-info {
    font-size: 0.8rem;
    color: var(--text2);
    padding: 0 8px;
}

/* --- Timeline (Side Panel) --- */
.timeline {
    position: relative;
    padding-left: 20px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    padding-bottom: 20px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -18px;
    top: 6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border);
    border: 2px solid var(--bg-card);
}

.timeline-item.current::before {
    background: var(--blue);
}

.timeline-date {
    font-size: 0.72rem;
    color: var(--text3);
    margin-bottom: 4px;
}

.timeline-content {
    font-size: 0.85rem;
}

.timeline-status {
    font-weight: 600;
}

/* --- Comments --- */
.comment-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 16px;
}

.comment-item {
    background: var(--bg);
    border-radius: var(--radius-btn);
    padding: 12px;
}

.comment-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
}

.comment-author {
    font-size: 0.8rem;
    font-weight: 600;
}

.comment-date {
    font-size: 0.72rem;
    color: var(--text3);
}

.comment-text {
    font-size: 0.85rem;
    color: var(--text2);
    line-height: 1.5;
}

.comment-form {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.comment-form textarea {
    flex: 1;
    min-height: 60px;
}

/* --- Section within panels/cards --- */
.section-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 12px;
    margin-top: 24px;
}

.section-title:first-child {
    margin-top: 0;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(30,51,72,0.3);
    font-size: 0.85rem;
}

.detail-label {
    color: var(--text2);
}

.detail-value {
    font-weight: 500;
    text-align: right;
}

.detail-grid {
    display: flex;
    flex-direction: column;
}

/* Доп. контактные лица в блоке «Контакты» карточки лида */
.contact-person .detail-row:last-child { border-bottom: none; }

/* Красивая модалка-подтверждение */
.confirm-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    width: 92%;
    max-width: 340px;
    padding: 28px 24px 22px;
    text-align: center;
    animation: modalSlideIn 0.3s var(--spring) forwards;
}
.confirm-icon {
    width: 52px;
    height: 52px;
    margin: 0 auto 14px;
    border-radius: 50%;
    background: rgba(229, 72, 77, 0.12);
    color: var(--red, #e5484d);
    display: flex;
    align-items: center;
    justify-content: center;
}
.confirm-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 10px;
}
.confirm-name {
    font-size: 0.95rem;
    font-weight: 600;
    margin-top: 2px;
}
.confirm-text {
    font-size: 0.8rem;
    color: var(--text2);
    margin-top: 10px;
}
.confirm-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}
.confirm-actions .btn {
    flex: 1;
    height: 40px;
    border-radius: 10px;
    font-size: 0.9rem;
    justify-content: center;
}
.contact-role {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--blue, #3b82f6);
    opacity: 0.85;
    margin-bottom: 2px;
}
#contacts-card > .detail-grid .detail-row:last-child { border-bottom: none; }

.tab-count {
    font-size: 0.7rem;
    background: var(--bg-card);
    color: var(--text2);
    padding: 1px 7px;
    border-radius: 999px;
    margin-left: 4px;
    font-weight: 600;
    vertical-align: middle;
}
.sub-tab.active .tab-count {
    background: rgba(67,97,238,0.15);
    color: var(--blue);
}

/* --- Tooltip --- */
.has-tooltip {
    position: relative;
    cursor: pointer;
}
.has-tooltip[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 0;
    top: calc(100% + 6px);
    z-index: 50;
    background: #1a2a3a;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.78rem;
    font-weight: 400;
    white-space: pre-wrap;
    max-width: 280px;
    min-width: 140px;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
    line-height: 1.4;
}

.tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--blue);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    margin-left: 6px;
    vertical-align: middle;
    line-height: 1;
}
.sub-tab:not(.active) .tab-badge {
    background: #3a4a5c;
    color: var(--text2);
}

/* --- Animations --- */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes toastIn {
    from { transform: translateX(120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes toastOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(120%); opacity: 0; }
}

@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes barGrow {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
}

@keyframes btnShimmer {
    from { transform: translateX(-100%); }
    to { transform: translateX(100%); }
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: scale(0.95) translateY(-20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes skeletonPulse {
    0% { background-position: -200px 0; }
    100% { background-position: calc(200px + 100%) 0; }
}

@keyframes countUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Stat card value count-up animation on load */
.stat-card-value {
    animation: countUp 0.4s ease-out;
}

/* --- Responsive --- */

/* Collapsed sidebar (tablet) */
@media (max-width: 1024px) {
    .sidebar {
        width: var(--sidebar-collapsed-w);
    }
    .sidebar .nav-text {
        display: none;
    }
    .sidebar .nav-section-title {
        display: none;
    }
    .sidebar .nav-item {
        justify-content: center;
        padding: 10px;
    }
    .content {
        margin-left: var(--sidebar-collapsed-w);
    }
}

/* Mobile */
@media (max-width: 768px) {
    .burger-btn {
        display: flex;
    }

    .sidebar {
        width: var(--sidebar-w);
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar.open + .sidebar-overlay,
    .sidebar-overlay.visible {
        display: block;
    }

    .sidebar .nav-text {
        display: inline;
    }

    .sidebar .nav-item {
        justify-content: flex-start;
        padding: 10px 12px;
    }

    .content {
        margin-left: 0;
        padding: 12px 8px;
    }

    .header-logo-text {
        display: none;
    }

    .rates-widget {
        display: none;
    }

    .user-name {
        display: none;
    }

    /* Page header */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 12px;
    }
    .page-header h1 {
        font-size: 1.15rem;
    }
    .page-header-actions {
        width: 100%;
    }
    .page-header-actions .btn {
        flex: 1;
        font-size: 12px;
        padding: 0 12px;
    }

    /* Sub-tabs: horizontal scroll, compact */
    .sub-tabs {
        gap: 0;
        margin-bottom: 12px;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
    .sub-tabs::-webkit-scrollbar { display: none; }
    .sub-tab {
        padding: 8px 12px;
        font-size: 12px;
        flex-shrink: 0;
    }

    /* Filters: stack vertically */
    .filters-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 6px !important;
    }
    .filters-bar input,
    .filters-bar select {
        max-width: 100% !important;
        width: 100% !important;
        min-width: 0 !important;
        font-size: 13px;
    }

    /* Stat cards */
    .stat-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .stat-card {
        padding: 12px;
    }
    .stat-card-value {
        font-size: 1.2rem;
    }

    /* Tables */
    .table-wrapper {
        border-radius: 8px;
        margin-bottom: 12px;
    }
    table {
        font-size: 0.78rem;
    }
    thead th {
        padding: 8px 6px;
        font-size: 0.7rem;
    }
    tbody td {
        padding: 8px 6px;
    }
    td.wrap {
        min-width: 140px;
    }

    /* Inline selects in tables */
    .inline-edit, .pipeline-status-select {
        min-width: 100px !important;
        font-size: 11px !important;
        height: 28px !important;
    }

    /* Action buttons in tables */
    .btn-sm {
        font-size: 11px !important;
        padding: 0 8px !important;
        height: 26px !important;
    }

    /* Side panel */
    .side-panel {
        width: 100vw;
    }

    /* Modal */
    .modal-content {
        width: 95%;
        max-width: none;
        max-height: 90vh;
        margin: 5vh auto;
        border-radius: 12px;
    }
    .modal-content .form-group {
        margin-bottom: 10px;
    }

    /* Funnel */
    .funnel-container {
        flex-wrap: wrap;
    }
    .funnel-bar {
        min-width: calc(33% - 2px);
    }
    .funnel-pipeline {
        gap: 0;
        padding: 8px 4px;
        flex-wrap: wrap;
    }
    .funnel-stage {
        padding: 0 4px;
        flex: 1 1 30%;
        min-width: 0;
    }
    .funnel-stage-count {
        font-size: 0.9rem;
    }
    .funnel-stage-label {
        font-size: 0.6rem;
    }

    /* Pagination */
    .page-btn {
        min-width: 28px !important;
        height: 28px !important;
        padding: 0 4px !important;
        font-size: 11px !important;
    }

    /* Detail grid in side panel */
    .detail-grid {
        font-size: 0.82rem;
    }
    .detail-label {
        min-width: 80px;
    }

    /* Toast on mobile */
    .toast-container {
        left: 8px;
        right: 8px;
        top: auto;
        bottom: 12px;
    }
    .toast {
        min-width: auto;
    }
}

@media (max-width: 480px) {
    .stat-cards {
        grid-template-columns: 1fr;
    }
    .content {
        padding: 8px 6px;
    }
    .page-header h1 {
        font-size: 1rem;
    }
    .sub-tab {
        padding: 7px 8px;
        font-size: 11px;
    }
    .tab-badge {
        min-width: 16px;
        height: 16px;
        font-size: 9px;
        padding: 0 4px;
        margin-left: 3px;
    }
    table {
        font-size: 0.72rem;
    }
    thead th {
        padding: 6px 4px;
        font-size: 0.65rem;
    }
    tbody td {
        padding: 6px 4px;
    }
}

/* --- Print --- */
@media print {
    .header, .sidebar, .sidebar-overlay,
    .side-panel, .side-panel-overlay,
    .toast-container, .burger-btn,
    .btn, button, .filters-bar,
    .pagination, .bulk-bar {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
        font-size: 11pt;
    }

    .content {
        margin: 0 !important;
        padding: 0 !important;
    }

    .stat-card, .table-wrapper, .alert-card {
        border: 1px solid #ccc;
        background: #fff;
        break-inside: avoid;
    }

    table {
        font-size: 9pt;
    }

    thead th {
        background: #eee !important;
        color: #333;
    }

    .badge {
        border: 1px solid currentColor;
    }

    a {
        color: #000;
        text-decoration: underline;
    }
}

.company-link:hover { color: var(--blue) !important; text-decoration: underline !important; }

/* ===== Сегментный переключатель статуса встречи (карточка лида) ===== */
.lead-status-seg {
    display: inline-flex;
    align-items: center;
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    gap: 2px;
    padding: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.06);
}
.lead-status-seg::-webkit-scrollbar { display: none; }
.lead-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: none;
    background: transparent;
    padding: 5px 10px;
    border-radius: 9px;
    font-size: 0.72rem;
    font-weight: 600;
    font-family: inherit;
    color: var(--text2);
    opacity: 0.75;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease,
                transform 0.12s ease, font-size 0.18s ease, padding 0.18s ease, opacity 0.18s ease;
}
.lead-status-pill:hover:not(.active) { background: var(--bg-hover); color: var(--text); opacity: 1; }
.lead-status-pill:active { transform: scale(0.97); }
.lsp-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    flex: 0 0 auto;
    transition: background 0.18s ease, box-shadow 0.18s ease;
}
.lead-status-pill .lsp-dot { background: var(--pdot, #94a3b8); }
.lead-status-pill.active { color: #fff; }
.lead-status-pill.active .lsp-dot { background: #fff; box-shadow: 0 0 6px rgba(255,255,255,0.9); }
.lead-status-pill.active {
    background: linear-gradient(135deg, var(--pc1, #5a78f5), var(--pc2, #3a56d4));
    box-shadow: 0 2px 10px var(--pglow, rgba(58,86,212,0.4));
    font-size: 0.85rem;
    padding: 8px 18px;
    opacity: 1;
}
.lead-status-pill.preview, .lead-status-pill.preview-danger { opacity: 1; }
.lead-status-pill.preview {
    color: #4f6ef2;
    background: rgba(79,110,242,0.08);
    box-shadow: inset 0 0 0 1.5px #4f6ef2;
}

/* Панель переноса встречи */
.lead-status-extra {
    display: none;
    margin-top: 10px;
    padding: 14px 16px;
    background: var(--blue-bg);
    border: 1px solid rgba(79,110,242,0.25);
    border-radius: 12px;
    animation: lseIn 0.2s ease;
}
@keyframes lseIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: none; }
}
.lse-title {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--blue);
    margin-bottom: 10px;
}
.lse-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.lse-row input[type="date"], .lse-row input[type="time"] {
    height: 34px;
    font-size: 0.82rem;
    padding: 0 10px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.lse-row input:focus {
    outline: none;
    border-color: #4f6ef2;
    box-shadow: 0 0 0 3px rgba(79,110,242,0.18);
}

/* Полоса статуса под названием компании (карточка лида) */
.lead-status-bar {
    max-width: 900px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 20px;
    margin-bottom: 16px;
}
.lsb-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.lsb-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text2);
    padding: 4px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    position: relative;
}
html[data-theme="light"] .lead-status-bar {
    background-image: linear-gradient(180deg, #ffffff, #fafcfe);
    box-shadow: 0 1px 2px rgba(30,54,90,0.06), 0 4px 12px rgba(30,54,90,0.05);
}

/* Панель причины отказа */
.lead-status-extra.danger {
    background: rgba(239,68,68,0.07);
    border-color: rgba(239,68,68,0.3);
}
.lead-status-pill.preview-danger {
    color: #ef4444;
    background: rgba(239,68,68,0.08);
    box-shadow: inset 0 0 0 1.5px #ef4444;
}
.lse-row select {
    height: 34px;
    font-size: 0.82rem;
    min-width: 220px;
    padding: 0 10px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
}

/* Закреплённый комментарий (как в TG) */
.pinned-bar {
    max-width: 900px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--blue);
    border-radius: 12px;
    padding: 10px 16px;
    margin-bottom: 16px;
    animation: lseIn 0.2s ease;
}
.pinned-bar .pin-icon { font-size: 1rem; line-height: 1.4; }
.pinned-bar .pin-body { flex: 1; min-width: 0; }
.pinned-bar .pin-title {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--blue);
    margin-bottom: 3px;
}
.pinned-bar .pin-text {
    display: block;
    font-size: 0.86rem;
    line-height: 1.45;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}
.pinned-bar .pin-unpin {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text2);
    font-size: 0.9rem;
    padding: 2px 4px;
    border-radius: 6px;
    transition: background 0.15s ease, color 0.15s ease;
}
.pinned-bar .pin-unpin:hover { background: var(--bg-hover); color: var(--text); }
html[data-theme="light"] .pinned-bar {
    background-image: linear-gradient(180deg, #ffffff, #fafcfe);
    box-shadow: 0 1px 2px rgba(30,54,90,0.06), 0 4px 12px rgba(30,54,90,0.05);
}

/* Form inputs */
.form-input {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
}
.form-input:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

/* Подсказка занятости слота под селектом времени встречи */
.slot-hint {
    font-size: 0.75rem;
    color: var(--text2);
    margin-top: 4px;
    line-height: 1.35;
}
.slot-hint-full {
    color: var(--red, #ef4444);
    font-weight: 500;
}
.slot-hint:empty {
    display: none;
}

/* Чипы прикреплённых файлов в модалках письма (mail.js, lead-detail.js) */
.attach-chip {
    display: inline-block;
    margin: 2px 4px 2px 0;
    padding: 2px 7px;
    cursor: pointer;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    font-size: 0.78rem;
}
.attach-chip:hover {
    border-color: #c0392b;
    color: #c0392b;
}
.attach-chip b {
    font-weight: 400;
    color: var(--text2);
}
