/* ===== CRM v2 — тема ===== */
:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-2: #f7f9fc;
    --surface-3: #eef2f8;
    --border: #e3e8f0;
    --border-strong: #cfd7e3;
    --text: #0f172a;
    --text-2: #334155;
    --muted: #64748b;
    --faint: #94a3b8;
    --accent: #2f6fd6;
    --accent-2: #5b84c4;
    --accent-soft: #e8f0fc;
    --accent-grad: linear-gradient(180deg, #7d9fd3 0%, #5b84c4 100%);
    --green: #16a34a; --green-soft: #dcfce7;
    --red: #dc2626; --red-soft: #fee2e2;
    --amber: #d97706; --amber-soft: #fef3c7;
    --violet: #7c3aed; --violet-soft: #ede9fe;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow: 0 4px 18px rgba(15, 23, 42, .07);
    --shadow-lg: 0 18px 50px rgba(15, 23, 42, .18);
    --radius: 20px;
    --radius-sm: 12px;
    --sidebar-w: 96px;
    --topbar-h: 82px;
    color-scheme: light;
}
:root[data-theme="dark"] {
    --bg: #0b1220;
    --surface: #111a2c;
    --surface-2: #142035;
    --surface-3: #1a2840;
    --border: #22314c;
    --border-strong: #2e4062;
    --text: #e6edf7;
    --text-2: #c3cede;
    --muted: #8a9ab3;
    --faint: #64748b;
    --accent: #6ea0ff;
    --accent-2: #5b84c4;
    --accent-soft: #1b2b48;
    --accent-grad: linear-gradient(180deg, #5d82c2 0%, #46699f 100%);
    --green-soft: #12301f; --red-soft: #3a1717; --amber-soft: #3a2c10; --violet-soft: #2a1f47;
    --shadow: 0 4px 18px rgba(0, 0, 0, .35);
    --shadow-lg: 0 18px 50px rgba(0, 0, 0, .55);
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.ic { width: 1em; height: 1em; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 16px; }

/* ===== Каркас ===== */
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
    background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; align-items: stretch;
    padding: 10px 0; overflow-y: auto; z-index: 30;
    scrollbar-width: thin;
}
.sidebar .brand-mini { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-bottom: 10px; font-size: 11px; color: var(--muted); }
.logo-dot {
    width: 34px; height: 34px; border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #4f86e8, #102a5c 75%);
    color: #fff; font-weight: 800; font-size: 10px; letter-spacing: -.3px;
    display: flex; align-items: center; justify-content: center;
}
.nav-item {
    position: relative; display: flex; flex-direction: column; align-items: center;
    gap: 3px; padding: 9px 4px; color: var(--text); font-size: 12px; text-decoration: none !important;
    border-radius: 12px; margin: 1px 6px;
}
.nav-item svg.ic { width: 28px; height: 28px; stroke-width: 1.7; }
.nav-item:hover { background: var(--surface-3); }
.nav-item.active { color: var(--accent); }
.nav-item.active::before { content: ''; position: absolute; left: -6px; top: 12px; bottom: 12px; width: 3px; border-radius: 3px; background: var(--accent); }
.nav-item .plus { position: absolute; right: 8px; top: 12px; width: 18px; height: 18px; border-radius: 50%; border: 1.6px solid currentColor; display: flex; align-items: center; justify-content: center; color: var(--text); background: var(--surface); }
.nav-item .plus svg.ic { width: 11px; height: 11px; stroke-width: 2.4; }
.nav-item .plus:hover { color: var(--accent); }
.nav-badge {
    position: absolute; top: 4px; left: calc(50% + 6px);
    min-width: 17px; height: 17px; padding: 0 5px; border-radius: 999px;
    background: var(--red); color: #fff; font-size: 10px; font-weight: 700;
    display: flex; align-items: center; justify-content: center; border: 2px solid var(--surface);
}
.nav-item.disabled { opacity: .35; pointer-events: none; }

.topbar {
    position: fixed; left: var(--sidebar-w); right: 0; top: 0; height: var(--topbar-h);
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: 6px 24px 0 16px; z-index: 25;
}
.topbar .crumbs { font-size: 12px; color: var(--muted); height: 16px; }
.topbar .bar { display: flex; align-items: center; gap: 16px; height: 54px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; white-space: nowrap; text-decoration: none !important; color: var(--text); }
.brand .logo-dot { width: 34px; height: 34px; }
.top-search { position: relative; width: min(420px, 36vw); }
.top-search input { width: 100%; height: 34px; padding: 0 12px 0 34px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); }
.top-search input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.top-search > svg.ic { position: absolute; left: 11px; top: 9px; color: var(--muted); font-size: 16px; }
.search-pop { position: absolute; top: 40px; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); max-height: 420px; overflow: auto; z-index: 60; }
.search-pop a { display: flex; gap: 10px; padding: 9px 12px; color: var(--text); border-bottom: 1px solid var(--border); text-decoration: none; }
.search-pop a:hover { background: var(--surface-2); }
.top-company { font-size: 12px; color: var(--muted); }
.theme-toggle { width: 48px; height: 26px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--accent-soft); position: relative; cursor: pointer; padding: 0; }
.theme-toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-sm); transition: left .2s; }
:root[data-theme="dark"] .theme-toggle::after { left: 25px; }
.icon-btn { width: 34px; height: 34px; border-radius: 10px; border: 0; background: transparent; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text); font-size: 19px; position: relative; }
.icon-btn:hover { background: var(--surface-3); }
.icon-btn.sm { width: 28px; height: 28px; font-size: 15px; border-radius: 8px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding-left: 16px; border-left: 1px solid var(--border); height: 36px; cursor: pointer; position: relative; white-space: nowrap; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.avatar.lg { width: 44px; height: 44px; font-size: 15px; }
.menu-pop { position: absolute; right: 0; top: 44px; min-width: 230px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 70; }
.menu-pop .mi { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; cursor: pointer; color: var(--text); }
.menu-pop .mi:hover { background: var(--surface-2); }
.menu-pop .head { padding: 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }

.main { margin-left: var(--sidebar-w); padding: calc(var(--topbar-h) + 16px) 82px 40px 22px; min-height: 100vh; }
.main.flush { padding-right: 82px; }

/* ===== Карточки / заголовки ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.card.tight { padding: 14px 16px; }
.card + .card { margin-top: 16px; }
.card h2 { margin: 0 0 4px; font-size: 19px; }
.card h3 { margin: 0 0 10px; font-size: 16px; }
.card .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.page-head .ph-icon { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); display: flex; align-items: center; justify-content: center; font-size: 20px; color: var(--text-2); }
.page-head h1 { margin: 0; font-size: 19px; }
.page-head .sub { color: var(--muted); font-size: 13px; }
.hero { padding: 22px 20px; }
.hero .eyebrow { font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.hero h1 { margin: 0 0 10px; font-size: 22px; }
.hero p { margin: 0; color: var(--muted); font-size: 13px; }

/* ===== Кнопки / поля ===== */
.btn { height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 500; white-space: nowrap; color: var(--text); text-decoration: none !important; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent-grad); color: #fff; border: 0; box-shadow: 0 6px 16px rgba(91, 132, 196, .35); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.outline { border-color: var(--accent); color: var(--accent); }
.btn.danger { background: var(--red-soft); border-color: #fca5a5; color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 30px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.btn.lg { height: 46px; padding: 0 22px; font-size: 15px; border-radius: 14px; }
.btn:disabled { opacity: .55; cursor: default; }
.input, .select, textarea.input {
    width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 10px;
    background: var(--surface); color: var(--text);
}
textarea.input { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.input:focus, .select:focus, textarea.input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.input.sm, .select.sm { height: 32px; font-size: 13px; border-radius: 8px; }
.input[readonly] { background: var(--surface-2); }
label.fl { display: block; font-size: 12px; color: var(--muted); margin: 0 0 4px; }
.field { margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { height: 26px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); font-size: 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.radio-chip { height: 32px; padding: 0 12px 0 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.radio-chip::before { content: ''; width: 14px; height: 14px; border-radius: 50%; border: 1.6px solid var(--border-strong); }
.radio-chip.on::before { border: 4px solid var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 0 14px; height: 38px; cursor: pointer; border-right: 1px solid var(--border); white-space: nowrap; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: #8bc34a; color: #fff; }
.seg.sm button { height: 30px; padding: 0 12px; font-size: 13px; }
.seg.blue button.on { background: var(--accent-soft); color: var(--accent); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; user-select: none; }
.switch input { display: none; }
.switch .tr { width: 34px; height: 20px; border-radius: 999px; background: var(--border-strong); position: relative; transition: .2s; }
.switch .tr::after { content: ''; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + .tr { background: var(--accent); }
.switch input:checked + .tr::after { left: 16px; }

/* ===== Бейджи ===== */
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-3); color: var(--text-2); }
.badge.status { color: #fff; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.violet { background: var(--violet-soft); color: var(--violet); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }
.badge.outline { background: transparent; border: 1px solid var(--border-strong); }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--border); font-size: 12px; background: var(--surface); }
.platform { font-size: 11px; font-weight: 700; letter-spacing: .03em; padding: 2px 7px; border-radius: 5px; }
.platform.AVITO { background: #e0f2fe; color: #0369a1; }
.platform.AUTO_RU { background: #fee2e2; color: #b91c1c; }
.platform.TELEGRAM { background: #e0f2fe; color: #0284c7; }
.platform.WHATSAPP { background: #dcfce7; color: #15803d; }
.platform.INTERNAL { background: var(--surface-3); color: var(--muted); }
:root[data-theme="dark"] .platform { filter: brightness(.85) saturate(1.2); }

/* ===== Таблицы ===== */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-2); padding: 14px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; z-index: 1; }
.tbl td { padding: 13px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl tr.unread td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.tbl .num { font-weight: 700; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.tbl.spaced th { letter-spacing: .18em; font-size: 11px; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 6px; }
.pager button { min-width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.pager button.on { background: var(--accent-2); color: #fff; border-color: var(--accent-2); }
.pager button:disabled { opacity: .4; cursor: default; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty svg.ic { font-size: 40px; color: var(--faint); display: block; margin: 0 auto 10px; }

/* ===== Главная ===== */
.period-bar { display: flex; justify-content: center; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.period-bar .p { height: 34px; padding: 0 13px; border-radius: 8px; border: 1px solid transparent; background: transparent; cursor: pointer; font-size: 13px; }
.period-bar .p.on { border-color: var(--border-strong); background: var(--surface); box-shadow: var(--shadow-sm); }
.widgets { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.widget { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 22px 24px; min-height: 120px; cursor: pointer; transition: box-shadow .15s, transform .15s; }
.widget:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.widget .wt { font-weight: 700; font-size: 17px; margin-bottom: 14px; }
.widget .wv { font-size: 30px; font-weight: 700; }
.widget .wh { color: var(--muted); font-size: 12px; margin-top: 4px; }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 40px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .track { height: 8px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--accent-2); border-radius: 99px; }

/* ===== Фильтры сделок ===== */
.filters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; margin-top: 16px; }
.filters h4 { margin: 0 0 8px; font-size: 14px; }
.filters .fg { margin-bottom: 12px; }
.filters .fg > label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.date-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 6px; }
.quick { display: flex; gap: 4px; flex-wrap: wrap; }
.quick button { height: 24px; padding: 0 8px; border-radius: 5px; border: 1px solid var(--border); background: var(--surface); font-size: 12px; cursor: pointer; color: var(--text-2); }
.quick button:hover { border-color: var(--accent); color: var(--accent); }

/* ===== Карточка сделки ===== */
.deal-tabs { display: flex; align-items: center; gap: 6px; margin: -4px 0 14px; border-bottom: 1px solid var(--border); padding-bottom: 0; overflow-x: auto; }
.deal-tab { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border: 1px solid var(--border); border-bottom: 0; border-radius: 10px 10px 0 0; background: var(--surface-2); cursor: pointer; font-weight: 600; font-size: 13px; color: var(--text); white-space: nowrap; }
.deal-tab.on { background: var(--surface); box-shadow: 0 -2px 0 var(--accent) inset; }
.deal-tab .x { color: var(--faint); cursor: pointer; padding: 2px; border-radius: 4px; }
.deal-tab .x:hover { color: var(--red); background: var(--red-soft); }
.deal-layout { display: grid; grid-template-columns: minmax(380px, 440px) 1fr; gap: 20px; align-items: start; }
.deal-left { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 18px 22px; }
.deal-right { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h) - 90px); min-height: 520px; position: sticky; top: calc(var(--topbar-h) + 16px); overflow: hidden; }
.dl-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.circ { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--border-strong); background: var(--surface); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-size: 15px; color: var(--text-2); }
.circ:hover { border-color: var(--accent); color: var(--accent); }
.circ.green { color: var(--green); }
.status-btn { height: 38px; padding: 0 14px; border-radius: 8px; border: 0; color: #fff; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; font-size: 15px; }
.status-menu { position: absolute; z-index: 80; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; width: 260px; max-height: 420px; overflow: auto; }
.status-menu .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); padding: 8px 8px 4px; }
.status-menu .opt { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.status-menu .opt:hover { background: var(--surface-2); }
.status-menu .dot { width: 10px; height: 10px; border-radius: 50%; }
.kv { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 8px 10px; }
.kv > label { color: var(--text-2); font-size: 14px; text-align: right; }
.kv .input, .kv .select { height: 36px; }
.src-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0; font-size: 14px; }
.sec-title { display: flex; align-items: center; gap: 12px; margin: 18px 0 12px; font-weight: 600; color: var(--text-2); }
.sec-title::before, .sec-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }
details.fold { border-top: 1px solid var(--border); padding: 10px 0 2px; }
details.fold > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 6px; color: var(--text-2); padding: 2px 0 8px; }
details.fold > summary::before { content: '›'; display: inline-block; transition: transform .15s; font-size: 18px; line-height: 1; color: var(--muted); }
details.fold[open] > summary::before { transform: rotate(90deg); }
.yn { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.yn button { border: 0; background: var(--surface); padding: 0 11px; height: 32px; cursor: pointer; border-right: 1px solid var(--border); font-size: 13px; }
.yn button:last-child { border-right: 0; }
.yn button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.trio label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.trio .input { height: 34px; font-size: 12px; padding: 0 6px; }
.car-box { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: var(--surface-2); }
.save-hint { font-size: 12px; color: var(--faint); }
.save-hint.dirty { color: var(--amber); font-weight: 600; }
.related a { display: flex; gap: 8px; align-items: center; padding: 4px 0; font-size: 13px; }

.feed { flex: 1; overflow-y: auto; padding: 18px 22px; scroll-behavior: smooth; }
.feed-day { display: flex; align-items: center; gap: 14px; margin: 14px 0; }
.feed-day::before, .feed-day::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.feed-day span { background: var(--surface-3); border-radius: 999px; padding: 3px 14px; font-weight: 700; font-size: 13px; }
.ev { border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 9px 12px; margin-bottom: 8px; position: relative; }
.ev .eh { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); margin-bottom: 3px; }
.ev .eh .who { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.ev .tools { display: none; gap: 2px; }
.ev:hover .tools { display: inline-flex; }
.ev .et { white-space: pre-wrap; word-break: break-word; }
.ev.note { background: var(--surface-2); }
.ev.pinned { border-color: #fcd34d; background: var(--amber-soft); }
.ev.system, .ev.status_change, .ev.callback { background: transparent; border-style: dashed; padding: 6px 12px; }
.ev.system .et, .ev.status_change .et, .ev.callback .et { font-size: 13px; color: var(--text-2); }
.ev.sale { background: var(--green-soft); border-color: #86efac; }
.ev.call_missed { border-left: 3px solid var(--red); }
.ev.call_in, .ev.call_out { border-left: 3px solid var(--green); }
.ev.lead { border-left: 3px solid var(--accent); }
.ev img.att { max-width: 260px; max-height: 200px; border-radius: 8px; margin-top: 6px; display: block; cursor: zoom-in; }
.msg { display: flex; margin: 6px 0 10px; }
.msg .bubble { max-width: 72%; padding: 8px 12px 6px; border-radius: 14px; background: var(--surface-3); position: relative; }
.msg.out { justify-content: flex-end; }
.msg.out .bubble { background: var(--accent-soft); border-bottom-right-radius: 4px; }
.msg.in .bubble { border-bottom-left-radius: 4px; }
.msg .mh { display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg .mt { white-space: pre-wrap; word-break: break-word; }
.pinned-bar { border-bottom: 1px solid var(--border); padding: 8px 22px; background: var(--amber-soft); font-size: 13px; display: flex; gap: 8px; align-items: flex-start; max-height: 90px; overflow: auto; }
.composer { border-top: 1px solid var(--border); padding: 10px 18px 12px; background: var(--surface); }
.composer .ctabs { display: flex; gap: 4px; margin-bottom: 8px; flex-wrap: wrap; }
.composer .ctabs button { border: 0; background: transparent; height: 34px; padding: 0 12px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--text-2); }
.composer .ctabs button.on { background: var(--accent-soft); color: var(--accent); }
.composer .box { border: 1px solid var(--border-strong); border-radius: 12px; padding: 8px 10px; background: var(--surface); }
.composer textarea { width: 100%; border: 0; resize: none; min-height: 56px; max-height: 200px; outline: none; background: transparent; }
.composer .cfoot { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.send-btn { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent-2); color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-size: 16px; }
.send-btn:disabled { opacity: .4; }
.lost-box { margin-top: 16px; }

/* ===== Чаты / мессенджер ===== */
.inbox { display: grid; grid-template-columns: 360px 1fr; height: calc(100vh - var(--topbar-h) - 50px); min-height: 520px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.inbox .list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.inbox .list-head { padding: 14px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.inbox .items { flex: 1; overflow-y: auto; }
.inbox .it { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.inbox .it:hover { background: var(--surface-2); }
.inbox .it.on { background: var(--accent-soft); }
.inbox .it .nm { font-weight: 600; display: flex; gap: 6px; align-items: center; }
.inbox .it .lm { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 230px; }
.inbox .it .tm { margin-left: auto; font-size: 11px; color: var(--faint); white-space: nowrap; text-align: right; }
.unread-dot { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; margin-top: 4px; }
.conv { display: flex; flex-direction: column; min-height: 0; }
.conv-head { padding: 12px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.conv-body { flex: 1; overflow-y: auto; padding: 16px 22px; }
.conv-foot { border-top: 1px solid var(--border); padding: 10px 16px; }
.conv-foot .qr { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.conv-foot form { display: flex; gap: 10px; align-items: flex-end; }
.conv-foot textarea { flex: 1; min-height: 44px; max-height: 160px; resize: none; }
.tmsg { display: flex; gap: 10px; margin-bottom: 14px; }
.tmsg .tb { flex: 1; }
.tmsg .tn { font-weight: 600; font-size: 13px; }
.tmsg .tn span { font-weight: 400; color: var(--faint); font-size: 12px; margin-left: 6px; }

/* ===== Команда ===== */
.tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 4px; gap: 2px; margin-bottom: 16px; }
.tabs button { border: 0; background: transparent; height: 38px; padding: 0 18px; border-radius: 10px; cursor: pointer; font-weight: 500; }
.tabs button.on { background: var(--accent-soft); }
.team-grid { display: grid; grid-template-columns: 1fr 420px; gap: 16px; align-items: start; }
.ucard { border: 1px solid var(--border); border-radius: 16px; padding: 16px 18px; display: grid; grid-template-columns: 1.2fr 1fr auto; gap: 14px; align-items: start; cursor: pointer; }
.ucard + .ucard { margin-top: 12px; }
.ucard:hover { box-shadow: var(--shadow); }
.ucard .nm { font-weight: 700; font-size: 16px; }
.ucard .lbl { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); margin-top: 6px; }
.perm-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.access-box { border-radius: 12px; padding: 10px 14px; font-size: 13px; min-width: 170px; }
.access-box.open { background: var(--red-soft); color: var(--red); }
.access-box b { display: block; font-size: 14px; }
.dep-card { border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; }
.dep-card + .dep-card { margin-top: 10px; }

/* ===== Колонка напоминалок справа (из v1) ===== */
.alerts-rail { position: fixed; right: 14px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 10px; z-index: 40; }
.alert-pill { position: relative; width: 44px; min-height: 40px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: 0 2px 10px rgba(20, 22, 31, .14); display: flex; align-items: center; justify-content: center; padding: 4px; cursor: pointer; transition: transform .15s, box-shadow .15s; }
.alert-pill:hover { box-shadow: 0 4px 16px rgba(20, 22, 31, .22); transform: translateX(-3px); }
.alert-pill.zero { opacity: .4; }
.alert-pill .lb { font-size: 10px; font-weight: 700; color: var(--muted); text-align: center; line-height: 1.1; }
.alert-pill .ab { position: absolute; top: -7px; right: -6px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px; color: #fff; font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; box-shadow: 0 0 0 2px var(--surface); }
.alert-pill .tip { position: absolute; right: 54px; top: 50%; transform: translateY(-50%); background: #0f172a; color: #fff; font-size: 12px; padding: 5px 10px; border-radius: 8px; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .12s; }
.alert-pill:hover .tip { opacity: 1; }
.alert-pill.pulse .ab { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }

/* ===== Модалки / тосты ===== */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; animation: fade .12s; }
.modal { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; padding: 22px; position: relative; }
.modal.wide { max-width: 920px; }
.modal h3 { margin: 0 0 16px; font-size: 18px; padding-right: 30px; }
.modal .close { position: absolute; right: 14px; top: 14px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.toasts { position: fixed; right: 76px; bottom: 20px; z-index: 120; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 12px 14px; width: 340px; animation: slidein .2s; cursor: pointer; }
.toast.err { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }
.toast b { display: block; margin-bottom: 2px; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Логин ===== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; padding: 30px; box-shadow: var(--shadow); }

/* ===== Адаптив ===== */
@media (max-width: 1200px) {
    .deal-layout { grid-template-columns: 1fr; }
    .deal-right { position: static; height: 720px; }
    .team-grid { grid-template-columns: 1fr; }
    .filters { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
    :root { --sidebar-w: 0px; --topbar-h: 64px; }
    .sidebar { transform: translateX(-100%); width: 96px; transition: transform .2s; }
    body.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
    .topbar { padding: 4px 12px 0; }
    .topbar .crumbs, .top-company, .user-chip .nm { display: none; }
    .top-search { width: auto; flex: 1; }
    .brand span { display: none; }
    .main { padding: calc(var(--topbar-h) + 12px) 16px 90px 16px; }
    .main.flush { padding-right: 16px; }
    .alerts-rail { top: auto; bottom: 10px; right: 50%; transform: translateX(50%); flex-direction: row; background: var(--surface); padding: 8px; border-radius: 999px; border: 1px solid var(--border); box-shadow: var(--shadow-lg); }
    .alerts-rail .alert-pill { width: 36px; min-height: 34px; }
    .alert-pill .tip { display: none; }
    .filters, .form-grid, .trio { grid-template-columns: 1fr; }
    .inbox { grid-template-columns: 1fr; height: auto; }
    .inbox.has-conv .list { display: none; }
    .inbox:not(.has-conv) .conv { display: none; }
    .ucard { grid-template-columns: 1fr; }
    .toasts { right: 16px; left: 16px; bottom: 70px; }
    .toast { width: 100%; }
}
.menu-btn { display: none; }
@media (max-width: 760px) { .menu-btn { display: inline-flex; } }

/* фикс: поля в узкой левой колонке карточки не вылезают за край */
.deal-left .trio > * { min-width: 0; }
.deal-left .trio input { width: 100%; min-width: 0; font-size: 12px; padding-left: 6px; padding-right: 4px; }
.deal-left .row > input, .deal-left .row > select { min-width: 0; flex: 1 1 auto; }
.deal-left .seg.sm { flex-shrink: 0; }
.deal-left .seg.sm button { padding-left: 10px; padding-right: 10px; }


/* ---- VK, папки чатов, карточка товара ---- */
.platform.VK { background: #0077ff1a; color: #0077ff; }
.folders { display: flex; flex-wrap: wrap; gap: 4px; padding: 10px 12px 0; align-items: center; }
.folders .fld { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; color: var(--text); }
.folders .fld.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.folders .fld .n { opacity: .7; }
.folders .fld .unread-dot { margin-left: 2px; }
.vk-st { margin-left: auto; font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.vk-st i { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; display: inline-block; }
.vk-st i.ok { background: #22c55e; }
img.avatar { object-fit: cover; padding: 0; }
.product-card { display: flex; gap: 10px; margin-top: 8px; padding: 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); text-decoration: none; max-width: 460px; }
.product-card:hover { border-color: var(--accent); }
.product-card img, .product-card .pc-ph { width: 112px; height: 80px; border-radius: 8px; object-fit: cover; flex-shrink: 0; background: var(--surface-2); display: flex; align-items: center; justify-content: center; }
.product-card .pc-b { display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: 13px; }
.product-card .pc-price { font-weight: 700; font-size: 14px; }
.pc-diff { font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 6px; border: 1px solid; }
.pc-diff.down { color: #16a34a; border-color: #86efac; }
.pc-diff.up { color: #dc2626; border-color: #fca5a5; }


/* ---- телефония ---- */
.src-tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px; background: #c4b5fd55; color: var(--text); margin-left: 4px; }
.chip-t { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); margin-left: 4px; }
audio.rec { display: block; margin-top: 6px; height: 32px; width: 100%; max-width: 420px; }
#ringing { position: fixed; right: 84px; bottom: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.ring-card { background: var(--surface); border: 2px solid var(--green, #22c55e); border-radius: 12px; padding: 12px 14px; width: 300px; box-shadow: 0 10px 30px #0003; animation: ringPulse 1.2s ease-in-out infinite; }
.ring-card .rc-h { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--green, #16a34a); }
.ring-card .rc-n { font-size: 16px; font-weight: 700; margin-top: 4px; }
@keyframes ringPulse { 0%, 100% { box-shadow: 0 10px 30px #0003; } 50% { box-shadow: 0 0 0 6px #22c55e33, 0 10px 30px #0003; } }


/* ---- главная: вкладки, телефония ---- */
.home-tabs { display: inline-flex; gap: 6px; }
.home-tabs .ht { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px; padding: 7px 16px; font-weight: 600; cursor: pointer; }
.home-tabs .ht.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); color: var(--accent); }
.widget .wv .dl { font-size: 13px; font-weight: 700; margin-left: 6px; vertical-align: middle; }
.dl.up { color: #16a34a; } .dl.down { color: #dc2626; }
.tbl th.r, .tbl td.r { text-align: right; }
.tel-ops tr.tot td { background: var(--surface-2); }
.tel-line { display: flex; align-items: center; gap: 6px; padding: 7px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.tel-line:last-child { border-bottom: 0; }
.tel-days { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.tel-days .td { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.tel-days .stack { width: 100%; display: flex; flex-direction: column; border-radius: 3px 3px 0 0; overflow: hidden; min-height: 2px; }
.tel-days i, i.lg { display: block; }
.tel-days i.a, i.lg.a { background: #22c55e; } .tel-days i.m, i.lg.m { background: #ef4444; } .tel-days i.o, i.lg.o { background: #3b82f6; }
i.lg { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; }
.call-ic { display: inline-flex; color: var(--muted); } .call-ic.green { color: #16a34a; } .call-ic.red { color: #dc2626; }
td.nowrap { white-space: nowrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; vertical-align: middle; } .dot.green { background: #22c55e; } .dot.red { background: #ef4444; }

.op-chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 10%, var(--surface)); color: var(--text); margin-left: 6px; }
.op-chip.miss { background: #fee2e2; color: #b91c1c; }
.calls-grid tr.grp th { text-align: center; letter-spacing: 0; text-transform: none; font-size: 13px; border-right: 1px solid var(--border); }
.calls-grid td, .calls-grid th { white-space: normal; }

.alert-pill .ai { display: flex; align-items: center; justify-content: center; }
.alert-pill.zero .ai { color: var(--muted) !important; }

/* ---- КМ4: свой стиль ---- */
.logo-dot { background: none !important; padding: 0 !important; border-radius: 9px; overflow: hidden; box-shadow: 0 4px 12px rgba(79,70,229,.25); color: inherit; }
svg.ic { stroke-width: 1.65; }
.sidebar .nav-item .ic, .side .nav-item .ic, nav .nav-item .ic { width: 34px; height: 34px; padding: 6px; border-radius: 10px; background: color-mix(in srgb, #4f46e5 7%, transparent); }
.sidebar .nav-item.active .ic, .side .nav-item.active .ic, nav .nav-item.active .ic { background: linear-gradient(135deg, #0ea5a4, #4f46e5); color: #fff; }
.ev-who { font-size: 12px; color: var(--muted); margin: 10px 0 3px 30px; }
.ev.task-row, .ev.status-row { display: flex; align-items: center; gap: 8px; padding: 9px 12px; }
.ev.task-row { background: #fef6e4; border-color: #fde7b0; }
.ev.task-row.done { background: var(--surface-2); border-color: var(--border); opacity: .7; }
.ev.task-row.done b { text-decoration: line-through; }
.ev .ev-ic { display: inline-flex; color: var(--muted); }
:root[data-theme="dark"] .ev.task-row { background: #3a2f12; border-color: #5c4a1a; }

.chat-status { display: flex; justify-content: center; margin: 8px 0; }
.chat-status > span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 12px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.chat-status b { color: var(--text); font-weight: 600; }

.bal-wrap { position: relative; display: inline-flex; }
.bal-dot { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: #ef4444; box-shadow: 0 0 0 2px var(--surface); }
.bal-pop { position: absolute; top: 44px; right: -20px; z-index: 900; width: 260px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 14px 40px #0002; padding: 14px 16px; }
.bal-h { font-weight: 700; margin-bottom: 8px; }
.bal-g { font-weight: 700; font-size: 16px; margin: 10px 0 4px; }
.bal-i { padding: 4px 0 4px 10px; }
.bal-v { font-size: 16px; font-weight: 600; }
.bal-v.low { color: #dc2626; } .bal-v.ok { color: #15803d; }

.notif-ask { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 1100; display: flex; align-items: center; gap: 10px; max-width: 640px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 14px 40px #0003; font-size: 13px; }
.notif-ask svg.ic { flex-shrink: 0; color: #4f46e5; }
