/* =========================================================
   AI-компоненты: ассистент в калькуляторе, чат, фото-анализ, маршрут
   Использует фирменные цвета сайта + покрашен в фирменный синий
   ========================================================= */

/* ===== Общие AI-токены ===== */
:root {
    --ai-purple: #7c5cff;
    --ai-gradient: linear-gradient(135deg, var(--brand-blue) 0%, #7c5cff 100%);
    --ai-glow: 0 0 24px rgba(124, 92, 255, .3);
}

.ai-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: var(--ai-gradient);
    color: #fff;
    border-radius: var(--radius-pill);
    font-size: .82rem;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(124, 92, 255, .25);
}
.ai-badge svg { width: 14px; height: 14px; }
.ai-badge::before {
    content: '';
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #fff;
    animation: ai-pulse 1.4s infinite;
}
@keyframes ai-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .5; transform: scale(.7); }
}

/* ===== Умный калькулятор: AI-блок наверху ===== */
.ai-prompt-box {
    background: linear-gradient(135deg, #f8f7ff 0%, #f0f7ff 100%);
    border: 1.5px solid rgba(124, 92, 255, .2);
    border-radius: var(--radius-md);
    padding: 22px;
    margin-bottom: 20px;
    position: relative;
    overflow: hidden;
}
.ai-prompt-box::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%;
    width: 200%; height: 200%;
    background: radial-gradient(circle, rgba(124, 92, 255, .08) 0, transparent 50%);
    animation: ai-orbit 8s linear infinite;
    pointer-events: none;
}
@keyframes ai-orbit {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.ai-prompt-box > * { position: relative; z-index: 1; }
.ai-prompt-head {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 14px;
    font-weight: 600;
    color: var(--text);
}
.ai-prompt-head svg { width: 22px; height: 22px; color: var(--ai-purple); }
.ai-prompt-textarea {
    width: 100%;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 56px 14px 16px;
    font-size: 1rem;
    font-family: inherit;
    color: var(--text);
    background: #fff;
    resize: vertical;
    min-height: 70px;
    transition: border-color .2s ease, box-shadow .2s ease;
}
.ai-prompt-textarea:focus {
    outline: none;
    border-color: var(--ai-purple);
    box-shadow: 0 0 0 4px rgba(124, 92, 255, .12);
}
.ai-prompt-wrap { position: relative; }
.ai-mic-btn {
    position: absolute;
    right: 12px; top: 12px;
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--ai-gradient);
    color: #fff;
    border: none;
    display: grid; place-items: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(124, 92, 255, .3);
    transition: transform .15s ease;
}
.ai-mic-btn:hover { transform: scale(1.08); }
.ai-mic-btn.listening { animation: mic-pulse 1s infinite; background: var(--danger); }
.ai-mic-btn svg { width: 18px; height: 18px; }
@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(230, 56, 106, .55); }
    50% { box-shadow: 0 0 0 12px rgba(230, 56, 106, 0); }
}

.ai-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}
.ai-suggestion {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 6px 14px;
    font-size: .82rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all .15s ease;
}
.ai-suggestion:hover {
    border-color: var(--ai-purple);
    color: var(--ai-purple);
    background: rgba(124, 92, 255, .04);
}

/* AI распознал — показываем результат */
.ai-parsed {
    margin-top: 14px;
    padding: 14px 16px;
    background: #fff;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--ai-purple);
    font-size: .9rem;
    color: var(--text);
    display: none;
}
.ai-parsed.show { display: block; animation: slide-in .3s ease; }
.ai-parsed-head {
    display: flex; align-items: center; gap: 8px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--ai-purple);
}
.ai-parsed-head svg { width: 16px; height: 16px; }
.ai-parsed-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 14px;
    font-size: .88rem;
}
.ai-parsed-list b { color: var(--text); }

