/* is-com Chat — Frappe-ui design system (полная consistency с CRM)
 *
 * Использует ТОЛЬКО semantic tokens Frappe-ui (источник: frappe-ui/tailwind/colors.json):
 *  - --ink-gray-{1..9}, --ink-blue-{1..3}, --ink-blue-link, --ink-red-{1..4}, --ink-green-{1..3}, --ink-amber-{1..3}
 *  - --surface-{white,cards,modal,gray-1..7,blue-1..3,red-1..7,green-1..3,amber-1..3}
 *  - --outline-{gray-1..5,gray-modals,red-1..3,green-1..2,blue-1}
 *
 * Шрифт: InterVar (грузится Frappe-ui сам), font-weight 420 default, 400 для display.
 * Border-radius: 4/8/10/12/16/20 px scale. Shadow: shadow-sm/shadow/md/lg/xl/2xl.
 *
 * Никаких собственных hex или Google Fonts — всё наследуется от Frappe-ui.
 */

/* ─── ОБЩИЕ — соответствие шрифта/веса Frappe-ui ─── */
.ic-chat-bubble,
.ic-chat-panel,
.ic-chat-toast,
.ic-chats-app,
.ic-chat-tab-view {
    font-family: 'InterVar', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-weight: 420;
    color: var(--ink-gray-8);
    font-variation-settings: 'opsz' 24;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Tabular numbers — время, счётчики */
.ic-chats-list-time,
.ic-chat-msg-meta,
.ic-chat-thread-row-time,
.ic-chats-filter-count,
.ic-chats-list-unread,
.ic-chats-nav-badge,
.ic-channel-tab-badge,
.ic-chat-tab-badge,
.ic-chat-bubble-count {
    font-variant-numeric: tabular-nums;
}

/* ─── BUBBLE ─── */
.ic-chat-bubble {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 52px;
    height: 52px;
    border-radius: 9999px;
    background: var(--surface-gray-7);
    color: var(--ink-white);
    border: none;
    box-shadow: 0 0 1px rgba(0,0,0,0.45), 0 1px 2px rgba(0,0,0,0.1);
    cursor: pointer;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.ic-chat-bubble:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 1px rgba(0,0,0,0.35), 0 6px 8px -4px rgba(0,0,0,0.1);
}
.ic-chat-bubble.ic-chat-bubble-active { background: var(--surface-red-5); }
.ic-chat-bubble-icon { font-size: 22px; line-height: 1; }
.ic-chat-bubble-count {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 9999px;
    background: var(--surface-red-5);
    color: var(--ink-white);
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ─── FLOATING PANEL ─── */
.ic-chat-panel {
    position: fixed;
    right: 24px;
    bottom: 84px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 110px);
    background: var(--surface-cards);
    border-radius: 12px;
    box-shadow: 0 0 1px rgba(0,0,0,0.19), 0 1px 2px rgba(0,0,0,0.07), 0 6px 15px -5px rgba(0,0,0,0.11);
    z-index: 9001;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    font-size: 14px;
}
.ic-chat-panel.ic-chat-panel-visible { opacity: 1; transform: translateY(0); }
.ic-chat-panel-header {
    flex-shrink: 0;
    height: 52px;
    display: flex;
    align-items: center;
    padding: 0 8px 0 16px;
    border-bottom: 1px solid var(--outline-gray-modals);
    background: var(--surface-menu-bar);
}
.ic-chat-panel-title {
    flex: 1;
    font-weight: 500;
    font-size: 14px;
    color: var(--ink-gray-9);
    line-height: 1.3;
    min-width: 0;
}
.ic-chat-title-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ic-chat-title-listing {
    font-size: 13px;
    font-weight: 420;
    color: var(--ink-gray-5);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ic-chat-listing-label { color: var(--ink-gray-9); font-weight: 500; }
.ic-chat-listing-link {
    color: var(--ink-blue-link) !important;
    font-weight: 420;
    text-decoration: none;
}
.ic-chat-listing-link:hover { text-decoration: underline; color: var(--ink-blue-3) !important; }
.ic-chat-back, .ic-chat-close {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--ink-gray-6);
    cursor: pointer;
    font-size: 18px;
    border-radius: 4px;
    transition: background 0.12s ease, color 0.12s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.ic-chat-back:hover, .ic-chat-close:hover {
    background: var(--surface-gray-2);
    color: var(--ink-gray-9);
}
.ic-chat-back { margin-right: 4px; }
.ic-chat-panel-body { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }

/* ─── THREAD LIST (panel) ─── */
.ic-chat-thread-list { flex: 1; overflow-y: auto; }
.ic-chat-thread-row {
    display: block;
    width: 100%;
    text-align: left;
    border: none;
    background: var(--surface-cards);
    padding: 12px 16px;
    border-bottom: 1px solid var(--outline-gray-modals);
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    font-weight: 420;
    color: var(--ink-gray-8);
    transition: background 0.12s ease;
}
.ic-chat-thread-row:hover { background: var(--surface-gray-1); }
.ic-chat-thread-row-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.ic-chat-thread-row-sender {
    flex: 1;
    font-weight: 500;
    color: var(--ink-gray-9);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ic-chat-thread-row-unread {
    background: var(--surface-red-5);
    color: var(--ink-white);
    border-radius: 9999px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 700;
}
.ic-chat-thread-row-listing {
    font-size: 14px;
    color: var(--ink-gray-5);
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ic-chat-thread-row-preview {
    color: var(--ink-gray-7);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 4px;
}
.ic-chat-thread-row-meta { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-gray-5); }
.ic-chat-thread-ref { color: var(--ink-blue-link); text-decoration: none; font-weight: 500; }
.ic-chat-thread-ref:hover { text-decoration: underline; color: var(--ink-blue-3); }
.ic-chat-thread-orphan { color: var(--ink-gray-5); font-style: italic; }

/* ─── MESSAGES (bubbles) ─── */
.ic-chat-messages, .ic-chat-tab-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: var(--surface-menu-bar);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.ic-chat-day-sep {
    align-self: center;
    background: var(--surface-gray-3);
    color: var(--ink-gray-6);
    font-size: 12px;
    font-weight: 500;
    padding: 3px 10px;
    border-radius: 9999px;
    margin: 8px 0;
}
.ic-chat-msg { display: flex; max-width: 85%; }
.ic-chat-msg-in { align-self: flex-start; }
.ic-chat-msg-out { align-self: flex-end; flex-direction: row-reverse; }
.ic-chat-msg-bubble {
    background: var(--surface-cards);
    color: var(--ink-gray-9);
    border-radius: 10px;
    padding: 8px 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    font-size: 14px;
    font-weight: 420;
}
.ic-chat-msg-out .ic-chat-msg-bubble {
    background: var(--surface-blue-2);
    color: var(--ink-blue-3);
}
.ic-chat-msg-text { white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
.ic-chat-msg-meta {
    margin-top: 2px;
    font-size: 11px;
    color: var(--ink-gray-5);
    display: flex;
    gap: 6px;
    align-items: center;
}
.ic-chat-msg-failed { color: var(--ink-red-3); font-weight: 500; }
.ic-chat-msg-sending { color: var(--ink-amber-3); }

/* ─── ATTACHMENTS ─── */
.ic-chat-msg-attachments { display: flex; flex-direction: column; gap: 4px; margin-bottom: 4px; }
.ic-chat-att-image { display: block; border-radius: 6px; overflow: hidden; max-width: 280px; }
.ic-chat-att-image img { display: block; width: 100%; height: auto; max-height: 240px; object-fit: cover; }
.ic-chat-att-audio, .ic-chat-att-video { width: 280px; max-width: 100%; border-radius: 6px; }
.ic-chat-att-video { max-height: 220px; }
.ic-chat-att-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--surface-gray-1);
    border: 1px solid var(--outline-gray-modals);
    border-radius: 6px;
    color: var(--ink-gray-8);
    text-decoration: none;
    font-size: 13px;
    max-width: 280px;
    transition: background 0.15s ease;
}
.ic-chat-att-file:hover { background: var(--surface-gray-2); color: var(--ink-gray-9); text-decoration: none; }
.ic-chat-att-icon { font-size: 18px; flex-shrink: 0; }
.ic-chat-att-meta { display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.ic-chat-att-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ic-chat-att-size { font-size: 11px; color: var(--ink-gray-5); font-variant-numeric: tabular-nums; }

/* ─── COMPOSER (form-input pattern Frappe-ui) ─── */
.ic-chat-composer-pending {
    padding: 4px 12px 0;
    display: flex; flex-wrap: wrap; gap: 4px;
}
.ic-chat-composer-pending:empty { padding: 0; }
.ic-chat-pending-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 4px 4px 2px;
    background: var(--surface-blue-1);
    color: var(--ink-blue-3);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    max-width: 220px;
}
.ic-chat-pending-chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; }
.ic-chat-pending-icon { font-size: 15px; }
.ic-chat-pending-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.ic-chat-pending-remove { background: none; border: none; color: var(--ink-gray-5); font-size: 15px; cursor: pointer; padding: 0 2px; line-height: 1; }
.ic-chat-pending-remove:hover { color: var(--ink-red-3); }
.ic-chat-pending-uploading { background: var(--surface-gray-2); color: var(--ink-gray-6); }
.ic-chat-pending-error { background: var(--surface-red-2); color: var(--ink-red-3); }

.ic-chat-composer {
    padding: 12px;
    border-top: 1px solid var(--outline-gray-modals);
    background: var(--surface-cards);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    overflow: visible;
}

/* Button ghost (📎) — Frappe-ui pattern */
.ic-chat-attach {
    width: 28px;
    height: 28px;
    min-width: 28px;
    padding: 0 !important;
    margin: 0 !important;
    border: 1px solid var(--outline-gray-modals) !important;
    border-radius: 6px;
    background: var(--surface-cards);
    color: var(--ink-gray-6);
    cursor: pointer;
    flex-shrink: 0 !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    box-sizing: border-box;
    line-height: 1;
}
.ic-chat-attach:hover {
    background: var(--surface-gray-2);
    color: var(--ink-gray-9);
    border-color: var(--outline-gray-3) !important;
}
.ic-chat-attach svg { display: block; width: 16px !important; height: 16px !important; }

/* Textarea — Frappe-ui form-input pattern */
.ic-chat-composer textarea {
    flex: 1;
    border: 1px solid var(--surface-gray-2);
    background: var(--surface-gray-2);
    border-radius: 4px;
    padding: 6px 10px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 420;
    color: var(--ink-gray-8);
    resize: none;
    max-height: 120px;
    min-height: 28px;
    outline: none;
    line-height: 1.4;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.ic-chat-composer textarea::placeholder { color: var(--ink-gray-4); }
.ic-chat-composer textarea:hover {
    border-color: var(--outline-gray-modals);
    background: var(--surface-gray-3);
}
.ic-chat-composer textarea:focus {
    border-color: var(--outline-gray-4);
    background: var(--surface-white);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Button solid primary — Frappe gray-7 fill */
.ic-chat-send {
    height: 28px;
    padding: 0 12px;
    border: none;
    border-radius: 4px;
    background: var(--surface-gray-7);
    color: var(--ink-white);
    font-family: inherit;
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    flex-shrink: 0;
    box-sizing: border-box;
    transition: background 0.15s ease;
}
.ic-chat-send:hover:not(:disabled) { background: var(--surface-gray-6); }
.ic-chat-send:disabled {
    background: var(--surface-gray-3);
    color: var(--ink-gray-4);
    cursor: not-allowed;
}

/* ─── TOAST ─── */
.ic-chat-toast {
    position: fixed;
    right: 16px;
    bottom: 84px;
    width: 320px;
    padding: 12px 16px;
    background: var(--surface-cards);
    border-radius: 10px;
    box-shadow: 0 0 1px rgba(0,0,0,0.12), 0 0.5px 2px rgba(0,0,0,0.15), 0 2px 3px rgba(0,0,0,0.16);
    z-index: 10000;
    transform: translateY(20px);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    font-size: 13px;
    font-weight: 420;
    line-height: 1.4;
}
.ic-chat-toast-visible { transform: translateY(0); opacity: 1; }
.ic-chat-toast-channel {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 2px 8px;
    border-radius: 9999px;
    margin-bottom: 6px;
}
.ic-chat-toast-preview {
    color: var(--ink-gray-9);
    font-weight: 420;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}
.ic-chat-toast-meta { margin-top: 4px; font-size: 11px; color: var(--ink-gray-5); font-style: italic; }

/* ─── CHIP канала — ТОЧНО Frappe Badge subtle (Badge.vue из frappe-ui) ─── */
/* size=md → h-5 text-xs px-1.5 rounded-full
 * variant=subtle theme=*: bg-surface-{theme}-1/2 + text-ink-{theme}-2/3
 */
.ic-chat-chip {
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 6px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.02em;
    line-height: 1.15;
    flex-shrink: 0;
    background: var(--surface-gray-2);
    color: var(--ink-gray-6);
}
.ic-chat-chip[data-channel="avito"]    { background: var(--surface-amber-1);  color: var(--ink-amber-3); }
.ic-chat-chip[data-channel="telegram"] { background: var(--surface-blue-1);   color: var(--ink-blue-2); }
.ic-chat-chip[data-channel="whatsapp"] { background: var(--surface-green-2);  color: var(--ink-green-3); }
.ic-chat-chip[data-channel="max"]      { background: var(--surface-violet-1); color: var(--ink-violet-1); }

/* В списке тредов и фильтре — ghost-вариант (без фона, только цвет текста) */
.ic-chat-thread-row-head .ic-chat-chip,
.ic-chats-list-row1 .ic-chat-chip {
    background: transparent !important;
    padding: 0 !important;
    height: auto;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Toast — оставляем subtle (там читается как лейбл канала) */
.ic-chat-toast[data-channel="avito"] .ic-chat-toast-channel    { background: var(--surface-amber-1); color: var(--ink-amber-3); }
.ic-chat-toast[data-channel="telegram"] .ic-chat-toast-channel { background: var(--surface-blue-1); color: var(--ink-blue-2); }
.ic-chat-toast[data-channel="whatsapp"] .ic-chat-toast-channel { background: var(--surface-green-2); color: var(--ink-green-3); }

/* ─── Per-channel TAB кнопки в Activity navbar ─── */
.ic-chat-tab-btn { position: relative; display: inline-flex !important; align-items: center; gap: 6px; }
.ic-chat-tab-badge,
.ic-channel-tab-badge,
.ic-chats-nav-badge {
    background: var(--surface-red-5);
    color: var(--ink-white);
    font-size: 11px;
    font-weight: 700;
    border-radius: 9999px;
    padding: 1px 6px;
    min-width: 18px;
    text-align: center;
    margin-left: auto;
}
.ic-chat-tab-btn.ic-chat-tab-active {
    border-bottom: 2px solid var(--ink-gray-9) !important;
    color: var(--ink-gray-9) !important;
    font-weight: 500;
}

/* ─── SPLIT: каналов sidebar + pane ─── */
.ic-chat-tab-split {
    flex: 1;
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 12px;
    min-height: 0;
}
@media (max-width: 768px) {
    .ic-chat-tab-split { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
    .ic-chat-tab-sidebar { max-height: 200px; overflow-y: auto; }
}
.ic-chat-tab-sidebar {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--surface-cards);
    border: 1px solid var(--outline-gray-modals);
    border-radius: 8px;
    padding: 8px;
    min-width: 0;
}
.ic-channel-side-btn {
    width: 100% !important;
    justify-content: flex-start !important;
    border-bottom: none !important;
    padding: 6px 10px !important;
    border-radius: 6px;
    gap: 8px !important;
    font-size: 13px !important;
}
.ic-channel-side-btn:hover { background: var(--surface-gray-2) !important; }
.ic-channel-side-active {
    background: var(--surface-gray-3) !important;
    color: var(--ink-gray-9) !important;
    font-weight: 500 !important;
}
.ic-channel-side-inactive { opacity: 0.65; }
.ic-channel-side-inactive-label,
.ic-channel-side-trail { margin-left: auto; flex-shrink: 0; }
.ic-channel-side-inactive-label { font-size: 11px; color: var(--ink-gray-5); font-style: italic; }
.ic-channel-icon-avito    { color: var(--ink-amber-3); }
.ic-channel-icon-telegram { color: var(--ink-blue-3); }
.ic-channel-icon-whatsapp { color: var(--ink-green-3); }

/* ─── chat-view inside Activity wrapper ─── */
.ic-chat-tab-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100%;
    min-height: 60vh;
    padding: 12px;
    background: var(--surface-menu-bar);
    overflow: hidden;
}
.ic-chat-tab-view > .ic-chat-tab-pane { flex: 1; }
.ic-chat-tab-pane {
    background: var(--surface-cards);
    border: 1px solid var(--outline-gray-modals);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
}
.ic-chat-tab-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--outline-gray-modals);
    flex-shrink: 0;
}
.ic-chat-tab-header-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.ic-chat-tab-header-name {
    font-size: 16px;
    font-weight: 500;
    color: var(--ink-gray-9);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ic-chat-tab-header-listing { font-size: 14px; color: var(--ink-gray-5); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ic-chat-tab-pane .ic-chat-tab-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    background: var(--surface-menu-bar);
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 200px;
}
.ic-chat-tab-pane .ic-chat-tab-composer-wrap {
    flex-shrink: 0;
    background: var(--surface-cards);
    border-top: 1px solid var(--outline-gray-modals);
}

/* Empty state */
.ic-chat-pane-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 24px;
    text-align: center;
}
.ic-chat-pane-empty-chip { font-size: 13px; padding: 4px 12px; }
.ic-chat-pane-empty-title { font-size: 16px; font-weight: 500; color: var(--ink-gray-9); }
.ic-chat-pane-empty-subtitle { font-size: 14px; color: var(--ink-gray-5); max-width: 400px; }

.ic-chat-action-row { display: flex; gap: 8px; width: 100%; max-width: 480px; margin-top: 8px; }
.ic-chat-action-input {
    flex: 1;
    border: 1px solid var(--outline-gray-modals);
    background: var(--surface-gray-1);
    border-radius: 4px;
    padding: 6px 10px;
    font-family: ui-monospace, 'SF Mono', Consolas, monospace;
    font-feature-settings: "tnum";
    font-size: 13px;
    color: var(--ink-gray-8);
}
.ic-chat-action-btn {
    height: 28px;
    padding: 0 12px;
    border: 1px solid var(--outline-gray-modals);
    background: var(--surface-cards);
    color: var(--ink-gray-8);
    border-radius: 4px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.ic-chat-action-btn:hover { background: var(--surface-gray-2); color: var(--ink-gray-9); border-color: var(--outline-gray-3); }
.ic-chat-action-btn-primary {
    background: var(--surface-gray-7);
    color: var(--ink-white) !important;
    border-color: var(--surface-gray-7);
}
.ic-chat-action-btn-primary:hover { background: var(--surface-gray-6); border-color: var(--surface-gray-6); color: var(--ink-white) !important; }

/* «↗ Открыть на Авито» (overlay у поля avito_listing_url) */
.ic-listing-open-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    color: var(--ink-gray-5) !important;
    border-radius: 4px;
    text-decoration: none !important;
    transition: background 0.15s ease, color 0.15s ease;
    z-index: 2;
}
.ic-listing-open-btn:hover { background: var(--surface-gray-2); color: var(--ink-gray-8) !important; }

/* ============== ГЛАВНАЯ СТРАНИЦА «Чаты» ============== */

.ic-chats-app {
    position: fixed;
    top: 0;
    left: 240px;
    right: 0;
    bottom: 0;
    background: var(--surface-cards);
    z-index: 50;
    display: grid;
    grid-template-columns: 240px 380px 1fr;
    gap: 0;
}
@media (max-width: 1100px) { .ic-chats-app { grid-template-columns: 220px 340px 1fr; left: 200px; } }
@media (max-width: 768px)  { .ic-chats-app { left: 0; grid-template-columns: 1fr; } }
body.ic-chats-page-open .ic-chats-app { display: grid; }

.ic-chats-loading, .ic-chats-error {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-gray-5);
    padding: 80px;
    font-weight: 420;
}
.ic-chats-error { color: var(--ink-red-3); }

