:root {
    --primary-color: #007bff;
    --primary-hover: #0056b3;
    --background-color: #f8f9fa;
    --modal-bg-color: #ffffff;
    --border-color: #dee2e6;
    --user-bubble-color: #007bff;
    --user-text-color: #ffffff;
    --operator-bubble-color: #e9ecef;
    --operator-text-color: #212529;
    --shadow-light: 0 4px 12px rgba(0, 0, 0, 0.15);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.container h1 {
    font-size: clamp(24px, 5vw, 32px);
}

/* Chat Button */
.chat-button {
    position: fixed;
    bottom: max(20px, var(--safe-area-bottom));
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: var(--user-text-color);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 123, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.chat-button:hover,
.chat-button:focus {
    background-color: var(--primary-hover);
    transform: scale(1.05);
}

.chat-button:active {
    transform: scale(0.95);
}

.chat-button:focus-visible {
    outline: 3px solid rgba(0, 123, 255, 0.5);
    outline-offset: 2px;
}

.chat-button-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background-color: #dc3545;
    color: var(--user-text-color);
    font-size: 11px;
    font-weight: bold;
    border-radius: 50%;
    padding: 2px 6px;
    min-width: 20px;
    text-align: center;
    line-height: 1.2;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Chat Modal */
.chat-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1001;
    background-color: rgba(0, 0, 0, 0);
    transition: background-color 0.3s ease;
}

.chat-modal.active {
    display: block;
    background-color: rgba(0, 0, 0, 0.4);
}

.chat-container {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 40px);
    background-color: var(--modal-bg-color);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-modal.active .chat-container {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* Mobile Styles */
@media (max-width: 576px) {
    .chat-button {
        width: 60px;
        height: 60px;
        bottom: max(16px, var(--safe-area-bottom));
        right: 16px;
    }

    .chat-container {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }

    .chat-modal.active {
        background-color: var(--background-color);
    }
}

/* Chat Header */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: var(--user-text-color);
    border-radius: 16px 16px 0 0;
    min-height: 70px;
}

@media (max-width: 576px) {
    .chat-header {
        border-radius: 0;
        padding-top: max(16px, env(safe-area-inset-top, 0px));
    }
}

.chat-header-info h3 {
    margin: 0 0 4px 0;
    font-size: 18px;
    font-weight: 600;
}

.chat-status {
    font-size: 13px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #4caf50;
    animation: pulse 2s infinite;
}

.chat-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: var(--user-text-color);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.chat-close:hover,
.chat-close:focus {
    background: rgba(255, 255, 255, 0.3);
}

.chat-close:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* Verification Form */
.chat-verification {
    padding: 24px 20px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
}

.verification-content {
    width: 100%;
    max-width: 320px;
}

.verification-content h4 {
    margin: 0 0 8px 0;
    font-size: 22px;
    color: #212529;
}

.verification-content > p {
    margin: 0 0 24px 0;
    color: #6c757d;
    font-size: 15px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #495057;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.2s;
    -webkit-appearance: none;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.error-message {
    display: block;
    color: #dc3545;
    font-size: 13px;
    margin-top: 6px;
    min-height: 18px;
}

.btn-primary {
    width: 100%;
    padding: 14px;
    background-color: var(--primary-color);
    color: var(--user-text-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary:focus-visible {
    outline: 3px solid rgba(0, 123, 255, 0.5);
    outline-offset: 2px;
}

/* Chat Area */
.chat-area {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    overflow: hidden;
}

.chat-messages {
    flex-grow: 1;
    padding: 16px;
    overflow-y: auto;
    overflow-x: hidden;
    background-color: var(--background-color);
    -webkit-overflow-scrolling: touch;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

/* Messages */
.message-bubble {
    display: flex;
    margin-bottom: 12px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-content {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 18px;
    line-height: 1.5;
    font-size: 15px;
    word-wrap: break-word;
    word-break: break-word;
}

.message-user {
    justify-content: flex-end;
}

.message-user .message-content {
    background-color: var(--user-bubble-color);
    color: var(--user-text-color);
    border-bottom-right-radius: 4px;
}

.message-operator {
    justify-content: flex-start;
}

.message-operator .message-content {
    background-color: var(--operator-bubble-color);
    color: var(--operator-text-color);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    display: block;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    font-size: 13px;
    color: #6c757d;
}

.typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #6c757d;
    margin: 0 2px;
    animation: bounce 1.4s infinite ease-in-out;
}

.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); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* Chat Input */
.chat-input {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 12px 16px;
    padding-bottom: max(12px, var(--safe-area-bottom));
    border-top: 1px solid var(--border-color);
    background-color: var(--modal-bg-color);
}

.chat-input textarea {
    flex-grow: 1;
    resize: none;
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    border-radius: 20px;
    font-size: 15px;
    font-family: inherit;
    max-height: 120px;
    min-height: 40px;
    line-height: 1.4;
    transition: border-color 0.2s;
    -webkit-appearance: none;
}

.chat-input textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn-send {
    width: 40px;
    height: 40px;
    min-width: 40px;
    background-color: var(--primary-color);
    color: var(--user-text-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.btn-send:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: scale(1.05);
}

.btn-send:active:not(:disabled) {
    transform: scale(0.95);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-send:focus-visible {
    outline: 3px solid rgba(0, 123, 255, 0.5);
    outline-offset: 2px;
}

/* System Message */
.system-message {
    text-align: center;
    padding: 12px;
    color: #6c757d;
    font-size: 13px;
    line-height: 1.4;
}

/* Loading State */
.loading-dots::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible for keyboard navigation */
:focus:not(:focus-visible) {
    outline: none;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .chat-button,
    .btn-primary,
    .btn-send {
        border: 2px solid currentColor;
    }
}