@import url('https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wdth,wght@8..144,75..100,100..1000&family=TikTok+Sans:opsz,wdth,wght@12..36,75..100,300..900&display=swap');

/* CSS Custom Properties для темизации */
:root {
    /* Argument Digital Theme */
    --primary: #0575e6;
    /* Blue */
    --success: #00f260;
    /* Green */
    --brand-gradient: linear-gradient(135deg, #00f260 0%, #0575e6 100%);

    --surface: #f8fafc;
    --surface-light: #ffffff;
    --surface-lighter: #f1f5f9;

    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --warning: #f59e0b;
    --error: #ef4444;

    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 20px rgba(5, 117, 230, 0.4);

    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 12px;
}

/* Базовые стили */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Roboto Flex';
}

body {
    font-family: 'Roboto Flex', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--surface);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Контейнер чата */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 100%;
    background: var(--surface);
    position: relative;
}

/* Шапка */
.chat-header {
    padding: 0 3rem 0 2.25rem;
    background: #000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 4rem;
    z-index: 10;
    gap: 40px;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-title h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.025em;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* Кнопки в шапке */
.theme-toggle,
.tts-toggle {
    border-radius: 50%;
    width: 2.75rem;
    height: 2.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

/* Область сообщений */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
    background: var(--surface);
}

/* Скроллбар */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 10px;
    opacity: 0.5;
}

/* Сообщения */
.message {
    display: flex;
    gap: 1rem;
    max-width: 80%;
    animation: messageSlide 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Аватар */
.avatar {
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.25rem;
}

.avatar img{
    width: 2.75rem;
}

/* Сообщения пользователя */
.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.user-message .avatar {
    background: var(--primary-light);
    color: white;
    border: none;
}

.user-message .message-content {
    background: #C6FFDF;
    color: #005A06;
    border: 1px solid #00441e5e;
    border-radius: 10px 10px 0;
    padding: 1.25rem 1.5rem;
}

.user-message .message-content strong {
    color: var(--primary);
}

/* Сообщения бота */
.bot-message {
    align-self: flex-start;
}

.bot-message .avatar {
    align-self: flex-end;
    width: 4rem;
    height: 4rem;
}

.bot-message .avatar img{
    width: 4rem;
    display: block;
    background-color: #00ccff47;
    border-radius: 50%;
}

.bot-message .avatar.preloader{
    background-image: url(img/avatar-ellipse.svg);
    transform: rotate(36000deg);
    transition: all 100s linear;
} 

.bot-message .message-content {
    background: #CCEBFF;
    color: #003965;
    border-radius: 10px 10px 10px 0;
    padding: 1.25rem 1.5rem;
    border: 1px solid var(--border);
}

.bot-message .message-content.helper{
    background-color: #FFC868;
    border: 1px solid #0000004d;
}

.bot-message .message-content.helper .audio-progress-container{
    background: #ab3c004a;
}

.bot-message .message-content.helper .audio-progress-bar{
    background: #ab3c00;
}

.bot-message .message-content.helper .audio-time{
    color: #AB3C00;
}

.bot-message .message-content.helper .tts-container{
    border-top: 1px solid #0000004d;
}

.bot-message .message-content.helper .title-help{
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
    gap: .3rem;
    font-weight: bold;
}
.bot-message .message-content.helper .title-help{
    width: 2.5rem;
    height: 2.5rem;
}

.message-content {
    line-height: 1.6;
    font-size: 1rem;
    position: relative;
    max-width: 100%;
}

.bot-message-img{
    max-width: 100%;
    border-radius: 8px;
}
.bot-message-img.center{
    margin: 0 auto;
    display: block;
}
.bot-message-img.right{
    margin-left: auto;
    display: block;
}

.message-content strong {
    font-weight: 600;
    color: var(--primary);
}

.message-content code {
    font-family: 'JetBrains Mono', monospace;
    background: rgba(0, 0, 0, 0.05);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.9em;
    color: var(--primary-dark);
}

[data-theme="dark"] .message-content code {
    background: rgba(255, 255, 255, 0.1);
    color: var(--primary-light);
}

/* TTS элементы */
.tts-container {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid #003965;
    display: flex;
    gap: 1.25rem;
    align-items: center;
}
.tts-container.hide{
    display: none;
}

.tts-button {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 2.25rem;
    height: 2.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--primary);
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.tts-button.playing {
    color: white;
}

/* Прогресс-бар аудио */
.audio-progress-container {
    width: 100%;
    background: #00396530;
    border-radius: 10px;
    height: 4px;
    overflow: hidden;
    display: none;
}

.audio-progress-container.visible {
    display: block;
}

.audio-progress-bar {
    height: 100%;
    background: #003965;
    width: 0%;
    border-radius: 10px;
    transition: width 0.1s linear;
}

.audio-time {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: #003965;
    font-weight: 600;
    display: none;
}

.audio-time.visible {
    display: flex;
}
.audio-time span:last-child{
    display: none;
}


/* Область ввода */
.chat-input-container {
    padding: 1.5rem 2rem;
    background: var(--surface-light);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.02);
    z-index: 10;
}