@keyframes slide-in {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== AI-загрузка фото груза ===== */
.ai-photo-zone {
    border: 2px dashed var(--ai-purple);
    border-radius: var(--radius-md);
    padding: 32px 20px;
    text-align: center;
    background: rgba(124, 92, 255, .03);
    cursor: pointer;
    transition: all .2s ease;
    position: relative;
}
.ai-photo-zone:hover, .ai-photo-zone.dragover {
    background: rgba(124, 92, 255, .08);
    border-color: var(--ai-purple);
    transform: scale(1.005);
}
.ai-photo-zone input[type=file] { display: none; }
.ai-photo-icon {
    width: 56px; height: 56px;
    margin: 0 auto 14px;
    background: var(--ai-gradient);
    color: #fff;
    border-radius: 14px;
    display: grid; place-items: center;
}
.ai-photo-icon svg { width: 28px; height: 28px; }
.ai-photo-zone h4 { color: var(--text); margin-bottom: 6px; }
.ai-photo-zone p { font-size: .88rem; margin: 0; }

.ai-photo-result {
    margin-top: 18px;
    background: #fff;
    border-radius: var(--radius-md);
    padding: 18px;
    border-left: 3px solid var(--ai-purple);
    display: none;
    gap: 18px;
}
.ai-photo-result.show { display: flex; animation: slide-in .3s ease; }
.ai-photo-preview {
    width: 100px; height: 100px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-soft);
    flex-shrink: 0;
}
.ai-photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.ai-photo-info { flex: 1; }
.ai-photo-info h5 { color: var(--ai-purple); font-weight: 600; margin-bottom: 6px; font-size: .92rem; }
.ai-photo-info ul { list-style: none; padding: 0; margin: 0; font-size: .9rem; }
.ai-photo-info li { padding: 3px 0; color: var(--text-secondary); }
.ai-photo-info li b { color: var(--text); }

/* ===== AI-планировщик маршрута ===== */
.ai-route-card {
    background: #fff;
    border-radius: var(--radius-md);
    padding: 20px;
    border-left: 3px solid var(--ai-purple);
    margin-top: 14px;
    display: none;
}
.ai-route-card.show { display: block; animation: slide-in .3s ease; }
.ai-route-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 14px;
}
.ai-route-stat {
    text-align: center;
    padding: 12px;
    background: var(--bg-soft);
    border-radius: var(--radius-sm);
}
.ai-route-stat .v {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--ai-purple);
    line-height: 1;
}
.ai-route-stat .l {
    font-size: .76rem;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}
.ai-route-tips {
    background: rgba(124, 92, 255, .05);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: .88rem;
    color: var(--text-secondary);
}
.ai-route-tips b { color: var(--ai-purple); }

/* ===== AI-чат FAB ===== */
.ai-chat-fab {
    position: fixed;
    bottom: 24px; right: 24px;
    z-index: 90;
    width: 64px; height: 64px;
    border-radius: 50%;
    background: var(--ai-gradient);
    border: none;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(124, 92, 255, .35);
    display: grid; place-items: center;
    transition: transform .2s ease, box-shadow .2s ease;
    animation: fab-bounce .6s cubic-bezier(.68, -.55, .27, 1.55) .8s backwards;
}
.ai-chat-fab:hover { transform: scale(1.08); box-shadow: 0 14px 40px rgba(124, 92, 255, .5); }
.ai-chat-fab svg { width: 28px; height: 28px; }
.ai-chat-fab .ai-chat-badge {
    position: absolute;
    top: 4px; right: 4px;
    width: 14px; height: 14px;
    background: #1FBA72;
    border: 2px solid #fff;
    border-radius: 50%;
    animation: ai-pulse 1.4s infinite;
}
.ai-chat-fab.hidden { display: none; }
@keyframes fab-bounce {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

/* ===== AI-чат окно ===== */
.ai-chat-window {
    position: fixed;
    bottom: 24px; right: 24px;
    z-index: 91;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 32px);
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,.18), 0 8px 24px rgba(124, 92, 255, .15);
    border: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(.9) translateY(40px);
    opacity: 0;
    pointer-events: none;
    transition: all .25s cubic-bezier(.2, .8, .3, 1);
}
.ai-chat-window.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: auto;
}
.ai-chat-head {
    background: var(--ai-gradient);
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.ai-chat-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    display: grid; place-items: center;
    flex-shrink: 0;
}
.ai-chat-avatar svg { width: 22px; height: 22px; }
.ai-chat-title { flex: 1; }
.ai-chat-title h4 { color: #fff; font-size: 1rem; margin: 0; font-weight: 600; }
.ai-chat-title .status { font-size: .78rem; opacity: .85; display: flex; align-items: center; gap: 6px; }
.ai-chat-title .status::before {
    content: '';
    width: 7px; height: 7px;
    background: #1FBA72;
    border-radius: 50%;
    box-shadow: 0 0 6px rgba(31, 186, 114, .8);
}
.ai-chat-close {
    background: rgba(255,255,255,.2);
    border: none;
    color: #fff;
    width: 32px; height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: grid; place-items: center;
    transition: background .15s ease;
}
.ai-chat-close:hover { background: rgba(255,255,255,.3); }
.ai-chat-close svg { width: 16px; height: 16px; }

.ai-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg-soft);
}

