/* ConnectWave — operator UI */

/* Screen-reader only — visually hidden but accessible */
.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

:root {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --border: #e3e8ef;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --in-bubble: #ffffff;
    --out-bubble: #dcf8c6;
    --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
    --topbar-h: 56px;

    /* ── Chat theme (меняется через JS) ── */
    --chat-bg:           #eef1f6;
    --bubble-out-bg:     #2563eb;
    --bubble-out-text:   #ffffff;
    --bubble-out-shadow: rgba(37, 99, 235, .25);
    --bubble-in-bg:      #ffffff;
    --bubble-in-text:    #1f2937;
    --bubble-in-shadow:  rgba(15, 23, 42, .10);
    --msg-meta-color:    #8a96a8;
    --msg-sep-pill:      #dce3ed;
    --msg-sep-line:      #d1d9e4;
    --msg-sender-in:     #5b6b7c;
}

* { box-sizing: border-box; }
/* HTML hidden-атрибут всегда имеет приоритет, даже если у элемента display: flex */
[hidden] { display: none !important; }

html, body {
    margin: 0; padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
                 Ubuntu, Cantarell, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100%;
}

input, textarea, select, button { font: inherit; color: inherit; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
    background: var(--panel); cursor: pointer; transition: background .15s, border-color .15s;
    font-weight: 500;
}
.btn:hover { background: var(--panel-soft); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--border); }
/* .btn-call — заменён на .btn-call-compact в шапке карточки */
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; }
.field > span { font-size: 11px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .03em; }
.field input, .field textarea, .field select {
    padding: 6px 10px; border: 1px solid var(--border); border-radius: 7px;
    background: #fff; outline: none; font-size: 13px;
}
.field input:focus, .field textarea:focus, .field select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.field-row { display: grid; grid-template-columns: 1fr 90px; gap: 8px; }
.field-row--half { grid-template-columns: 1fr 1fr; }
.field-narrow { width: 100%; }

/* ─── FLASH ─────────────────────────────────────────────── */
.flash-stack {
    position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
    z-index: 50; display: flex; flex-direction: column; gap: 8px;
}
.flash {
    padding: 10px 16px; border-radius: 8px; background: #fee2e2; color: #991b1b;
    box-shadow: var(--shadow); font-size: 14px;
}
.flash-error { background: #fee2e2; color: #991b1b; }

/* ─── LOGIN ─────────────────────────────────────────────── */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #eef2ff 0%, #e0f2fe 100%);
}
.login-card {
    width: 100%; max-width: 380px; background: var(--panel);
    padding: 32px; border-radius: 16px; box-shadow: 0 12px 40px rgba(15, 23, 42, .08);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-logo {
    display: inline-flex; width: 56px; height: 56px; align-items: center; justify-content: center;
    border-radius: 14px; background: var(--primary); color: #fff;
    font-weight: 700; font-size: 22px; margin-bottom: 12px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.login-hint {
    margin: 18px 0 0; text-align: center; color: var(--muted); font-size: 12px;
}
.login-hint code {
    background: var(--panel-soft); padding: 2px 5px; border-radius: 4px; font-size: 12px;
}

/* ─── APP SHELL ─────────────────────────────────────────── */
.app-shell { height: 100vh; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-h);
    display: flex; align-items: center; padding: 0 18px;
    background: var(--panel); border-bottom: 1px solid var(--border); gap: 18px;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
    width: 32px; height: 32px; border-radius: 8px; background: var(--primary);
    color: #fff; display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px;
}
.brand-name { font-weight: 600; }
.topbar-status {
    display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted);
}
.topbar-status .dot {
    width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
}
.topbar-status.online .dot { background: var(--success); }
.topbar-user {
    margin-left: auto; display: flex; align-items: center; gap: 10px;
}
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--primary); color: #fff;
    font-size: 13px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; user-select: none;
}
.user-info {
    display: flex; flex-direction: column; gap: 1px; line-height: 1;
}
.user-name { font-weight: 600; font-size: 13px; }
.user-role-label { font-size: 11px; color: var(--muted); }

.btn-topbar-admin {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 500;
    background: var(--primary); color: #fff; border: none;
    text-decoration: none; cursor: pointer; transition: opacity .15s;
}
.btn-topbar-admin:hover { opacity: .85; }

