/**
 * @file
 * Telegram Chat Widget CSS.
 *
 * Modern, animated live chat widget for anonymous visitors.
 */

/* CSS Custom Properties */
:root {
    --tg-chat-primary: #0077B5;
    --tg-chat-primary-dark: #005a8c;
    --tg-chat-bg: #ffffff;
    --tg-chat-text: #1a1a1a;
    --tg-chat-text-light: #666666;
    --tg-chat-border: #e0e0e0;
    --tg-chat-message-bg: #f0f2f5;
    --tg-chat-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

/* ==========================================================================
   Widget Container
   ========================================================================== */

.telegram-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
}

.telegram-chat-widget.position-left {
    right: auto;
    left: 20px;
}

.telegram-chat-widget.position-left .tg-chat-window {
    right: auto;
    left: 0;
}

/* ==========================================================================
   Chat Launcher Button
   ========================================================================== */

.tg-chat-launcher {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--tg-chat-primary) 0%, var(--tg-chat-primary-dark) 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 119, 181, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: #fff;
    position: relative;
    outline: none;
}

.tg-chat-launcher:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0, 119, 181, 0.45);
}

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

.tg-chat-launcher svg {
    width: 28px;
    height: 28px;
    transition: transform 0.3s ease;
}

.tg-chat-launcher .unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: #e74c3c;
    border-radius: 11px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(231, 76, 60, 0.4);
}

/* ==========================================================================
   Chat Window
   ========================================================================== */

.tg-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 520px;
    background: var(--tg-chat-bg);
    border-radius: 16px;
    box-shadow: var(--tg-chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: tgSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes tgSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==========================================================================
   Chat Header
   ========================================================================== */

.tg-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--tg-chat-primary) 0%, var(--tg-chat-primary-dark) 100%);
    color: #fff;
}

.tg-chat-header .header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.tg-chat-header .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.tg-chat-header .avatar svg {
    width: 24px;
    height: 24px;
}

.tg-chat-header .header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tg-chat-header .title {
    font-weight: 600;
    font-size: 16px;
}

.tg-chat-header .status {
    font-size: 12px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tg-chat-header .status.online::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    display: inline-block;
}

.tg-chat-header .close-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: background 0.2s;
}

.tg-chat-header .close-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.tg-chat-header .close-btn svg {
    width: 20px;
    height: 20px;
}

/* ==========================================================================
   Visitor Info Form
   ========================================================================== */

.tg-visitor-form {
    flex: 1;
    padding: 24px;
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
}

.tg-visitor-form .form-header {
    text-align: center;
    margin-bottom: 24px;
}

.tg-visitor-form .form-header h4 {
    margin: 0 0 8px;
    font-size: 18px;
    font-weight: 600;
    color: var(--tg-chat-text);
}

.tg-visitor-form .form-header p {
    margin: 0;
    color: var(--tg-chat-text-light);
    font-size: 14px;
}

.tg-visitor-form .form-group {
    margin-bottom: 16px;
}

.tg-visitor-form label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--tg-chat-text);
}

.tg-visitor-form input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--tg-chat-border);
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    box-sizing: border-box;
}

.tg-visitor-form input:focus {
    border-color: var(--tg-chat-primary);
    box-shadow: 0 0 0 3px rgba(0, 119, 181, 0.1);
}

.tg-visitor-form .start-chat-btn {
    width: 100%;
    padding: 14px;
    background: var(--tg-chat-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    margin-top: 8px;
}

.tg-visitor-form .start-chat-btn:hover {
    background: var(--tg-chat-primary-dark);
}

.tg-visitor-form .start-chat-btn:active {
    transform: scale(0.98);
}

/* ==========================================================================
   Chat Body (Messages Area)
   ========================================================================== */

.tg-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    background: #fff;
}

.messages-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ==========================================================================
   Messages
   ========================================================================== */

.tg-chat-body .message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    background: var(--tg-chat-message-bg);
    color: var(--tg-chat-text);
    align-self: flex-start;
    animation: tgMessageIn 0.25s ease;
    position: relative;
}

@keyframes tgMessageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tg-chat-body .message.own {
    background: var(--tg-chat-primary);
    color: #fff;
    align-self: flex-end;
}

.tg-chat-body .message-sender {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--tg-chat-primary);
}

.tg-chat-body .message.own .message-sender {
    color: rgba(255, 255, 255, 0.8);
}

.tg-chat-body .message-content {
    font-size: 14px;
    line-height: 1.45;
    word-break: break-word;
    white-space: pre-wrap;
}

