/* ==========================================================
   AI Chat – Floating Widget Styles
   ========================================================== */

/* ---- Launcher button ---- */
.aichat-launcher {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 99999;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0088cc, #00bfff);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 136, 204, 0.4);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.aichat-launcher:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(0, 136, 204, 0.6);
}

/* Unread badge */
.aichat-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e74c3c;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* ---- Chat window ---- */
.aichat-window {
    position: fixed;
    bottom: 90px;
    left: 20px;
    width: 380px;
    height: 520px;
    z-index: 99999;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: aichat-slide-up 0.3s ease;
}

@keyframes aichat-slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---- Header ---- */
.aichat-header {
    background: linear-gradient(135deg, #0088cc, #00bfff);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.aichat-header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}
.aichat-header-title {
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.aichat-header-user {
    font-size: 12px;
    opacity: 0.85;
}
.aichat-badge-admin {
    background: rgba(255,255,255,0.25);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px;
    margin-left: 4px;
}
.aichat-header-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.aichat-header-btn:hover {
    background: rgba(255,255,255,0.35);
}

/* ---- Messages area ---- */
.aichat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
    background: #f7f8fa;
}
.aichat-messages::-webkit-scrollbar { width: 4px; }
.aichat-messages::-webkit-scrollbar-track { background: transparent; }
.aichat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

/* Loading */
.aichat-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 0;
    color: #999;
    font-size: 13px;
    gap: 8px;
}
.aichat-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #e0e0e0;
    border-top-color: #0088cc;
    border-radius: 50%;
    animation: aichat-spin 0.8s linear infinite;
}
@keyframes aichat-spin {
    to { transform: rotate(360deg); }
}

/* No messages */
.aichat-no-messages {
    text-align: center;
    color: #aaa;
    font-size: 13px;
    padding: 40px 0;
}

/* ---- Message bubbles ---- */
.aichat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    position: relative;
    word-wrap: break-word;
    animation: aichat-fade-in 0.3s ease;
}