/* === Колонка 1: ФИЛЬТРЫ === */
.ic-chats-filters {
    border-right: 1px solid var(--outline-gray-modals);
    background: var(--surface-menu-bar);
    overflow-y: auto;
}
.ic-chats-filters-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--outline-gray-modals);
    background: var(--surface-cards);
}
.ic-chats-filters-title { font-size: 16px; font-weight: 500; color: var(--ink-gray-9); }
.ic-chats-close {
    border: none;
    background: transparent;
    color: var(--ink-gray-6);
    cursor: pointer;
    font-size: 18px;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
}
.ic-chats-close:hover { background: var(--surface-gray-2); color: var(--ink-gray-9); }

.ic-chats-filters-group { padding: 8px; }
.ic-chats-filter-section {
    font-size: 11px;
    font-weight: 600;
    color: var(--ink-gray-5);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 12px 8px 4px;
}
.ic-chats-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 10px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 420;
    color: var(--ink-gray-8);
    text-align: left;
    transition: background 0.12s ease;
}
.ic-chats-filter:hover { background: var(--surface-gray-2); }
.ic-chats-filter-active {
    background: var(--surface-gray-3) !important;
    color: var(--ink-gray-9) !important;
    font-weight: 500;
}
.ic-chats-filter-count {
    background: var(--surface-red-5);
    color: var(--ink-white);
    font-size: 11px;
    font-weight: 700;
    border-radius: 9999px;
    padding: 1px 7px;
    min-width: 18px;
    text-align: center;
    margin-left: auto;
}
.ic-chats-filter .ic-chat-chip {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
    font-size: 13px !important;
    font-weight: 420 !important;
    color: var(--ink-gray-8) !important;
    flex: 1;
    justify-content: flex-start;
}

