/* ========================================
   УНИВЕРСАЛЬНЫЙ ЧАТ-БОТ AIRA
   Версия 3.0 - Гибрид версий 1 и 2
   ======================================== */

/* === ЦВЕТОВАЯ СХЕМА === */
:root {
    --bg-dark: #0A0F1D;
    --surface: #12172B;
    --accent-blue: #00A3FF;
    --glow-blue: #0088FF;
    --text: #FFFFFF;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --border-glow: rgba(0, 163, 255, 0.3);
    
    /* Дополнительные цвета для таблиц */
    --table-header: #394854;
    --table-row-odd: #eef0f1;
    --table-border: #d5dde0;
}

/* === ОБЩИЕ СТИЛИ === */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Open Sans', sans-serif;
}

/* === ОВЕРЛЕЙ === */
.overlay {
    position: fixed;
    display: none;
    background: transparent;
    z-index: 9999;
    pointer-events: auto;
    transition: none;
}

.overlay.visible {
    display: block;
}

/* === КОНТЕЙНЕР ЧАТА === */
.chat-container {
    position: fixed;  /* ИЗМЕНЕНО: fixed вместо relative */
    bottom: 20px;     /* ДОБАВЛЕНО */
    right: 20px;      /* ДОБАВЛЕНО */
    width: 600px;
    height: 400px;
    min-width: 500px;  /* ИЗМЕНЕНО 021225 */
    min-height: 360px; /* ИЗМЕНЕНО 021225 */
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 40px);
    margin: 0;        /* ИЗМЕНЕНО: убрали margin */
    
    background: var(--bg-dark);
    border: 1px solid var(--border-glow);
    border-radius: 20px;
    box-shadow: 0 0 40px rgba(0, 163, 255, 0.3);
    
    display: flex;
    flex-direction: column;
    overflow: hidden;
    pointer-events: auto;
    z-index: 10000;   /* ДОБАВЛЕНО: выше overlay */
    
    /* Анимация появления из правого нижнего угла */
    transform: translateY(calc(100% + 40px));
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
}

.chat-container.loaded {
    transform: translateY(0);
    opacity: 1;
}

/* Фоновая сетка */
.chat-container::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: 
        linear-gradient(rgba(18, 23, 43, 0.8) 1.1px, transparent 1.1px),
        linear-gradient(90deg, rgba(18, 23, 43, 0.8) 1.1px, transparent 1.1px);
    background-size: 20px 20px;
    pointer-events: none;
    z-index: 0;
}

/* === РУЧКИ ДЛЯ RESIZE === */
.resize-handle {
    position: absolute;
    z-index: 10;
}

/* Углы — внутри контейнера, чтобы не резались overflow:hidden */
.resize-handle.top-left {
    top: 0;
    left: 0;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
}

.resize-handle.top-right {
    top: 0;
    right: 0;
    width: 14px;
    height: 14px;
    cursor: nesw-resize;
}

.resize-handle.bottom-left {
    bottom: 0;
    left: 0;
    width: 14px;
    height: 14px;
    cursor: nesw-resize;
}

.resize-handle.bottom-right {
    bottom: 0;
    right: 0;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
}

/* Стороны */
.resize-handle.top {
    top: 0;
    left: 14px;
    right: 14px;
    height: 6px;
    cursor: ns-resize;
}

.resize-handle.bottom {
    bottom: 0;
    left: 14px;
    right: 14px;
    height: 6px;
    cursor: ns-resize;
}

.resize-handle.left {
    left: 0;
    top: 14px;
    bottom: 14px;
    width: 6px;
    cursor: ew-resize;
}

.resize-handle.right {
    right: 0;
    top: 14px;
    bottom: 14px;
    width: 6px;
    cursor: ew-resize;
}


/* Подсветка при наведении */
.resize-handle:hover::after {
    content: '';
    position: absolute;
    inset: -2px;
    background: var(--accent-blue);
    opacity: 0.3;
    border-radius: 2px;
}

