/* Support Widget Styles */

:root {
    --primary-color: #2563eb;
    --bg-color: #ffffff;
    --text-color: #1f2937;
    --muted-color: #6b7280;
    --border-color: #e5e7eb;
    --hover-color: #f3f4f6;
    --user-bubble: #2563eb;
    --bot-bubble: #f3f4f6;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --widget-width: 360px;
    --widget-height: 500px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: transparent;
    color: var(--text-color);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Toggle Button (collapsed state) */
.widget-toggle-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    z-index: 1000;
}

.widget-toggle-btn.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0);
}

.widget-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.5);
}

.widget-toggle-btn:active {
    transform: scale(0.95);
}

.widget-toggle-btn svg {
    width: 28px;
    height: 28px;
}

.unread-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 2s infinite;
}

.unread-badge:empty,
.unread-badge[style*="display: none"] {
    display: none !important;
}

/* Widget Container */
.widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: var(--widget-width);
    height: var(--widget-height);
    max-height: calc(100vh - 40px);
    background: var(--bg-color);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: scale(0.95) translateY(20px);
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 999;
}

.widget-container.expanded {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

/* Header */
.widget-header {
    background: var(--primary-color);
    color: white;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.widget-header h1 {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.widget-header h1::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-indicator {
    font-size: 11px;
    opacity: 0.9;
}

.minimize-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.minimize-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.minimize-btn svg {
    width: 20px;
    height: 20px;
}

/* Chat Messages */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: linear-gradient(to bottom, #f9fafb, #ffffff);
}

.message {
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
}

.message.bot {
    align-self: flex-start;
}

.message-content {
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
}

.message.user .message-content {
    background: var(--user-bubble);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.bot .message-content {
    background: var(--bot-bubble);
    color: var(--text-color);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 10px;
    color: var(--muted-color);
    margin-top: 4px;
    padding: 0 4px;
}

.message.user .message-time {
    text-align: right;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    background: var(--bot-bubble);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--muted-color);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Typing text ("печатает...") */
.typing-text {
    padding: 10px 14px;
    background: var(--bot-bubble);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    font-size: 14px;
    color: var(--muted-color);
    font-style: italic;
}

.typing-text .dots::after {
    content: '';
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}

/* Markdown styles */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    display: none; /* Hide headers as requested */
}

.message-content p {
    margin: 0 0 8px 0;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content strong {
    font-weight: 600;
}

.message-content em {
    font-style: italic;
}

.message-content code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Fira Code', 'Monaco', monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message-content ul,
.message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin: 4px 0;
}

.message-content a {
    color: var(--primary-color);
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-content blockquote {
    border-left: 3px solid var(--primary-color);
    margin: 8px 0;
    padding-left: 12px;
    color: var(--muted-color);
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
}

.message-content th,
.message-content td {
    border: 1px solid var(--border-color);
    padding: 6px 10px;
    text-align: left;
}

.message-content th {
    background: var(--hover-color);
    font-weight: 600;
}

/* Input Area */
.input-container {
    padding: 12px 16px;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
}

.input-wrapper {
    flex: 1;
    position: relative;
}

.message-input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    resize: none;
    max-height: 100px;
    font-family: inherit;
    line-height: 1.4;
}

.message-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.message-input::placeholder {
    color: var(--muted-color);
}

.send-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    background: #1d4ed8;
}

.send-button:active:not(:disabled) {
    transform: scale(0.95);
}

.send-button:disabled {
    background: var(--border-color);
    cursor: not-allowed;
}

.send-button svg {
    width: 18px;
    height: 18px;
}

/* Welcome message */
.welcome-message {
    text-align: center;
    padding: 30px 16px;
    color: var(--muted-color);
}

.welcome-message h2 {
    font-size: 18px;
    margin-bottom: 10px;
    color: var(--text-color);
}

.welcome-message p {
    font-size: 13px;
    line-height: 1.6;
}

/* Error message */
.error-message {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Connection status */
.connection-warning {
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-left: 4px solid #fbbf24;
    color: #92400e;
    padding: 8px 12px;
    font-size: 11px;
    flex-shrink: 0;
}

/* Scrollbar */
.chat-container::-webkit-scrollbar {
    width: 4px;
}

.chat-container::-webkit-scrollbar-track {
    background: transparent;
}

.chat-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
    background: var(--muted-color);
}

/* Responsive */
@media (max-width: 480px) {
    :root {
        --widget-width: calc(100vw - 40px);
    }
    
    .widget-header h1 {
        font-size: 15px;
    }
    
    .chat-container {
        padding: 12px;
    }
    
    .message {
        max-width: 90%;
    }
    
    .input-container {
        padding: 10px 12px;
    }
    
    .widget-toggle-btn {
        bottom: 16px;
        right: 16px;
    }
    
    .widget-container {
        bottom: 16px;
        right: 16px;
        width: calc(100vw - 32px);
        height: calc(100vh - 100px);
        max-height: 600px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1f2937;
        --text-color: #f9fafb;
        --muted-color: #9ca3af;
        --border-color: #374151;
        --hover-color: #4b5563;
        --bot-bubble: #374151;
    }
    
    body {
        background-color: transparent;
    }
    
    .widget-container {
        background: var(--bg-color);
    }
    
    .chat-container {
        background: linear-gradient(to bottom, #111827, #1f2937);
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible for keyboard navigation */
.send-button:focus-visible,
.message-input:focus-visible,
.widget-toggle-btn:focus-visible,
.minimize-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}