/* === Колонка 2: СПИСОК ТРЕДОВ === */
.ic-chats-list {
    border-right: 1px solid var(--outline-gray-modals);
    overflow-y: auto;
    background: var(--surface-cards);
}
.ic-chats-list-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--ink-gray-5);
    gap: 12px;
    padding: 40px;
    text-align: center;
}
.ic-chats-list-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 12px 16px;
    border: none;
    border-bottom: 1px solid var(--outline-gray-modals);
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    font-weight: 420;
    color: var(--ink-gray-8);
    transition: background 0.12s ease;
}
.ic-chats-list-item:hover { background: var(--surface-gray-1); }
.ic-chats-list-item-active { background: var(--surface-blue-1) !important; }
.ic-chats-list-row1 { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }
.ic-chats-list-sender {
    flex: 1;
    font-weight: 500;
    font-size: 14px;
    color: var(--ink-gray-9);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ic-chats-list-time { font-size: 13px; color: var(--ink-gray-5); flex-shrink: 0; }
.ic-chats-list-listing {
    font-size: 13px;
    color: var(--ink-gray-5);
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ic-chats-list-preview {
    font-size: 13px;
    color: var(--ink-gray-7);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    margin-bottom: 4px;
}
.ic-chats-list-row3 { display: flex; align-items: center; justify-content: space-between; }
.ic-chats-list-ref {
    font-size: 11px;
    color: var(--ink-blue-link);
    font-family: ui-monospace, 'SF Mono', Consolas, monospace;
    font-weight: 500;
}
.ic-chats-list-orphan { font-size: 11px; color: var(--ink-gray-5); font-style: italic; }
.ic-chats-list-unread {
    background: var(--surface-red-5);
    color: var(--ink-white);
    font-size: 11px;
    font-weight: 700;
    border-radius: 9999px;
    padding: 1px 7px;
    min-width: 18px;
    text-align: center;
}

/* === Колонка 3: АКТИВНЫЙ ЧАТ === */
.ic-chats-active {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface-cards);
    min-width: 0;
}
.ic-chats-active-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--ink-gray-5);
    padding: 40px;
    text-align: center;
    font-weight: 420;
}
.ic-chats-active-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--outline-gray-modals);
}
.ic-chats-active-header-info { flex: 1; min-width: 0; }
.ic-chats-active-header-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 500;
    color: var(--ink-gray-9);
}
.ic-chats-active-header-listing { font-size: 14px; color: var(--ink-gray-5); margin-top: 4px; }
.ic-chats-active-ref-btn {
    display: inline-flex;
    align-items: center;
    height: 28px;
    padding: 0 12px;
    border-radius: 4px;
    background: var(--surface-gray-2);
    color: var(--ink-gray-8);
    text-decoration: none;
    font-family: ui-monospace, 'SF Mono', Consolas, monospace;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid var(--surface-gray-2);
    transition: background 0.15s ease, border-color 0.15s ease;
}
.ic-chats-active-ref-btn:hover {
    background: var(--surface-gray-3);
    color: var(--ink-gray-9);
    border-color: var(--outline-gray-3);
    text-decoration: none;
}
.ic-chats-active .ic-chat-tab-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
    background: var(--surface-menu-bar);
}
.ic-chats-active .ic-chat-tab-composer-wrap {
    flex-shrink: 0;
    border-top: 1px solid var(--outline-gray-modals);
    background: var(--surface-cards);
}