/* === ШАПКА ЧАТА === */
.chat-header {
    position: relative;
    z-index: 1;
    padding: 16px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-glow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid var(--accent-blue);
    overflow: hidden;
    box-shadow: 0 0 10px rgba(0, 163, 255, 0.4);
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.bot-info h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.bot-info h3 {
    margin: 4px 0 0;
    font-size: 13px;
    font-weight: 400;
    color: var(--text-secondary);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #22d67b;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.9); }
}

/* === КНОПКА КОРЗИНЫ === */
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.basket-button {
    position: relative;
    padding: 10px 16px;
    background: rgba(0,163,255,0.12);
    border: 1px solid var(--accent-blue);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
	color: #ffffff; /* ← корзина белая белая*/
}
.basket-button svg {
    fill: var(--accent-blue);
}
.basket-button.active {
    background: var(--accent-blue);
}
.basket-button.active svg {
    fill: var(--text);
	color: #ffffff; /* ← корзина белая белая*/
}
.basket-button .basket-label {
    margin-left: 6px;
    color: var(--text);
    opacity: 0.8;
    font-size: 12px;
}
.basket-button.active .basket-label {
    opacity: 1;
}

.basket-button:hover {
    background: rgba(0, 163, 255, 0.2);
    transform: translateY(-2px);
}

.basket-button svg {
    width: 20px;
    height: 20px;
    fill: var(--accent-blue);
}

.basket-count {
    min-width: 24px;
    height: 24px;
    background: var(--accent-blue);
    color: var(--text);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
}

.basket-button.active {
    background: var(--accent-blue);
}

.basket-button.active svg {
    fill: var(--text);
}

/* === КНОПКА ЗАКРЫТИЯ === */
.close-chat-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.close-chat-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* === ТЕЛО ЧАТА === */
.chat-body-wrapper {
    position: relative;
    flex: 1;
    overflow: hidden;
    background: transparent;
}

.chat-body {
    height: 100%;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Кастомный скроллбар */
.chat-body::-webkit-scrollbar {
    width: 8px;
}

.chat-body::-webkit-scrollbar-track {
    background: transparent;
}

.chat-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.chat-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* === СООБЩЕНИЯ === */
.chat-message {
    margin: 16px 0;
    animation: messageAppear 0.3s ease;
}

@keyframes messageAppear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Сообщения бота */
.chat-message.aira-message .message-content {
    background: var(--surface);
    border-left: 3px solid var(--accent-blue);
    padding: 12px 16px;
    border-radius: 12px 12px 12px 2px;
    max-width: 80%;
    color: var(--text);
}

/* Сообщения пользователя */
.chat-message.user-message .message-content {
    background: var(--accent-blue);
    padding: 12px 16px;
    border-radius: 12px 12px 2px 12px;
    max-width: 80%;
    margin-left: auto;
    color: var(--text);
}

.message-text {
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 4px;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: right;
}

/* === ИНДИКАТОР "ПЕЧАТАЕТ" === */
.typing-indicator {
    display: inline-block;
    padding: 12px 16px;
    margin: 8px 0;
    background: var(--surface);
    border-left: 3px solid var(--accent-blue);
    border-radius: 12px 12px 12px 2px;
    color: var(--text-secondary);
    font-size: 14px;
    animation: messageAppear 0.3s ease;
}

.typing-indicator .dots {
    display: inline-block;
    min-width: 20px;
}

/* === ТАБЛИЦЫ РЕЗУЛЬТАТОВ === */
.table-message {
    width: 100%;
}

.table-container {
    background: var(--surface);
    border: 1px solid var(--border-glow);
    border-radius: 12px;
    overflow: hidden;
}

.table-header {
    padding: 12px 16px;
    background: var(--table-header);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.table-title {
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
}

.table-toggle {
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.table-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

.table-wrapper {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.table-wrapper.open {
    max-height: 600px;
}

.table-scroll {
    overflow-x: auto;
    overflow-y: visible;
}

/* Горизонтальный скролл таблицы */
.table-scroll::-webkit-scrollbar {
    height: 6px;
}

.table-scroll::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.table-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.parts-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.parts-table th {
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--border-glow);
}

.parts-table td {
    padding: 10px 12px;
    color: var(--text);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.parts-table tr:hover td {
    background: rgba(0, 163, 255, 0.05);
}

.parts-table input[type="number"] {
    width: 60px;
    padding: 6px 8px;
    background: var(--bg-dark);
    border: 1px solid var(--border-glow);
    border-radius: 6px;
    color: var(--text);
    text-align: center;
    font-size: 13px;
}

.parts-table button {
    padding: 6px 12px;
    background: var(--accent-blue);
    border: none;
    border-radius: 6px;
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.parts-table button:hover {
    background: var(--glow-blue);
    transform: translateY(-1px);
}

.show-more-btn {
    width: calc(100% - 32px);
    margin: 16px;
    padding: 10px;
    background: rgba(0, 163, 255, 0.1);
    border: 1px solid var(--accent-blue);
    border-radius: 8px;
    color: var(--accent-blue);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.show-more-btn:hover {
    background: rgba(0, 163, 255, 0.2);
}

/* Памятка по кнопкам */
.button-guide {
    margin: 16px 0;
    padding: 12px 16px;
    background: var(--surface);
    border-left: 3px solid var(--accent-blue);
    border-radius: 12px;
}

.button-guide .guide-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.button-guide .guide-list {
    margin: 0;
    padding-left: 20px;
    list-style: none;
}

.button-guide .guide-list li {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 4px 0;
    position: relative;
}

.button-guide .guide-list li::before {
    content: '•';
    color: var(--accent-blue);
    position: absolute;
    left: -15px;
}

.button-guide .guide-list li strong {
    color: var(--accent-blue);
}

/* === ТАБЛИЦА КОРЗИНЫ === */
.cart-table-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 15, 29, 0.95);
    backdrop-filter: blur(3px);
    z-index: 5;
    padding: 20px;
    overflow-y: auto;
}

.cart-content {
    background: var(--surface);
    border: 1px solid var(--border-glow);
    border-radius: 12px;
    padding: 20px;
}

.cart-content > p {
    margin: 0 0 20px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    text-align: center;
}

.cart-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.cart-table th {
    padding: 12px;
    background: var(--table-header);
    color: var(--text);
    font-weight: 600;
    text-align: left;
}

.cart-table td {
    padding: 12px;
    color: var(--text);
    border-bottom: 1px solid var(--border-glow);
}

.cart-table .quantity-cell input {
    width: 60px;
    padding: 4px 8px;
    background: var(--bg-dark);
    border: 1px solid var(--border-glow);
    border-radius: 6px;
    color: var(--text);
    text-align: center;
}

.cart-table tr:nth-child(odd) td {
    background: rgba(255, 255, 255, 0.03);
}

.cart-table .quantity-cell input {
    width: 60px;
    padding: 4px 8px;
    background: var(--bg-dark);
    border: 1px solid var(--border-glow);
    border-radius: 6px;
    color: var(--text);
    text-align: center;
    font-size: 13px;
}

.cart-table .delete-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(255, 0, 0, 0.1);
    border: 1px solid rgba(255, 0, 0, 0.3);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ff4444;
    font-size: 16px;
}

.cart-table .delete-btn:hover {
    background: rgba(255, 0, 0, 0.2);
}

.cart-table .total-row td {
    padding: 16px 12px;
    font-weight: 600;
    font-size: 15px;
    border-top: 2px solid var(--accent-blue);
    background: rgba(0, 163, 255, 0.05);
}

.cart-table .confirm-btn {
    width: 100%;
    padding: 12px;
    background: var(--accent-blue);
    border: none;
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cart-table .confirm-btn:hover {
    background: var(--glow-blue);
    transform: translateY(-2px);
}

/* === КОМПАКТНЫЙ ЛОАДЕР === */
#aira-compact-loader {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 90px;
    z-index: 50;
    
    width: 280px;
    padding: 12px 16px;
    border-radius: 12px;
    
    background: rgba(18, 23, 43, 0.95);
    border: 1px solid var(--border-glow);
    box-shadow: 0 10px 30px rgba(0, 163, 255, 0.2);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.battery {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.battery-body {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    width: 100%;
    height: 16px;
    padding: 3px;
    border-radius: 8px;
    border: 1px solid var(--border-glow);
    background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
}

.battery-body .cell {
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    transition: background 0.3s ease;
}

.battery-body .cell.active {
    background: linear-gradient(180deg, #b5f1c9, #8ee0aa);
}

.progress {
    width: 100%;
    height: 4px;
    margin-top: 8px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

.progress > i {
    display: block;
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--accent-blue), var(--glow-blue));
    transition: width 0.3s ease;
}

.status {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    min-height: 18px;
}

/* === ФУТЕР === */
.chat-footer {
    position: relative;
    z-index: 1;
    padding: 16px 20px;
    background: var(--surface);
    border-top: 1px solid var(--border-glow);
    flex-shrink: 0;
}

#messageForm {
    display: flex;
    gap: 12px;
    align-items: center;
}

#messageInput {
    flex: 1;
    padding: 12px 20px;
    background: var(--bg-dark);
    border: 1px solid var(--border-glow);
    border-radius: 24px;
    color: var(--text);
    font-size: 14px;
    transition: all 0.2s ease;
}

#messageInput:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(0, 163, 255, 0.1);
}

#messageInput::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

#sendButton {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--accent-blue);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

#sendButton:hover {
    background: var(--glow-blue);
    transform: scale(1.05);
}

#sendButton svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* === КНОПКА ОТКРЫТИЯ ЧАТА === */
.open-chat-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 300px;   /* десктоп 300x80 */
    height: 80px;
    padding: 10px 16px;
    
    background: var(--surface);
    border: 1px solid var(--border-glow);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 163, 255, 0.3);
    
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    z-index: 9998;
    transition: all 0.3s ease;
}