.ai-msg {
    max-width: 85%;
    padding: 11px 14px;
    border-radius: 16px;
    font-size: .92rem;
    line-height: 1.45;
    animation: msg-in .25s ease;
}
@keyframes msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
.ai-msg.bot {
    background: #fff;
    color: var(--text);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.ai-msg.user {
    background: var(--ai-gradient);
    color: #fff;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}
.ai-msg b { color: inherit; font-weight: 600; }
.ai-msg.bot a { color: var(--ai-purple); font-weight: 600; }

.ai-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
}
.ai-typing span {
    width: 8px; height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing-bounce 1.2s infinite;
}
.ai-typing span:nth-child(2) { animation-delay: .2s; }
.ai-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.ai-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}
.ai-quick-reply {
    background: rgba(124, 92, 255, .08);
    border: 1px solid rgba(124, 92, 255, .2);
    color: var(--ai-purple);
    border-radius: var(--radius-pill);
    padding: 6px 12px;
    font-size: .82rem;
    cursor: pointer;
    transition: all .15s ease;
}
.ai-quick-reply:hover {
    background: var(--ai-purple);
    color: #fff;
}

.ai-chat-input-wrap {
    padding: 12px;
    background: #fff;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 8px;
}
.ai-chat-input {
    flex: 1;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 10px 16px;
    font-size: .92rem;
    font-family: inherit;
    transition: border-color .15s ease;
}
.ai-chat-input:focus { outline: none; border-color: var(--ai-purple); }
.ai-chat-send {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--ai-gradient);
    border: none;
    color: #fff;
    cursor: pointer;
    display: grid; place-items: center;
    flex-shrink: 0;
    transition: transform .15s ease;
}
.ai-chat-send:hover { transform: scale(1.08); }
.ai-chat-send svg { width: 18px; height: 18px; }

.ai-chat-disclaimer {
    font-size: .68rem;
    color: var(--text-muted);
    text-align: center;
    padding: 0 18px 10px;
    background: #fff;
}

