.chat-button {
    position: fixed;
    bottom: 44px;
    right: 20px;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background:
        radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.24), transparent 28%),
        linear-gradient(135deg, #0d9488 0%, #0f766e 52%, #2563eb 100%);
    box-shadow: 0 14px 30px rgba(13, 148, 136, 0.28);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    border: 0;
    outline: none;
}

.chat-button::before {
    content: "";
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(37, 99, 235, 0.3) 0%, rgba(13, 148, 136, 0.22) 48%, transparent 70%);
    animation: chatHalo 2.2s ease-out infinite;
    pointer-events: none;
    z-index: -1;
}

.chat-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 18px 34px rgba(13, 148, 136, 0.42);
}

.chat-button:active {
    transform: scale(0.95);
}

.chat-button-tip {
    position: absolute;
    left: 50%;
    top: calc(100% + 8px);
    transform: translateX(-50%);
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.56);
    border-radius: 8px;
    color: #ffffff;
    background: linear-gradient(135deg, #083c37 0%, #0d6b60 62%, #2563eb 100%);
    box-shadow: 0 12px 24px rgba(13, 107, 96, 0.28);
    white-space: nowrap;
    font-size: 13px;
    font-weight: 800;
    line-height: 1;
    pointer-events: none;
}

.chat-icon-svg {
    width: auto;
    height: auto;
    color: white;
    transform: none;
    font-size: 26px;
    line-height: 1;
}

.chat-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 20px;
    height: 20px;
    border-radius: 999px;
    background: #ef4444;
    color: white;
    font-size: 12px;
    font-weight: bold;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid #fff;
    box-shadow: 0 8px 16px rgba(239, 68, 68, 0.32);
}

.chat-badge.show {
    display: flex;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(13, 107, 96, 0.42);
    }
    70% {
        box-shadow: 0 0 0 15px rgba(13, 107, 96, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(13, 107, 96, 0);
    }
}

@keyframes chatHalo {
    0% {
        opacity: 0.72;
        transform: scale(0.86);
    }
    70% {
        opacity: 0;
        transform: scale(1.45);
    }
    100% {
        opacity: 0;
        transform: scale(1.45);
    }
}

.chat-button.has-notification {
    animation: pulse 2s infinite;
}

.chat-button.has-notification .chat-icon-svg {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px) rotate(-5deg); }
    50% { transform: translateX(3px) rotate(5deg); }
    75% { transform: translateX(-3px) rotate(-5deg); }
}

.chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(8, 30, 27, 0.44);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.chat-overlay.show {
    opacity: 1;
    visibility: visible;
}

.chat-window {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100vh;
    height: 100dvh;
    background: #ffffff;
    border: 1px solid #dfe5e2;
    display: flex;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-window.show {
    transform: translateY(0);
}

.chat-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, #083c37 0%, #0d6b60 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    padding-top: max(16px, env(safe-area-inset-top));
}

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

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2ed573;
    flex-shrink: 0;
}

.status-dot.offline {
    background: #ff6b6b;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f6f7f8;
    -webkit-overflow-scrolling: touch;
}

.welcome-message {
    text-align: center;
    padding: 20px;
    color: #666;
    font-size: 14px;
}

.message {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}

.message.visitor {
    align-items: flex-end;
}

.message.admin {
    align-items: flex-start;
}

.message-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.visitor .message-bubble {
    background: #0d6b60;
    color: white;
    border-bottom-right-radius: 3px;
}

.message.admin .message-bubble {
    background: white;
    color: #17201d;
    border: 1px solid #dfe5e2;
    border-bottom-left-radius: 3px;
    box-shadow: 0 8px 18px rgba(17, 32, 29, 0.05);
}

.message-time {
    font-size: 11px;
    color: #8c9692;
    margin-top: 4px;
    padding: 0 4px;
}

.chat-input-area {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #dfe5e2;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
    position: relative;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

#message-input {
    flex: 1;
    border: 1px solid #dfe5e2;
    border-radius: 8px;
    padding: 12px 18px;
    font-size: 16px;
    resize: none;
    outline: none;
    max-height: 100px;
    line-height: 1.4;
    font-family: inherit;
}

#message-input:focus {
    border-color: #0d6b60;
    box-shadow: 0 0 0 3px rgba(13, 107, 96, 0.11);
}

.send-btn {
    padding: 12px 24px;
    background: #0d6b60;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.send-btn:hover {
    opacity: 1;
    background: #083c37;
}

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

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-tool-btn {
    width: 42px;
    height: 42px;
    border: 1px solid #dfe5e2;
    border-radius: 8px;
    background: #f6f7f8;
    color: #17201d;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    cursor: pointer;
    font-size: 17px;
}

.chat-tool-btn:hover {
    background: #eef2f0;
}

.emoji-panel {
    position: absolute;
    left: 16px;
    bottom: calc(100% + 8px);
    display: grid;
    grid-template-columns: repeat(5, 34px);
    gap: 6px;
    padding: 10px;
    border: 1px solid #dfe5e2;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 14px 34px rgba(17, 32, 29, 0.12);
    z-index: 2;
}

.emoji-panel[hidden] {
    display: none;
}

.emoji-option {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 20px;
    cursor: pointer;
}

.emoji-option:hover {
    background: #f1f4f3;
}

.message-bubble.image-bubble {
    padding: 6px;
    background: transparent;
    border: 0;
    box-shadow: none;
}

.chat-image-link {
    display: block;
    line-height: 0;
}

.chat-image {
    display: block;
    max-width: min(240px, 100%);
    max-height: 220px;
    border-radius: 8px;
    border: 1px solid #dfe5e2;
    object-fit: contain;
    background: #fff;
}

.chat-text-link {
    color: #0d6b60;
    font-weight: 800;
    text-decoration: underline;
    text-underline-offset: 2px;
    overflow-wrap: anywhere;
}

.message.visitor .chat-text-link {
    color: #ffffff;
}

.offline-notice {
    padding: 12px 16px;
    background: rgba(184, 138, 46, 0.12);
    color: #7a581d;
    font-size: 13px;
    text-align: center;
    flex-shrink: 0;
}

.offline-notice.hidden {
    display: none;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 8px;
    border-bottom-left-radius: 3px;
    border: 1px solid #dfe5e2;
    box-shadow: 0 8px 18px rgba(17, 32, 29, 0.05);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #0d6b60;
    animation: typing 1.4s infinite ease-in-out;
}

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

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-4px);
    }
}

@media (min-width: 480px) {
    .chat-button {
        width: 58px;
        height: 58px;
        bottom: 48px;
        right: 24px;
    }

    .chat-icon-svg {
        font-size: 28px;
    }

    .chat-overlay {
        display: block;
    }

    .chat-window {
        position: fixed;
        bottom: 96px;
        right: 24px;
        left: auto;
        width: 360px;
        height: 520px;
        max-height: calc(100vh - 120px);
        border-radius: 8px;
        box-shadow: 0 18px 44px rgba(17, 32, 29, 0.12);
        transform: translateY(20px) scale(0.95);
        opacity: 0;
    }

    .chat-window.show {
        transform: translateY(0) scale(1);
        opacity: 1;
    }

    .chat-header {
        border-radius: 8px 8px 0 0;
        padding-top: 16px;
    }

    .chat-messages {
        border-radius: 0;
    }

    .chat-input-area {
        border-radius: 0 0 8px 8px;
        padding-bottom: 12px;
    }
}

@media (min-width: 768px) {
    .chat-button {
        bottom: 54px;
        right: 30px;
    }

    .chat-window {
        right: 30px;
        bottom: 100px;
    }
}
