/* ===== WebDoc Chat Widget v2 — Responsive ===== */

/* Reset inherited site styles inside modal */
.webdoc-modal,
.webdoc-modal * {
    box-sizing: border-box;
}
.webdoc-modal button,
.webdoc-modal input {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
}

/* Hide old helpdesk "Напишите нам" floating button — replaced by WebDoc */
.mail-button.js-open-feedback {
    display: none !important;
}

/* Chat Button */
.chat-button {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    box-shadow: 0 8px 30px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 1000;
    animation: webdoc-pulse 2s infinite;
    border: none;
}
.chat-button:hover {
    transform: scale(1.1) rotate(10deg);
    box-shadow: 0 12px 40px rgba(102, 126, 234, 0.6);
}
.chat-button.hidden {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}
.chat-button-icon {
    font-size: 32px;
    color: white;
}
.chat-button .online-indicator {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 14px;
    height: 14px;
    background: #10b981;
    border: 3px solid white;
    border-radius: 50%;
    animation: webdoc-blink 2s infinite;
}

/* Chat Modal */
.webdoc-modal {
    position: fixed;
    bottom: 120px;
    right: 30px;
    width: 400px;
    height: 600px;
    max-height: calc(100vh - 140px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 10000;
}
.webdoc-modal.open {
    display: flex;
    animation: webdoc-slideUp 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Header */
.webdoc-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}
.webdoc-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.webdoc-title {
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}
.webdoc-back-btn {
    display: none;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    font-size: 18px;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    margin-right: 8px;
}
.webdoc-back-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}
.webdoc-controls {
    display: flex;
    gap: 8px;
}
.webdoc-control-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.webdoc-control-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}
.webdoc-status {
    font-size: 13px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}
.webdoc-status-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    animation: webdoc-blink 2s infinite;
}

/* Messages */
.webdoc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f9fafb;
    display: flex;
    flex-direction: column;
    gap: 16px;
    -webkit-overflow-scrolling: touch;
}
.webdoc-msg {
    display: flex;
    gap: 10px;
    animation: webdoc-messageIn 0.3s ease-out;
}
.webdoc-msg--user {
    flex-direction: row-reverse;
}
.webdoc-msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 16px;
    flex-shrink: 0;
}
.webdoc-msg--user .webdoc-msg-avatar {
    background: #6b7280;
}
.webdoc-msg-content {
    max-width: 70%;
}
.webdoc-msg-bubble {
    background: white;
    padding: 12px 16px;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 14px;
    touch-action: manipulation;
}
.webdoc-msg--user .webdoc-msg-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}
.webdoc-msg-bubble strong { color: #667eea; }
.webdoc-msg--user .webdoc-msg-bubble strong { color: #fff; }
.webdoc-msg-bubble code {
    background: rgba(0,0,0,0.06);
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 13px;
}
.webdoc-msg-bubble pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 12px;
    margin: 8px 0;
}
.webdoc-msg-bubble pre code {
    background: none;
    padding: 0;
    color: inherit;
}
.webdoc-msg-bubble a {
    color: #667eea;
    text-decoration: underline;
}
.webdoc-msg--user .webdoc-msg-bubble a {
    color: #c7d2fe;
}
.webdoc-msg-bubble ul, .webdoc-msg-bubble ol {
    margin: 8px 0 0 20px;
    line-height: 1.6;
}
.webdoc-msg-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
}
.webdoc-msg-bubble--error {
    background: #fff3f3 !important;
    color: #c00 !important;
}

/* Typing indicator */
.webdoc-typing-wrap { display: none; }
.webdoc-typing-wrap.active { display: flex; }
.webdoc-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.webdoc-typing span {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: webdoc-typingDot 1.4s infinite;
}
.webdoc-typing span:nth-child(2) { animation-delay: 0.2s; }
.webdoc-typing span:nth-child(3) { animation-delay: 0.4s; }

/* Quick replies */
.webdoc-quick-replies {
    padding: 0 20px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    background: #f9fafb;
    flex-shrink: 0;
    justify-content: center;
}
.webdoc-quick-replies.hidden { display: none; }
.webdoc-quick-btn {
    background: white;
    color: #333;
    border: 1px solid #e5e7eb;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    line-height: 1.4;
}
.webdoc-quick-btn:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

/* Input Area */
.webdoc-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-shrink: 0;
}
.webdoc-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 14px;
    padding: 12px;
    border-radius: 8px;
    background: #f9fafb;
}
.webdoc-send-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: white;
    font-size: 18px;
    cursor: pointer;
    transition: transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.webdoc-send-btn:hover { transform: scale(1.1); }
.webdoc-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Animations */
@keyframes webdoc-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}
@keyframes webdoc-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
@keyframes webdoc-slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
@keyframes webdoc-slideUpMobile {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
@keyframes webdoc-messageIn {
    from { transform: translateY(10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
@keyframes webdoc-typingDot {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-10px); }
}

/* Scrollbar */
.webdoc-messages::-webkit-scrollbar { width: 6px; }
.webdoc-messages::-webkit-scrollbar-track { background: #f9fafb; }
.webdoc-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
.webdoc-messages::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

body.webdoc-chat-open {
    overscroll-behavior: contain;
}

/* ===== Mobile (< 768px) ===== */
@media (max-width: 768px) {
    /* Hide floating button on mobile — bottom-nav has WebDoc item */
    .chat-button {
        display: none !important;
    }

    .webdoc-modal {
        bottom: 0 !important;
        right: 0 !important;
        left: 0;
        top: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    .webdoc-modal.open {
        animation: webdoc-slideUpMobile 0.3s ease-out;
    }
    .webdoc-header { padding: 16px; }
    .webdoc-title { font-size: 16px; }
    .webdoc-back-btn { display: flex; }
    .webdoc-messages { padding: 16px; }
    .webdoc-msg-content { max-width: 85%; }
    .webdoc-msg-bubble { font-size: 15px; }
    .webdoc-msg-avatar { width: 32px; height: 32px; font-size: 14px; }
    .webdoc-quick-replies { padding: 12px 16px; }
    .webdoc-quick-btn {
        flex: 1 1 calc(50% - 4px);
        min-width: calc(50% - 4px);
        text-align: center;
    }
    .webdoc-input-area { padding: 12px 16px; }
    .webdoc-input { font-size: 16px; }
    .webdoc-send-btn { width: 36px; height: 36px; }
}

/* Safe Area (iOS notch) */
@supports (padding-top: env(safe-area-inset-top)) {
    @media (max-width: 768px) {
        .webdoc-header {
            padding-top: calc(16px + env(safe-area-inset-top));
        }
        .webdoc-input-area {
            padding-bottom: calc(12px + env(safe-area-inset-bottom));
        }
    }
}