/* ===== AI-toggle (раскрывающиеся блоки в калькуляторе) ===== */
.ai-toggle {
    background: linear-gradient(135deg, #f8f7ff 0%, #f0f7ff 100%);
    border: 1.5px solid rgba(124, 92, 255, .18);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    overflow: hidden;
    transition: border-color .25s ease, box-shadow .25s ease;
}
.ai-toggle:hover { border-color: rgba(124, 92, 255, .35); box-shadow: 0 6px 20px rgba(124, 92, 255, .08); }
.ai-toggle[open] { border-color: var(--ai-purple); box-shadow: 0 8px 28px rgba(124, 92, 255, .14); }
.ai-toggle summary {
    list-style: none;
    cursor: pointer;
    padding: 18px 22px;
    display: flex;
    align-items: center;
    gap: 16px;
    user-select: none;
}
.ai-toggle summary::-webkit-details-marker { display: none; }
.ai-toggle summary::marker { display: none; }
.ai-toggle-icon {
    width: 44px; height: 44px;
    border-radius: 12px;
    background: var(--ai-gradient);
    color: #fff;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    transition: transform .25s ease;
}
.ai-toggle-icon svg { width: 22px; height: 22px; }
.ai-toggle:hover .ai-toggle-icon { transform: scale(1.05); }
.ai-toggle-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.ai-toggle-title {
    font-weight: 600;
    color: var(--text);
    font-size: 1rem;
    line-height: 1.3;
}
.ai-toggle-desc {
    font-size: .85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}
.ai-toggle-chev {
    width: 22px; height: 22px;
    color: var(--ai-purple);
    flex-shrink: 0;
    transition: transform .3s ease;
}
.ai-toggle[open] .ai-toggle-chev { transform: rotate(180deg); }
.ai-toggle-body {
    padding: 4px 22px 22px;
    border-top: 1px solid rgba(124, 92, 255, .1);
    margin-top: 2px;
}
.ai-toggle-body > *:first-child { margin-top: 16px; }

@media (max-width: 540px) {
    .ai-toggle summary { padding: 14px 16px; gap: 12px; }
    .ai-toggle-icon { width: 38px; height: 38px; border-radius: 10px; }
    .ai-toggle-icon svg { width: 18px; height: 18px; }
    .ai-toggle-title { font-size: .95rem; }
    .ai-toggle-desc { font-size: .8rem; }
    .ai-toggle-body { padding: 4px 16px 18px; }
}

/* Адаптив для AI-чата */
@media (max-width: 540px) {
    .ai-chat-window {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
    .ai-chat-fab {
        width: 56px; height: 56px;
        bottom: 16px; right: 16px;
    }
    .ai-prompt-box { padding: 18px 14px; }
}

/* ========== Живая Марина: аватар, курсор печатания, статусы ========== */
.ai-chat-avatar.persona {
    position: relative;
    background: linear-gradient(135deg, #FF8B3D, #E5634A);
    color: #fff;
    font-weight: 700;
    font-size: 18px;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    overflow: visible;
    box-shadow: 0 4px 14px rgba(229,99,74,.35);
}
.ai-chat-avatar.persona .ai-avatar-letter {
    font-family: Inter, sans-serif;
    letter-spacing: -.5px;
}
.ai-chat-avatar.persona .ai-avatar-online {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: #1FBA72;
    border: 2.5px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(31,186,114,.6);
    animation: ai-online-pulse 2s ease-out infinite;
}
@keyframes ai-online-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(31,186,114,.6); }
    70%      { box-shadow: 0 0 0 8px rgba(31,186,114,0); }
}

/* Динамический статус */
.ai-chat-title .status {
    transition: color .2s ease;
}
.ai-chat-title .status[data-mood="typing"] { color: #5eead4 !important; font-weight: 500; }
.ai-chat-title .status[data-mood="reading"] { color: rgba(255,255,255,.95) !important; }
.ai-chat-title .status::before {
    transition: background .2s ease;
}
.ai-chat-title .status[data-mood="typing"]::before { background: #5eead4; }

/* Курсор «печатания» в конце сообщения */
.ai-typing-cursor {
    display: inline-block;
    color: var(--ai-purple, #7c5cff);
    font-weight: 700;
    animation: ai-cursor-blink 0.9s steps(2) infinite;
    margin-left: 1px;
    transform: translateY(-1px);
}
@keyframes ai-cursor-blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .ai-chat-avatar.persona .ai-avatar-online,
    .ai-typing-cursor { animation: none; }
}

/* Фото вместо буквы у Риммы */
.ai-chat-avatar.persona .ai-avatar-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
    position: relative;
    z-index: 2;
}
/* Фолбек-буква под фото — видна, если фото 404 */
.ai-chat-avatar.persona { padding: 0; background: linear-gradient(135deg, #FF8B3D, #E5634A); overflow: hidden; }
.ai-chat-avatar.persona .ai-avatar-letter {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-family: Inter, sans-serif;
    font-weight: 700;
    font-size: 1.15rem;
    color: #fff;
    z-index: 1;
    pointer-events: none;
}
