@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
    --chat-primary: #4F46E5;
    --chat-gradient: linear-gradient(135deg, var(--chat-primary) 0%, #4338ca 100%);
    --chat-bg: #ffffff;
    --chat-gray: #f3f4f6;
    --chat-text: #1f2937;
    --chat-user-bg: var(--chat-primary);
    --chat-user-text: #ffffff;
    --chat-admin-bg: #f3f4f6;
    --chat-admin-text: #1f2937;
    --chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

/* --- Container & Launcher --- */
#dlab-chat-widget {
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 10000;
    font-family: 'Inter', sans-serif;
    line-height: 1.5;
}

.dlab-chat-launcher {
    width: 60px;
    height: 60px;
    background: var(--chat-gradient);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    z-index: 10002;
}

.dlab-chat-launcher:hover {
    transform: scale(1.05);
}

.dlab-chat-launcher.active {
    transform: rotate(90deg);
    box-shadow: none;
}

.dlab-chat-launcher.active svg {
    display: none;
}

.dlab-chat-launcher::after {
    content: '✕';
    position: absolute;
    color: white;
    font-size: 24px;
    font-weight: 300;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s;
}

.dlab-chat-launcher.active::after {
    opacity: 1;
    transform: scale(1);
}

.dlab-chat-launcher svg {
    width: 32px;
    height: 32px;
    fill: #ffffff !important;
    stroke: #ffffff !important;
    transition: transform 0.3s;
}

.dlab-chat-launcher svg path {
    fill: #ffffff !important;
}

.dlab-chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ef4444;
    color: white;
    border: 2px solid #fff;
    border-radius: 50%;
    min-width: 22px;
    height: 22px;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s;
    z-index: 2;
}
.dlab-chat-badge.show { opacity: 1; transform: scale(1); }

/* --- Chat Window --- */
.dlab-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 360px;
    height: 550px;
    max-height: calc(100vh - 120px);
    background: var(--chat-bg);
    border-radius: 16px;
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 10001;
}

.dlab-chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

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

.dlab-chat-title h4 { margin: 0; font-size: 16px; font-weight: 600; line-height: 1.2; }

/* Статуси */
.dlab-status-wrapper {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}
.dlab-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.2);
}
.dlab-status-dot.online { background-color: #34d399 !important; box-shadow: 0 0 5px #34d399; }
.dlab-status-dot.offline { background-color: #ef4444 !important; }

/* Кнопки в хедері */
.dlab-header-btn, .dlab-header-actions {
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    color: white;
}
.dlab-header-btn:hover, .dlab-header-actions:hover { background: rgba(255,255,255,0.25); }

/* --- Body --- */
.dlab-chat-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Screens */
.dlab-screen { display: none; height: 100%; flex-direction: column; }
.dlab-screen.active { display: flex; }

/* Welcome Form */
.dlab-welcome-text { margin-bottom: 25px; text-align: center; margin-top: auto; margin-bottom: auto; }
.dlab-welcome-text h3 { margin: 0 0 10px; color: var(--chat-text); font-size: 20px; }
.dlab-welcome-text p { color: #6b7280; font-size: 14px; margin: 0; }

.dlab-form-group { margin-bottom: 12px; position: relative; }
.dlab-input {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    font-size: 14px;
    transition: 0.2s;
    outline: none;
    box-sizing: border-box;
    background: #f9fafb;
}
.dlab-input:focus { border-color: var(--chat-primary); background: #fff; }
.dlab-textarea { resize: none; font-family: inherit; height: 80px; }

.dlab-btn {
    width: 100%;
    padding: 12px;
    background: var(--chat-primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    font-size: 14px;
    margin-top: 10px;
}
.dlab-btn:hover { filter: brightness(110%); }
.dlab-btn:disabled { background: #9ca3af; cursor: not-allowed; }

/* Messages */
.dlab-messages-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 10px;
}

.dlab-msg-wrapper { display: flex; flex-direction: column; max-width: 85%; }
.dlab-msg-wrapper.user { align-self: flex-end; align-items: flex-end; }
.dlab-msg-wrapper.admin { align-self: flex-start; align-items: flex-start; }
.dlab-msg-wrapper.system { align-self: center; max-width: 100%; margin: 15px 0; }

.dlab-msg {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.dlab-msg-wrapper.user .dlab-msg {
    background: var(--chat-user-bg);
    color: var(--chat-user-text);
    border-bottom-right-radius: 2px;
}
.dlab-msg-wrapper.admin .dlab-msg {
    background: var(--chat-admin-bg);
    color: var(--chat-admin-text);
    border-bottom-left-radius: 2px;
}
.dlab-msg-wrapper.system .dlab-msg {
    background: #f3f4f6;
    font-size: 12px;
    color: #6b7280;
    padding: 6px 12px;
    text-align: center;
    border-radius: 20px;
    box-shadow: none;
}

.dlab-msg-meta {
    font-size: 10px;
    margin-top: 4px;
    opacity: 0.7;
    display: flex;
    align-items: center;
    gap: 4px;
}
.dlab-msg-wrapper.user .dlab-msg-meta { justify-content: flex-end; color: rgba(255,255,255,0.9); }
.dlab-msg-img { max-width: 100%; border-radius: 8px; margin-top: 5px; cursor: pointer; }

/* --- Footer (Input) --- */
.dlab-chat-footer {
    padding: 10px 15px;
    border-top: 1px solid #f3f4f6;
    background: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.dlab-file-btn {
    cursor: pointer;
    color: #9ca3af;
    padding: 8px;
    transition: 0.2s;
    border-radius: 50%;
}
.dlab-file-btn:hover { background: #f3f4f6; color: var(--chat-primary); }

.dlab-chat-footer input {
    flex: 1;
    border: 1px solid #e5e7eb;
    background: #f9fafb;
    padding: 10px 15px;
    border-radius: 20px;
    outline: none;
    font-family: inherit;
    font-size: 14px;
}
.dlab-chat-footer input:focus { background: #fff; border-color: var(--chat-primary); }

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

/* --- MOBILE OPTIMIZATION --- */
@media (max-width: 480px) {
    #dlab-chat-widget {
        bottom: 0;
        right: 0;
        width: 100%;
        height: 0;
        z-index: 99999;
    }

    .dlab-chat-launcher {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    }

    .dlab-chat-window {
        position: fixed;
        bottom: 0;
        right: 0;
        width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 0;
        transform: translateY(100%);
        opacity: 1;
    }

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

    .dlab-chat-header {
        padding: 12px 15px;
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .dlab-chat-footer {
        padding: 10px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .dlab-header-actions {
        display: flex;
    }
}