.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
}

.chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--accent-purple);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(121, 129, 166, 0.4);
    transition: all 0.2s ease;
}

.chat-button:hover {
    transform: scale(1.05);
}

.chat-button svg {
    width: 28px;
    height: 28px;
}

.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 550px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chat-window.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

.chat-header {
    padding: 20px 24px;
    background: var(--bg-input);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.chat-header h3 {
    font-family: 'Unbounded', sans-serif;
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.btn-close-chat {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s ease;
    padding: 0;
}

.btn-close-chat:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.btn-close-chat svg {
    width: 20px;
    height: 20px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-message-wrapper.animate {
    animation: messageAppear 0.2s ease;
}

.chat-message-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    max-width: 80%;
    align-self: flex-start;
}

.chat-message-wrapper.own {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
    flex-wrap: wrap;
}

.chat-username {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: inherit;
    transition: opacity 0.2s ease;
}

.chat-username:hover {
    opacity: 0.8;
}

.chat-username strong {
    display: inline;
    font-size: 13px;
    color: var(--accent-purple-light);
    font-weight: 600;
    margin-bottom: 0;
}

.chat-rank {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    opacity: 0.8;
}

.chat-time {
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.6;
    font-weight: 400;
}

.chat-text {
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-primary);
    display: block;
}

@keyframes messageAppear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message-wrapper.consecutive {
    margin-top: -10px;
}

.chat-message-wrapper.consecutive .chat-avatar,
.chat-message-wrapper.consecutive .chat-avatar-placeholder {
    visibility: hidden;
    height: 0;
    margin: 0;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid var(--border-color);
}

.chat-avatar-placeholder {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.chat-message {
    background: var(--bg-input);
    padding: 10px 14px;
    border-radius: 18px;
    border-bottom-left-radius: 6px;
    word-break: break-word;
    max-width: 100%;
}

.chat-message-wrapper.own .chat-message {
    background: var(--accent-purple);
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 6px;
}

.chat-message-wrapper.consecutive .chat-message {
    border-top-left-radius: 6px;
}

.chat-message-wrapper.own.consecutive .chat-message {
    border-top-right-radius: 6px;
    border-top-left-radius: 18px;
}

.chat-message strong {
    display: block;
    font-size: 13px;
    color: var(--accent-purple-light);
    margin-bottom: 2px;
    font-weight: 600;
}

.chat-message-wrapper.own .chat-message strong {
    color: rgba(255,255,255,0.9);
    text-align: right;
}

.chat-message span {
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-primary);
    display: block;
}

.chat-message-wrapper.own .chat-message span {
    color: white;
}

.chat-input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
    flex-shrink: 0;
    background: var(--bg-card);
    position: relative;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
    resize: none;
    overflow-y: auto;
    min-height: 48px;
    max-height: 120px;
    line-height: 1.5;
    padding: 12px 70px 12px 18px;
}

.chat-input::-webkit-scrollbar {
    width: 6px;
}

.chat-input::-webkit-scrollbar-track {
    background: transparent;
}