.input-wrapper {
    display: flex;
    gap: 1rem;
    max-width: 100%;
    background: transparent;
    padding: 0;
    border: none;
    align-items: center;
    position: relative;
}

.input-wrapper:focus-within {
    border-color: transparent;
    box-shadow: none;
}

.chat-input {
    flex: 1;
    min-height: 3rem;
    max-height: 8rem;
    padding: 0.75rem 4.25rem 0.75rem 1.25rem;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 1.5rem;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-primary);
    resize: none;
    transition: all 0.3s ease;
    line-height: 1.5;
}

.chat-input:focus {
    outline: none;
}

.chat-input::placeholder {
    color: var(--text-muted);
}

/* Кнопка голосового ввода */
.voice-button {
    background: transparent;
    border: 0;
    font-size: 1.5rem;
    cursor: pointer;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 9rem;
}


@keyframes pulse-glow-blue {
    0% {
        box-shadow: 0 0 0 0 rgba(5, 117, 230, 0.4);
        transform: scale(1);
    }

    50% {
        box-shadow: 0 0 0 15px rgba(5, 117, 230, 0);
        transform: scale(1.05);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(5, 117, 230, 0);
        transform: scale(1);
    }
}

@keyframes pulse-recording {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 242, 96, 0.4);
        transform: scale(1);
    }

    50% {
        box-shadow: 0 0 0 10px rgba(0, 242, 96, 0);
        transform: scale(1.05);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(0, 242, 96, 0);
        transform: scale(1);
    }
}

/* Inline Helper Styles */
.helper-inline {
    margin-top: 1rem;
    background: linear-gradient(135deg, #FFB6C1 0%, #ADD8E6 100%) !important;
    border-left: none;
    padding: 1.2rem;
    border-radius: 16px;
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    position: relative;
    z-index: 1;
}

/* Более специфичный селектор для гарантии применения градиента */
.bot-message-content .helper-inline,
.message-content .helper-inline {
    background: linear-gradient(135deg, #FFB6C1 0%, #ADD8E6 100%) !important;
}

.helper-icon {
    width: 32px;
    height: 32px;
    background: transparent;
    color: inherit;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: normal;
    font-size: 20px;
    flex-shrink: 0;
    box-shadow: none;
}

.helper-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.send-button {
    background: #fff;
    font-size: 1rem;
    font-weight: 600;
    box-shadow: none;
    border: 1px solid #9D9F9F;
    height: 2.5rem;
    color: #000;
    width: 6.875rem;
    border-radius: 4rem;
    text-transform: uppercase;
    cursor: pointer;
}

.send-button:disabled {
    background: var(--surface-lighter);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
    opacity: 0.7;
}

/* Но для voice button у нас там span внутри, поправим селектор */
.voice-button span {
    display: block;
}

.blocks-progress{
    display: flex;
    height: 64px;
    flex-grow: 1;
    align-items: center;
    gap: 40px;
}

/* Прогресс обучения */
.progress-container { 
    flex-grow: 1;
}
.progress-container.hidden{
    display: none;
}   
.progress-header {
    display: flex;
    align-items: center;
    margin-bottom: 0.2rem;
    gap: 3px;
}

.progress-title {
    font-size: 0.85rem;
    color: #fff;
    font-weight: 600;
    letter-spacing: 0.0085em;
}

.progress-percentage {
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
}

.progress-bar, .percent-bar {
    width: 100%;
    height: 8px;
    background: #2a8fdc80;
    border-radius: 10px;
    overflow: hidden;
}
.progress-bar{
    background: #1AAC5980;
}

.progress-fill, .percent-fill {
    height: 100%;
    background: #2a8fdc;
    border-radius: 10px;
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    width: 0%;
}
.progress-fill{
    background: #1AAC59;
    
}

/* Статус подключения */
.connection-status {
    position: absolute;
    top: -2rem;
    left: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--surface-light);
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    opacity: 0;
    /* Скрываем если все ок, показываем JS-ом если надо, или оставим видимым */
    opacity: 1;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--error);
}

.status-dot.connected {
    background-color: var(--success);
}

