/* ============================================================
   AI-наставник LazyCommission — виджет чата
   Desktop: правая панель | Mobile: bottom-sheet
   ============================================================ */

#ai-mentor-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1a5c3a, #2d8a52);
    border: 3px solid #fff;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    cursor: pointer;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    transition: transform 0.2s;
}
#ai-mentor-fab:hover { transform: scale(1.08); }
#ai-mentor-fab img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.ai-header .ai-avatar img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: #fff; display: block; }
#ai-mentor-fab .ai-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e74c3c;
    color: #fff;
    font-size: 11px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

#ai-mentor-panel {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 140px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.25);
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
}
#ai-mentor-panel.open { display: flex; }

.ai-header {
    background: linear-gradient(135deg, #1a5c3a, #2d8a52);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.ai-header .ai-avatar { font-size: 36px; }
.ai-header .ai-title { flex: 1; }
.ai-header .ai-title b { display: block; font-size: 16px; }
.ai-header .ai-title span { font-size: 12px; opacity: 0.85; }
.ai-header button {
    background: rgba(255,255,255,0.2);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
}

.ai-conv-list {
    padding: 8px;
    border-bottom: 1px solid #eee;
    max-height: 120px;
    overflow-y: auto;
    display: none;
}
.ai-conv-list.show { display: block; }
.ai-conv-item {
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-conv-item:hover { background: #f0f7f2; }
.ai-conv-item.active { background: #e0f0e6; font-weight: bold; }

#ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fafafa;
}

.ai-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}
.ai-msg.user {
    align-self: flex-end;
    background: #1a5c3a;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ai-msg.assistant {
    align-self: flex-start;
    background: #fff;
    color: #21332a;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
}
/* Кабинет — тёмная тема: текст в белой панели виджета не должен наследовать светлый цвет страницы */
#ai-mentor-panel .ai-conv-item,
#ai-mentor-panel .ai-memory-panel,
#ai-mentor-panel .ai-tools-panel { color: #21332a; }
.ai-header .ai-title span { white-space: nowrap; }
.ai-msg .ai-sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed #ddd;
    font-size: 12px;
    color: #666;
}
.ai-msg .ai-feedback {
    margin-top: 6px;
    display: flex;
    gap: 8px;
}
.ai-msg .ai-feedback button {
    background: none;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 2px 8px;
    cursor: pointer;
    font-size: 14px;
}
.ai-msg .ai-feedback button.active { background: #e0f0e6; border-color: #1a5c3a; }

.ai-typing {
    align-self: flex-start;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 14px;
    font-size: 14px;
    color: #999;
}

.ai-input-area {
    padding: 12px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    background: #fff;
}
.ai-input-area input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
}
.ai-input-area input:focus { border-color: #1a5c3a; }
.ai-input-area button {
    background: #1a5c3a;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    cursor: pointer;
    font-size: 18px;
}
.ai-input-area button:disabled { opacity: 0.5; }

.ai-limit-warning {
    padding: 10px 16px;
    background: #fff3cd;
    color: #856404;
    font-size: 13px;
    text-align: center;
}

/* Mobile: bottom-sheet */
@media (max-width: 480px) {
    #ai-mentor-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 85vh;
        max-height: 85vh;
        border-radius: 20px 20px 0 0;
    }
    #ai-mentor-fab {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
}