/* Цветной dot маркер канала (вместо chip в списке тредов и фильтре) */
.ic-chats-channel-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 9999px;
    flex-shrink: 0;
    background: var(--surface-gray-4);
}
.ic-chats-channel-dot[data-channel="avito"]    { background: var(--ink-amber-3); }
.ic-chats-channel-dot[data-channel="telegram"] { background: var(--ink-blue-2); }
.ic-chats-channel-dot[data-channel="whatsapp"] { background: var(--ink-green-3); }
.ic-chats-channel-dot[data-channel="max"]      { background: var(--ink-violet-1); }

/* === FIX: idealn круглые badges — но уважают [hidden] === */
.ic-chats-filter-count:not([hidden]),
.ic-chats-list-unread:not([hidden]),
.ic-chats-nav-badge:not([hidden]),
.ic-channel-tab-badge:not([hidden]),
.ic-chat-tab-badge:not([hidden]),
.ic-chat-thread-row-unread:not([hidden]) {
    height: 18px;
    min-width: 18px;
    padding: 0 6px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}
.ic-chats-filter-count[hidden],
.ic-chats-list-unread[hidden],
.ic-chats-nav-badge[hidden],
.ic-channel-tab-badge[hidden],
.ic-chat-tab-badge[hidden],
.ic-chat-thread-row-unread[hidden] { display: none !important; }

