/* ==========================================================================
   Chat widget — «Данияр, менеджер»
   ========================================================================== */
.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 100;
}

.chat-launcher {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 22px 10px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 100px;
    box-shadow: var(--shadow-lg);
    color: var(--ink);
    transition: transform .25s ease, box-shadow .25s ease;
    cursor: pointer;
    max-width: 260px;
}
.chat-launcher:hover {
    transform: translateY(-3px);
    box-shadow: 0 20px 50px -15px rgba(var(--primary-rgb), .3);
}
.chat-launcher-avatar {
    position: relative;
    width: 40px; height: 40px;
    flex-shrink: 0;
}
.chat-launcher-avatar svg {
    width: 100%; height: 100%;
    border-radius: 50%;
}
.chat-status {
    position: absolute;
    bottom: 0; right: 0;
    width: 12px; height: 12px;
    background: #22c55e;
    border: 2px solid var(--surface);
    border-radius: 50%;
    box-shadow: 0 0 8px #22c55e;
    animation: pulse-dot 2s infinite;
}
.chat-launcher-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    line-height: 1.2;
}
.chat-launcher-text b {
    font-family: 'Inter', sans-serif;
    font-size: .87rem;
    font-weight: 700;
    color: var(--ink);
}
.chat-launcher-text span {
    font-size: .75rem;
    color: var(--ink-3);
    font-weight: 500;
}
.chat-launcher-close {
    display: none;
    width: 40px; height: 40px;
    background: var(--bg-2);
    border-radius: 50%;
    place-items: center;
    color: var(--ink);
}
.chat-launcher-close svg { width: 18px; height: 18px; }

.chat-widget.open .chat-launcher-text,
.chat-widget.open .chat-launcher-avatar { display: none; }
.chat-widget.open .chat-launcher { padding: 0; }
.chat-widget.open .chat-launcher-close { display: grid; }

.chat-panel {
    position: absolute;
    bottom: calc(100% + 12px);
    right: 0;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 560px;
    max-height: calc(100vh - 100px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 30px 80px -20px rgba(var(--primary-rgb), .3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(.96);
    pointer-events: none;
    transition: opacity .25s ease, transform .3s cubic-bezier(.2, .8, .2, 1);
}
.chat-widget.open .chat-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.chat-head {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
    background: var(--primary);
    color: var(--on-dark);
    position: relative;
}
.chat-head-avatar {
    position: relative;
    width: 44px; height: 44px;
    flex-shrink: 0;
}
.chat-head-avatar svg { width: 100%; height: 100%; border-radius: 50%; }
.chat-head-avatar .chat-status {
    bottom: 0; right: 0;
    width: 12px; height: 12px;
    border-color: var(--primary);
}
.chat-head-info {
    flex-grow: 1;
    line-height: 1.2;
}
.chat-head-info b {
    display: block;
    font-family: 'Inter', sans-serif;
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--on-dark);
}
.chat-head-info span {
    font-size: .78rem;
    color: rgba(var(--on-dark-rgb), .7);
    display: flex;
    align-items: center;
    gap: 6px;
}
.chat-close {
    width: 32px; height: 32px;
    background: rgba(var(--on-dark-rgb), .1);
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: var(--on-dark);
    transition: background .2s;
}
.chat-close svg { width: 16px; height: 16px; }
.chat-close:hover { background: rgba(var(--on-dark-rgb), .2); }

.chat-body {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px 18px;
    background: var(--bg-2);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.chat-body::-webkit-scrollbar { width: 6px; }
.chat-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.chat-msg {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: msg-in .35s cubic-bezier(.2,.7,.2,1);
}
@keyframes msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
.chat-msg-avatar {
    width: 32px; height: 32px;
    flex-shrink: 0;
    align-self: flex-end;
}
.chat-msg-avatar svg { width: 100%; height: 100%; border-radius: 50%; }
.chat-msg-bubble {
    padding: 10px 14px;
    background: var(--surface);
    border-radius: 4px 14px 14px 14px;
    color: var(--ink);
    font-size: .92rem;
    line-height: 1.5;
    box-shadow: var(--shadow-sm);
}
.chat-msg-bubble b { color: var(--accent); font-weight: 700; }
.chat-msg-bubble a { color: var(--accent); text-decoration: underline; }

.chat-msg.user { flex-direction: row-reverse; align-self: flex-end; }
.chat-msg.user .chat-msg-avatar { display: none; }
.chat-msg.user .chat-msg-bubble {
    background: var(--primary);
    color: var(--on-dark);
    border-radius: 14px 4px 14px 14px;
}
.chat-msg.user .chat-msg-bubble b { color: var(--accent); }

.chat-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    align-items: center;
}
.chat-typing span {
    width: 6px; height: 6px;
    background: var(--ink-3);
    border-radius: 50%;
    animation: typing-bounce 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.chat-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 16px 4px;
    background: var(--bg-2);
    border-top: 1px solid var(--border);
}
.chat-quick button {
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 100px;
    color: var(--ink);
    font-size: .82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
}
.chat-quick button:hover {
    background: var(--accent);
    color: var(--on-accent);
    border-color: var(--accent);
}
.chat-quick.empty { display: none; }

.chat-form {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.chat-form input {
    flex-grow: 1;
    padding: 12px 14px;
    background: var(--bg-2);
    border: 1px solid transparent;
    border-radius: 100px;
    font-size: .92rem;
    outline: none;
    transition: border-color .2s;
    color: var(--ink);
    font-family: inherit;
}
.chat-form input:focus { border-color: var(--accent); background: var(--surface); }
.chat-form button {
    width: 42px; height: 42px;
    display: grid;
    place-items: center;
    background: var(--accent);
    color: var(--on-accent);
    border-radius: 50%;
    transition: background .2s, transform .2s;
}
.chat-form button svg { width: 18px; height: 18px; }
.chat-form button:hover { background: var(--accent-2); transform: scale(1.05); }

@media (max-width: 500px) {
    .chat-widget { bottom: 16px; right: 16px; }
    .chat-launcher { max-width: 200px; padding: 8px 16px 8px 8px; }
    .chat-launcher-text b { font-size: .8rem; }
    .chat-launcher-text span { font-size: .7rem; }
    .chat-panel { height: calc(100vh - 90px); width: calc(100vw - 32px); bottom: calc(100% + 8px); }
}

.to-top {
    position: fixed;
    bottom: 24px;
    left: 24px;
    width: 46px; height: 46px;
    display: grid; place-items: center;
    background: var(--primary);
    color: var(--on-dark);
    border: none;
    border-radius: 50%;
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
    transition: opacity .3s, transform .3s;
    z-index: 80;
}
.to-top svg { width: 18px; height: 18px; }
.to-top.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.to-top:hover { background: var(--accent); }