@keyframes aichat-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* User (right) */
.aichat-msg-web,
.aichat-msg-guest {
    background: #e8f4fd;
    color: #1a1a1a;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Owner (right, green) */
.aichat-msg-owner,
.aichat-msg-telegram {
    background: #d4f8e8;
    color: #1a1a1a;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Admin (right, purple) */
.aichat-msg-admin {
    background: #f0e6ff;
    color: #1a1a1a;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Bot (left) */
.aichat-msg-bot {
    background: #fff;
    color: #1a1a1a;
    align-self: flex-start;
    border: 1px solid #e8e8e8;
    border-bottom-left-radius: 4px;
}

/* Other user messages (left) */
.aichat-msg-other {
    background: #fff;
    color: #1a1a1a;
    align-self: flex-start;
    border: 1px solid #e8e8e8;
    border-bottom-left-radius: 4px;
}

/* Message header (name + time) */
.aichat-msg-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.aichat-msg-name {
    font-size: 12px;
    font-weight: 600;
    color: #0088cc;
}
.aichat-msg-bot .aichat-msg-name { color: #00b894; }
.aichat-msg-owner .aichat-msg-name,
.aichat-msg-telegram .aichat-msg-name { color: #00a86b; }
.aichat-msg-admin .aichat-msg-name { color: #8b5cf6; }

.aichat-msg-time {
    font-size: 10px;
    color: #999;
}
.aichat-msg-text {
    font-size: 14px;
    line-height: 1.5;
}

/* Anonymous badge */
.aichat-anonim-badge {
    font-size: 11px;
    color: #999;
    font-style: italic;
    margin-left: 4px;
}

/* ---- Reply quote ---- */
.aichat-reply-quote {
    border-left: 3px solid #0088cc;
    padding: 4px 8px;
    margin-bottom: 6px;
    font-size: 12px;
    color: #666;
    background: rgba(0, 136, 204, 0.06);
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    max-height: 40px;
    overflow: hidden;
}
.aichat-reply-quote strong {
    color: #0088cc;
}

/* ---- Message actions (hover) ---- */
.aichat-msg-actions {
    position: absolute;
    top: -8px;
    right: 6px;
    display: none;
    gap: 2px;
}
.aichat-msg-bot .aichat-msg-actions,
.aichat-msg-other .aichat-msg-actions {
    right: auto;
    left: 6px;
}
.aichat-msg:hover .aichat-msg-actions {
    display: flex;
}
.aichat-msg-actions button {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid #e0e0e0;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    color: #666;
}
.aichat-msg-actions button:hover {
    background: #f0f0f0;
}
.aichat-msg-actions .aichat-btn-delete {
    color: #e74c3c;
}

/* Highlight on reply click */
.aichat-highlight {
    animation: aichat-highlight-pulse 1.5s ease;
}
@keyframes aichat-highlight-pulse {
    0%, 100% { box-shadow: none; }
    50% { box-shadow: 0 0 0 3px rgba(0, 136, 204, 0.3); }
}

/* ---- Typing indicator ---- */
.aichat-typing {
    align-self: flex-start;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid #e8e8e8;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #999;
}
.aichat-typing-dots {
    display: inline-flex;
    gap: 3px;
}
.aichat-typing-dots span {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    animation: aichat-dot-pulse 1.4s infinite both;
}
.aichat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.aichat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aichat-dot-pulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* ---- Footer / Input area ---- */
.aichat-footer {
    border-top: 1px solid #eee;
    background: #fff;
    padding: 10px 12px;
    flex-shrink: 0;
}

/* Reply preview */
.aichat-reply-preview {
    background: #f0f7ff;
    border-left: 3px solid #0088cc;
    padding: 6px 10px;
    margin-bottom: 8px;
    border-radius: 0 6px 6px 0;
    font-size: 12px;
    color: #555;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.aichat-cancel-reply {
    background: none;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 16px;
    padding: 0 4px;
}

/* Input row */
.aichat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.aichat-input-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: flex-end;
}
.aichat-input {
    width: 100%;
    min-height: 38px;
    max-height: 100px;
    padding: 8px 40px 8px 12px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 14px;
    resize: none;
    outline: none;
    font-family: inherit;
    line-height: 1.4;
    transition: border-color 0.2s;
}
.aichat-input:focus {
    border-color: #0088cc;
}

/* Emoji toggle */
.aichat-emoji-toggle {
    position: absolute;
    right: 8px;
    bottom: 6px;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
    padding: 0;
    line-height: 1;
}
.aichat-emoji-toggle:hover {
    opacity: 1;
}

/* Send button */
.aichat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #0088cc;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s;
}
.aichat-send-btn:hover {
    background: #006fa8;
    transform: scale(1.05);
}
.aichat-send-btn:active {
    transform: scale(0.95);
}

/* Emoji panel */
.aichat-emoji-panel {
    position: absolute;
    bottom: 50px;
    right: 0;
    width: 320px;
    max-height: 280px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 10px;
    z-index: 100000;
    overflow: hidden;
    animation: aichat-fade-in 0.2s ease;
}
.aichat-emoji-scroll {
    max-height: 260px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
}
.aichat-emoji-item {
    cursor: pointer;
    font-size: 24px;
    padding: 4px;
    border-radius: 8px;
    text-align: center;
    transition: background 0.15s, transform 0.15s;
    line-height: 1.2;
}
.aichat-emoji-item:hover {
    background: #f0f0f0;
    transform: scale(1.15);
}

/* Controls row */
.aichat-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    gap: 8px;
    flex-wrap: wrap;
}
.aichat-anonim-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #888;
    cursor: pointer;
    white-space: nowrap;
}
.aichat-anonim-label input[type="checkbox"] {
    width: 14px;
    height: 14px;
    margin: 0;
}

/* Telegram link */
.aichat-telegram-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #0088cc;
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.2s;
}
.aichat-telegram-link:hover {
    color: #006fa8;
    text-decoration: underline;
}

/* Login notice */
.aichat-login-notice {
    text-align: center;
    font-size: 13px;
    color: #666;
    padding: 8px 0;
}
.aichat-login-notice a {
    color: #0088cc;
    text-decoration: underline;
}

/* Loading history */
.aichat-loading-history {
    text-align: center;
    padding: 10px;
    font-size: 12px;
    color: #999;
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
    .aichat-window {
        left: 8px;
        right: 8px;
        bottom: 80px;
        width: auto;
        height: calc(100vh - 100px);
        max-height: 600px;
        border-radius: 12px;
    }
    .aichat-launcher {
        left: 12px;
        bottom: 12px;
        width: 52px;
        height: 52px;
    }
    .aichat-msg {
        max-width: 90%;
    }
    .aichat-emoji-panel {
        width: 280px;
    }
}

.aichat-header-user-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.aichat-ai-toggle-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.12);
    padding: 2px 6px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: background 0.2s;
}
.aichat-ai-toggle-wrap:hover {
    background: rgba(255, 255, 255, 0.2);
}
.aichat-ai-label {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.9);
}
.aichat-switch {
    position: relative;
    display: inline-block;
    width: 26px;
    height: 14px;
}
.aichat-switch input { opacity: 0; width: 0; height: 0; }
.aichat-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255, 255, 255, 0.3);
    transition: .3s;
    border-radius: 14px;
}
.aichat-slider:before {
    position: absolute;
    content: "";
    height: 10px;
    width: 10px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
input:checked + .aichat-slider { background-color: #2ecc71; }
input:checked + .aichat-slider:before { transform: translateX(12px); }

/* Status indicator dot (Restored) */
.aichat-status-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: 8px;
    flex-shrink: 0;
}
.aichat-status-indicator.online,
.aichat-status-dot.online {
    background-color: #2ecc71;
    box-shadow: 0 0 8px #2ecc71;
}
.aichat-status-indicator.offline,
.aichat-status-dot.offline {
    background-color: #bdc3c7;
}
.aichat-status-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin: 0 4px;
}

/* Greeting Bubble */
.aichat-bubble {
    position: fixed;
    bottom: 85px;
    left: 20px;
    background: #fff;
    padding: 10px 14px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    font-size: 13px;
    color: #333;
    max-width: 200px;
    z-index: 100000;
    cursor: pointer;
    animation: aichat-fade-in 0.3s ease;
}
.aichat-bubble:after {
    content: "";
    position: absolute;
    bottom: -8px;
    left: 20px;
    border-width: 8px 8px 0;
    border-style: solid;
    border-color: #fff transparent;
}
.aichat-bubble-close {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: #e74c3c;
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
@media (max-width: 480px) {
    .aichat-bubble {
        left: 12px;
        bottom: 75px;
        max-width: 180px;
    }
}