.chat-input::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.chat-input::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.chat-input:focus {
    border-color: var(--accent-purple);
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.chat-input[style*="overflow-y: auto"]::-webkit-scrollbar {
    width: 6px;
}

.chat-input[style*="overflow-y: auto"]::-webkit-scrollbar-track {
    background: transparent;
}

.chat-input[style*="overflow-y: auto"]::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.char-counter {
    position: absolute;
    right: 95px;
    bottom: 30px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.2s ease;
    pointer-events: none;
}

.char-counter.warning {
    color: #ff9500;
}

.char-counter.danger {
    color: #ff3333;
}

.chat-input.input-danger {
    border-color: #ff3333 !important;
    box-shadow: 0 0 0 1px #ff3333;
}

.btn-send {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 14px;
    background: var(--accent-purple);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
}

.btn-send:hover {
    background: var(--accent-purple-light);
    transform: scale(1.05);
}

.btn-send:active {
    transform: scale(0.95);
}

.btn-send svg {
    width: 22px;
    height: 22px;
    margin-left: -2px;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

@media (min-width: 1920px) {
    .chat-window {
        width: 420px;
        height: 600px;
    }
    
    .chat-messages {
        padding: 24px;
    }
}

@media (max-width: 1600px) {
    .chat-window {
        width: 360px;
        height: 520px;
    }
}

@media (max-width: 1280px) {
    .chat-window {
        width: 340px;
        height: 480px;
    }
    
    .chat-button {
        width: 56px;
        height: 56px;
    }
    
    .chat-button svg {
        width: 26px;
        height: 26px;
    }
}

@media (max-width: 1024px) {
    .chat-widget {
        bottom: 20px;
        right: 20px;
    }
    
    .chat-window {
        width: 380px;
        height: 500px;
        border-radius: 20px;
    }
    
    .chat-header {
        padding: 18px 20px;
    }
    
    .chat-messages {
        padding: 16px;
    }
    
    .chat-input-area {
        padding: 14px 16px;
    }
}

@media (max-width: 800px) {
    .chat-widget {
        bottom: 16px;
        right: 16px;
    }
    
    .chat-button {
        width: 52px;
        height: 52px;
    }
    
    .chat-button svg {
        width: 24px;
        height: 24px;
    }
    
    .chat-window {
        width: calc(100vw - 32px);
        max-width: 400px;
        height: 60vh;
        max-height: 500px;
        bottom: 72px;
        right: 0;
        border-radius: 20px;
    }
    
    .chat-header h3 {
        font-size: 15px;
    }
    
    .chat-message-wrapper {
        max-width: 85%;
    }
    
    .chat-avatar {
        width: 32px;
        height: 32px;
    }
}

@media (max-width: 480px) {
    .chat-widget {
        bottom: 12px;
        right: 12px;
    }
    
    .chat-button {
        width: 48px;
        height: 48px;
    }
    
    .chat-button svg {
        width: 22px;
        height: 22px;
    }
    
    .chat-window {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        width: 100%;
        height: 85vh;
        max-height: none;
        border-radius: 24px 24px 0 0;
        border: none;
        border-top: 1px solid var(--border-color);
        
        transform: translateY(100%);
        opacity: 1;
        transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    }
    
    .chat-window.active {
        transform: translateY(0);
    }
    
    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }
    
    .chat-header {
        padding: 20px;
        border-radius: 24px 24px 0 0;
    }
    
    .chat-header h3 {
        font-size: 16px;
    }
    
    .chat-messages {
        padding: 12px 16px;
        gap: 10px;
    }
    
    .chat-input-area {
        padding: 12px 16px 20px;
        gap: 10px;
    }
    
    .chat-input {
        min-height: 44px;
        max-height: 100px;
        font-size: 16px;
        border-radius: 12px;
        padding: 10px 90px 10px 16px;
    }
    
    .btn-send {
        width: 44px;
        height: 44px;
        border-radius: 12px;
    }
    
    .btn-send svg {
        width: 20px;
        height: 20px;
    }
    
    .chat-message-wrapper {
        max-width: 85%;
        gap: 10px;
    }
    
    .chat-message-wrapper.consecutive {
        margin-top: -8px;
    }
    
    .chat-avatar,
    .chat-avatar-placeholder {
        width: 32px;
        height: 32px;
    }
    
    .chat-message {
        padding: 8px 12px;
        border-radius: 16px;
    }
    
    .chat-message strong {
        font-size: 12px;
    }
    
    .chat-message span {
        font-size: 13px;
    }

    .char-counter {
        position: absolute;
        right: 90px;
        bottom: 55%;
        transform: translateY(50%);
        font-size: 11px;
        color: var(--text-muted);
        pointer-events: none;
        line-height: 1;
    }
    
    .btn-close-chat {
        width: 36px;
        height: 36px;
    }
    
    .btn-close-chat svg {
        width: 24px;
        height: 24px;
    }
}

@media (max-width: 375px) {
    .chat-input {
        padding: 10px 85px 10px 14px;
        font-size: 15px;
    }
    
    .char-counter {
        right: 78px;
        font-size: 10px;
    }
    
    .btn-send {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }
    
    .chat-input-area {
        padding: 10px 12px 16px;
        gap: 8px;
    }
}

@media (max-width: 320px) {
    .chat-input {
        padding: 10px 80px 10px 12px;
    }
    
    .char-counter {
        right: 68px;
        font-size: 10px;
    }
    
    .btn-send {
        width: 38px;
        height: 38px;
        min-width: 38px;
    }
    
    .btn-send svg {
        width: 18px;
        height: 18px;
    }
}

@media (max-width: 360px) {
    .chat-window {
        height: 90vh;
    }
    
    .chat-input-area {
        padding-bottom: 16px;
    }
}

/* Горизонтальная ориентация на мобильных устройствах */
@media (max-height: 500px) and (orientation: landscape) {
    .chat-widget {
        bottom: 8px;
        right: 8px;
    }
    
    .chat-button {
        width: 44px;
        height: 44px;
    }
    
    .chat-button svg {
        width: 20px;
        height: 20px;
    }
    
    .chat-window {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: 0;
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        border: none;
        transform: translateY(100%);
        opacity: 1;
        transition: transform 0.3s ease;
    }
    
    .chat-window.active {
        transform: translateY(0);
    }
    
    .chat-header {
        padding: 12px 16px;
        border-radius: 0;
        flex-shrink: 0;
    }
    
    .chat-header h3 {
        font-size: 14px;
    }
    
    .chat-messages {
        padding: 12px 16px;
        gap: 8px;
        flex: 1;
        min-height: 0;
    }
    
    .chat-input-area {
        padding: 10px 16px;
        gap: 8px;
        flex-shrink: 0;
    }
    
    .chat-input {
        min-height: 40px;
        max-height: 80px;
        font-size: 14px;
        border-radius: 10px;
        padding: 8px 80px 8px 14px;
    }
    
    .btn-send {
        width: 40px;
        height: 40px;
        border-radius: 10px;
    }
    
    .btn-send svg {
        width: 18px;
        height: 18px;
    }
    
    .char-counter {
        right: 72px;
        bottom: 50%;
        transform: translateY(50%);
        font-size: 10px;
    }
    
    .chat-message-wrapper {
        max-width: 75%;
        gap: 8px;
    }
    
    .chat-avatar,
    .chat-avatar-placeholder {
        width: 28px;
        height: 28px;
    }
    
    .chat-message {
        padding: 6px 10px;
        border-radius: 14px;
    }
    
    .chat-message strong {
        font-size: 11px;
    }
    
    .chat-message span {
        font-size: 12px;
    }
    
    .chat-text {
        font-size: 12px;
        line-height: 1.3;
    }
    
    .btn-close-chat {
        width: 32px;
        height: 32px;
    }
    
    .btn-close-chat svg {
        width: 20px;
        height: 20px;
    }
}

/* Очень низкие экраны в горизонтальной ориентации */
@media (max-height: 400px) and (orientation: landscape) {
    .chat-window {
        height: 100vh;
    }
    
    .chat-messages {
        padding: 8px 12px;
    }
    
    .chat-input-area {
        padding: 8px 12px;
    }
    
    .chat-input {
        min-height: 36px;
        max-height: 60px;
        font-size: 13px;
    }
    
    .btn-send {
        width: 36px;
        height: 36px;
    }
}

@supports (padding: max(0px)) {
    @media (max-width: 480px) {
        .chat-input-area {
            padding-bottom: max(20px, env(safe-area-inset-bottom));
        }
        
        .chat-widget {
            bottom: max(12px, env(safe-area-inset-bottom));
        }
    }
    
    @media (max-height: 500px) and (orientation: landscape) {
        .chat-input-area {
            padding-bottom: max(10px, env(safe-area-inset-bottom));
        }
        
        .chat-widget {
            bottom: max(8px, env(safe-area-inset-bottom));
        }
    }
}