/* Живой чат: кнопка в правом нижнем углу и панель диалога */
.chat-root {
    --chat-navy: var(--ink);
    --chat-gold: var(--gold);
    --chat-border: var(--rule);
    --chat-muted: var(--muted);
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1080;
    font-size: 14px;
}

.chat-launcher {
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: var(--chat-navy);
    color: #fff;
    font-size: 22px;
    box-shadow: 0 8px 24px rgba(15, 37, 72, 0.28);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, background 0.15s;
}
.chat-launcher:hover { background: #1B3A69; }
.chat-launcher:focus-visible { outline: none; box-shadow: var(--focus); }
.chat-root.is-open .chat-launcher { background: var(--ink-2); }

/* Точка непрочитанных ответов оператора */
.chat-dot {
    position: absolute;
    top: -2px; right: -2px;
    min-width: 20px; height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--gold);
    color: var(--sidebar);
    font-size: 11px;
    font-weight: 600;
    line-height: 20px;
    text-align: center;
    display: none;
}
.chat-root.has-unread .chat-dot { display: block; }

.chat-panel {
    position: absolute;
    right: 0;
    bottom: 72px;
    width: 364px;
    max-height: min(560px, calc(100vh - 140px));
    background: #fff;
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-pop);
    border: 1px solid var(--rule);
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.chat-root.is-open .chat-panel { display: flex; }

.chat-header {
    background: var(--chat-navy);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}
.chat-header-title { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-lg); }
.chat-header-sub { font-size: 12px; color: rgba(255, 255, 255, 0.72); margin-top: 2px; }
.chat-close {
    background: transparent; border: 0; color: rgba(255, 255, 255, 0.75);
    font-size: 16px; line-height: 1; cursor: pointer; padding: 2px 4px;
}
.chat-close:hover { color: #fff; }

.chat-body { flex: 1 1 auto; overflow-y: auto; padding: 14px 16px; }
.chat-section { display: none; }
.chat-section.is-active { display: block; }

/* FAQ */
.chat-faq-title { font-weight: 700; color: var(--chat-navy); margin-bottom: 10px; }
.chat-faq-item { border: 1px solid var(--chat-border); border-radius: var(--r-md); margin-bottom: 8px; overflow: hidden; }
.chat-faq-q {
    width: 100%; text-align: left; background: #fff; border: 0;
    padding: 11px 13px; font-size: var(--fs-md); font-weight: 400; color: var(--chat-navy);
    cursor: pointer; display: flex; justify-content: space-between; gap: 10px; align-items: center;
}
.chat-faq-q:hover { background: var(--paper); }
.chat-faq-q i { color: var(--chat-muted); font-size: 12px; transition: transform 0.15s; flex-shrink: 0; }
.chat-faq-item.is-open .chat-faq-q i { transform: rotate(180deg); }
.chat-faq-a {
    display: none; padding: 0 13px 12px; font-size: 13px; line-height: 1.6;
    color: var(--ink-2); white-space: pre-line;
}
.chat-faq-item.is-open .chat-faq-a { display: block; }

.chat-ask {
    width: 100%; margin-top: 10px; padding: 11px;
    background: var(--surface); color: var(--chat-navy); border: 1px solid var(--rule-strong); border-radius: var(--r-md);
    font-size: var(--fs-md); font-weight: 700; cursor: pointer;
}

.chat-ask:hover { border-color: var(--chat-navy); }

.chat-back {
    background: none; border: 0; color: var(--chat-muted);
    font-size: var(--fs-sm); padding: 0 0 8px; cursor: pointer;
}
.chat-back:hover { color: var(--chat-navy); }

/* Форма обращения */
.chat-hint { font-size: var(--fs-sm); color: var(--chat-muted); line-height: 1.5; margin-bottom: 12px; }
.chat-field { margin-bottom: 10px; }
.chat-field label { display: block; font-size: var(--fs-sm); color: var(--chat-muted); margin-bottom: 4px; }
.chat-field input, .chat-field textarea {
    width: 100%; border: 1px solid var(--chat-border); border-radius: var(--r-md);
    padding: 9px 11px; font-size: var(--fs-md); font-family: inherit; color: var(--ink);
}
.chat-field input:focus, .chat-field textarea:focus {
    outline: none; border-color: var(--chat-gold); box-shadow: var(--focus);
}
.chat-field textarea { resize: vertical; min-height: 84px; }
.chat-error { color: var(--void); font-size: var(--fs-sm); margin-bottom: 10px; display: none; }
.chat-error.is-visible { display: block; }
.chat-submit {
    width: 100%; padding: 11px; border: 0; border-radius: var(--r-md);
    background: var(--chat-gold); color: #fff; font-size: var(--fs-md); font-weight: 700; cursor: pointer;
}
.chat-submit:hover { background: var(--gold-hover); }
.chat-submit:disabled { opacity: 0.6; cursor: default; }

/* Переписка */
.chat-messages { display: flex; flex-direction: column; gap: 8px; }
.chat-msg { max-width: 84%; padding: 9px 12px; border-radius: var(--r-lg); font-size: var(--fs-md); line-height: 1.55; white-space: pre-line; word-break: break-word; }
.chat-msg-visitor { align-self: flex-end; background: var(--chat-navy); color: #fff; border-bottom-right-radius: var(--r-sm); }
.chat-msg-operator { align-self: flex-start; background: var(--tint); color: var(--ink); border-bottom-left-radius: var(--r-sm); }
.chat-msg-system { align-self: center; max-width: 100%; background: none; color: var(--muted); font-size: var(--fs-sm); text-align: center; }
.chat-msg-meta { display: block; margin-top: 4px; font-size: var(--fs-xs); opacity: 0.65; }

.chat-footer { border-top: 1px solid var(--chat-border); padding: 10px 12px; display: none; gap: 8px; }
.chat-root.is-chatting .chat-footer { display: flex; }
.chat-footer textarea {
    flex: 1 1 auto; border: 1px solid var(--chat-border); border-radius: var(--r-md);
    padding: 8px 11px; font-size: var(--fs-md); font-family: inherit; resize: none; height: 40px; max-height: 110px;
}
.chat-footer textarea:focus { outline: none; border-color: var(--chat-gold); }
.chat-send {
    width: 40px; height: 40px; flex-shrink: 0; border: 0; border-radius: var(--r-md);
    background: var(--chat-gold); color: #fff; cursor: pointer;
}
.chat-send:hover { background: var(--gold-hover); }
.chat-send:disabled { opacity: 0.6; cursor: default; }

.chat-notice {
    margin-top: 10px; padding: 9px 11px; border-radius: var(--r-md);
    background: var(--tint); color: var(--chat-muted); font-size: var(--fs-sm); text-align: center;
    display: none;
}
.chat-notice.is-visible { display: block; }

@media (max-width: 600px) {
    .chat-root { right: 16px; bottom: 16px; }
    .chat-panel {
        position: fixed;
        right: 12px; left: 12px; bottom: 84px;
        width: auto;
        max-height: calc(100vh - 120px);
    }
}

@media print { .chat-root { display: none; } }