.tg-chat-body .message-time {
    font-size: 10px;
    color: rgba(0, 0, 0, 0.45);
    margin-top: 6px;
    text-align: right;
}

.tg-chat-body .message.own .message-time {
    color: rgba(255, 255, 255, 0.7);
}

/* System Messages */
.tg-chat-body .message.system {
    background: #fff3cd;
    color: #856404;
    align-self: center;
    font-size: 13px;
    text-align: center;
    max-width: 90%;
    border-radius: 8px;
}

.tg-chat-body .message.system.error {
    background: #f8d7da;
    color: #721c24;
}

/* Message Attachments */
.message-attachment {
    margin-top: 8px;
}

.message-attachment img {
    max-width: 200px;
    max-height: 150px;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.message-attachment img:hover {
    opacity: 0.9;
}

.message-attachment.file a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: background 0.2s;
}

.message.own .message-attachment.file a {
    background: rgba(255, 255, 255, 0.2);
}

.message-attachment.file a:hover {
    background: rgba(0, 0, 0, 0.12);
}

.message.own .message-attachment.file a:hover {
    background: rgba(255, 255, 255, 0.3);
}

.message-attachment .file-ext {
    background: #dc3545;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
}

.message-attachment .file-name {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    color: var(--tg-chat-text-light);
    font-size: 13px;
}

.typing-indicator span:not(.typing-text) {
    width: 8px;
    height: 8px;
    background: var(--tg-chat-primary);
    border-radius: 50%;
    animation: tgTyping 1.4s infinite ease-in-out;
}

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

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

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

@keyframes tgTyping {

    0%,
    80%,
    100% {
        transform: scale(0.7);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ==========================================================================
   Chat Input Area
   ========================================================================== */

.tg-chat-input-area {
    border-top: 1px solid var(--tg-chat-border);
    background: #fff;
}

/* File Preview */
.file-preview-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px 0;
}

.file-preview-container:empty {
    display: none;
}

.file-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f5f5f5;
    border: 1px solid var(--tg-chat-border);
    border-radius: 8px;
    padding: 6px 10px;
    max-width: 160px;
}

.file-preview .file-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 4px;
    overflow: hidden;
}

.file-preview .file-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.file-preview .file-icon.file-doc {
    background: #dc3545;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
}

.file-preview .file-name {
    flex: 1;
    font-size: 11px;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-preview .remove-file {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 16px;
    padding: 2px;
    line-height: 1;
}

.file-preview .remove-file:hover {
    color: #dc3545;
}

/* Message Form */
.chat-message-form {
    padding: 12px 16px 16px;
}

.chat-message-form .input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f5f5f5;
    border-radius: 24px;
    padding: 6px 6px 6px 12px;
    transition: background 0.2s;
}

.chat-message-form .input-wrapper:focus-within {
    background: #eee;
}

.chat-message-form .attach-btn {
    background: none;
    border: none;
    color: var(--tg-chat-text-light);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-message-form .attach-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--tg-chat-primary);
}

.chat-message-form .attach-btn svg {
    width: 20px;
    height: 20px;
}

.chat-message-form .message-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 4px;
    font-size: 14px;
    outline: none;
    resize: none;
    min-height: 20px;
    max-height: 100px;
    overflow-y: auto;
    line-height: 1.4;
    font-family: inherit;
}

.chat-message-form .message-input::placeholder {
    color: #999;
}

.chat-message-form .send-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--tg-chat-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-message-form .send-btn:hover {
    background: var(--tg-chat-primary-dark);
    transform: scale(1.05);
}

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

.chat-message-form .send-btn svg {
    width: 18px;
    height: 18px;
    margin-left: 2px;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media (max-width: 480px) {
    .telegram-chat-widget {
        bottom: 16px;
        right: 16px;
    }

    .telegram-chat-widget.position-left {
        left: 16px;
    }

    .tg-chat-window {
        width: calc(100vw - 32px);
        height: calc(100vh - 120px);
        max-height: 600px;
        bottom: 76px;
        right: 0;
        border-radius: 12px;
    }

    .telegram-chat-widget.position-left .tg-chat-window {
        left: 0;
        right: auto;
    }
}

/* ==========================================================================
   Scrollbar Styling
   ========================================================================== */

.tg-chat-body::-webkit-scrollbar {
    width: 6px;
}

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

.tg-chat-body::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 3px;
}

.tg-chat-body::-webkit-scrollbar-thumb:hover {
    background: #b0b0b0;
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .telegram-chat-widget {
        display: none !important;
    }
}