/* ── Тёмная тема (по умолчанию) ─────────────────────── */
:root {
    --bg: #0f1117; --surface: #18181b; --border: #27272a;
    --text: #e4e4e7; --muted: #71717a; --accent: #3b82f6;
    --green: #22c55e; --orange: #f59e0b; --red: #ef4444;
    --bubble-in: #1e293b; --bubble-out: #1e3a5f;
    --file-bg: rgba(255,255,255,0.05); --file-hover: rgba(255,255,255,0.1);
    --input-bg: #0f1117; --login-btn-disabled: #334155;
}

/* ── Светлая тема (по умолчанию) ────────────────────── */
[data-theme="light"] {
    --bg: #f5f5f5; --surface: #ffffff; --border: #e5e5e5;
    --text: #18181b; --muted: #71717a; --accent: #2563eb;
    --green: #16a34a; --orange: #d97706; --red: #dc2626;
    --bubble-in: #e8f0fe; --bubble-out: #dbeafe;
    --file-bg: rgba(0,0,0,0.04); --file-hover: rgba(0,0,0,0.08);
    --input-bg: #ffffff; --login-btn-disabled: #d4d4d8;
}
[data-theme="light"] .msg.out .msg-sender { color: #1d4ed8; }
[data-theme="light"] .login-error { background: rgba(239,68,68,0.08); }

/* ── Гамбургер: скрыт на десктопе ── */
.admin-toggle { display: none; }

/* ── Фильтры: полные/короткие метки ── */
.f-short { display: none; }
.f-full { display: inline; }
/* ── Сброс и базовые ───────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; -webkit-font-smoothing: antialiased; overflow: hidden; transition: background 0.2s, color 0.2s; }
a { color: inherit; text-decoration: none; }
/* ── Экраны ────────────────────────────────────────── */
.screen { height: 100dvh; display: flex; flex-direction: column; }
.chat-screen { height: 100dvh; }
/* ── Топбар ────────────────────────────────────────── */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; min-height: 56px; gap: 8px; }
.topbar-title { font-weight: 700; font-size: 17px; }
.topbar-right { display: flex; align-items: center; gap: 10px; position: relative; }
.topbar-user { font-size: 13px; color: var(--muted); }
.logo { font-size: 20px; margin-right: 4px; }
/* ── Панель онлайн-админов ─────────────────────────── */
.online-panel { display: flex; align-items: center; gap: 8px; }
.admin-dot { display: inline-flex; align-items: center; gap: 5px; font-size: 14px; font-weight: 600; color: var(--text); padding: 5px 14px; border-radius: 12px; background: var(--bg); border: 1px solid var(--border); white-space: nowrap; }
.admin-dot .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-active { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-idle { background: var(--orange); box-shadow: 0 0 6px var(--orange); }
.dot-offline { background: #52525b; }
/* ── Переключатель темы ────────────────────────────── */
.theme-toggle { cursor: pointer; font-size: 18px; opacity: 0.5; transition: opacity 0.15s; padding: 2px; user-select: none; }
.theme-toggle:hover { opacity: 1; }
/* ── Кнопка выхода ─────────────────────────────────── */
.logout-btn { color: var(--red); font-size: 18px; text-decoration: none; opacity: 0.7; padding: 4px 8px; border-radius: 6px; transition: all 0.15s; }
.logout-btn:hover { opacity: 1; background: rgba(220, 38, 38, 0.12); }
/* ── Фильтры ───────────────────────────────────────── */
.filters { display: flex; flex-wrap: nowrap; gap: 8px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; flex-shrink: 0; }
.filter-btn { padding: 6px 14px; border-radius: 20px; font-size: 13px; font-weight: 600; white-space: nowrap; background: var(--bg); border: 1px solid var(--border); color: var(--muted); cursor: pointer; transition: all 0.15s; }
.filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
/* ── Список чатов ──────────────────────────────────── */
.chat-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.search-bar { padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; display: flex; align-items: center; gap: 8px; }
.chat-search-input { flex: 1; min-width: 0; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit; outline: none; transition: border-color 0.2s; }
.chat-search-input:focus { border-color: var(--accent, #3b82f6); }
.chat-search-input::placeholder { color: var(--text-muted, #71717a); }
.chat-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; overflow: hidden; border-bottom: 1px solid var(--border); transition: background 0.1s; cursor: pointer; }
.chat-item:active { background: rgba(59,130,246,0.06); }
.chat-item.unread { background: rgba(59,130,246,0.04); }
.chat-channel { font-size: 24px; flex-shrink: 0; width: 40px; height: 40px; text-align: center; display: flex; align-items: center; justify-content: center; border-radius: 50%; }
.chat-channel.ch-telegram { background: #2AABEE; }
.chat-channel.ch-telegram svg { width: 22px; height: 22px; fill: #fff; }
.chat-channel.ch-avito { background: #f0f0f0; border-radius: 50%; }
.chat-channel.ch-avito svg { width: 32px; height: 32px; }
.chat-channel.ch-whatsapp { background: #25D366; }
.chat-channel.ch-whatsapp svg { width: 22px; height: 22px; fill: #fff; }
.chat-channel.ch-sutochno { background: #FF6600; color: #fff; font-size: 16px; }
.chat-channel.ch-cian { background: #fff; border: 1px solid #e0e0e0; }
.chat-channel.ch-cian svg { width: 22px; height: 22px; fill: #fff; }
.chat-channel.ch-max { background: #fff; }
.chat-channel.ch-max img { width: 28px; height: 28px; border-radius: 6px; }
.chat-body { flex: 1; min-width: 0; overflow: hidden; }
.chat-header { display: flex; align-items: center; margin-bottom: 3px; }
.chat-name { font-weight: 600; font-size: 15px; white-space: nowrap; }
.chat-item.unread .chat-name { font-weight: 800; }
.chat-time { font-size: 12px; color: var(--muted); flex-shrink: 0; margin-left: 8px; }
.chat-preview { font-size: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; max-width: 100%; }
.chat-badge { background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; min-width: 22px; height: 22px; border-radius: 11px; display: flex; align-items: center; justify-content: center; padding: 0 6px; flex-shrink: 0; }
.chat-viewer { font-size: 12px; flex-shrink: 0; opacity: 0.5; }
/* ── Шапка чата ────────────────────────────────────── */
.chat-topbar { gap: 8px; }
.back-btn { font-size: 22px; padding: 4px 8px; flex-shrink: 0; color: var(--accent); }
.topbar-info { flex: 1; min-width: 0; }
.topbar-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.status-badge { font-size: 11px; padding: 2px 8px; border-radius: 6px; font-weight: 600; }
.status-new { background: rgba(59,130,246,0.15); color: var(--accent); }
.status-active { background: rgba(245,158,11,0.15); color: var(--orange); }
.status-paused { background: rgba(239,68,68,0.15); color: var(--red); }
.status-closed { background: rgba(34,197,94,0.15); color: var(--green); }
.status-reopened { background: rgba(255,255,255,0.1); color: var(--text); }
.topbar-actions { display: flex; gap: 6px; flex-shrink: 0; }
.action-btn { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.15s; }
.action-btn.take { color: var(--orange); }
.action-btn.pause { color: var(--red); }
.action-btn.close-chat { color: var(--green); }
.action-btn:active { transform: scale(0.9); }
/* ── Присутствие в чате ────────────────────────────── */
.presence-dots { font-size: 11px; }
.pdot { color: var(--green); margin-left: 4px; }
.pdot.me { opacity: 0.5; }
/* ── Сообщения ─────────────────────────────────────── */
.messages { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { display: flex; }
.msg.in { justify-content: flex-start; }
.msg.out { justify-content: flex-end; }
.msg-bubble { max-width: 80%; padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.45; word-break: break-word; }
.msg-bubble.in { background: var(--bubble-in); border-bottom-left-radius: 4px; }
.msg-bubble.out { background: var(--bubble-out); border-bottom-right-radius: 4px; }
.msg-sender { font-size: 11px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.msg.out .msg-sender { color: #60a5fa; }
.msg-text { white-space: pre-wrap; }
.msg-text a { color: var(--accent); text-decoration: underline; word-break: break-all; }
.msg-text a:hover { opacity: 0.8; }
.msg-time { font-size: 10px; color: var(--muted); text-align: right; margin-top: 4px; }
/* ── Медиа ─────────────────────────────────────────── */
.msg-photo { max-width: 100%; max-height: 300px; border-radius: 10px; margin: 4px 0; cursor: pointer; display: block; object-fit: cover; }
.msg-audio { width: 100%; max-width: 260px; height: 36px; margin: 4px 0; }
.msg-video { max-width: 100%; max-height: 300px; border-radius: 10px; margin: 4px 0; }
/* ── Документы ─────────────────────────────────────── */
.msg-file { display: flex; align-items: center; gap: 8px; padding: 10px 14px; margin: 4px 0; background: var(--file-bg); border-radius: 10px; border: 1px solid var(--border); text-decoration: none; color: var(--text); transition: background 0.15s; }
.msg-file:hover { background: var(--file-hover); }
.msg-file-icon { font-size: 24px; flex-shrink: 0; }
.msg-file-name { flex: 1; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-file-dl { font-size: 16px; flex-shrink: 0; opacity: 0.5; }
/* ── Превью PDF ────────────────────────────────────── */
.msg-pdf-wrap { margin: 4px 0; }
.msg-pdf-canvas { width: 100%; max-height: 400px; border-radius: 10px; background: var(--surface); display: block; cursor: pointer; object-fit: contain; }
.msg-pdf-open { display: block; font-size: 12px; color: var(--accent); margin-top: 4px; text-decoration: none; }
.msg-pdf-open:hover { text-decoration: underline; }
/* ── Ввод ──────────────────────────────────────────── */
.input-bar { position: relative; padding: 8px 12px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); background: var(--surface); border-top: 1px solid var(--border); flex-shrink: 0; }
.input-bar form { display: flex; gap: 8px; align-items: flex-end; }
.input-bar textarea { flex: 1; padding: 10px 16px; border-radius: 24px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-size: 15px; outline: none; resize: none; min-height: 22px; max-height: 300px; line-height: 1.4; font-family: inherit; overflow-y: auto; }
.input-bar textarea:focus { border-color: var(--accent); }
.input-bar button { width: 44px; height: 44px; border-radius: 50%; border: none; background: var(--accent); color: #fff; font-size: 18px; cursor: pointer; flex-shrink: 0; transition: transform 0.1s; }
.input-bar button:active { transform: scale(0.9); }
.attach-btn { font-size: 22px; cursor: pointer; padding: 0 4px; display: flex; align-items: center; opacity: 0.5; transition: opacity 0.15s; flex-shrink: 0; }
.attach-btn:hover { opacity: 1; }
/* ── Пустое состояние ──────────────────────────────── */
.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); padding: 40px; }
.empty-icon { font-size: 48px; }
.empty-text { font-size: 15px; }
/* ── Логин ─────────────────────────────────────────── */
.login-screen { height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-logo { font-size: 56px; margin-bottom: 12px; }
.login-card h1 { font-size: 22px; font-weight: 800; margin-bottom: 16px; }
.login-error { background: rgba(239,68,68,0.12); color: var(--red); padding: 10px 16px; border-radius: 10px; font-size: 13px; margin-bottom: 16px; }
.login-card input { width: 100%; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 15px; outline: none; margin-bottom: 12px; }
.login-card input:focus { border-color: var(--accent); }
.login-card button { width: 100%; padding: 14px; border-radius: 12px; border: none; background: var(--accent); color: #fff; font-size: 16px; font-weight: 700; cursor: pointer; transition: opacity 0.15s; }
.login-card button:active { opacity: 0.8; }
.login-card button:disabled { background: var(--login-btn-disabled); cursor: not-allowed; }
/* ── Легенда (всплывающая) ─────────────────────────── */
.legend-popup { position: absolute; top: 44px; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; box-shadow: 0 8px 24px rgba(0,0,0,0.3); z-index: 100; min-width: 220px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 0; color: var(--text); }
.legend-link { display: block; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 13px; color: var(--accent); text-decoration: none; }
.legend-link:hover { text-decoration: underline; }
/* ── Кнопка справки ────────────────────────────────── */
.help-btn { width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--border); background: var(--bg); color: var(--muted); font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center; text-decoration: none; transition: all 0.15s; }
.help-btn:hover { color: var(--accent); border-color: var(--accent); }
/* ── Страница справки ──────────────────────────────── */
.help-content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 24px 20px; max-width: 700px; margin: 0 auto; }
.help-section { margin-bottom: 32px; }
.help-section h2 { font-size: 19px; font-weight: 700; margin-bottom: 12px; color: var(--text); }
.help-section p { font-size: 16px; line-height: 1.7; color: var(--text); margin-bottom: 8px; }
.help-row { display: flex; align-items: center; gap: 10px; font-size: 16px; padding: 6px 0; color: var(--text); }
.help-row code { background: var(--bg); border: 1px solid var(--border); padding: 3px 10px; border-radius: 6px; font-size: 15px; font-family: monospace; }
.help-note { font-size: 14px; color: var(--muted); margin-top: 10px; font-style: italic; }
/* ── Карточка клиента (внутренний чат) ─────────────── */
.client-card { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin: 6px 0; }
.cc-header { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.cc-row { font-size: 13px; color: var(--muted); padding: 2px 0; }
.cc-link { display: inline-block; margin-top: 8px; font-size: 13px; color: var(--accent); text-decoration: none; font-weight: 600; }
.cc-link:hover { text-decoration: underline; }
.cc-apartment { font-size: 14px; font-weight: 600; color: var(--text); padding: 4px 0 6px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.cc-row.last-msg { font-style: italic; opacity: 0.8; }
.team-btn { position: relative; }
.team-badge { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; border-radius: 9px; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 5px; color: #fff; }
.team-badge-card { background: #ef4444; animation: badge-pulse 2s infinite; }
.team-badge-text { background: #3b82f6; }
@keyframes badge-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }
.action-btn.share { color: var(--accent); }
.btn-delete-chat { background: none; border: none; font-size: 16px; cursor: pointer; opacity: 0; transition: opacity 0.2s; padding: 4px 8px; position: absolute; right: 8px; top: 50%; transform: translateY(-50%); z-index: 2; }
.chat-item { position: relative; }
.chat-item:hover .btn-delete-chat { opacity: 0.6; }
.btn-delete-chat:hover { opacity: 1 !important; }
/* ── Удалённые сообщения (v2.4) ────────────────────── */
.msg-deleted .msg-bubble { opacity: 0.45; border: 1px dashed var(--muted); position: relative; }
.msg-deleted .msg-bubble::before { content: '🗑️'; position: absolute; top: -8px; right: -8px; font-size: 14px; }
.deleted-label { color: var(--red); font-weight: 600; font-size: 10px; }

/* === Date separators (v2.6) === */
.date-separator{text-align:center;margin:18px 0 10px;position:relative}
.date-separator::before{content:"";position:absolute;left:10%;right:10%;top:50%;height:1px;background:var(--border,#e0e0e0)}
.date-separator span{position:relative;z-index:1;padding:2px 14px;font-size:12px;font-weight:500;color:var(--text-secondary,#888);background:var(--bg,#f5f5f5);border-radius:10px}
[data-theme="dark"] .date-separator span{background:var(--bg,#1a1a2e)}

.msg-reaction { font-size: 1.2em; margin-top: 2px; opacity: 0.9; }

/* WhatsApp phone number next to name */
.chat-phone{font-size:10px;color:var(--muted);font-weight:400;margin-left:4px;opacity:0.55;letter-spacing:-0.3px}
.topbar-title .chat-phone{font-size:12px}

/* Reply info + preview prefix */
.chat-reply{font-size:9px;color:var(--muted);opacity:0.4;flex-shrink:0;white-space:nowrap}
.preview-you{color:var(--accent);font-weight:600}

.chat-name-group{display:flex;align-items:center;gap:4px;min-width:0;overflow:hidden;text-overflow:ellipsis}

.f-dot{display:inline-block;width:8px;height:8px;border-radius:50%;margin-right:5px;vertical-align:middle}

/* B13: Индикатор «ждёт ответа» */
.chat-waiting {
    background: rgba(255, 152, 0, 0.08) !important;
    border-left: 3px solid #ff9800;
}
.chat-waiting:hover {
    background: rgba(255, 152, 0, 0.14) !important;
}
[data-theme="light"] .chat-waiting {
    background: rgba(255, 152, 0, 0.10) !important;
}
[data-theme="light"] .chat-waiting:hover {
    background: rgba(255, 152, 0, 0.18) !important;
}

/* B14: Название квартиры */
.chat-item-title {
    font-size: 11px;
    color: #888;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}
[data-theme="light"] .chat-item-title {
    color: #999;
}

/* ── B15: Быстрые сообщения ── */
.quick-msg-btn { font-size: 20px; cursor: pointer; padding: 0 4px; background: none; border: none; opacity: 0.5; transition: opacity 0.15s; flex-shrink: 0; line-height: 1; }
.quick-msg-btn:hover { opacity: 1; }
.quick-panel { position: absolute; bottom: 60px; left: 0; right: 0; max-height: 55vh; background: var(--surface); border-top: 1px solid var(--border); flex-direction: column; z-index: 50; box-shadow: 0 -4px 20px rgba(0,0,0,0.3); border-radius: 16px 16px 0 0; }
.quick-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 14px; color: var(--text); }
.quick-panel-close { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 8px; }
.quick-panel-body { overflow-y: auto; padding: 8px; flex: 1; }
.qp-search { width: 100%; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-size: 14px; margin-bottom: 8px; box-sizing: border-box; }
.qp-city { font-size: 11px; text-transform: uppercase; color: var(--muted); padding: 8px 8px 4px; letter-spacing: 0.5px; }
.qp-apt-btn { display: block; width: 100%; text-align: left; padding: 10px 12px; background: none; border: none; color: var(--text); font-size: 14px; cursor: pointer; border-radius: 8px; transition: background 0.15s; }
.qp-apt-btn:hover { background: var(--hover); }
.qp-back-btn { display: block; width: 100%; text-align: left; padding: 8px 12px; background: none; border: none; color: var(--accent); font-size: 13px; cursor: pointer; margin-bottom: 4px; }
.qp-tpl-btn { display: block; width: 100%; text-align: left; padding: 12px; background: none; border: none; color: var(--text); font-size: 14px; cursor: pointer; border-radius: 8px; transition: background 0.15s; border-bottom: 1px solid var(--border); }
.qp-tpl-btn:last-child { border-bottom: none; }
.qp-tpl-btn:hover { background: var(--hover); }
.qp-empty { text-align: center; padding: 24px; color: var(--muted); font-size: 13px; }
.qp-empty a { color: var(--accent); }
.qp-loading { text-align: center; padding: 24px; color: var(--muted); }
/* v2.74: Плоский UI шаблонов (B-TEMPLATES-UX-FLAT) */
.qp-section-title { font-size: 11px; text-transform: uppercase; color: var(--muted); padding: 12px 8px 6px; letter-spacing: 0.5px; font-weight: 600; }
.qp-section-title:first-child { padding-top: 4px; }
.qp-tpl-disabled { color: var(--muted); opacity: 0.55; cursor: not-allowed; }
.qp-tpl-disabled:hover { background: none; }
.qp-alert { background: #fef3c7; border: 1px solid #f59e0b; color: #92400e; padding: 10px 12px; border-radius: 8px; font-size: 13px; margin: 4px 0 8px; line-height: 1.4; }

/* ── B15: Страница квартир ── */
.apt-page { max-width: 900px; margin: 0 auto; padding: 16px; overflow-y: auto; flex: 1; }
.apt-page h2 { margin: 0 0 16px; color: var(--text); font-size: 18px; }
.apt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.apt-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; cursor: pointer; transition: border-color 0.15s; }
.apt-card:hover { border-color: var(--accent); }
.apt-card-name { font-weight: 600; font-size: 15px; color: var(--text); margin-bottom: 4px; }
.apt-card-addr { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.apt-card-codes { display: flex; gap: 8px; flex-wrap: wrap; }
.apt-code-tag { font-size: 11px; padding: 2px 8px; border-radius: 4px; background: var(--hover); color: var(--muted); }
.apt-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.apt-modal-content { background: var(--surface); border-radius: 12px; padding: 24px; max-width: 500px; width: 100%; max-height: 80vh; overflow-y: auto; }
.apt-modal-content h3 { margin: 0 0 16px; font-size: 16px; color: var(--text); }
.apt-field { margin-bottom: 12px; }
.apt-field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.apt-field input, .apt-field select, .apt-field textarea { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--input-bg); color: var(--text); font-size: 14px; box-sizing: border-box; }
.apt-field textarea { min-height: 60px; resize: vertical; }
.apt-btn-row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.apt-btn { padding: 8px 20px; border-radius: 8px; border: none; font-size: 14px; cursor: pointer; }
.apt-btn-primary { background: var(--accent); color: #fff; }
.apt-btn-secondary { background: var(--hover); color: var(--text); }
.apt-btn-add { padding: 10px 20px; background: var(--accent); color: #fff; border: none; border-radius: 8px; font-size: 14px; cursor: pointer; margin-bottom: 16px; }

/* ── B16: Привязка чатов ── */
.link-btn.link-active { color: var(--accent) !important; background: rgba(59,130,246,0.15); border-color: var(--accent); font-size: 13px; }
.link-panel { position: absolute; bottom: 60px; left: 0; right: 0; max-height: 55vh; background: var(--surface); border-top: 1px solid var(--border); flex-direction: column; z-index: 50; box-shadow: 0 -4px 20px rgba(0,0,0,0.3); border-radius: 16px 16px 0 0; }
.link-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 14px; color: var(--text); }
.link-panel-body { overflow-y: auto; padding: 8px; flex: 1; }
.link-item { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.link-item-info { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; color: var(--text); text-decoration: none; }
.link-item-info:hover .link-name { color: var(--accent); }
.link-ch { font-size: 16px; flex-shrink: 0; }
.link-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-apt { font-size: 11px; color: var(--muted); white-space: nowrap; }
.link-remove { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 4px 8px; opacity: 0.5; transition: opacity 0.15s; }
.link-remove:hover { opacity: 1; color: var(--red); }
.link-empty { text-align: center; padding: 16px; color: var(--muted); font-size: 13px; }
.link-search-wrap { padding: 8px 4px; border-top: 1px solid var(--border); margin-top: 4px; }
.link-result { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; width: 100%; text-align: left; padding: 10px 12px; background: none; border: none; color: var(--text); font-size: 14px; cursor: pointer; border-radius: 8px; border-bottom: 1px solid var(--border); transition: background 0.15s; }
.link-result:hover { background: rgba(59,130,246,0.08); }
.link-result:last-child { border-bottom: none; }
.link-preview { width: 100%; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.7; }
.link-badge { font-size: 11px; margin-left: -8px; margin-right: -4px; flex-shrink: 0; opacity: 0.5; }

/* B17: Схлопнутые связанные каналы */
.chat-channel-group { display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; align-items: center; width: 40px; }
.chat-channel-mini { width: 18px; height: 18px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; }
.chat-channel-mini svg { width: 12px; height: 12px; }
.chat-channel-mini img { width: 14px; height: 14px; }
.chat-channel-mini.ch-telegram { background: #2AABEE; }
.chat-channel-mini.ch-telegram svg { fill: #fff; }
.chat-channel-mini.ch-avito { background: #f0f0f0; }
.chat-channel-mini.ch-whatsapp { background: #25D366; }
.chat-channel-mini.ch-whatsapp svg { fill: #fff; }
.chat-channel-mini.ch-sutochno { background: #FF6600; color: #fff; }
.chat-channel-mini.ch-cian { background: #fff; border: 1px solid #e0e0e0; }
.chat-channel-mini.ch-max { background: #fff; }
.chat-channel-mini.ch-max img { width: 16px; height: 16px; border-radius: 4px; }
.group-toggle { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 16px; flex-shrink: 0; opacity: 0.4; transition: opacity 0.2s, background 0.2s; }
.group-toggle:hover { opacity: 0.7; }
.group-toggle.active { opacity: 1; background: var(--accent-bg, #e0f2fe); border-color: var(--accent, #3b82f6); }
.service-badge { background: #ef4444; color: #fff; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 10px; margin-left: 4px; }
.service-btn { opacity: 1; transition: opacity 0.2s; font-size: 22px; }
.service-btn:hover { opacity: 1; }
.service-btn.service-active { opacity: 1; background: var(--accent-bg, #e0f2fe); }

/* ── Справка: иконки каналов ── */
.help-ch { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; vertical-align: middle; margin-right: 4px; }
.help-ch.ch-telegram { background: #2AABEE; }
.help-ch.ch-telegram svg { fill: #fff; }
.help-ch.ch-avito { background: #f0f0f0; }
.help-ch.ch-cian { background: #fff; border: 1px solid #e0e0e0; }
.help-ch.ch-whatsapp { background: #25D366; }
.help-ch.ch-whatsapp svg { fill: #fff; }
.help-ch.ch-max { background: #fff; }
.help-ch.ch-max img { width: 16px; height: 16px; border-radius: 4px; }

/* ── Связанные каналы в шапке чата ── */
.linked-channels { display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; }
.linked-ch-link { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; opacity: 0.7; transition: opacity 0.15s; text-decoration: none; }
.linked-ch-link:hover { opacity: 1; }
.linked-ch-link svg { width: 18px; height: 18px; }
.linked-ch-link img { width: 16px; height: 16px; }


/* ═══════════════════════════════════════════════════════
   МОБИЛЬНАЯ АДАПТАЦИЯ (только <768px, десктоп не затронут)
   ═══════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* ── Главная: шапка ── */
    .topbar { padding: 8px 12px; min-height: 48px; flex-wrap: wrap; gap: 6px; }
    .topbar-title { font-size: 15px; }
    .logo { font-size: 17px; }

    /* ── Главная: панель сотрудников → гамбургер ── */
    .online-panel { display: none; position: absolute; top: 100%; right: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.15); z-index: 100; flex-direction: column; gap: 4px; min-width: 160px; }
    .online-panel.admin-panel-open { display: flex; }
    .admin-dot { font-size: 13px; padding: 6px 10px; border-radius: 8px; justify-content: flex-start; }
    .admin-toggle { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; font-size: 16px; cursor: pointer; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); }

    /* ── Главная: правая часть шапки ── */
    .topbar-right { gap: 6px; flex-wrap: nowrap; }
    .topbar-user { display: none; }
    .help-btn { width: 22px; height: 22px; font-size: 12px; }
    .theme-toggle { font-size: 16px; }
    .logout-btn { font-size: 20px; padding: 6px 10px; }

    /* ── Фильтры каналов ── */
    .filters { padding: 8px 12px; gap: 6px; }
    .filter-btn { padding: 5px 10px; font-size: 12px; }

    /* ── Список чатов ── */
    .chat-item { padding: 10px 12px; gap: 10px; }
    .chat-channel { width: 36px; height: 36px; font-size: 20px; }
    .chat-name { font-size: 14px; }
    .chat-phone { font-size: 9px; }
    .chat-preview { font-size: 13px; }
    .chat-time { font-size: 11px; }
    .chat-item-title { font-size: 10px; max-width: 200px; }
    .chat-reply { font-size: 8px; }

    /* ── Шапка диалога — КРИТИЧЕСКАЯ СЕКЦИЯ ── */
    .chat-topbar { flex-wrap: nowrap; padding: 8px 8px; min-height: 44px; }
    .back-btn { font-size: 18px; padding: 2px 4px; }

    .topbar-info { min-width: 0; }
    .topbar-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .topbar-sub { font-size: 11px; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
    .status-badge { font-size: 10px; padding: 1px 6px; }

    /* Кнопки действий: уменьшаем и скроллим */
    .topbar-actions { gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; flex-shrink: 0; max-width: 50vw; }
    .action-btn { width: 30px; height: 30px; font-size: 13px; border-radius: 6px; flex-shrink: 0; }

    /* Связанные каналы в шапке */
    .linked-channels { gap: 2px; margin-left: 4px; }
    .linked-ch-link { width: 20px; height: 20px; }
    .linked-ch-link svg { width: 14px; height: 14px; }

    /* ── Диалог: сообщения ── */
    .messages { padding: 8px 10px; gap: 4px; }
    .msg-bubble { max-width: 85%; padding: 8px 12px; font-size: 14px; }
    .msg-sender { font-size: 10px; }
    .msg-time { font-size: 9px; }

    /* ── Поле ввода ── */
    .input-bar { padding: 6px 8px; padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
    .input-bar textarea { padding: 8px 12px; font-size: 14px; }
    .input-bar button { width: 38px; height: 38px; font-size: 16px; }
    .attach-btn { font-size: 20px; }
    .quick-msg-btn { font-size: 18px; }

    /* ── Панели (быстрые сообщения, привязка) ── */
    .quick-panel, .link-panel { max-height: 60vh; }
    .qp-search, .link-search-wrap input { font-size: 14px; }

    /* ── Справка ── */
    .help-content { padding: 16px 14px; }
    .help-section h2 { font-size: 17px; }
    .help-section p, .help-row { font-size: 14px; }

    /* ── Квартиры ── */
    .apt-grid { grid-template-columns: 1fr; }
    .apt-modal-content { padding: 16px; }

    /* ── Легенда ── */
    .legend-popup { right: -8px; min-width: 200px; }

    /* ── Фильтры: короткие метки ── */
    .f-short { display: inline; }
    .f-full { display: none; }
    .filter-btn { padding: 5px 8px; font-size: 12px; gap: 2px; }

    /* ── PDF: убрать iframe, оставить ссылку ── */
    .msg-pdf-canvas { max-height: 250px; }
    .msg-pdf-open { display: flex; align-items: center; gap: 6px; padding: 10px 14px; background: var(--file-bg); border: 1px solid var(--border); border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--accent); text-decoration: none; }
    .msg-pdf-open::before { content: '📄'; font-size: 20px; }
}

/* ── Маленькие экраны (SE, mini) ── */
@media (max-width: 380px) {
    .online-panel { max-width: calc(100vw - 160px); }
    .admin-dot { font-size: 11px; padding: 2px 6px; }
    .topbar-actions { max-width: 45vw; }
    .action-btn { width: 28px; height: 28px; font-size: 12px; }
    .chat-name { font-size: 13px; }
    .topbar-title { font-size: 13px; }
}

/* Привязка квартиры (v2.14) */
.apt-select { font-size:11px; padding:1px 4px; border:1px solid currentColor; border-radius:4px; background:transparent; color:inherit; opacity:0.6; cursor:pointer; max-width:150px; margin-left:6px; vertical-align:middle; }
.apt-select:focus { opacity:1; outline:none; }
.apt-select option { background:var(--bg-card,#fff); color:var(--text,#333); }
@media(max-width:768px) { .apt-select { max-width:170px; margin-left:6px; margin-top:2px; padding:4px 8px; font-size:12px; font-weight:500; opacity:1; border:1.5px solid var(--accent,#2AABEE); background:var(--bg2,#f0f7ff); color:var(--accent,#2AABEE); border-radius:6px; } }

/* ── Merged chat channel icons ─────────────────────── */
.msg-ch-icon { display: inline-block; width: 14px; height: 14px; border-radius: 50%; margin-right: 4px; vertical-align: middle; background-size: contain; background-repeat: no-repeat; }
.msg-ch-icon.ch-avito { background: url("data:image/svg+xml,%3Csvg viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='14' cy='12' r='7' fill='%2300AAFF'/%3E%3Ccircle cx='28' cy='10' r='5' fill='%23F45B69'/%3E%3Ccircle cx='11' cy='27' r='4.5' fill='%239B59B6'/%3E%3Ccircle cx='27' cy='26' r='6.5' fill='%2397C93D'/%3E%3C/svg%3E"); }
.msg-ch-icon.ch-telegram { background-color: #2AABEE; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg' fill='white'%3E%3Cpath d='M9.78 18.65l.28-4.23 7.68-6.92c.34-.31-.07-.46-.52-.19L7.74 13.3 3.64 12c-.88-.25-.89-.86.2-1.3l15.97-6.16c.73-.33 1.43.18 1.15 1.3l-2.72 12.81c-.19.91-.74 1.13-1.5.71L12.6 16.3l-1.99 1.93c-.23.23-.42.42-.83.42z'/%3E%3C/svg%3E"); background-size: 10px 10px; background-position: center; }
.msg-ch-icon.ch-whatsapp { background-color: #25D366; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg' fill='white'%3E%3Cpath d='M17.47 14.38c-.3-.15-1.76-.87-2.03-.97-.27-.1-.47-.15-.67.15-.2.3-.77.97-.94 1.17-.17.2-.35.22-.64.07-.3-.15-1.26-.46-2.4-1.48-.89-.79-1.49-1.77-1.66-2.07-.17-.3-.02-.46.13-.61.14-.13.3-.35.45-.52.15-.17.2-.3.3-.5.1-.2.05-.37-.02-.52-.08-.15-.67-1.62-.92-2.22-.24-.58-.49-.5-.67-.51h-.58c-.2 0-.52.07-.79.37-.27.3-1.04 1.02-1.04 2.49s1.07 2.89 1.22 3.09c.15.2 2.1 3.22 5.1 4.51.71.31 1.27.49 1.7.63.72.23 1.37.2 1.88.12.58-.09 1.76-.72 2.01-1.41.25-.7.25-1.29.17-1.41-.07-.13-.27-.2-.57-.35z'/%3E%3C/svg%3E"); background-size: 10px 10px; background-position: center; }
.msg-ch-icon.ch-cian { background: #fff; border: 1px solid #e0e0e0; background-image: url("/static/cian_logo.png"); background-size: 10px 10px; background-position: center; }
.msg-ch-icon.ch-max { background: #fff; border: 1px solid #e0e0e0; background-image: url("/static/max_logo.png"); background-size: 10px 10px; background-position: center; }

/* ── Channel switch in merged view ─────────────────── */
.ch-switch-btn { background: transparent !important; border: none !important; border-radius: 4px !important; padding: 2px 4px !important; cursor: pointer; display: flex; align-items: center; gap: 1px; width: auto !important; height: 32px !important; color: var(--text) !important; font-size: 12px !important; flex-direction: column; }
.ch-switch-btn:active { transform: none !important; }
.ch-switch-btn .msg-ch-icon { width: 18px; height: 18px; }
.ch-switch-arrow { font-size: 8px !important; line-height: 1; color: var(--muted); }
.ch-switch-arrow { font-size: 10px; color: var(--muted); }
.ch-switch-wrap { position: relative; display: flex; align-items: center; }
.ch-switch-popup { position: absolute; bottom: 100%; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px 0; box-shadow: 0 4px 16px rgba(0,0,0,0.15); z-index: 100; min-width: 180px; margin-bottom: 4px; }
.ch-switch-item { display: flex; align-items: center; gap: 8px; padding: 8px 14px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.ch-switch-item:hover { background: var(--hover, rgba(59,130,246,0.08)); }
.ch-switch-item.ch-active { background: rgba(59,130,246,0.1); }
.ch-current { font-size: 11px; color: var(--muted); margin-left: auto; }

/* ── Протоколы ────────────────────────────────────────── */
.proto-screen { overflow: auto; }
.proto-list { padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.proto-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; cursor: pointer; transition: border-color 0.2s; }
.proto-card:hover { border-color: var(--accent); }
.proto-card.proto-pinned { border-color: var(--accent); }
.proto-preview { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.proto-preview-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.proto-preview-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.proto-date { font-size: 12px; color: var(--muted); }
.proto-expand-icon { font-size: 14px; color: var(--muted); }
.proto-preview-problem { font-size: 13px; color: var(--muted); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proto-details { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.proto-header { margin-bottom: 12px; }
.proto-title { font-weight: 700; font-size: 16px; }
.proto-pin { font-size: 14px; }
.proto-number { font-size: 13px; color: var(--accent); font-weight: 700; }
.proto-cat { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--border); color: var(--muted); }
.proto-meta { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; align-items: center; gap: 8px; }
.proto-action { background: none; border: none; cursor: pointer; font-size: 14px; opacity: 0.5; padding: 2px; }
.proto-action:hover { opacity: 1; }
.proto-body { display: flex; flex-direction: column; gap: 10px; }
.proto-section { padding: 10px 12px; border-radius: 8px; background: var(--bg); }
.proto-label { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.proto-text { font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.proto-reads { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.proto-reads-label { font-size: 12px; color: var(--muted); }
.proto-read-badge { font-size: 12px; padding: 2px 6px; border-radius: 6px; }
.proto-read-badge.read-yes { background: rgba(34,197,94,0.15); color: var(--green); }
.proto-read-badge.read-no { opacity: 0.4; }
.proto-comments { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.proto-comment { padding: 6px 10px; background: var(--bg); border-radius: 8px; font-size: 13px; }
.proto-comment-author { font-weight: 600; margin-right: 6px; }
.proto-comment-time { font-size: 11px; color: var(--muted); }
.proto-comment-text { margin-top: 2px; }
.proto-comment-form { margin-top: 8px; display: flex; gap: 6px; }
.proto-comment-input { flex: 1; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 13px; font-family: inherit; outline: none; }
.proto-comment-input:focus { border-color: var(--accent); }
.proto-btn { border: none; cursor: pointer; border-radius: 8px; font-size: 13px; padding: 6px 14px; font-family: inherit; }
.proto-btn-save { background: var(--accent); color: #fff; }
.proto-btn-cancel { background: var(--border); color: var(--text); }
.proto-btn-read { background: var(--green); color: #fff; font-size: 12px; padding: 4px 10px; }
.proto-btn-comment { background: var(--accent); color: #fff; padding: 6px 12px; }
.proto-form { margin: 12px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.proto-form-title { font-weight: 700; font-size: 16px; margin-bottom: 12px; }
.proto-input { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit; outline: none; margin-bottom: 8px; box-sizing: border-box; }
.proto-textarea { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit; outline: none; resize: vertical; margin-bottom: 8px; box-sizing: border-box; }
.proto-input:focus, .proto-textarea:focus { border-color: var(--accent); }
.proto-form-actions { display: flex; gap: 8px; }

/* ── Оплата собственникам ─────────────────────────────── */
.pay-screen { overflow: auto; }
.pay-year-select { font-size: 13px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); cursor: pointer; }

/* Сводка */
.pay-summary { display: flex; gap: 12px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.pay-card { flex: 1; min-width: 110px; padding: 10px 14px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
.pay-card-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 2px; }
.pay-card-val { font-size: 18px; font-weight: 700; }
.pay-green { color: var(--green); }
.pay-red { color: var(--red); }
.pay-debt-bg { background: rgba(255, 165, 0, 0.12); color: #b37400; font-weight: 600; }

/* Таблица */
.pay-table-wrap { flex: 1; overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 0 12px; }
.pay-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 920px; }
.pay-table thead th { position: sticky; top: 0; z-index: 3; background: var(--surface); padding: 10px 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; color: var(--muted); border-bottom: 2px solid var(--border); text-align: center; white-space: nowrap; }
.pay-th-fix { text-align: left !important; min-width: 160px; padding-left: 16px !important; position: sticky; left: 0; z-index: 4; background: var(--surface); }
.pay-th-name { text-align: left !important; min-width: 140px; }
.pay-th-amt { min-width: 70px; }
.pay-th-m { min-width: 48px; }

/* Строки */
.pay-row { border-bottom: 1px solid var(--border); transition: background 0.1s; }
.pay-row:hover { background: rgba(59,130,246,0.03); }
.pay-row-group { background: rgba(245,158,11,0.04); }
.pay-row-group:hover { background: rgba(245,158,11,0.08); }
.pay-row-group .pay-c-apt { background: rgba(245,158,11,0.04); }

/* Ячейки */
.pay-c-apt { padding: 8px 8px 8px 16px; font-weight: 600; white-space: nowrap; position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: 2px 0 4px rgba(0,0,0,0.06); clip-path: inset(0 -4px 0 0); }
.pay-link { cursor: pointer; transition: color 0.15s; }
.pay-link:hover { color: var(--accent); }
.pay-edit { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 11px; padding: 2px 4px; opacity: 0; transition: opacity 0.15s; margin-left: 4px; }
.pay-row:hover .pay-edit { opacity: 0.5; }
.pay-edit:hover { opacity: 1 !important; }
.pay-c-name { padding: 8px; color: var(--muted); white-space: nowrap; font-size: 12px; }
.pay-c-phone { padding: 8px 6px; white-space: nowrap; font-size: 12px; color: var(--muted); }
.pay-phone-num { cursor: pointer; font-variant-numeric: tabular-nums; letter-spacing: 0.3px; transition: color 0.15s; }
.pay-phone-num:hover { color: var(--accent); }
.pay-c-bank { padding: 8px 6px; white-space: nowrap; font-size: 11px; color: var(--muted); }
.pay-th-extra { text-align: left !important; min-width: 100px; }
.pay-sortable { cursor: pointer; user-select: none; transition: color 0.15s; }
.pay-sortable:hover { color: var(--accent); }
.pay-sort-icon { font-size: 10px; opacity: 0.7; }
.pay-c-amt { padding: 8px 6px; text-align: center; color: var(--muted); font-size: 12px; white-space: nowrap; }
.pay-toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; padding: 8px 20px; border-radius: 8px; font-size: 13px; font-weight: 600; z-index: 1000; box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.pay-rub { font-size: 0.7em; font-weight: 400; opacity: 0.7; }
.pay-cell { padding: 6px 2px; text-align: center; cursor: pointer; border-left: 1px solid var(--border); min-width: 48px; font-size: 12px; transition: all 0.15s; user-select: none; }
.pay-cell:hover { background: rgba(59,130,246,0.08); }
.pay-cell.paid { background: rgba(34,197,94,0.12); color: var(--green); font-weight: 700; font-size: 14px; }
.pay-cell.partial { background: rgba(245,158,11,0.12); color: var(--orange); font-weight: 600; }
.pay-cell.unpaid-due { background: rgba(239,68,68,0.08); }
.pay-due-amt { font-size: 11px; color: var(--red); opacity: 0.7; }
.pay-th-day { min-width: 36px; width: 36px; text-align: center !important; }
.pay-c-day { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 4px; }
.pay-toggle-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; white-space: nowrap; padding: 0 8px; user-select: none; }
.pay-toggle-label input { width: 16px; height: 16px; margin: 0; }
.pay-c-total { padding: 8px 6px; text-align: center; font-weight: 700; border-left: 2px solid var(--border); white-space: nowrap; font-size: 12px; }

/* Просрочка */
.pay-overdue-section { padding: 12px 16px; border-top: 1px solid var(--border); }
.pay-overdue-title { font-size: 13px; font-weight: 700; color: var(--red); margin-bottom: 8px; }
.pay-overdue-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.pay-ov-chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; background: var(--bg); border: 1px solid var(--border); border-radius: 20px; font-size: 13px; font-weight: 500; color: var(--text); cursor: pointer; transition: all 0.15s; font-family: inherit; }
.pay-ov-chip:hover { background: rgba(239,68,68,0.08); border-color: rgba(239,68,68,0.3); }
.pay-ov-m { font-size: 11px; color: var(--red); font-weight: 600; }

.apt-btn-danger { background: var(--red); color: #fff; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.apt-btn-danger:hover { filter: brightness(1.1); }

/* ── Мобилка ── */
@media (max-width: 768px) {
    .pay-summary { gap: 6px; padding: 8px 10px; }
    .pay-card { padding: 8px 10px; min-width: 0; }
    .pay-card-label { font-size: 10px; }
    .pay-card-val { font-size: 14px; }
    .pay-rub { font-size: 0.65em; }
    .pay-table-wrap { padding: 0 4px; }
    .pay-table { min-width: 600px; font-size: 11px; }
    .pay-th-fix { min-width: 110px; padding-left: 8px !important; }
    .pay-th-name { min-width: 80px; }
    .pay-th-extra { min-width: 70px; }
    .pay-th-day { min-width: 28px; width: 28px; }
    .pay-th-m { min-width: 48px; }
    .pay-cell { min-width: 48px; padding: 4px 1px; font-size: 11px; }
    .pay-c-apt { padding: 6px 4px 6px 8px; font-size: 11px; }
    .pay-c-day { font-size: 11px; padding: 6px 2px; }
    .pay-c-name { font-size: 10px; padding: 6px 4px; }
    .pay-c-phone { font-size: 10px; padding: 6px 4px; }
    .pay-c-bank { font-size: 10px; padding: 6px 4px; }
    .pay-c-amt { font-size: 10px; }
    .pay-c-total { font-size: 10px; }
    .pay-edit { opacity: 0.4; }
    .pay-overdue-btns { gap: 6px; }
    .pay-ov-chip { padding: 6px 12px; font-size: 12px; border-radius: 16px; }
    .pay-toggle-label { font-size: 11px; }
}

/* Patch SI-B: system_internal cards (30.04.2026) */
.si-wrap { padding: 4px 12px; }
.si {
    background: #fef9e7;
    border-left: 3px solid #f59e0b;
    border-radius: 8px;
    padding: 10px 14px;
    margin: 6px 0;
    max-width: 480px;
    font-size: 14px;
    line-height: 1.45;
    color: #1f2937;
}
.si-header { font-weight: 600; font-size: 14.5px; margin-bottom: 4px; }
.si-badge {
    font-size: 11px;
    color: #6b7280;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px dashed #e5e7eb;
}
.si-body { display: flex; flex-direction: column; gap: 4px; }
.si-row { line-height: 1.5; }
.si-i { display: inline-block; width: 22px; }
.si-muted { color: #6b7280; font-size: 13px; }
.si-warn { color: #c2410c; font-weight: 500; margin-top: 6px; }
.si-footer {
    font-size: 12px;
    color: #92400e;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed #d97706;
}
.si-test-label {
    background: #1f2937;
    color: #fff;
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    margin-bottom: 6px;
}
.si-paid {
    background: #ecfdf5;
    border-left-color: #10b981;
    color: #064e3b;
}
.si-paid .si-footer {
    color: #047857;
    border-top-color: #6ee7b7;
}
.si-cancelled {
    background: #f3f4f6;
    border-left-color: #9ca3af;
    color: #4b5563;
    opacity: 0.85;
}
.si-cancelled .si-header { text-decoration: line-through; }
.si-test {
    opacity: 0.85;
    background: #f3f4f6 !important;
    border-left-color: #6b7280 !important;
}
.si-time {
    font-size: 11px;
    color: #9ca3af;
    text-align: right;
    margin-top: 4px;
    padding-right: 10px;
}
@media (max-width: 480px) {
    .si { max-width: 100%; font-size: 13.5px; }
    .si-row { word-break: break-word; }
}
/* /Patch SI-B */


/* ── v2.41: edit history + delete badges ── */

/* Edited message — тонкая подсветка слева, мягче чем deleted */
.msg-edited .msg-bubble {
    border-left: 3px solid var(--accent);
    padding-left: 11px;
}

/* Бейджи в строке времени */
.msg-edited-badge {
    color: var(--muted);
    font-size: 10px;
    margin-left: 6px;
    font-style: italic;
    cursor: help;
}

/* Подпись «удалено» — наследует .deleted-label из существующих стилей */

/* Аккордеон с историей правок/удалений */
.msg-history-acc {
    margin-top: 6px;
    font-size: 11px;
}
.msg-history-acc summary {
    list-style: none;
    cursor: pointer;
    color: var(--muted);
    padding: 4px 8px;
    border-radius: 6px;
    background: rgba(255,255,255,0.04);
    user-select: none;
    transition: background 0.12s, color 0.12s;
    display: inline-block;
}
.msg-history-acc summary::-webkit-details-marker { display: none; }
.msg-history-acc summary:hover {
    background: rgba(59,130,246,0.12);
    color: var(--accent);
}
.msg-history-acc[open] summary {
    background: rgba(59,130,246,0.1);
    color: var(--accent);
    margin-bottom: 6px;
}

/* Список версий */
.msg-history-list {
    background: rgba(0,0,0,0.18);
    border-left: 2px solid var(--accent);
    border-radius: 4px;
    padding: 6px 10px;
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
[data-theme="light"] .msg-history-list {
    background: rgba(0,0,0,0.04);
}

.msg-history-item {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: baseline;
    line-height: 1.35;
}
.hist-time {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 10px;
    color: var(--muted);
    flex-shrink: 0;
}
.hist-event {
    font-size: 10px;
    color: var(--muted);
    font-weight: 600;
    flex-shrink: 0;
}
.hist-text {
    color: var(--text);
    word-break: break-word;
    font-size: 11px;
}



/* ── v2.41: усиление визуала карточек system_internal ── */
.si {
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04);
    border-left-width: 4px;
}
.si-badge {
    background: rgba(0,0,0,0.04);
    padding: 4px 8px;
    border-radius: 4px;
    border-bottom: none;
    display: inline-block;
}

/* B-CHAT-INVOICE-INDICATOR — индикаторы оплат */
.chat-pay-indicators {
    margin-left: 8px;
    user-select: none;
    white-space: nowrap;
    display: inline-flex;
    gap: 3px;
    vertical-align: -2px;
}
.chat-pay-badge {
    font-size: 16px;
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", sans-serif;
    cursor: help;
    line-height: 1;
}


/* ── v2.62.3: UI edit/delete сообщений (Telegram-style) ─ */
.msg-actions {
    display: inline-flex;
    gap: 4px;
    margin-left: 8px;
    vertical-align: middle;
}
.msg-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 3px;
    font-size: 13px;
    line-height: 1;
    opacity: 0.45;
    transition: opacity 0.15s;
    color: inherit;
}
.msg-action-btn:hover,
.msg-action-btn:active,
.msg-action-btn:focus { opacity: 1; outline: none; }

/* Подсветка сообщения, которое сейчас редактируется */
.msg.editing-target .msg-bubble {
    box-shadow: 0 0 0 2px var(--accent, #2563eb);
    transition: box-shadow 0.15s;
}

/* Баннер «Редактирование» над строкой ввода */
.edit-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: var(--bg-elevated, #eff6ff);
    border-top: 1px solid var(--border, #e5e7eb);
    border-left: 3px solid var(--accent, #2563eb);
    font-size: 13px;
}
.edit-banner-icon {
    font-size: 16px;
    line-height: 1;
    color: var(--accent, #2563eb);
}
.edit-banner-content {
    flex: 1;
    overflow: hidden;
    min-width: 0;
}
.edit-banner-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent, #2563eb);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.edit-banner-preview {
    font-size: 13px;
    color: var(--muted, #6b7280);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}
.edit-banner-cancel {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 4px 8px;
    color: var(--muted, #6b7280);
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}
.edit-banner-cancel:hover {
    background: var(--bg, rgba(0,0,0,0.05));
    color: var(--text, #000);
}


/* v2.67: модалка завершения чата */
.gh-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 16px;
}
.gh-modal {
    background: var(--card, #fff);
    border-radius: 12px;
    padding: 20px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.gh-modal-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--text, #000);
}
.gh-modal-option {
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.gh-modal-option:hover {
    background: var(--bg, #f9fafb);
    border-color: var(--accent, #2563eb);
}
.gh-modal-option-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text, #000);
}
.gh-modal-option-desc {
    font-size: 12px;
    color: var(--muted, #6b7280);
    line-height: 1.5;
}
.gh-modal-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 6px;
}
.gh-modal-cancel {
    background: transparent;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    color: var(--muted, #6b7280);
}
.gh-modal-cancel:hover {
    background: var(--bg, #f9fafb);
    color: var(--text, #000);
}


/* v2.69: кнопка пина в шапке чата */
.action-btn.pin-active {
    background: #fef3c7;
    border-color: #f59e0b;
}

/* v2.69: панель «Забрать чат сюда» */
.take-bar {
    padding: 8px 12px 4px 12px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    background: var(--bg, #f9fafb);
}
.take-btn {
    width: 100%;
    background: var(--card, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text, #000);
}
.take-btn:hover {
    background: var(--bg, #f3f4f6);
    border-color: var(--accent, #2563eb);
}
.take-panel {
    margin-top: 6px;
    background: var(--card, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    padding: 8px;
}
.take-panel-row {
    display: flex;
    gap: 6px;
    align-items: center;
}
.take-panel-row .qp-search {
    flex: 1;
}
.take-panel-close {
    background: transparent;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 14px;
    color: var(--muted, #6b7280);
}
.take-results {
    margin-top: 6px;
    max-height: 240px;
    overflow-y: auto;
}
.take-result {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border, #e5e7eb);
    padding: 8px 6px;
    cursor: pointer;
    font-size: 13px;
    text-align: left;
}
.take-result:hover { background: var(--bg, #f3f4f6); }
.take-result:last-child { border-bottom: none; }
.take-name { font-weight: 500; color: var(--text, #000); }
.take-apt { color: var(--muted, #6b7280); font-size: 12px; margin-left: 4px; }
.take-empty {
    padding: 14px 8px;
    color: var(--muted, #6b7280);
    font-size: 13px;
    text-align: center;
}

/* v2.69: метка 📌 на закреплённых в списке + стрелки ↑↓ */
.chat-item-pin-marker {
    display: inline-block;
    margin-right: 4px;
    font-size: 12px;
    opacity: 0.85;
}
.pin-arrows {
    display: inline-flex;
    gap: 2px;
    margin-left: 6px;
    vertical-align: middle;
}
.pin-arrow {
    background: transparent;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 4px;
    width: 22px;
    height: 22px;
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    color: var(--muted, #6b7280);
    padding: 0;
}
.pin-arrow:hover { background: var(--bg, #f3f4f6); color: var(--text, #000); }
.pin-arrow:disabled { opacity: 0.3; cursor: default; }


/* v2.69.2: компактная кнопка «Забрать чат сюда» в строке поиска */
.take-toggle {
    width: 36px;
    height: 36px;
    background: var(--card, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--muted, #6b7280);
    flex-shrink: 0;
    margin-left: 4px;
    padding: 0;
}
.take-toggle:hover {
    background: var(--bg, #f3f4f6);
    border-color: var(--accent, #2563eb);
    color: var(--text, #000);
}


/* === USER_MENU_v1: меню ⚙️ Опции пользователя === */
.user-menu-wrap { position: relative; display: inline-block; }
.user-menu-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; font-size: 13px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); cursor: pointer; font-family: inherit;
    transition: background 0.15s, border-color 0.15s;
}
.user-menu-btn:hover { background: var(--surface); border-color: var(--accent); }
.user-menu-icon { font-size: 14px; line-height: 1; }
.user-menu-name { font-weight: 500; }

.user-menu-dropdown {
    display: none;
    position: absolute; top: calc(100% + 6px); right: 0;
    min-width: 240px; padding: 6px 0;
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    z-index: 1000;
}
.user-menu-dropdown.open { display: block; }

.user-menu-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; font-size: 14px;
    color: var(--text); text-decoration: none; cursor: pointer;
    transition: background 0.1s;
}
.user-menu-item:hover { background: var(--bg); }
.user-menu-item-icon { font-size: 16px; line-height: 1; flex-shrink: 0; }
.user-menu-item-label { flex: 1; }
.user-menu-item-danger { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 12px; }
.user-menu-item-danger:hover { background: rgba(220, 38, 38, 0.08); }

.push-dot {
    width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.1);
}
.push-dot.on { background: #22c55e; }
.push-dot.off { background: #a1a1aa; }
.push-dot.denied { background: #ef4444; }


/* === USER_MENU_v1_TOGGLE === */
.user-menu-toggle {
    position: relative; flex-shrink: 0;
    width: 36px; height: 20px;
    background: #a1a1aa; border-radius: 10px;
    transition: background 0.2s;
}
.user-menu-toggle.on { background: #22c55e; }
.user-menu-toggle.denied { background: #ef4444; }
.user-menu-toggle-knob {
    position: absolute; top: 2px; left: 2px;
    width: 16px; height: 16px;
    background: #fff; border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.25);
    transition: left 0.2s;
}
.user-menu-toggle.on .user-menu-toggle-knob { left: 18px; }


/* === USER_MENU_v1_STATE_LABEL === */
.user-menu-toggle-state {
    font-size: 12px; color: var(--muted);
    margin-left: auto; padding-right: 8px;
    flex-shrink: 0; min-width: 50px; text-align: right;
}