/* === FIX: отступ для badge в кнопке «Чаты» — не упирается в правый край === */
[data-ic-chats-nav] .ic-chats-nav-badge {
    margin-right: 4px;
}

/* Кнопка закрытия открытого чата (× в правом верхнем углу) */
.ic-chats-active-close {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--ink-gray-6);
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.12s ease, color 0.12s ease;
}
.ic-chats-active-close:hover {
    background: var(--surface-gray-2);
    color: var(--ink-gray-9);
}

/* Когда тред открыт — центральная колонка сжимается, левая не трогается */
body.ic-chats-page-open .ic-chats-app.ic-chats-app-thread-open {
    grid-template-columns: 240px 280px 1fr;
}
@media (max-width: 1100px) {
    body.ic-chats-page-open .ic-chats-app.ic-chats-app-thread-open {
        grid-template-columns: 220px 240px 1fr;
    }
}
@media (max-width: 768px) {
    /* На мобильном — список скрывается, остаётся только переписка */
    body.ic-chats-page-open .ic-chats-app.ic-chats-app-thread-open {
        grid-template-columns: 1fr;
    }
    body.ic-chats-page-open .ic-chats-app.ic-chats-app-thread-open .ic-chats-filters,
    body.ic-chats-page-open .ic-chats-app.ic-chats-app-thread-open .ic-chats-list {
        display: none;
    }
}

/* ─── Kanban empty-state placeholders ─── */
/* Серый italic для отсутствующих полей в kanban-tile.
 * Заполняется DOM-patcher'ом из chat.js (см. applyKanbanPlaceholders). */
.ic-empty-placeholder {
    color: var(--ink-gray-4);
    font-style: italic;
    font-weight: 400;
    opacity: 0.85;
}
.ic-empty-placeholder .ic-empty-icon {
    /* плейсхолдерная иконка-аватарка — серый круг с тем же стилем */
    width: 20px;
    height: 20px;
    border-radius: 9999px;
    background: var(--surface-gray-2);
    flex-shrink: 0;
    display: inline-block;
}
