/* AI Chat — строка в шапке (стиль «Госуслуги»: мягкая плашка, сливается с фоном) */

.site-header {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    padding-bottom: 18px;
}

.header-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.ai-chat-container {
    max-width: 1200px;
    margin: 0 auto 0 auto;
    padding: 0;
    width: 100%;
}

.ai-chat-in-header {
    max-width: none;
    margin: 0;
}

.ai-chat-wrapper {
    position: relative;
    /* Финиш бега: ~половина полосы ввода, не залезая на кнопку */
    --ai-robot-run-end: min(56%, calc(100% - 118px));
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 60px;
    padding: 6px 10px 6px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    backdrop-filter: blur(12px);
    transition: all 0.25s ease;
    overflow: visible;
    min-height: 48px;
}

.ai-chat-wrapper:hover,
.ai-chat-wrapper:focus-within {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(0, 210, 255, 0.35);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
}

.ai-chat-input {
    position: relative;
    z-index: 6;
    flex: 1;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 15px;
    padding: 12px 0;
    outline: none;
}

.ai-chat-input::placeholder {
    color: rgba(255, 255, 255, 0.42);
    font-weight: 300;
}

.ai-chat-send-btn {
    position: relative;
    z-index: 6;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.65);
    cursor: pointer;
    padding: 12px 18px;
    border-radius: 40px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-chat-send-btn:hover {
    background: rgba(14, 165, 233, 0.18);
    color: #fff;
}

.ai-chat-send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ai-chat-suggestions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.ai-suggestion-chip {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 40px;
    padding: 7px 16px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.72);
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(6px);
}

.ai-suggestion-chip:hover {
    background: rgba(14, 165, 233, 0.14);
    border-color: rgba(14, 165, 233, 0.35);
    color: #fff;
}

.ai-chat-response {
    margin-top: 14px;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 18px;
    border-left: 3px solid #0ea5e9;
    color: rgba(255, 255, 255, 0.92);
    font-size: 14px;
    line-height: 1.55;
    display: none;
    backdrop-filter: blur(6px);
}

.ai-chat-response.show {
    display: block;
    animation: aiFadeIn 0.28s ease;
}

.ai-chat-response-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.ai-chat-response-avatar {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
}

.ai-chat-response-name {
    font-weight: 600;
    color: #fff;
}

.ai-chat-response-text {
    padding-left: 38px;
    color: rgba(255, 255, 255, 0.82);
    white-space: pre-wrap;
}

.ai-chat-loading {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.12);
    border-top-color: #0ea5e9;
    border-radius: 50%;
    animation: aiSpin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

@keyframes aiFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes aiSpin {
    to {
        transform: rotate(360deg);
    }
}

/* Резерв слева под иконку; сам робот позиционируется от всей капсулы .ai-chat-wrapper */
.ai-chat-mascot-slot {
    flex-shrink: 0;
    width: 34px;
    height: 40px;
    pointer-events: none;
}

/* AI Robot — бег по ширине строки (left), наклон в сторону движения; клики проходят к полю ввода */
.ai-robot {
    position: absolute;
    bottom: 7px;
    left: 8px;
    width: 32px;
    height: 34px;
    z-index: 4;
    cursor: default;
    transform-origin: 50% 100%;
    pointer-events: none;
    animation: robotRunLane 6s ease-in-out infinite alternate;
}

.ai-robot::before {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -2px;
    width: 54px;
    height: 54px;
    transform: translate(-50%, 18%);
    border-radius: 50%;
    background: radial-gradient(
        circle at 50% 40%,
        rgba(56, 189, 248, 0.38) 0%,
        rgba(99, 102, 241, 0.2) 45%,
        transparent 70%
    );
    border: 1px solid rgba(255, 255, 255, 0.08);
    z-index: -1;
    pointer-events: none;
    animation: mascotGlowPulse 2.8s ease-in-out infinite;
}

.ai-robot:hover {
    animation-play-state: paused;
}

.ai-robot.loading,
.ai-robot.thinking,
.ai-robot.success,
.ai-robot.error,
.ai-robot.not-found {
    animation: none;
}