.open-chat-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 30px rgba(0, 163, 255, 0.4);
}

.open-chat-btn .info-column {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.open-chat-btn .name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.open-chat-btn .indicator {
    display: flex;
    align-items: center;
    gap: 6px;
}

.open-chat-btn .dot {
    width: 6px;
    height: 6px;
    background: #22d67b;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.open-chat-btn .purpose {
    font-size: 12px;
    color: var(--text-secondary);
}

/* === МОБИЛЬНАЯ ВЕРСИЯ === */
@media (max-width: 768px) {
    .chat-container {
        position: fixed !important;  /* ДОБАВЛЕНО: fixed и на мобилке */
        bottom: 10px !important;     /* ДОБАВЛЕНО */
        right: 10px !important;      /* ДОБАВЛЕНО */
        width: calc(100vw - 20px) !important;
        height: calc(100vh - 100px) !important;
        max-width: calc(100vw - 20px) !important;
        max-height: calc(100vh - 100px) !important;
        min-width: 320px !important;
        min-height: 400px !important;
        margin: 0 !important;        /* ИЗМЕНЕНО */
        border-radius: 20px;
        border: 1px solid var(--border-glow);
    }

    
    /* Таблицы скроллятся горизонтально */
    .table-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .parts-table {
        min-width: 700px;
    }
    
    .cart-table {
        min-width: 600px;
    }
    
    /* Корзина на весь экран */
    .cart-table-overlay {
        padding: 10px;
    }
    
    /* Лоадер компактнее */
    #aira-compact-loader {
        width: 240px;
        bottom: 80px;
    }
    
    /* Кнопка открытия (мобилка) */
    .open-chat-btn {
        width: 260px;      /* мобилка 260x60 */
        height: 60px;
        bottom: 10px;
        left: 50%;         /* центрируем под рамку свечения */
        right: auto;
        margin-left: -130px;  /* половина ширины кнопки */
    }


@media (max-width: 480px) {
    /* Скрываем ручки resize на совсем узких экранах (телефон) */
    .resize-handle {
        display: none;
    }	

    .chat-header {
        padding: 12px 16px;
    }
    
    .avatar {
        width: 40px;
        height: 40px;
    }
    
    .bot-info h2 {
        font-size: 16px;
    }
    
    .bot-info h3 {
        font-size: 11px;
    }
    
    .basket-button {
        padding: 8px 12px;
    }
    
    .chat-body {
        padding: 12px;
    }
    
    .message-text {
        font-size: 13px;
    }
    
    .parts-table {
        font-size: 11px;
    }
    
    .parts-table th,
    .parts-table td {
        padding: 6px 8px;
    }
}

.open-chat-btn {
    min-width: 300px;
}
.open-chat-btn .name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
    line-height: 1;
}
@media (max-width: 420px){
    .open-chat-btn { min-width: 0; }
    .open-chat-btn .name { font-size: 13px; }
}