.btn-topbar-logout {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 500;
    background: transparent; color: var(--muted);
    border: 1px solid var(--border);
    text-decoration: none; cursor: pointer; transition: color .15s, border-color .15s;
}
.btn-topbar-logout:hover { color: var(--danger, #dc2626); border-color: var(--danger, #dc2626); }

/* 3 columns: chats | chat | debtor */
.layout-3col {
    flex: 1; min-height: 0;
    display: grid;
    grid-template-columns: 320px 1fr 340px;
}

/* ─── COL: CHATS ────────────────────────────────────────── */
.col-chats {
    background: var(--panel); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; min-height: 0;
}
.col-head {
    padding: 12px 14px; border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 8px;
}
.col-head h2 { margin: 0; font-size: 16px; }
.col-head input[type="search"] {
    padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--panel-soft); outline: none;
}
.chat-list {
    list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1;
}
.chat-item {
    padding: 12px 14px; cursor: pointer; border-bottom: 1px solid var(--border);
    display: flex; gap: 10px; align-items: flex-start;
    transition: background .12s;
    border-left: 5px solid transparent;
}
.chat-item:hover { background: var(--panel-soft); }
.chat-item.active { background: #eff6ff; }
/* Цветные полоски по статусу должника */
.chat-item--new           { border-left-color: #9ca3af; }
.chat-item--in_progress   { border-left-color: #3b82f6; }
.chat-item--promised_to_pay { border-left-color: #f59e0b; }
.chat-item--paid          { border-left-color: #22c55e; }
.chat-item--refused       { border-left-color: #ef4444; }
/* sf-chip стили удалены — статус-фильтр заменён дропдауном (см. .op-filter-bar) */

/* ─── OPERATOR FILTER BAR ──────────────────────────────────── */
.op-filter-bar {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 12px 7px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
}
.op-filter-label {
    font-size: 12px; color: var(--muted); white-space: nowrap; flex-shrink: 0;
}
.op-filter-select {
    flex: 1; font-size: 12px; padding: 3px 6px;
    border: 1.5px solid var(--border); border-radius: 8px;
    background: var(--panel); color: var(--text);
    cursor: pointer; outline: none; min-width: 0;
}
.op-filter-select:focus { border-color: var(--primary); }

/* ─── DATE FILTER BAR ──────────────────────────────────────── */
.op-filter-bar--date {
    flex-wrap: wrap; gap: 6px;
}
.op-date-range {
    display: flex; align-items: center; gap: 4px; flex: 1;
}
.op-date-input {
    flex: 1; font-size: 12px; padding: 3px 6px;
    border: 1.5px solid var(--border); border-radius: 8px;
    background: var(--panel); color: var(--text);
    outline: none; min-width: 0; cursor: pointer;
}
.op-date-input:focus { border-color: var(--primary); }
.op-date-sep {
    font-size: 13px; color: var(--muted); flex-shrink: 0;
}
.op-date-clear {
    flex-shrink: 0; padding: 2px 7px; font-size: 13px;
    background: none; border: 1.5px solid var(--border);
    border-radius: 8px; color: var(--muted); cursor: pointer;
    line-height: 1.4; transition: border-color .15s, color .15s;
}
.op-date-clear:hover { border-color: #ef4444; color: #ef4444; }

.chat-avatar {
    width: 38px; height: 38px; border-radius: 50%; background: var(--primary);
    color: #fff; flex: 0 0 38px;
    display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.chat-meta { flex: 1; min-width: 0; }
.chat-row {
    display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
}
.chat-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.chat-preview {
    color: var(--muted); font-size: 13px; margin-top: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-badge {
    background: var(--primary); color: #fff; font-size: 11px; padding: 2px 7px;
    border-radius: 999px; margin-left: 6px;
}
.contact-unread {
    background: var(--primary); color: #fff; font-size: 11px; padding: 2px 7px;
    border-radius: 999px; margin-left: 6px;
}
.chat-empty { padding: 20px; color: var(--muted); text-align: center; }

/* ─── COL: CHAT ─────────────────────────────────────────── */
.col-chat {
    display: flex; flex-direction: column; min-height: 0;
    background: var(--chat-bg);
    transition: background .3s;
}
.chat-head {
    padding: 12px 18px; min-height: 56px;
    border-bottom: 1px solid var(--border); background: var(--panel);
    display: flex; align-items: center; gap: 12px;
    box-shadow: 0 1px 4px rgba(15,23,42,.06);
}
.chat-head-empty { color: var(--muted); }
.chat-head .name { font-weight: 600; }
.chat-head .phone { color: var(--muted); font-size: 13px; }

.chat-body {
    flex: 1; overflow-y: auto; padding: 16px 20px;
    display: flex; flex-direction: column; gap: 2px;
}
.chat-placeholder {
    margin: auto; color: var(--muted); font-size: 14px;
}

/* ── Date separator ───────────────── */
.msg-date-sep {
    display: flex; align-items: center; gap: 10px;
    margin: 14px 0 10px; user-select: none;
}
.msg-date-sep::before, .msg-date-sep::after {
    content: ''; flex: 1; height: 1px; background: var(--msg-sep-line);
}
.msg-date-sep span {
    font-size: 11px; font-weight: 600; color: var(--msg-meta-color);
    padding: 2px 10px; background: var(--msg-sep-pill); border-radius: 999px;
    white-space: nowrap;
}

/* ── Message wrapper ──────────────── */
.message {
    display: flex; flex-direction: column;
    max-width: 68%; margin-bottom: 1px;
}
.message.in  { align-self: flex-start; }
.message.out { align-self: flex-end; }

/* ── Sender name ──────────────────── */
.msg-sender {
    font-size: 11px; font-weight: 600; margin-bottom: 3px;
    padding: 0 2px;
}
.msg-sender.in  { color: var(--msg-sender-in); align-self: flex-start; }
.msg-sender.out { color: var(--primary);        align-self: flex-end; }

/* ── Bubble ───────────────────────── */
.msg-bubble {
    padding: 10px 14px; border-radius: 18px;
    word-wrap: break-word; white-space: pre-wrap;
    font-size: 14px; line-height: 1.5;
    transition: background .3s, color .3s, box-shadow .3s;
}
.message.in  .msg-bubble {
    background:    var(--bubble-in-bg);
    color:         var(--bubble-in-text);
    border-bottom-left-radius: 5px;
    box-shadow: 0 1px 3px var(--bubble-in-shadow);
}
.message.out .msg-bubble {
    background:    var(--bubble-out-bg);
    color:         var(--bubble-out-text);
    border-bottom-right-radius: 5px;
    box-shadow: 0 1px 3px var(--bubble-out-shadow);
}

/* ── Meta (time + status) ─────────── */
.message-meta {
    display: flex; gap: 5px; align-items: center;
    margin-top: 3px; padding: 0 2px;
}
.message.in  .message-meta { justify-content: flex-start; }
.message.out .message-meta { justify-content: flex-end; }

.msg-time { font-size: 11px; color: var(--msg-meta-color); }

/* Status badges */
.msg-status { font-size: 11px; font-weight: 500; }
.msg-status--queued    { color: var(--msg-meta-color); }
.msg-status--sent      { color: var(--msg-meta-color); }
.msg-status--delivered { color: #5b6b7c; }
.msg-status--read      { color: #2563eb; font-weight: 600; }
.msg-status--received  { color: var(--msg-meta-color); }
.msg-status--failed    { color: #dc2626; }

/* ── Chat input ───────────────────── */
.chat-input {
    padding: 8px 14px 10px; border-top: 1px solid var(--border); background: var(--panel);
    display: flex; flex-direction: column; gap: 6px;
    box-shadow: 0 -1px 4px rgba(15,23,42,.04);
}
.chat-input-row {
    display: flex; gap: 8px; align-items: flex-end;
}
.chat-input textarea {
    flex: 1; resize: none; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 12px;
    max-height: 120px; outline: none; background: #f5f7fa;
}
.chat-input textarea:focus {
    border-color: var(--primary); background: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
/* Кнопки прикрепления и записи */
.btn-attach, .btn-record { padding: 9px 10px; font-size: 16px; flex: 0 0 auto; }

/* Панель записи и предпросмотра */
.recording-bar,
.rec-preview-bar {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 4px;
}
.rec-dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: #dc2626; flex: 0 0 auto;
    animation: rec-pulse 1s ease-in-out infinite;
}
@keyframes rec-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: .4; transform: scale(.8); }
}
.rec-time {
    font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums;
    color: var(--text); min-width: 36px;
}

/* Превью прикреплённого файла */
.attach-preview {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 10px; border-radius: 10px;
    background: var(--panel-soft); border: 1px solid var(--border);
}
.attach-preview-inner {
    flex: 1; display: flex; align-items: center; gap: 8px;
    font-size: 13px; min-width: 0;
}
.attach-preview-inner img {
    height: 52px; width: 52px; object-fit: cover;
    border-radius: 6px; flex: 0 0 auto;
}
.attach-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attach-size { font-size: 11px; color: var(--muted); white-space: nowrap; }
.attach-clear {
    background: none; border: none; cursor: pointer; font-size: 14px;
    color: var(--muted); padding: 4px 6px; border-radius: 5px; flex: 0 0 auto;
    transition: background .15s, color .15s;
}
.attach-clear:hover { background: #fee2e2; color: var(--danger); }

/* ── Theme picker ─────────────────── */
.theme-btn {
    background: none; border: 1px solid var(--border);
    border-radius: 8px; cursor: pointer; padding: 5px 9px;
    font-size: 19px; line-height: 1; color: var(--muted);
    transition: background .15s, border-color .15s;
    position: relative;
}
.topbar-icon { font-size: 19px; vertical-align: -3px; }
.theme-btn:hover { background: var(--panel-soft); border-color: var(--muted); }

.theme-dropdown {
    position: absolute; top: calc(100% + 8px); right: 0;
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 12px; padding: 12px;
    box-shadow: 0 8px 24px rgba(15,23,42,.14);
    display: flex; flex-direction: column; gap: 8px;
    z-index: 300; min-width: 190px;
}
.theme-dropdown[hidden] { display: none !important; }
.theme-dropdown-title {
    font-size: 11px; font-weight: 600; color: var(--muted);
    text-transform: uppercase; letter-spacing: .06em;
    margin-bottom: 2px;
}
.theme-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-swatch {
    width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
    border: 3px solid transparent;
    transition: transform .15s, border-color .15s;
    box-shadow: 0 1px 4px rgba(0,0,0,.18);
}
.theme-swatch:hover { transform: scale(1.15); }
.theme-swatch.active { border-color: var(--primary); transform: scale(1.1); }

/* ── Language switcher ────────────── */
.lang-switch {
    display: flex; align-items: center; gap: 4px;
    background: var(--panel-soft); border: 1px solid var(--border);
    border-radius: 8px; padding: 3px 6px;
}
.lang-btn {
    background: none; border: none; cursor: pointer;
    font-size: 12px; font-weight: 600; color: var(--muted);
    padding: 3px 7px; border-radius: 5px; transition: all .15s;
}
.lang-btn.active  { background: var(--primary); color: #fff; }
.lang-btn:hover:not(.active) { color: var(--text); background: var(--border); }
.lang-sep { font-size: 11px; color: var(--border); }

/* ─── COL: DEBTOR ───────────────────────────────────────── */
.col-debtor {
    background: var(--panel); border-left: 1px solid var(--border);
    overflow-y: auto; padding: 18px;
}
.debtor-empty {
    margin: 40px 12px; color: var(--muted); text-align: center; font-size: 14px;
}
.debtor-head {
    display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
}
.debtor-avatar {
    width: 40px; height: 40px; border-radius: 50%; background: var(--primary);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 16px; flex-shrink: 0;
}
.debtor-id { flex: 1; min-width: 0; }
.d-name {
    width: 100%; padding: 3px 6px; border: 1px solid transparent; border-radius: 6px;
    background: transparent; font-weight: 600; font-size: 15px;
}
.d-name:hover, .d-name:focus {
    background: var(--panel-soft); border-color: var(--border);
}
.d-phone { color: var(--muted); font-size: 12px; padding: 0 6px; }
.phone-icon { font-size: 14px; }
/* Компактная кнопка звонка в шапке */
.btn-call-compact {
    flex-shrink: 0;
    width: 36px; height: 36px; padding: 0;
    border-radius: 50%;
    background: var(--success); color: #fff; border-color: var(--success);
    font-size: 15px; display: flex; align-items: center; justify-content: center;
}
.btn-call-compact:hover { filter: brightness(.92); background: var(--success); }
.btn-call-compact.in-call { background: var(--danger); border-color: var(--danger); }
.save-state {
    margin-top: 6px; font-size: 12px; min-height: 14px; text-align: center;
    color: var(--muted);
}
.save-state.ok { color: var(--success); }
.save-state.err { color: var(--danger); }

.debtor-fields { margin-top: 12px; }

/* ── Строка статуса: бейдж + кнопка ── */
.status-row {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.status-badge {
    font-size: 12px; font-weight: 600; padding: 4px 9px;
    background: var(--panel-soft); border: 1px solid var(--border);
    border-radius: 7px;
}
.btn-mark-paid {
    white-space: nowrap;
    margin-bottom: 4px;
}

/* ── Readonly field value (age, etc.) ── */
.field-readonly .field-value {
    padding: 5px 10px;
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: 13px;
    color: var(--text);
    min-height: 30px;
    display: flex;
    align-items: center;
}

/* ── Collapsible AI profile toggle ── */
.debtor-extra-toggle {
    display: flex; align-items: center; gap: 7px;
    width: 100%; margin-top: 16px; margin-bottom: 4px; padding: 9px 12px;
    background: #eff6ff; border: 1px solid #bfdbfe;
    border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
    color: #1d4ed8; transition: background .12s, border-color .12s;
    text-align: left;
}
.debtor-extra-toggle:hover { background: #dbeafe; border-color: #93c5fd; }
.ai-profile-warn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px; border-radius: 50%;
    background: #f59e0b; color: #fff;
    font-size: 11px; font-weight: 800; line-height: 1;
    flex-shrink: 0; cursor: help;
    box-shadow: 0 0 0 2px #fef3c7;
    animation: ai-warn-pulse 2.5s ease-in-out infinite;
}
@keyframes ai-warn-pulse {
    0%, 100% { box-shadow: 0 0 0 2px #fef3c7; }
    50%       { box-shadow: 0 0 0 4px #fde68a; }
}
.debtor-extra-toggle .ai-spark { font-size: 14px; flex-shrink: 0; }
.debtor-extra-toggle .ai-chevron {
    margin-left: auto; flex-shrink: 0;
    transition: transform .2s;
    color: #60a5fa;
}
.debtor-extra-toggle.open .ai-chevron { transform: rotate(180deg); }
.debtor-extra-toggle svg { flex-shrink: 0; transition: transform .2s; }
.debtor-extra-toggle.open svg { transform: rotate(180deg); }

/* ── Extra fields panel ── */
.debtor-extra-fields {
    margin-top: 4px;
    padding: 12px;
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex; flex-direction: column; gap: 10px;
}

/* Цветные пилюли статуса */
select#d-status[data-status="new"]             { color: #9ca3af; }
select#d-status[data-status="in_progress"]     { color: #3b82f6; }
select#d-status[data-status="promised_to_pay"] { color: #d97706; }
select#d-status[data-status="paid"]            { color: #16a34a; }
select#d-status[data-status="refused"]         { color: #ef4444; }
select#d-status[data-status="closed"]          { color: #9ca3af; }

/* ─── ADMIN ──────────────────────────────────────────────── */
.admin-nav {
    display: flex; gap: 4px; margin-left: 12px;
}
.admin-nav-link {
    padding: 6px 14px; border-radius: 8px; font-size: 14px; font-weight: 500;
    color: var(--muted); text-decoration: none; transition: background .12s, color .12s;
}
.admin-nav-link:hover { background: var(--panel-soft); color: var(--text); }
.admin-nav-link.active { background: #eff6ff; color: var(--primary); }
.admin-nav-link .nav-icon { font-size: 17px; vertical-align: -3px; }

.admin-main {
    flex: 1; overflow-y: auto; padding: 28px 32px;
}

.admin-section { max-width: 1200px; margin: 0 auto; }

.section-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    margin-bottom: 20px; gap: 16px;
}
.section-title { margin: 0; font-size: 22px; }
.section-sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.table-card {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 12px; overflow: hidden;
}

.data-table {
    width: 100%; border-collapse: collapse; font-size: 14px;
}
.data-table th {
    padding: 11px 16px; text-align: left; font-weight: 600; font-size: 12px;
    color: var(--muted); background: var(--panel-soft);
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td {
    padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--panel-soft); }

.op-name { font-weight: 500; }
.op-login { font-size: 12px; color: var(--muted); margin-top: 2px; }
.op-date { font-size: 13px; color: var(--muted); }
.op-actions { display: flex; gap: 6px; white-space: nowrap; }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { filter: brightness(.92); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { filter: brightness(.92); }

.role-badge {
    display: inline-block; padding: 3px 9px; border-radius: 999px;
    font-size: 12px; font-weight: 500;
}
.role-admin { background: #ede9fe; color: #6d28d9; }
.role-operator { background: #e0f2fe; color: #0369a1; }

.status-dot {
    display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
}
.status-dot::before {
    content: ''; width: 7px; height: 7px; border-radius: 50%; flex: 0 0 7px;
}
.status-active::before { background: var(--success); }
.status-inactive::before { background: var(--muted); }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,.45);
    display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay[hidden] { display: none; }
.modal {
    background: var(--panel); border-radius: 14px; padding: 28px;
    width: 100%; max-width: 440px; box-shadow: 0 20px 60px rgba(15,23,42,.18);
}
.modal-head {
    display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px;
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-close {
    background: none; border: none; font-size: 18px; color: var(--muted);
    cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: var(--panel-soft); }

.form-error {
    color: var(--danger); font-size: 13px; margin: 0 0 10px;
    padding: 8px 12px; background: #fef2f2; border-radius: 6px;
}

/* Import stats */
.import-stats {
    display: flex; gap: 12px; flex-wrap: wrap;
}
.stat-card {
    flex: 1; min-width: 100px; padding: 16px 18px; border-radius: 10px;
    text-align: center;
}
.stat-num { font-size: 28px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat-success { background: #f0fdf4; }
.stat-success .stat-num { color: var(--success); }
.stat-warning { background: #fffbeb; }
.stat-warning .stat-num { color: var(--warning); }
.stat-danger { background: #fef2f2; }
.stat-danger .stat-num { color: var(--danger); }

/* ─── CONTACTS (в карточке должника) ────────────────────────────────── */
/* ─── DEBTOR TABS ────────────────────────────────────────────────────────── */
.debtor-tabs {
    display: flex; margin: 14px -18px 0; border-bottom: 1px solid var(--border);
}
.debtor-tab {
    flex: 1; padding: 9px 6px; font-size: 12px; font-weight: 500;
    background: none; border: none; border-bottom: 2px solid transparent;
    cursor: pointer; color: var(--muted); margin-bottom: -1px; transition: color .15s;
    letter-spacing: .01em;
}
.debtor-tab:hover { color: var(--text); }
.debtor-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.debtor-tab-pane { }

/* ─── TIMELINE ───────────────────────────────────────────────────────────── */
.tl-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 40px 0; }
.tl-day-sep {
    text-align: center; margin: 6px 0 14px; position: relative; font-size: 11px; color: var(--muted);
}
.tl-day-sep::before {
    content: ''; position: absolute; left: 0; right: 0; top: 50%;
    height: 1px; background: var(--border);
}
.tl-day-sep span { background: var(--panel); padding: 0 8px; position: relative; }
.tl-item { display: flex; gap: 10px; padding-bottom: 16px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-left { display: flex; flex-direction: column; align-items: center; width: 28px; flex-shrink: 0; }
.tl-dot {
    width: 28px; height: 28px; border-radius: 50%; display: flex;
    align-items: center; justify-content: center; font-size: 12px; line-height: 1;
    border: 0.5px solid var(--border); background: var(--panel); flex-shrink: 0;
}
.tl-dot.tl-msg-out   { background: #EBF4FF; border-color: #B5D4F4; color: #185FA5; }
.tl-dot.tl-msg-in    { background: #F0FFF4; border-color: #C0DD97; color: #3B6D11; }
.tl-dot.tl-promise   { background: #FFFBEB; border-color: #FAC775; color: #854F0B; }
.tl-dot.tl-confirmed { background: #F0FFF4; border-color: #C0DD97; color: #3B6D11; }
.tl-dot.tl-declined  { background: #FFF1F2; border-color: #F09595; color: #A32D2D; }
.tl-dot.tl-expired   { background: #F1EFE8; border-color: #D3D1C7; color: #5F5E5A; }
.tl-dot.tl-contact   { background: #FFF0F6; border-color: #F4C0D1; color: #72243E; }
.tl-dot.tl-created   { background: #F0FFF4; border-color: #C0DD97; color: #3B6D11; }
.tl-line { width: 1px; flex: 1; background: var(--border); margin-top: 4px; }
.tl-body { flex: 1; padding-top: 4px; min-width: 0; }
.tl-title { font-size: 13px; font-weight: 500; color: var(--text); line-height: 1.4; }
.tl-desc  { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.5; }
.tl-time  { font-size: 11px; color: var(--muted); margin-top: 4px; opacity: .7; }
.tl-bubble {
    background: var(--bg); border: 0.5px solid var(--border); border-radius: 8px;
    padding: 6px 9px; margin-top: 6px; font-size: 12px; color: var(--muted);
    line-height: 1.5; word-break: break-word;
}
#tab-timeline { padding-top: 14px; }

.contacts-section {
    margin-top: 14px; padding-top: 0;
}
.contacts-head {
    display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.contacts-title { font-weight: 600; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.contact-item {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
    padding: 8px 0; border-bottom: 1px solid var(--border);
}
.contact-item:last-child { border-bottom: none; }
.contact-info { flex: 1; min-width: 0; }
.contact-name { font-weight: 500; font-size: 14px; }
.contact-phone { font-size: 12px; color: var(--muted); margin-top: 1px; }
.contact-note { font-size: 12px; color: var(--muted); font-style: italic; margin-top: 1px; }
.contact-actions { flex: 0 0 auto; }

.contact-badge {
    display: inline-block; margin-top: 4px; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 500;
}
.contact-badge.debtor-extra { background: #e0f2fe; color: #0369a1; }
.contact-badge.third-party  { background: #fef3c7; color: #92400e; }

/* Метки в шапке чата и списке */
.chat-contact-mark {
    display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 999px;
    font-size: 10px; font-weight: 500; vertical-align: middle;
}
.chat-contact-mark.third { background: #fef3c7; color: #92400e; }
.chat-contact-mark.extra  { background: #e0f2fe; color: #0369a1; }
.chat-contact-label {
    display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px;
    font-size: 11px; font-weight: 500; background: #fef3c7; color: #92400e;
    vertical-align: middle;
}

/* ─── RESTRICTION NOTICE ────────────────────────────────────────────── */
/* Лимит подряд идущих сообщений */
.msg-limit-notice {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px; border-bottom: 1px solid;
    font-size: 13px; transition: background .2s, border-color .2s;
}
.msg-limit-notice.state-warn {
    background: #fffbeb; border-color: #fde68a;
}
.msg-limit-notice.state-block {
    background: #fef2f2; border-color: #fecaca;
}
.msg-limit-icon { font-size: 20px; flex-shrink: 0; }
.msg-limit-body { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.msg-limit-body strong { font-size: 13px; }
.state-warn  .msg-limit-body strong { color: #92400e; }
.state-block .msg-limit-body strong { color: #991b1b; }
.msg-limit-body span { font-size: 12px; }
.state-warn  .msg-limit-body span { color: #b45309; }
.state-block .msg-limit-body span { color: #b91c1c; }
.msg-limit-counter {
    font-size: 22px; font-weight: 700; flex-shrink: 0; min-width: 32px; text-align: center;
}
.state-warn  .msg-limit-counter { color: #d97706; }
.state-block .msg-limit-counter { color: #dc2626; }

.msg-restriction-notice {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px; background: #fffbeb; border-bottom: 1px solid #fde68a;
    font-size: 13px;
}
.restriction-icon { font-size: 20px; flex-shrink: 0; }
.restriction-body { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.restriction-body strong { font-size: 13px; color: #92400e; }
.restriction-body span { font-size: 12px; color: #b45309; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ─── CHAT INPUT TOOLBAR ─────────────────────────────────────────────── */

/* Все кнопки тулбара — единый размер и стиль */
.btn-tmpl,
.btn-attach,
.btn-record {
    padding: 7px 9px; font-size: 19px; flex: 0 0 auto;
    border-radius: 8px; transition: background .12s, color .12s;
}

/* Цветные иконки тулбара */
.btn-tmpl--promise { color: #16a34a; }
.btn-tmpl--promise:hover { background: #f0fdf4; color: #15803d; }

.btn-tmpl--templates { color: var(--primary); }
.btn-tmpl--templates:hover { background: #eff6ff; }

.btn-tmpl--ai { color: #d97706; }
.btn-tmpl--ai:hover { background: #fffbeb; color: #b45309; }

.btn-tmpl--attach { color: #64748b; }
.btn-tmpl--attach:hover { background: var(--panel-soft); color: #334155; }

.btn-tmpl--record { color: #dc2626; }
.btn-tmpl--record:hover { background: #fef2f2; color: #b91c1c; }

/* Разделитель между группами */
.input-divider {
    width: 1px;
    height: 22px;
    background: var(--border);
    flex: 0 0 auto;
    margin: 0 3px;
}

/* Кнопка AI-помощника — такой же формат как остальные */
.btn-ai-suggest { font-size: 19px; }
.btn-ai-suggest:disabled { opacity: .45; cursor: default; }

/* ─── ТУЛТИПЫ для кнопок тулбара ────────────────────────────────────── */
.chat-input-row [data-tip] {
    position: relative;
}
.chat-input-row [data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 7px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    padding: 4px 8px;
    border-radius: 6px;
    pointer-events: none;
    opacity: 0;
    transition: opacity .15s;
    z-index: 100;
}
.chat-input-row [data-tip]::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: var(--text);
    pointer-events: none;
    opacity: 0;
    transition: opacity .15s;
    z-index: 100;
}
.chat-input-row [data-tip]:hover::after,
.chat-input-row [data-tip]:hover::before { opacity: 1; }

/* AI Suggest panel ──────────────────────────────────────────────────────── */
.ai-suggest-panel {
    flex-shrink: 0;
    background: var(--panel);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    max-height: 320px;
}
.ai-suggest-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px 8px;
    border-bottom: 1px solid var(--border);
}
.ai-suggest-title {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .03em;
    text-transform: uppercase;
    color: var(--accent);
    display: flex;
    align-items: center;
}
.ai-suggest-close,
.ai-suggest-refresh {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted);
    font-size: 12px;
    padding: 3px 7px;
    border-radius: 5px;
    line-height: 1;
    transition: color .15s, background .15s, opacity .15s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
}
.ai-suggest-close { font-size: 14px; padding: 2px 4px; }
.ai-suggest-close:hover,
.ai-suggest-refresh:hover:not(:disabled) { color: var(--text); background: var(--hover); }
.ai-suggest-refresh:disabled,
.ai-suggest-refresh.refresh-used {
    opacity: .35;
    cursor: not-allowed;
}
.ai-suggest-body {
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ai-suggest-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 4px;
    color: var(--muted);
    font-size: 13px;
}
.ai-suggest-error { color: #dc2626; font-size: 13px; padding: 12px 4px; }
.ai-suggest-card {
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    transition: border-color .15s, box-shadow .15s;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.ai-suggest-card:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 10px color-mix(in srgb, var(--accent) 15%, transparent);
}
.ai-suggest-card-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    display: flex;
    align-items: center;
    gap: 5px;
}
.tone-soft .ai-suggest-card-label    { color: #16a34a; }
.tone-neutral .ai-suggest-card-label { color: #2563eb; }
.tone-formal .ai-suggest-card-label  { color: #7c3aed; }
.tone-hard .ai-suggest-card-label    { color: #dc2626; }
.tone-soft    { border-left: 3px solid #16a34a; }
.tone-neutral { border-left: 3px solid #2563eb; }
.tone-formal  { border-left: 3px solid #7c3aed; }
.tone-hard    { border-left: 3px solid #dc2626; }
.ai-suggest-tone-icon { font-size: 14px; }
.ai-suggest-card-text {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
    white-space: pre-wrap;
}
.ai-suggest-use-btn {
    align-self: flex-end;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 6px;
    border: 1.5px solid var(--border);
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}
.ai-suggest-use-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* tmpl-panel — часть flex-колонки col-chat, появляется над инпутом */
.tmpl-panel {
    flex-shrink: 0;
    background: var(--panel); border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(15,23,42,.08);
    /* Занимаем до 55% высоты видимой области, чтобы прокрутка всегда работала */
    max-height: 55vh; min-height: 120px;
    display: flex; flex-direction: column;
    overflow: hidden;
}

.tmpl-panel-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; border-bottom: 1px solid var(--border);
    font-weight: 600; font-size: 14px; flex-shrink: 0;
}
.tmpl-panel-title { font-weight: 600; }
.tmpl-hint {
    display: inline-block; margin-left: 8px; padding: 2px 8px;
    border-radius: 999px; font-size: 11px; font-weight: 500;
}
.tmpl-hint.debtor      { background: #dbeafe; color: #1e40af; }
.tmpl-hint.third_party { background: #f3e8ff; color: #6b21a8; }
.tmpl-lang-switch {
    display: flex; gap: 2px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 8px; padding: 2px;
}
.tmpl-lang-btn {
    background: none; border: none; cursor: pointer;
    font-size: 11px; font-weight: 600; padding: 3px 10px;
    border-radius: 6px; color: var(--muted); transition: all .15s;
    line-height: 1;
}
.tmpl-lang-btn.active {
    background: var(--panel); color: var(--accent);
    box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.tmpl-close {
    background: none; border: none; font-size: 18px; cursor: pointer;
    color: var(--muted); padding: 2px 6px; line-height: 1;
}

/* Список карточек — прокручиваемый, с fade-маской снизу чтобы было видно что есть ещё */
.tmpl-list {
    overflow-y: auto; flex: 1;
    padding: 12px 12px 16px; display: flex; flex-direction: column; gap: 10px;
    /* Тонкая тень снизу когда есть что скроллить */
    mask-image: linear-gradient(to bottom, black calc(100% - 24px), transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 24px), transparent 100%);
}
.tmpl-list:not(:hover) { scroll-behavior: smooth; }
.tmpl-empty { padding: 16px; color: var(--muted); font-size: 13px; text-align: center; }

/* Карточки шаблонов */
.tmpl-card {
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--panel-soft); overflow: hidden;
    transition: border-color .15s, box-shadow .15s;
    /* Карточка не сжимается — всегда занимает своё место */
    flex-shrink: 0;
}
.tmpl-card:hover { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.08); }

.tmpl-card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 10px 14px 6px;
}
.tmpl-card-name { font-weight: 600; font-size: 13px; }
.tmpl-card-badge {
    padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 500; white-space: nowrap;
}
.tmpl-card-badge.greeting  { background: #dcfce7; color: #166534; }
.tmpl-card-badge.reminder  { background: #fef3c7; color: #92400e; }
.tmpl-card-badge.promise   { background: #dbeafe; color: #1e40af; }
.tmpl-card-badge.custom    { background: #f3f4f6; color: #374151; }

.tmpl-card-body {
    padding: 6px 14px 10px; font-size: 13px; line-height: 1.55;
    color: var(--text); word-break: break-word;
    /* Ограничиваем текст 4 строками — остальное обрезается */
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.tmpl-card-warn {
    margin: 0 14px 8px; padding: 6px 10px; border-radius: 6px;
    background: #fff7ed; color: #c2410c; font-size: 12px;
}
.tmpl-card-footer {
    padding: 8px 14px 12px; display: flex; justify-content: flex-end;
    border-top: 1px solid var(--border);
    /* footer всегда прилеплен к низу карточки */
    flex-shrink: 0;
}
.tmpl-use-btn { gap: 4px; }

/* Адаптив (узкие экраны) */
@media (max-width: 1100px) {
    .layout-3col { grid-template-columns: 280px 1fr 300px; }
}
@media (max-width: 900px) {
    .layout-3col { grid-template-columns: 240px 1fr; }
    .col-debtor { display: none; }
}

/* ═══════════════════════════════════════════════════════════════════
   ANALYTICS PAGE
   ═══════════════════════════════════════════════════════════════════ */

.analytics-page { padding: 36px 56px; width: 100%; box-sizing: border-box; display: flex; flex-direction: column; gap: 28px; }

.analytics-header { display: flex; align-items: baseline; gap: 16px; }
.analytics-title  { font-size: 22px; font-weight: 700; margin: 0; }
.analytics-subtitle { font-size: 13px; color: var(--muted); }

/* KPI grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}
.kpi-card {
    background: var(--panel-soft); border: 1px solid var(--border);
    border-radius: 12px; padding: 20px 24px;
    display: flex; flex-direction: column; gap: 6px;
}
.kpi-card.kpi-accent { background: var(--primary); border-color: var(--primary); }
.kpi-card.kpi-accent .kpi-label,
.kpi-card.kpi-accent .kpi-value { color: #fff; }
.kpi-card.kpi-green { background: #16a34a; border-color: #16a34a; }
.kpi-card.kpi-green .kpi-label,
.kpi-card.kpi-green .kpi-value { color: #fff; }
.kpi-label { font-size: 12px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 32px; font-weight: 700; color: var(--text); line-height: 1.1; }

/* Charts row */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 860px) { .charts-row { grid-template-columns: 1fr; } }

.chart-card {
    background: var(--panel-soft); border: 1px solid var(--border);
    border-radius: 12px; overflow: hidden;
}
.chart-card-head {
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border);
}
.chart-card-title { font-size: 14px; font-weight: 600; }
.chart-wrap { padding: 16px 20px; height: 240px; position: relative; }

/* Analytics table */
.analytics-table {
    width: 100%; border-collapse: collapse; font-size: 13px;
}
.analytics-table thead th {
    padding: 10px 16px; text-align: left; font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
    border-bottom: 1px solid var(--border);
}
.analytics-table tbody tr:hover { background: var(--hover); }
.analytics-table tbody td {
    padding: 12px 16px; border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.analytics-table tbody tr:last-child td { border-bottom: none; }

.analytics-empty { text-align: center; color: var(--muted); padding: 24px !important; }

.msg-count {
    display: inline-block; min-width: 32px; text-align: center;
    padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
    background: var(--border); color: var(--muted);
}
.msg-count--active { background: #dbeafe; color: #1e40af; }

.promise-count {
    display: inline-block; min-width: 32px; text-align: center;
    padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
    background: var(--border); color: var(--muted);
}
.promise-count--active { background: #dcfce7; color: #15803d; }

/* field-readonly — read-only display inside debtor card */
.field-readonly { display: flex; flex-direction: column; gap: 4px; }
.field-readonly span { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field-value { font-size: 13px; color: var(--text); padding: 6px 0; }

/* ═══════════════════════════════════════════════════════════════════
   OPERATOR PAGE — ADD DEBTOR BUTTON + MODAL
   ═══════════════════════════════════════════════════════════════════ */

/* Кнопка над списком чатов */
.col-actions {
    padding: 8px 12px 4px;
    border-bottom: 1px solid var(--border);
}

/* Overlay */
.op-modal-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,.45);
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
}
.op-modal-overlay[hidden] { display: none !important; }

/* Modal box */
.op-modal {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 14px; width: 100%; max-width: 480px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    display: flex; flex-direction: column; gap: 0;
    max-height: 90vh; overflow-y: auto;
}

.op-modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px 0;
}
.op-modal-head h2 { font-size: 17px; font-weight: 700; margin: 0; }

.op-modal-close {
    background: none; border: none; font-size: 18px; cursor: pointer;
    color: var(--muted); padding: 2px 6px; line-height: 1;
    border-radius: 6px; transition: background .15s;
}
.op-modal-close:hover { background: var(--hover); }

/* Form inside modal */
.op-modal form {
    display: flex; flex-direction: column; gap: 16px;
    padding: 20px 24px 24px;
}

/* Field label row — label + badge */
.field-label-row {
    display: flex; align-items: center; gap: 6px;
    font-size: 11px; font-weight: 600; color: var(--muted);
    text-transform: uppercase; letter-spacing: .04em;
}
.field-required {
    background: #fee2e2; color: #b91c1c;
    padding: 1px 6px; border-radius: 999px; font-size: 10px;
    font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
}
.field-optional {
    background: #f3f4f6; color: #6b7280;
    padding: 1px 6px; border-radius: 999px; font-size: 10px;
    font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
}

/* Hint text under input */
.field-hint {
    font-size: 11px; color: var(--muted); line-height: 1.5;
    margin-top: 2px; display: block;
}
/* Highlight for ФИО hint */
.field:has(#nd-name) .field-hint {
    color: #92400e; background: #fef3c7;
    padding: 6px 9px; border-radius: 6px; margin-top: 4px;
}

.op-modal-footer {
    display: flex; gap: 8px;
    padding-top: 4px;
}

/* form-error (reuse admin style) */
.form-error { color: #dc2626; font-size: 13px; margin: 0; padding: 8px 10px; background: #fef2f2; border-radius: 6px; }

/* ── Toast notification ──────────────────────────────────────────── */
.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(16px);
    background: #1e293b; color: #f8fafc;
    padding: 12px 20px; border-radius: 10px;
    font-size: 13px; font-weight: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,.25);
    opacity: 0; transition: opacity .25s, transform .25s;
    z-index: 999; pointer-events: none; white-space: nowrap;
}
.toast--visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Super Admin ─────────────────────────────────────────────────── */
.sa-shell { display: flex; flex-direction: column; min-height: 100vh; background: var(--bg); }
.sa-main  { max-width: 960px; margin: 0 auto; width: 100%; padding: 24px 16px; }

.sa-kpi   { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.sa-kpi-card {
    flex: 1; min-width: 120px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; padding: 16px 20px; text-align: center;
}
.sa-kpi-val  { display: block; font-size: 2rem; font-weight: 700; color: var(--accent); }
.sa-kpi-lbl  { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

.sa-toolbar  { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sa-section-title { font-size: 1.1rem; font-weight: 600; margin: 0; }
.sa-section-sub   { font-size: .8rem; font-weight: 600; text-transform: uppercase;
                    letter-spacing: .06em; color: var(--text-muted); margin: 16px 0 6px; }

.sa-tenant-list  { display: flex; flex-direction: column; gap: 10px; }
.sa-empty, .sa-loading { text-align: center; color: var(--text-muted); padding: 32px; }

.sa-tenant-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; padding: 14px 16px;
    transition: box-shadow .15s;
}
.sa-tenant-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.sa-tenant-inactive   { opacity: .55; }

.sa-tc-head   { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sa-tc-identity { flex: 1; min-width: 0; }
.sa-tc-slug   { font-weight: 700; font-size: .95rem; margin-right: 6px; color: var(--accent); }
.sa-tc-name   { color: var(--text); font-size: .9rem; }
.sa-tc-badges { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.sa-tc-actions{ display: flex; gap: 6px; }
.sa-tc-twilio { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 8px;
                font-size: .78rem; color: var(--text-muted); padding-top: 8px;
                border-top: 1px solid var(--border); }

.badge        { padding: 2px 8px; border-radius: 99px; font-size: .72rem; font-weight: 600; }
.badge-green  { background: #d1fae5; color: #065f46; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-gray   { background: var(--border); color: var(--text-muted); }

.btn-warn { color: #b45309; }
.btn-ok   { color: #065f46; }
.modal-wide { max-width: 640px; width: 95%; }
.sa-form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.sa-form-row .field { flex: 1; min-width: 200px; }

/* ── Superadmin: вкладки ──────────────────────────────────────── */
.sa-tabs {
    display: flex; gap: 4px; border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}
.sa-tab {
    padding: 8px 20px; font-size: 14px; font-weight: 500;
    border: none; background: none; cursor: pointer;
    color: var(--text-muted); border-bottom: 2px solid transparent;
    margin-bottom: -2px; border-radius: 4px 4px 0 0; transition: color .15s;
}
.sa-tab:hover { color: var(--text); background: var(--hover); }
.sa-tab--active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ── Superadmin: таблица пользователей / должников ───────────── */
.sa-users-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sa-users-table th { text-align: left; padding: 8px 10px;
    border-bottom: 2px solid var(--border);
    font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.sa-users-table td { padding: 8px 10px; border-bottom: 1px solid var(--border);
    vertical-align: middle; }
.sa-users-table tbody tr:hover { background: var(--hover); }

/* ── Badges ───────────────────────────────────────────────────── */
.badge-warn { background: #fef3c7; color: #92400e; }

/* ── Extra-small buttons ──────────────────────────────────────── */
.btn-xs { padding: 3px 8px; font-size: 11px; border-radius: 5px; }
.btn-danger-ghost { color: var(--danger, #dc2626); }
.btn-danger-ghost:hover { background: #fee2e2; }

/* ── SA DB: поиск ─────────────────────────────────────────────── */
.sa-db-search {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; padding: 14px 16px; margin-bottom: 12px;
}
.sa-db-input {
    flex: 1; min-width: 220px; padding: 7px 12px;
    border: 1px solid var(--border); border-radius: 6px;
    font-size: 13px; background: var(--bg); color: var(--text);
}
.sa-db-input:focus { outline: none; border-color: var(--accent); }
.sa-db-select {
    padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 13px; background: var(--bg); color: var(--text);
}
.sa-db-results { overflow-x: auto; margin-bottom: 4px; }
.sa-db-table   { min-width: 820px; }
.sa-db-pagination {
    display: flex; gap: 6px; align-items: center;
    margin-top: 12px; flex-wrap: wrap;
}

/* ── SA DB: slug badge ────────────────────────────────────────── */
.sa-slug-badge {
    display: inline-block; background: #ede9fe; color: #6d28d9;
    font-size: 11px; font-weight: 600; padding: 1px 7px;
    border-radius: 4px; font-family: monospace; letter-spacing: .02em;
}

/* ── SA DB: tenant badge in edit modal ────────────────────────── */
.sa-db-tenant-badge {
    font-size: 12px; color: var(--text-muted); background: var(--hover);
    border-radius: 6px; padding: 5px 10px; margin-bottom: 14px;
}

/* ── SA DB: delete warning block ──────────────────────────────── */
.sa-delete-warn {
    background: #fef2f2; border: 1px solid #fca5a5; border-radius: 8px;
    padding: 12px 14px; font-size: 13px; color: #7f1d1d;
    margin-bottom: 4px;
}

/* ── Media messages ───────────────────────────────────────── */

/* ── Аудио ── */
.msg-bubble--audio {
    padding: 8px 12px;
    /* Пузырь только обёртывает контент, не растягивается */
    display: inline-flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}
/* Не даём .message растягиваться на всю max-width */
.message:has(.msg-bubble--audio) { max-width: fit-content; }

.msg-audio {
    display: flex; align-items: center; gap: 6px;
}
.msg-audio-icon { font-size: 18px; flex: 0 0 auto; line-height: 1; }
.msg-audio audio {
    height: 32px;
    width: 200px;       /* фиксированная ширина — не flex:1 */
    border-radius: 6px; outline: none;
    color-scheme: light;
}

/* Строка действий под плеером */
.msg-audio-actions {
    display: flex; align-items: center; gap: 6px;
    padding: 0 2px;
}
.msg-audio-action {
    font-size: 11px; font-weight: 500; color: inherit;
    opacity: .6; text-decoration: none;
    background: none; border: none; cursor: pointer; padding: 0;
    transition: opacity .15s;
}
.msg-audio-action:hover { opacity: 1; text-decoration: underline; }

/* ── Картинка ── */
.msg-bubble--image {
    /* Убираем padding — изображение занимает весь пузырь */
    padding: 0 !important;
    overflow: hidden;
    /* Скругления берём от родителя */
    line-height: 0;  /* убираем пустоту снизу */
}
.msg-bubble--image .msg-caption {
    padding: 7px 12px 8px;
    font-size: 13px; line-height: 1.4;
    /* Цвет текста наследуем от пузыря */
}
.msg-image {
    display: block;
    max-width: 280px;
    max-height: 320px;
    width: auto; height: auto;
    object-fit: cover;
    cursor: pointer;
    transition: opacity .15s;
}
.msg-image:hover { opacity: .92; }

/* ── Файл / Видео ── */
.msg-bubble--file { padding: 10px 14px; }
.msg-file {
    display: flex; align-items: center; gap: 10px;
    text-decoration: none; color: inherit;
}
.msg-file-icon { font-size: 24px; flex: 0 0 auto; }
.msg-file-name {
    font-size: 13px; font-weight: 500;
    text-decoration: underline; text-underline-offset: 2px;
    word-break: break-all; line-height: 1.4;
}
.message.out .msg-file-name { color: rgba(255,255,255,.9); }

.msg-caption { font-size: 13px; opacity: .88; }

/* ── Чипы с номерами телефонов под входящими сообщениями ── */
.msg-phone-chips {
    display: flex; flex-wrap: wrap; gap: 5px;
    margin-top: 4px; padding-left: 2px;
}
.msg-phone-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border-radius: 999px;
    background: #eff6ff; border: 1px solid #bfdbfe;
    color: var(--primary); font-size: 12px; font-weight: 500;
    cursor: pointer; white-space: nowrap;
    transition: background .12s, border-color .12s;
}
.msg-phone-chip:hover { background: #dbeafe; border-color: #93c5fd; }
.chip-add { font-size: 14px; font-weight: 700; opacity: .7; }

/* ── vCard пузырь ── */
.msg-bubble--vcard { padding: 10px 14px; }
.msg-vcard {
    display: flex; align-items: center; gap: 10px;
}
.msg-vcard-icon { font-size: 28px; flex: 0 0 auto; }
.msg-vcard-info {
    display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0;
}
.msg-vcard-title { font-size: 14px; font-weight: 600; }
.msg-vcard-sub   { font-size: 12px; opacity: .65; }
.btn-parse-vcard {
    flex: 0 0 auto;
    padding: 5px 12px; border-radius: 999px;
    background: #eff6ff; border: 1px solid #bfdbfe;
    color: var(--primary); font-size: 12px; font-weight: 600;
    cursor: pointer; white-space: nowrap;
    transition: background .12s;
}
.btn-parse-vcard:hover:not(:disabled) { background: #dbeafe; }
.btn-parse-vcard:disabled { opacity: .5; cursor: default; }

/* ── Расшифровка: текст прямо под плеером ── */
.msg-transcription {
    margin-top: 8px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    font-style: italic;
    background: rgba(0,0,0,.06);
    border-left: 3px solid rgba(0,0,0,.2);
    white-space: pre-wrap;
    word-break: break-word;
}
.message.out .msg-transcription {
    background: rgba(255,255,255,.15);
    border-left-color: rgba(255,255,255,.4);
}

/* ── PROMISE BUBBLE ─────────────────────────────────────────────────────────── */
.promise-bubble {
    position: relative;
    background: var(--panel);
    border: 0.5px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    padding: 14px 14px 14px 18px;
    min-width: 240px;
    max-width: 290px;
    width: fit-content;
    box-sizing: border-box;
    font-size: 13px;
    align-self: flex-end;
}

/* Цветная полоса слева — отдельный div в JS */
.promise-bar {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    background: #378ADD;
}
.promise-bar.bar-full     { background: #16a34a; }
.promise-bar.bar-schedule { background: #7c3aed; }
.promise-bar.bar-third    { background: #d97706; }

/* Заголовок */
.promise-bubble-head {
    display: flex; align-items: center; gap: 6px;
    margin-bottom: 10px;
}
.promise-bubble-head-text {
    font-size: 13px; font-weight: 500; color: var(--text);
}

/* Сетка ячеек — точно как в превью */
.promise-bubble-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 10px;
}
.promise-cell {
    background: var(--bg);
    border-radius: 8px;
    padding: 7px 9px;
}
.promise-label { font-size: 10px; color: var(--muted); margin-bottom: 2px; display: block; }
.promise-val   { font-size: 12px; font-weight: 500; color: var(--text); display: block; word-break: break-word; }

/* Плашка статуса — прямо в карточке без обёртки */
.promise-bubble-footer {
    display: block;
}
.promise-disclaimer {
    margin-bottom: 8px;
    padding: 5px 9px;
    font-size: 11px; color: #92400e;
    background: #fffbeb;
    border-radius: 8px;
    line-height: 1.4;
}

/* Статусы */
.promise-status {
    display: inline-flex; align-items: center; gap: 4px;
    border-radius: 999px; padding: 3px 9px;
    font-size: 11px; font-weight: 600;
}
.promise-status--pending   { background: #fef9c3; color: #854d0e; }
.promise-status--confirmed { background: #dcfce7; color: #15803d; }
.promise-status--declined  { background: #fee2e2; color: #b91c1c; }
.promise-status--expired   { background: #f1f5f9; color: #94a3b8; }
.promise-status--superseded{ background: #f1f5f9; color: #94a3b8; }

/* Кнопка "Договорённость" в инпуте */
.btn-promise {
    background: none; border: none; cursor: pointer;
    font-size: 18px; padding: 4px 7px; border-radius: 6px;
    color: var(--muted); transition: background .15s, color .15s;
}
.btn-promise:hover { background: var(--panel-soft); color: var(--primary); }

/* Табы выбора типа в модале */
.promise-type-tabs {
    display: flex; gap: 8px; margin-top: 4px;
}
.promise-type-tab {
    flex: 1; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--border);
    background: var(--panel); font-size: 12px; font-weight: 600;
    cursor: pointer; transition: all .15s; color: var(--muted);
    text-align: center;
}
.promise-type-tab.active {
    border-color: var(--primary); background: #eff6ff; color: var(--primary);
}


/* ─── AI MODAL ───────────────────────────────────────────────────────────── */
.ai-modal {
    max-width: 580px; width: 100%;
}
.ai-diff-wrap {
    display: flex; gap: 0; margin: 12px 0 0;
    border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.ai-diff-col {
    flex: 1; min-width: 0;
}
.ai-diff-col + .ai-diff-col {
    border-left: 1px solid var(--border);
}
.ai-diff-label {
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .04em; color: var(--muted);
    padding: 6px 12px; background: var(--panel-soft);
    border-bottom: 1px solid var(--border);
}
.ai-diff-text {
    padding: 10px 12px; font-size: 14px; line-height: 1.55;
    white-space: pre-wrap; word-break: break-word;
    min-height: 70px; color: var(--text);
}
.ai-diff-text--new { background: #f0fdf4; color: #166534; }
.ai-issue-tag {
    display: inline-flex; align-items: center; gap: 5px;
    background: #fef3c7; color: #92400e;
    border-radius: 999px; padding: 3px 10px; font-size: 12px;
    margin: 0 4px 6px 0;
}
.ai-modal-actions {
    padding: 12px 16px;
    display: flex; gap: 8px; flex-wrap: wrap;
    border-top: 1px solid var(--border);
}

/* Спиннер */
.ai-spinner {
    width: 32px; height: 32px; margin: 0 auto;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: ai-spin .7s linear infinite;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }

/* ─── AI SETTINGS PAGE ───────────────────────────────────────────────────── */
.ai-settings-page {
    max-width: 680px; margin: 0 auto; padding: 24px 16px; display: flex; flex-direction: column; gap: 16px;
}
.ai-header h1 { margin: 0 0 4px; font-size: 22px; }
.ai-subtitle   { color: var(--muted); font-size: 14px; margin: 0; }

.ai-card {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 12px; padding: 16px 18px;
}
.ai-card-row {
    display: flex; justify-content: space-between; align-items: center; gap: 16px;
}
.ai-card-title { font-weight: 600; font-size: 15px; }
.ai-card-desc  { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* Тоггл */
.ai-toggle {
    position: relative; display: inline-block;
    width: 44px; height: 24px; flex: 0 0 44px; cursor: pointer;
}
.ai-toggle input { opacity: 0; width: 0; height: 0; }
.ai-toggle-slider {
    position: absolute; inset: 0;
    background: var(--border); border-radius: 999px;
    transition: background .2s;
}
.ai-toggle-slider::before {
    content: ""; position: absolute;
    width: 18px; height: 18px; left: 3px; top: 3px;
    background: #fff; border-radius: 50%;
    transition: transform .2s;
}
.ai-toggle input:checked + .ai-toggle-slider { background: var(--primary); }
.ai-toggle input:checked + .ai-toggle-slider::before { transform: translateX(20px); }
.ai-toggle.sm { width: 36px; height: 20px; flex: 0 0 36px; }
.ai-toggle.sm .ai-toggle-slider::before { width: 14px; height: 14px; }
.ai-toggle.sm input:checked + .ai-toggle-slider::before { transform: translateX(16px); }

/* Режимы */
.ai-mode-options { display: flex; gap: 10px; }
.ai-mode-opt { flex: 1; cursor: pointer; }
.ai-mode-opt input { display: none; }
.ai-mode-box {
    border: 2px solid var(--border); border-radius: 10px;
    padding: 12px; text-align: center; transition: border-color .15s, background .15s;
}
.ai-mode-opt input:checked + .ai-mode-box {
    border-color: var(--primary); background: #eff6ff;
}
.ai-mode-icon  { font-size: 22px; margin-bottom: 4px; }
.ai-mode-label { font-weight: 600; font-size: 14px; }
.ai-mode-desc  { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.3; }

/* Предупреждение о рисках Meta */
.ai-mode-risk-warn {
    display: flex; align-items: flex-start; gap: 10px;
    margin-top: 14px; padding: 12px 14px;
    background: #fffbeb; border: 1px solid #f59e0b;
    border-radius: 10px; color: #92400e;
}
.ai-mode-risk-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.ai-mode-risk-text { font-size: 13px; line-height: 1.5; }
.ai-mode-risk-text strong { color: #78350f; }

/* Список правил */
.ai-rules-list { display: flex; flex-direction: column; gap: 2px; }
.ai-rule-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
}
.ai-rule-row:last-child { border-bottom: none; }
.ai-rule-name { font-size: 14px; font-weight: 500; }
.ai-rule-desc { font-size: 12px; color: var(--muted); margin-top: 1px; }

/* ── WhatsApp 24h window indicator ─────────────────────────────────────── */
.wa-win {
    display: inline-flex; align-items: center; gap: 3px;
    border-radius: 10px; padding: 2px 7px;
    font-size: 10px; font-weight: 600; white-space: nowrap;
    flex-shrink: 0;
}
.wa-win-dot {
    width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0;
}
.wa-win--open  { background: #dcfce7; color: #15803d; }
.wa-win--open  .wa-win-dot { background: #16a34a; animation: wa-pulse 2s ease-in-out infinite; }
.wa-win--warn  { background: #fef3c7; color: #92400e; }
.wa-win--warn  .wa-win-dot { background: #d97706; animation: wa-pulse 1.2s ease-in-out infinite; }
.wa-win--closed { background: #f1f5f9; color: #94a3b8; border: 1px solid #e2e8f0; }
.wa-win--closed .wa-win-dot { background: #cbd5e1; }
@keyframes wa-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.chat-row .wa-win { margin-right: 2px; }

.wa-window-block {
    margin: 6px 0 4px; padding: 8px 12px;
    background: var(--bg-secondary, #f8fafc);
    border-radius: 8px; border: 1px solid var(--border, #e5e7eb);
}
.wa-window-block .wa-win-label {
    font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--muted); margin-bottom: 4px;
}
.wa-window-block .wa-win-row { display: flex; align-items: center; gap: 8px; }
.wa-window-block .wa-win-timer {
    font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums;
    letter-spacing: .02em; color: var(--text);
}
.wa-window-block .wa-win-hint { font-size: 11px; color: var(--muted); margin-top: 5px; line-height: 1.4; }
.wa-window-block .wa-win-track {
    height: 3px; background: var(--border, #e5e7eb);
    border-radius: 2px; margin-top: 8px; overflow: hidden;
}
.wa-window-block .wa-win-fill { height: 100%; border-radius: 2px; transition: width 30s linear; }

/* ── Timeline: сообщения 3-м лицам ─────────────────────────────────────── */
.tl-dot.tl-msg-third {
    background: #7c3aed; color: #fff;
}
.tl-third-pill {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    background: #ede9fe;
    color: #5b21b6;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    vertical-align: middle;
    white-space: nowrap;
}

/* ── Кнопка сохранения карточки ─────────────────────────────────────────── */
#btn-save-debtor {
    margin-top: 16px;
}
#btn-save-debtor:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Поле "Назначен оператор" — дополнительный отступ сверху ── */
#d-assign-field {
    margin-top: 16px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   CALENDAR MODAL — Календарь обещаний
   ═══════════════════════════════════════════════════════════════════════════ */

.cal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(3px);
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.cal-overlay[hidden] { display: none !important; }

.cal-modal {
    background: var(--panel);
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(15,23,42,.22);
    width: min(1060px, 100%);
    max-height: calc(100vh - 32px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ── Header ── */
.cal-modal-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.cal-month-title {
    flex: 1;
    text-align: center;
    font-size: 17px;
    font-weight: 700;
    margin: 0;
    text-transform: capitalize;
}
.cal-nav-btn {
    width: 32px; height: 32px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-soft);
    color: var(--text);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background .15s;
}
.cal-nav-btn:hover { background: var(--border); }
.cal-close-btn {
    width: 32px; height: 32px;
    border: none; background: transparent;
    color: var(--muted); font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px; margin-left: 4px;
    transition: background .15s, color .15s;
    flex-shrink: 0;
}
.cal-close-btn:hover { background: #fee2e2; color: var(--danger); }

/* ── Operator filter bar (admin only) ── */
.cal-op-filter {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--panel-soft);
    flex-shrink: 0;
}
.cal-op-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
}
.cal-op-select {
    flex: 1;
    max-width: 280px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text);
    background: var(--panel);
    cursor: pointer;
    outline: none;
    transition: border-color .15s;
}
.cal-op-select:focus { border-color: var(--primary); }

/* ── KPI row ── */
.cal-kpi-row {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.cal-kpi {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 8px;
    border-right: 1px solid var(--border);
}
.cal-kpi:last-child { border-right: none; }
.cal-kpi-val {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
}
.cal-kpi-val.cal-kpi-ok  { color: var(--success); }
.cal-kpi-val.cal-kpi-warn { color: var(--warning); }
.cal-kpi-lbl {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* ── Status filter bar ── */
.cal-status-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}
.cal-status-bar-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
    margin-right: 2px;
}
.cal-status-btn {
    padding: 4px 12px;
    border-radius: 20px;
    border: 1.5px solid var(--border);
    background: var(--panel-soft);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
    user-select: none;
}
.cal-status-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}
/* Active states per status */
.cal-status-btn[data-status="all"].active {
    background: var(--text);
    border-color: var(--text);
    color: #fff;
}
.cal-status-btn[data-status="pending"].active {
    background: #fef3c7;
    border-color: #d97706;
    color: #92400e;
}
.cal-status-btn[data-status="confirmed"].active {
    background: #dcfce7;
    border-color: #16a34a;
    color: #166534;
}
.cal-status-btn[data-status="declined"].active {
    background: #fee2e2;
    border-color: #dc2626;
    color: #991b1b;
}
.cal-status-btn[data-status="expired"].active {
    background: #f3f4f6;
    border-color: #9ca3af;
    color: #4b5563;
}

/* ── Body: grid + detail ── */
.cal-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}
.cal-grid-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px;
    min-width: 0;
    overflow-y: auto;
}

/* ── Weekday headers ── */
.cal-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    margin-bottom: 4px;
}
.cal-weekdays span {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    padding: 4px 0;
}
.cal-weekdays .cal-weekend { color: #ef4444; }

/* ── Calendar grid ── */
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}
.cal-day {
    aspect-ratio: 1;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    border: 2px solid transparent;
    transition: border-color .15s, transform .1s;
    min-height: 50px;
}
.cal-day:hover { border-color: var(--primary); transform: scale(1.04); }
.cal-day.cal-day--selected { border-color: var(--primary); }
.cal-day.cal-day--empty { cursor: default; }
.cal-day.cal-day--empty:hover { border-color: transparent; transform: none; }
.cal-day.cal-day--today .cal-day-num { font-weight: 800; color: var(--primary); }

.cal-day-num {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    line-height: 1;
}
.cal-day-count {
    font-size: 10px;
    color: var(--muted);
    margin-top: 2px;
}
.cal-day-amount {
    font-size: 9px;
    color: var(--muted);
    margin-top: 1px;
    max-width: 90%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

/* ── Heat map backgrounds ── */
.cal-day.heat-0 { background: var(--panel-soft); }
.cal-day.heat-1 { background: #dcfce7; }
.cal-day.heat-2 { background: #86efac; }
.cal-day.heat-3 { background: #4ade80; }
.cal-day.heat-4 { background: #16a34a; }
.cal-day.heat-4 .cal-day-num,
.cal-day.heat-4 .cal-day-count,
.cal-day.heat-4 .cal-day-amount { color: #fff; }

/* ── Legend ── */
.cal-legend {
    display: flex;
    gap: 12px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    justify-content: flex-end;
}
.cal-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--muted);
}
.cal-dot {
    width: 12px; height: 12px;
    border-radius: 3px;
    display: inline-block;
}
.cal-dot.heat-1 { background: #dcfce7; border: 1px solid #86efac; }
.cal-dot.heat-2 { background: #86efac; }
.cal-dot.heat-3 { background: #4ade80; }
.cal-dot.heat-4 { background: #16a34a; }

/* ── Detail panel ── */
.cal-detail-panel {
    width: 320px;
    flex-shrink: 0;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.cal-detail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 46px;
}
.cal-detail-date {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

.cal-detail-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 100%;
    color: var(--muted);
    font-size: 13px;
    padding: 32px 16px;
    text-align: center;
}

.cal-detail-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.cal-detail-item {
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 6px;
    cursor: pointer;
    transition: background .12s;
}
.cal-detail-item:hover { background: var(--panel-soft); }
.cal-detail-item-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cal-detail-item-op {
    font-size: 11px;
    color: var(--muted);
    margin-top: 1px;
}
.cal-detail-item-amount {
    font-size: 12px;
    color: var(--success);
    font-weight: 600;
    margin-top: 2px;
}
.cal-detail-item-status {
    display: inline-block;
    margin-top: 4px;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.cal-status-pending  { background: #fef3c7; color: #92400e; }
.cal-status-confirmed { background: #dcfce7; color: #166534; }
.cal-status-declined  { background: #fee2e2; color: #991b1b; }
.cal-status-expired   { background: #f3f4f6; color: #6b7280; }
.cal-detail-empty {
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    padding: 24px 8px;
}

/* ── Spinner inside calendar ── */
.cal-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--muted);
    font-size: 13px;
    gap: 8px;
}
.cal-spinner {
    width: 18px; height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ── */
@media (max-width: 640px) {
    .cal-modal { border-radius: 12px; }
    .cal-detail-panel { width: 100%; min-width: 0; border-left: none; border-top: 1px solid var(--border); }
    .cal-body { flex-direction: column; }
    .cal-day { min-height: 38px; }
    .cal-day-amount { display: none; }
    .cal-kpi-val { font-size: 16px; }
}

/* ════════════════════════════════════════════════════════
   ANALYTICS SLIDE-OVER PANEL
   ════════════════════════════════════════════════════════ */

.analytics-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.35);
    z-index: 9000;
}
.analytics-panel {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: 460px; max-width: 96vw;
    background: #ffffff;
    border-left: 1px solid #e3e8ef;
    box-shadow: -8px 0 40px rgba(0,0,0,.18);
    z-index: 9001;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* NO animation — translateX caused off-screen rendering bug */
}

/* ── Head ── */
.analytics-panel-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    flex-shrink: 0;
}
.analytics-panel-title {
    font-size: 15px;
    font-weight: 700;
    flex: 1;
}
.analytics-period-tabs {
    display: flex;
    gap: 3px;
}
.ap-tab {
    font-size: 12px;
    padding: 4px 9px;
    border-radius: 6px;
    border: 1px solid var(--border, #e5e7eb);
    background: transparent;
    cursor: pointer;
    color: var(--text, #111);
    transition: background .15s, color .15s;
}
.ap-tab:hover { background: var(--hover, #f3f4f6); }
.ap-tab.active {
    background: var(--primary, #6366f1);
    color: #fff;
    border-color: var(--primary, #6366f1);
}
.analytics-panel-close {
    padding: 4px 8px;
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: var(--muted, #9ca3af);
    border-radius: 6px;
}
.analytics-panel-close:hover { background: var(--hover, #f3f4f6); color: var(--text, #111); }

/* ── Body ── */
.analytics-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.analytics-loading {
    text-align: center;
    color: var(--muted, #9ca3af);
    padding: 40px 0;
    font-size: 14px;
}

/* ── KPI row ── */
.an-kpi-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}
.an-kpi-card {
    background: var(--surface2, var(--hover, #f9fafb));
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 10px;
    padding: 12px 10px;
    text-align: center;
}
.an-kpi-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary, #6366f1);
    line-height: 1.1;
}
.an-kpi-label {
    font-size: 11px;
    color: var(--muted, #9ca3af);
    margin-top: 3px;
}

/* ── Chart ── */
.an-chart-wrap {
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 10px;
    padding: 12px;
    background: var(--surface2, var(--hover, #f9fafb));
}

/* ── Section ── */
.an-section { display: flex; flex-direction: column; gap: 8px; }
.an-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted, #6b7280);
    text-transform: uppercase;
    letter-spacing: .05em;
}

/* ── Funnel ── */
.an-funnel {
    display: flex;
    flex-direction: column;
    gap: 7px;
}
.an-funnel-step { display: flex; flex-direction: column; gap: 2px; }
.an-funnel-bar-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}
.an-funnel-bar {
    background: var(--primary, #6366f1);
    border-radius: 4px;
    height: 24px;
    display: flex;
    align-items: center;
    padding: 0 8px;
    min-width: 32px;
    transition: width .3s ease;
}
.an-funnel-count {
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
}
.an-funnel-pct {
    font-size: 11px;
    color: var(--muted, #9ca3af);
}
.an-funnel-label {
    font-size: 12px;
    color: var(--muted, #6b7280);
    padding-left: 2px;
}

/* ── Operators table ── */
.an-table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border, #e5e7eb); }
.an-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.an-table thead th {
    padding: 8px 10px;
    background: var(--surface2, var(--hover, #f9fafb));
    font-weight: 600;
    text-align: left;
    border-bottom: 1px solid var(--border, #e5e7eb);
    white-space: nowrap;
}
.an-table tbody td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border, #e5e7eb);
}
.an-table tbody tr:last-child td { border-bottom: none; }
.an-table tbody tr:hover { background: var(--hover, #f3f4f6); }

/* ── Analytics button highlight ── */
.btn-analytics-open { color: var(--text, #111); }
.btn-analytics-open:hover { color: var(--primary, #6366f1); }

/* ── Analytics team filter bar ── */
.an-team-filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border, #e3e8ef);
    background: var(--panel-soft, #f8fafc);
    flex-shrink: 0;
}
.an-team-filter-label {
    font-size: 12px;
    color: var(--muted, #6b7280);
    white-space: nowrap;
}
.an-team-filter-select {
    flex: 1;
    font-size: 12px;
    padding: 4px 8px;
    border: 1px solid var(--border, #e3e8ef);
    border-radius: 6px;
    background: var(--panel, #fff);
    color: var(--text, #1f2937);
    cursor: pointer;
    min-width: 0;
}
.an-table thead th:nth-child(2),
.an-table thead th:nth-child(3),
.an-table thead th:nth-child(4) { text-align: right; }

/* ─── WhatsApp Calling API — incoming call banner ──────────────────────── */
.call-incoming-banner {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1200;
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
    border: 1.5px solid #22c55e;
    border-radius: 14px;
    padding: 14px 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
    min-width: 300px;
    animation: call-slide-in .25s ease;
}
@keyframes call-slide-in {
    from { transform: translateX(120%); opacity: 0; }
    to   { transform: translateX(0);   opacity: 1; }
}
.call-incoming-avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: #dcfce7;
    color: #15803d;
    font-size: 20px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.call-incoming-info { flex: 1; min-width: 0; }
.call-incoming-name {
    font-size: 14px; font-weight: 600;
    color: var(--text, #1f2937);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.call-incoming-phone {
    font-size: 12px; color: var(--muted, #6b7280); margin-top: 2px;
}
.call-incoming-actions { display: flex; gap: 8px; flex-shrink: 0; }
.btn-call-answer, .btn-call-decline {
    width: 40px; height: 40px; border-radius: 50%; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: filter .15s;
}
.btn-call-answer  { background: #22c55e; color: #fff; }
.btn-call-decline { background: #ef4444; color: #fff; }
.btn-call-answer:hover  { filter: brightness(.9); }
.btn-call-decline:hover { filter: brightness(.9); }

/* ─── Active call bottom bar ────────────────────────────────────────────── */
.call-active-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    gap: 12px;
    background: #1f2937;
    color: #fff;
    padding: 10px 20px;
    box-shadow: 0 -4px 16px rgba(0,0,0,.2);
}
.call-active-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: #374151;
    font-size: 16px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.call-active-info { flex: 1; min-width: 0; }
.call-active-name {
    font-size: 14px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.call-active-timer { font-size: 12px; color: #9ca3af; font-variant-numeric: tabular-nums; }
.call-active-status { font-size: 13px; color: #9ca3af; flex-shrink: 0; }
.btn-call-hangup {
    width: 40px; height: 40px; border-radius: 50%; border: none; cursor: pointer;
    background: #ef4444; color: #fff;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: filter .15s;
}
.btn-call-hangup:hover { filter: brightness(.9); }

/* ─── WhatsApp number check badge ──────────────────────────────────────── */
.phone-check-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.phone-check-row input {
    flex: 1;
    min-width: 0;
}
.wa-check-badge {
    flex-shrink: 0;
    width: 28px; height: 28px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700;
    transition: all .2s;
    cursor: default;
}
.wa-check-badge.wa-checking {
    background: #f3f4f6;
    color: #9ca3af;
    font-size: 12px;
    animation: wa-pulse 1s infinite;
}
.wa-check-badge.wa-yes {
    background: #dcfce7;
    color: #16a34a;
}
.wa-check-badge.wa-no {
    background: #fee2e2;
    color: #dc2626;
}
@keyframes wa-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: .4; }
}
.wa-check-badge.wa-error {
    background: #f3f4f6;
    color: #9ca3af;
    font-size: 13px;
}