/* Резкий тормоз у левого края поля + «слушает» */
.ai-robot.loading {
    left: 10px;
    animation: robotBrakeListen 0.56s cubic-bezier(0.18, 0.82, 0.22, 1) forwards;
}

.ai-robot.thinking {
    left: 10px;
    animation: robotListenHold 2.4s ease-in-out infinite;
}

.ai-robot.success {
    left: 10px;
    animation: robotPop 0.55s ease;
}

.ai-robot.error,
.ai-robot.not-found {
    left: 10px;
    animation: robotShrug 0.55s ease;
}

/* Голова */
.robot-head {
    width: 28px;
    height: 22px;
    background: linear-gradient(145deg, #7c8df0 0%, #5b4bb8 48%, #4a3a9a 100%);
    border-radius: 10px 10px 7px 7px;
    position: absolute;
    top: 7px;
    left: 2px;
    box-shadow:
        0 3px 0 rgba(45, 55, 140, 0.95),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* «Уши» как в макете — вместо длинных рук в строке */
.robot-ear {
    position: absolute;
    width: 6px;
    height: 6px;
    background: linear-gradient(180deg, #5b7cff 0%, #3d52d8 100%);
    border-radius: 50%;
    top: 14px;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
    animation: earWiggle 2s ease-in-out infinite;
}

.robot-ear--left {
    left: -3px;
    animation-delay: 0s;
}

.robot-ear--right {
    right: -3px;
    animation-delay: 0.15s;
}

/* Длинные руки скрыты в компактном режиме */
.robot-arms {
    display: none;
}

/* Антенна */
.robot-antenna {
    width: 3px;
    height: 8px;
    background: linear-gradient(180deg, #ffe566 0%, #f5c400 100%);
    position: absolute;
    top: -6px;
    left: 12px;
    border-radius: 2px;
    transform-origin: bottom center;
    animation: antennaSway 1.4s ease-in-out infinite;
}

.robot-antenna::after {
    content: '';
    width: 6px;
    height: 6px;
    background: radial-gradient(circle at 30% 30%, #ff8a8a, #e04040);
    border-radius: 50%;
    position: absolute;
    top: -5px;
    left: -1.5px;
    box-shadow: 0 0 6px rgba(255, 90, 90, 0.7);
    animation: antennaTipPulse 0.9s ease-in-out infinite alternate;
}

/* Глаза */
.robot-eyes {
    display: flex;
    gap: 5px;
    position: absolute;
    top: 8px;
    left: 5px;
}

.robot-eye {
    width: 7px;
    height: 7px;
    background: #fff;
    border-radius: 50%;
    position: relative;
    overflow: hidden;
    transition: transform 0.15s ease;
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.08);
}

.robot-eye::after {
    content: '';
    width: 3px;
    height: 3px;
    background: #12122a;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    animation: eyeBlink 3.5s infinite;
}

/* Рот */
.robot-mouth {
    width: 12px;
    height: 3px;
    background: rgba(255, 255, 255, 0.75);
    border-radius: 0 0 6px 6px;
    position: absolute;
    bottom: 4px;
    left: 8px;
    transition: all 0.25s ease;
}

/* Тело */
.robot-body {
    width: 24px;
    height: 11px;
    background: linear-gradient(145deg, #6a7ee8 0%, #5a3d9c 100%);
    border-radius: 5px;
    position: absolute;
    bottom: 2px;
    left: 4px;
    box-shadow: 0 2px 0 rgba(45, 55, 140, 0.9);
}

/* Короткие ноги — чуть выступают вниз из капсулы */
.robot-legs {
    display: flex;
    gap: 7px;
    position: absolute;
    bottom: -3px;
    left: 9px;
}

.robot-leg {
    width: 5px;
    height: 5px;
    background: #3d4a9e;
    border-radius: 2px 2px 3px 3px;
    transform-origin: top center;
}

/* Ноги — быстрый шаг в такт бега по полосе */
.ai-robot:not(.loading):not(.thinking):not(.success):not(.error):not(.not-found) .robot-leg.left {
    animation: legRunStride 0.34s linear infinite;
}

.ai-robot:not(.loading):not(.thinking):not(.success):not(.error):not(.not-found) .robot-leg.right {
    animation: legRunStride 0.34s linear infinite;
    animation-delay: -0.17s;
}

/* Состояния */
.ai-robot.loading .robot-leg.left,
.ai-robot.thinking .robot-leg.left {
    animation: legListenShift 1.15s ease-in-out infinite alternate;
}

.ai-robot.loading .robot-leg.right,
.ai-robot.thinking .robot-leg.right {
    animation: legListenShift 1.15s ease-in-out infinite alternate-reverse;
}

.ai-robot.loading .robot-ear,
.ai-robot.thinking .robot-ear {
    animation: earListenTwitch 1.6s ease-in-out infinite;
}

.ai-robot.loading .robot-head,
.ai-robot.thinking .robot-head {
    animation: headListenTilt 2s ease-in-out infinite;
    transform-origin: 50% 100%;
}

.ai-robot.loading .robot-antenna,
.ai-robot.thinking .robot-antenna {
    animation: antennaListenStill 2.2s ease-in-out infinite;
}

.ai-robot.success .robot-head,
.ai-robot.error .robot-head,
.ai-robot.not-found .robot-head {
    animation: none;
}

.ai-robot.success .robot-ear,
.ai-robot.error .robot-ear,
.ai-robot.not-found .robot-ear {
    animation: earWiggle 2s ease-in-out infinite;
}

.ai-robot.success .robot-antenna,
.ai-robot.error .robot-antenna,
.ai-robot.not-found .robot-antenna {
    animation: antennaSway 1.4s ease-in-out infinite;
}

.ai-robot.success .robot-leg,
.ai-robot.error .robot-leg,
.ai-robot.not-found .robot-leg {
    animation: legIdleTap 1.1s ease-in-out infinite alternate;
}

.ai-robot.success .robot-leg.right,
.ai-robot.error .robot-leg.right,
.ai-robot.not-found .robot-leg.right {
    animation-direction: alternate-reverse;
}

.ai-robot.success .robot-mouth {
    width: 12px;
    height: 6px;
    background: #34d399;
    border-radius: 0 0 4px 4px;
}

.ai-robot.error .robot-mouth {
    width: 10px;
    height: 2px;
    background: #f87171;
    border-radius: 2px;
    transform: rotate(180deg);
}

.ai-robot.error .robot-ear,
.ai-robot.not-found .robot-ear {
    animation: earShrug 0.45s ease forwards;
}

.ai-robot.thinking .robot-eyes {
    animation: eyesThinking 0.85s infinite;
}

/* Подпись — под капсулой, не влияет на высоту строки */
.robot-status {
    font-size: 9px;
    color: rgba(255, 255, 255, 0.55);
    text-align: center;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.25s;
    position: absolute;
    left: 50%;
    top: calc(100% + 4px);
    transform: translateX(-50%);
    width: max-content;
    max-width: 160px;
    pointer-events: none;
    z-index: 3;
}

.ai-robot.loading .robot-status,
.ai-robot.thinking .robot-status {
    opacity: 1;
}


/* Ключевые кадры */
@keyframes mascotGlowPulse {
    0%, 100% { opacity: 0.85; filter: brightness(1); }
    50% { opacity: 1; filter: brightness(1.12); }
}

/* Бег по строке: вправо — наклон по часовой, влево — против; длина пути ~половина капсулы */
@keyframes robotRunLane {
    0% {
        left: 8px;
        transform: rotate(20deg) scaleY(1);
    }
    50% {
        left: var(--ai-robot-run-end, min(56%, calc(100% - 118px)));
        transform: rotate(-20deg) scaleY(0.93);
    }
    100% {
        left: 8px;
        transform: rotate(20deg) scaleY(1);
    }
}

@keyframes robotBrakeListen {
    0% {
        transform: translateX(22px) rotate(22deg) scaleY(0.96);
    }
    10% {
        transform: translateX(26px) rotate(14deg) scaleY(0.94);
    }
    26% {
        transform: translateX(-6px) rotate(-14deg) scaleX(1.12) scaleY(0.84);
    }
    42% {
        transform: translateX(2px) rotate(8deg) scaleX(0.95) scaleY(1.04);
    }
    58% {
        transform: translateX(0) rotate(-3deg) scale(1.02, 1.05);
    }
    78%,
    100% {
        transform: translateX(0) rotate(0deg) scale(1.04, 1.08);
    }
}

@keyframes robotListenHold {
    0%,
    100% {
        transform: translateX(0) rotate(0deg) scale(1.04, 1.08);
    }
    50% {
        transform: translateX(0) rotate(0.5deg) scale(1.05, 1.09);
    }
}

@keyframes legRunStride {
    0% {
        transform: rotate(-22deg) translateY(0);
    }
    50% {
        transform: rotate(18deg) translateY(-1px);
    }
    100% {
        transform: rotate(-22deg) translateY(0);
    }
}

@keyframes legListenShift {
    from {
        transform: rotate(-4deg) translateY(0);
    }
    to {
        transform: rotate(4deg) translateY(-0.5px);
    }
}

@keyframes earListenTwitch {
    0%,
    100% {
        transform: translateY(0) scale(1);
    }
    20% {
        transform: translateY(-1px) scale(1.08, 1.02);
    }
    40% {
        transform: translateY(0) scale(1);
    }
    60% {
        transform: translateY(-0.5px) scale(1.05, 1);
    }
}

@keyframes headListenTilt {
    0%,
    100% {
        transform: rotate(-1.5deg);
    }
    50% {
        transform: rotate(2.5deg);
    }
}

@keyframes antennaListenStill {
    0%,
    100% {
        transform: rotate(-2deg);
    }
    50% {
        transform: rotate(2deg);
    }
}

@keyframes robotPop {
    0% { transform: scale(1); }
    40% { transform: scale(1.12) translateY(-4px); }
    100% { transform: scale(1); }
}

@keyframes robotShrug {
    0% { transform: translateY(0); }
    35% { transform: translateY(-3px) rotate(-2deg); }
    70% { transform: translateY(1px) rotate(1deg); }
    100% { transform: translateY(0); }
}

@keyframes antennaSway {
    0%, 100% { transform: rotate(-6deg); }
    50% { transform: rotate(6deg); }
}

@keyframes antennaTipPulse {
    from { transform: scale(0.9); opacity: 0.85; }
    to { transform: scale(1.05); opacity: 1; }
}

@keyframes earWiggle {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-1px); }
}

@keyframes earFlap {
    from { transform: translateY(0) scaleY(1); }
    to { transform: translateY(-2px) scaleY(0.85); }
}

@keyframes earShrug {
    to { transform: translateY(2px); }
}

@keyframes eyeBlink {
    0%, 45%, 55%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(0.15); }
}

@keyframes legIdleTap {
    from { transform: rotate(-6deg); }
    to { transform: rotate(6deg); }
}

@keyframes legWalkFast {
    from { transform: rotate(-18deg); }
    to { transform: rotate(18deg); }
}

@keyframes eyesThinking {
    0%, 100% { transform: translateX(0); }
    33% { transform: translateX(-2px); }
    66% { transform: translateX(2px); }
}

@media (max-width: 768px) {
    .ai-chat-wrapper {
        padding: 5px 8px 5px 8px;
        min-height: 44px;
        --ai-robot-run-end: min(50%, calc(100% - 100px));
    }
    .ai-chat-mascot-slot {
        width: 28px;
        height: 36px;
    }
    .ai-robot {
        width: 30px;
        height: 32px;
    }
    .robot-head {
        width: 26px;
        height: 20px;
        top: 6px;
        left: 2px;
    }
    .robot-body {
        width: 22px;
        height: 10px;
        left: 4px;
    }
    .ai-chat-input {
        font-size: 14px;
    }
    .ai-suggestion-chip {
        padding: 6px 12px;
        font-size: 12px;
    }
}