/* Анимация волны */
.wave-animation {
    display: none;
    justify-content: center;
    gap: 3px;
    margin-bottom: 0.5rem;
    height: 20px;
    align-items: center;
}

.wave-animation.active {
    display: flex;
}

.wave-bar {
    width: 3px;
    height: 10px;
    background: var(--primary);
    border-radius: 2px;
    animation: wave 1s infinite ease-in-out;
}

.wave-bar:nth-child(1) {
    animation-delay: 0.0s;
}

.wave-bar:nth-child(2) {
    animation-delay: 0.1s;
}

.wave-bar:nth-child(3) {
    animation-delay: 0.2s;
}

.wave-bar:nth-child(4) {
    animation-delay: 0.3s;
}

.wave-bar:nth-child(5) {
    animation-delay: 0.4s;
}

@keyframes wave {

    0%,
    100% {
        height: 6px;
        opacity: 0.5;
    }

    50% {
        height: 16px;
        opacity: 1;
    }
}

/* Helper Button */
.helper-button {
    position: fixed;
    right: 2rem;
    bottom: 8rem;
    /* Подняли чуть выше */
    width: 3.5rem;
    height: 3.5rem;
    background: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--warning);
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
    z-index: 100;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.helper-button:hover {
    transform: scale(1.1) rotate(10deg);
    box-shadow: 0 8px 25px rgba(245, 158, 11, 0.4);
}

/* Helper Window */
.helper-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(4px);
    z-index: 1001;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.helper-overlay.active {
    display: block;
    opacity: 1;
}

.helper-window {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 90%;
    max-width: 500px;
    background: var(--surface-light);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.1);
    z-index: 1002;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Анимация появления окна (так как оно создается JS-ом) */
@keyframes popIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.helper-window {
    animation: popIn 0.3s forwards;
}

.helper-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.helper-title {
    color: #f59e0b;
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.close-helper {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background 0.2s;
    line-height: 1;
}

.close-helper:hover {
    background: var(--surface);
    color: var(--text-primary);
}

.chat-table-container{}
.chat-table-container table{
    border: 1px solid var(--primary);
    border-spacing: 0;
    border-collapse: separate;
}
.chat-table-container tr{}
.chat-table-container th, .chat-table-container td{
    padding: .5rem 1rem;
    
}
.chat-table-container th{
    border-bottom: 1px solid var(--primary);
    background-color: #fff;
}
.chat-table-container tr:nth-child(even) td{
    background-color: #fff;
}

/* Адаптивность */
@media screen and (max-width: 859px) {
    .chat-header {
        padding: 1rem;
        flex-wrap: wrap;
        gap: .1rem;
    }
    .header-title{
        flex-direction: row-reverse;
        align-items: flex-start;
        width: 100%;
        justify-content: space-between;
    }
    .avatar img{
        align-self: flex-start;
        margin-top: .5rem;
    }
    .progress-container{
        width: 70%;
        padding: 0;
    }

    .chat-header.scrolling{
        flex-wrap: nowrap;
        justify-content: space-between;
        padding: 0 1rem;
        min-height: 3rem;
    }
    .chat-header.scrolling .header-title{
        width: 2.75rem;
        align-items: center;
    }
    .chat-header.scrolling .avatar{
        align-items: center;
        width: 2.75rem;
        height: auto;
    }
    .chat-header.scrolling .avatar img{
        margin: 0;
    }
    .chat-header.scrolling .avatar + div{
        display: none;
    }

    .chat-header.scrolling .tts-toggle{
        width: 2rem;
        height: 2rem;
    }
    .chat-header.scrolling .tts-toggle img{
        width: 2rem;
    }

    .chat-messages {
        padding: 1rem 1rem 11rem;
    }

    .message {
        max-width: 100%;
    }
    .message.user-message{
        max-width: 80%;
    }
    .bot-message .avatar{
        display: none;
    }

    .chat-input-container {
        padding: 1rem;
        background: transparent;
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        border: none;
    }
    .connection-status{
        display: none;
    }
    .chat-input{
        height: 4rem;
    }

    .helper-button {
        bottom: 6rem;
        right: 1rem;
    }
    .voice-button{
        top: -5.5rem;
        right: auto;
        transform: translateX(-50%);
        left: 50%;
    }
    .voice-button img{
        width: 5rem;
    }
    .send-button{
        width: 2.5rem;
        height: 2.5rem;
        background-image: url(/img/send.svg) !important;
        border: 0;
        position: absolute;
        top: 50%;
        right: 1rem;
        transform: translateY(-50%);
    }
    .send-button span{
        display: none;
    }
}
