.dialogs-page{display:flex;flex-direction:column;gap:12px}.dialogs-stats{display:grid;grid-template-columns:repeat(4,minmax(110px,1fr));gap:10px}.dialog-stat{background:#fff;border:1px solid var(--border);border-radius:14px;padding:12px 14px;text-align:left;cursor:pointer;box-shadow:var(--shadow)}.dialog-stat b{font-size:20px;display:block;color:#211b43}.dialog-stat span{font-size:11px;color:var(--muted)}.dialog-stat.active{border-color:#7557d9;background:#f5f1ff}.dialogs-shell{display:grid;grid-template-columns:330px minmax(0,1fr);gap:14px;height:calc(100vh - 250px);min-height:560px}.dialogs-list,.dialogs-chat{background:#fff;border:1px solid var(--border);border-radius:18px;overflow:hidden;box-shadow:var(--shadow)}.dialogs-list{display:flex;flex-direction:column}.dialogs-tools{padding:14px;border-bottom:1px solid var(--border)}.dialogs-bot-select,.dialogs-search{width:100%;height:42px;border:1px solid var(--border);border-radius:11px;background:#fff;padding:0 12px}.dialogs-search{margin-top:9px}.dialogs-items{overflow:auto}.dialog-item{width:100%;border:0;border-bottom:1px solid var(--border);background:#fff;text-align:left;padding:14px;cursor:pointer}.dialog-item:hover,.dialog-item.active{background:#f3f0ff}.dialog-line{display:flex;justify-content:space-between;gap:10px;align-items:center}.dialog-name{font-weight:800;font-size:14px}.dialog-time{font-size:11px;color:var(--muted);white-space:nowrap}.dialog-preview{margin-top:6px;color:#6f7288;font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.dialog-meta{display:flex;align-items:center;gap:6px;margin-top:8px}.channel-badge,.status-badge{border-radius:999px;padding:3px 7px;font-size:10px;font-weight:700}.channel-badge{border:1px solid #d9d5ee;color:#5b46c4}.status-new{background:#fff0f1;color:#c54f5b}.status-in_progress{background:#eef1ff;color:#5263c7}.status-waiting{background:#fff7df;color:#a27617}.status-closed{background:#edf7f1;color:#39805e}.unread-badge{margin-left:auto;min-width:20px;height:20px;border-radius:999px;background:#e85b68;color:#fff;display:grid;place-items:center;font-size:10px;font-weight:800}.dialogs-chat{display:flex;flex-direction:column}.chat-head{padding:14px 18px;border-bottom:1px solid var(--border);display:flex;justify-content:space-between;align-items:center;gap:12px}.chat-person strong{display:block;font-size:16px}.chat-person span{display:block;color:var(--muted);font-size:12px;margin-top:3px}.chat-actions{display:flex;gap:8px;flex-wrap:wrap}.dialog-context{padding:10px 18px;border-bottom:1px solid var(--border);display:grid;grid-template-columns:160px 180px 1fr;gap:10px;background:#fbfaff}.dialog-context>div>span{display:block;font-size:10px;color:var(--muted);margin-bottom:4px}.dialog-context select{width:100%;height:34px;border:1px solid var(--border);border-radius:9px;background:#fff;padding:0 8px}.dialog-ai-state b{font-size:12px;color:#5b46c4}.chat-messages{flex:1;overflow:auto;padding:22px;background:#f7f7fc}.message-row{display:flex;margin:10px 0}.message-row.out{justify-content:flex-end}.message{max-width:72%;padding:12px 14px;border-radius:16px;background:#fff;border:1px solid var(--border);font-size:13px;line-height:1.45;overflow-wrap:anywhere}.message-row.out .message{background:#ece7ff;border-color:#ddd3ff}.message small{display:block;color:var(--muted);font-size:10px;margin-top:6px}.chat-compose{padding:12px;border-top:1px solid var(--border);display:flex;gap:9px;align-items:center}.chat-compose textarea{flex:1;resize:none;height:46px;max-height:120px;border:1px solid var(--border);border-radius:13px;padding:12px;outline:0}.chat-empty,.dialogs-none{display:grid;place-items:center;color:var(--muted);text-align:center;padding:30px}.ai-toggle.on{background:#e9f7f0;color:#2f8d66}.ai-toggle.off{background:#fff0f1;color:#cf505f}@media(max-width:900px){.dialogs-stats{grid-template-columns:repeat(2,1fr)}.dialogs-shell{grid-template-columns:1fr;height:auto}.dialogs-list{max-height:420px}.dialogs-chat{min-height:620px}.dialog-context{grid-template-columns:1fr}}

/* Keep dialog text readable when the browser or OS forces a dark color scheme. */
.dialogs-page,
.dialogs-list,
.dialogs-chat,
.dialog-item,
.chat-head,
.dialog-context,
.chat-messages,
.chat-compose{color:#17172a}
.dialog-name,
.chat-person strong{color:#17172a!important}
.dialog-preview,
.chat-person span{color:#6f7288!important}
.message{color:#252238!important}
.message-row.out .message{color:#29213f!important}
.message small{color:#7e8198!important}
.chat-compose textarea,
.dialogs-bot-select,
.dialogs-search,
.dialog-context select{color:#17172a!important;background:#fff!important}
.chat-compose textarea::placeholder,
.dialogs-search::placeholder{color:#85879a!important;opacity:1}

/* WhatsApp media messages */
.message-media{min-width:250px;max-width:100%}.message-media-title{font-weight:700;margin-bottom:9px;color:#342d58}.message-audio audio{display:block;width:min(360px,62vw);max-width:100%;height:42px}.message-image img{display:block;max-width:min(360px,60vw);max-height:420px;border-radius:12px;object-fit:contain;background:#f0f1f6}.message-video video{display:block;width:min(420px,62vw);max-height:440px;border-radius:12px;background:#111}.message-caption{margin-top:9px;white-space:normal}.message-file-link{display:inline-flex;align-items:center;justify-content:center;margin-top:2px;padding:9px 12px;border-radius:10px;background:#6f55db;color:#fff!important;font-weight:700;text-decoration:none}.message-file-link:hover{background:#5c43c8}.message-media-error{padding:10px 12px;border-radius:10px;background:#fff3f4;color:#b33c52;font-size:12px}@media(max-width:600px){.message{max-width:88%}.message-media{min-width:210px}.message-audio audio{width:100%}}

/* Referral source */
.dialog-source{display:block;margin-top:5px;font-size:12px;color:#74758d;max-width:620px}.dialog-source a{color:#6749d7;text-decoration:underline;text-underline-offset:2px;overflow-wrap:anywhere}.dialog-source a:hover{color:#4f34bd}

/* New outbound WhatsApp dialog */
.dialogs-new-btn{width:100%;margin-bottom:10px;min-height:44px}.dialogs-new-backdrop{z-index:1200}.dialogs-new-modal{width:min(680px,94vw);max-width:none;padding:28px}.dialogs-new-modal h2{margin:5px 0 6px}.dialogs-new-form{display:grid;gap:15px;margin-top:20px}.dialogs-new-form label{display:block;font-size:12px;font-weight:800;color:#68647b}.dialogs-new-form input,.dialogs-new-form select,.dialogs-new-form textarea{display:block;width:100%;margin-top:7px;border:1px solid #dcd8eb;border-radius:12px;background:#fff;color:#1d1837;padding:11px 13px;font:inherit}.dialogs-new-form input,.dialogs-new-form select{min-height:46px}.dialogs-new-form textarea{resize:vertical;min-height:115px}.dialogs-new-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}.dialogs-ai-check{display:flex!important;align-items:center;gap:9px;border:1px solid #e2deef;border-radius:12px;background:#f8f6ff;padding:12px}.dialogs-ai-check input{width:18px!important;min-height:18px!important;margin:0!important}.dialogs-ai-check span{font-size:12px;color:#5f5877}.dialogs-new-actions{display:flex;justify-content:flex-end;gap:10px;border-top:1px solid #e6e2f0;padding-top:16px}.dialogs-new-actions button{min-width:150px}
@media(max-width:600px){.dialogs-new-modal{width:96vw;padding:20px 16px;max-height:94vh;overflow:auto}.dialogs-new-grid{grid-template-columns:1fr}.dialogs-new-actions{flex-direction:column-reverse}.dialogs-new-actions button{width:100%}}


/* Outgoing image attachment */
.chat-compose-wrap{border-top:1px solid var(--border);background:#fff}.chat-compose-wrap .chat-compose{border-top:0}.chat-attach-btn{flex:0 0 46px;width:46px;height:46px;display:grid;place-items:center;border:1px solid #dcd8eb;border-radius:13px;background:#f5f2ff;color:#6248cd;font-size:21px;cursor:pointer;transition:.18s ease}.chat-attach-btn:hover{background:#e9e3ff;border-color:#aa96ef}.chat-attachment-preview{display:flex;align-items:center;gap:11px;margin:10px 12px 0;padding:10px;border:1px solid #ddd5f5;border-radius:13px;background:#f8f6ff}.chat-attachment-preview[hidden]{display:none}.chat-attachment-preview img{width:64px;height:64px;border-radius:10px;object-fit:cover;background:#eceaf4}.chat-attachment-preview div{display:flex;flex:1;min-width:0;flex-direction:column;gap:3px}.chat-attachment-preview b{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#29213f;font-size:12px}.chat-attachment-preview span{color:#77728a;font-size:11px}.chat-attachment-preview button{width:34px;height:34px;border:0;border-radius:50%;background:#ece7ff;color:#5e47c4;font-size:22px;cursor:pointer}.chat-attachment-preview button:hover{background:#ded5ff}@media(max-width:600px){.chat-compose{gap:6px;padding:10px}.chat-attach-btn{flex-basis:42px;width:42px;height:44px}.chat-compose textarea{min-width:0}.chat-compose .primary-btn{padding-left:12px;padding-right:12px}.chat-attachment-preview{margin:8px 10px 0}}

.dialog-emoji-picker{position:absolute;bottom:58px;left:54px;z-index:40;width:min(360px,calc(100vw - 80px));max-height:230px;overflow:auto;display:flex;flex-wrap:wrap;gap:5px;padding:12px;background:#fff;border:1px solid #ded9ee;border-radius:16px;box-shadow:0 12px 35px rgba(38,25,82,.18)}.dialog-emoji-picker button{border:0;background:transparent;font-size:24px;line-height:1;padding:7px;border-radius:9px;cursor:pointer}.dialog-emoji-picker button:hover{background:#f1edff}.chat-compose{position:relative}

.dialog-source-edit{border:0;background:transparent;color:#6749d7;font-size:11px;padding:2px 0;cursor:pointer;text-decoration:underline;text-underline-offset:2px}.dialog-source-edit:disabled{opacity:.55;cursor:wait}.dialog-older-messages{display:block;margin:0 auto 18px;padding:8px 14px;border:1px solid #d9d5ee;border-radius:10px;background:#fff;color:#5b46c4;font-weight:700;cursor:pointer}.dialog-older-messages:disabled{opacity:.6;cursor:wait}

/* Give the conversation more room on desktop while keeping lead attribution visible. */
@media (min-width:1101px){
  .dialogs-shell{height:calc(100dvh - 205px);min-height:650px}
  .chat-head{padding:9px 14px;align-items:flex-start}
  .chat-person{min-width:0}
  .chat-person strong{line-height:1.2}
  .chat-person span{margin-top:2px}
  .dialog-source{margin-top:3px;line-height:1.25}
  .dialog-source-card{margin-top:4px!important;padding:4px 6px!important;max-width:320px!important;font-size:12px;line-height:1.2}
  .dialog-source-card img{width:44px!important;height:44px!important}
  .dialog-source-edit{margin-top:2px;padding:0}
  .chat-actions{justify-content:flex-end}
  .chat-actions .secondary-btn{padding:8px 10px;font-size:12px}
  .dialog-context{padding:8px 14px;grid-template-columns:minmax(115px,.7fr) minmax(135px,.9fr) minmax(215px,1.5fr) minmax(135px,.8fr);align-items:end;gap:8px}
  .dialog-context select{height:32px}
  .dialog-context>div>span{margin-bottom:3px}
  .dialog-ai-state b{display:block;min-height:32px;line-height:32px;white-space:nowrap}
  .chat-messages{min-height:0;padding:14px 18px}
  .chat-compose{padding:9px 12px}
}
@media (min-width:901px) and (max-width:1100px){
  .dialogs-shell{height:calc(100dvh - 215px);min-height:650px}
  .chat-head{padding:10px 14px}
  .dialog-context{padding:8px 14px;grid-template-columns:repeat(2,minmax(0,1fr))}
  .dialog-source-card img{width:48px!important;height:48px!important}
}

/* Keep the mobile message composer above the fixed Zadarma WebRTC dial bar. */
@media (max-width:600px){
  .dialogs-chat .chat-compose-wrap{padding-bottom:calc(96px + env(safe-area-inset-bottom, 0px))}
  .dialogs-chat .chat-messages{min-height:180px}
}

/* Reply to a specific WhatsApp message. */
.dialog-quote-button{display:block;margin:7px 0 0 auto;padding:3px 7px;border:0;border-radius:7px;background:transparent;color:#6b50cf;font:inherit;font-size:13px;cursor:pointer}
.dialog-quote-button:hover,.dialog-quote-button:focus-visible{background:#eee9ff;outline:2px solid transparent}
.dialog-quote-preview{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:0 12px 7px;padding:8px 11px;border-left:3px solid #7459de;border-radius:8px;background:#f2efff;color:#281c53}
.dialog-quote-preview[hidden]{display:none}
.dialog-quote-preview div{display:flex;flex-direction:column;min-width:0;gap:2px}
.dialog-quote-preview b{font-size:13px}
.dialog-quote-preview span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:13px}
.dialog-quote-preview button{flex:none;border:0;background:transparent;color:#55438e;font-size:22px;cursor:pointer}
.dialog-quoted-message{margin-bottom:7px;padding:6px 8px;border-left:3px solid #7459de;border-radius:5px;background:rgba(255,255,255,.55);font-size:13px}

/* CRM stages are distinct from conversation status. */
.dialog-crm-stages{display:flex;flex-wrap:wrap;gap:5px;margin-top:7px;min-width:0}
.dialog-crm-stages .dialog-crm-stage{display:block;padding:4px 8px;border:1px solid #d7ccef;border-radius:8px;background:#eee8fa;color:#49317e!important;font-size:11px;font-weight:700;line-height:1.4;white-space:normal;overflow-wrap:anywhere;text-align:left;max-width:100%;margin:0}
.dialog-crm-stages .dialog-crm-stage.muted{background:#f4f4f7;color:#6f7288!important;border-color:#e1e1e8;font-weight:500}
.dialog-crm-stages-head .dialog-crm-stage{font-size:12px;padding:5px 9px}


/* CRM contact blacklist */
.dialog-blocked-notice{display:flex;flex-direction:column;gap:5px;padding:12px 18px;background:#fff3ef;color:#88382a;border-bottom:1px solid #efd5cd;font-size:13px;overflow-wrap:anywhere}
#dialogBlock{color:#a13f35;border-color:#e1b4ad}
.dialogs-stats{grid-template-columns:repeat(5,minmax(0,1fr))}
@media(max-width:700px){.dialogs-stats{grid-template-columns:repeat(2,minmax(0,1fr))}}
.chat-compose-wrap[hidden]{display:none!important}
