/* Вёрстка как на референсе: тёмный фон, сайдбар, группы чатов, круглая кнопка отправки */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #17191C;
    color: #E4E4E7;
    min-height: 100vh;
    overflow: hidden;
}

.app {
    display: flex;
    height: 100vh;
}

/* ——— Сайдбар (20–25%) ——— */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: #17191C;
    border-right: 1px solid #282A2E;
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.brand {
    font-weight: 700;
    font-size: 18px;
    color: #fff;
    letter-spacing: 0.02em;
}

.icon-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #9CA3AF;
    font-size: 18px;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: #282A2E;
    color: #fff;
}

/* Кнопка New chat */
.btn-new-chat {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    background: #282A2E;
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 16px;
}

.btn-new-chat:hover {
    background: #35373B;
}

.btn-new-chat-icon {
    font-size: 18px;
    line-height: 1;
}

/* Список чатов с группами */
.chats-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: #2a3c64 #282A2E;
}

.chats-list::-webkit-scrollbar {
    width: 6px;
}

.chats-list::-webkit-scrollbar-track {
    background: #282A2E;
    border-radius: 3px;
}

.chats-list::-webkit-scrollbar-thumb {
    background: #2a3c64;
    border-radius: 3px;
}

.chats-list::-webkit-scrollbar-thumb:hover {
    background: #2a3c64;
}

.chat-group {
    margin-bottom: 16px;
}

.chat-group-title {
    font-size: 12px;
    color: #9CA3AF;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 4px 8px 8px;
    font-weight: 500;
}

.chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
    margin-bottom: 2px;
}

.chat-item:hover {
    background: #282A2E;
}

.chat-item.active {
    background: #172035;
    color: #fff;
}

.chat-item.active .chat-title,
.chat-item.active .chat-date {
    color: #fff;
}

.chat-item.active .chat-more {
    color: rgba(255,255,255,0.9);
}

.chat-item-content {
    flex: 1;
    min-width: 0;
}

.chat-title {
    font-size: 14px;
    color: #E4E4E7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.chat-date {
    font-size: 12px;
    color: #9CA3AF;
}

.chat-more {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: #9CA3AF;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-item:hover .chat-more {
    color: #E4E4E7;
}

.chat-more:hover {
    background: rgba(255,255,255,0.12);
    color: #fff;
}

.chat-item.active .chat-more {
    color: rgba(255,255,255,0.9);
}

/* ——— Основная область ——— */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #17191C;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

/* Фоновая анимация — смещающийся цветной свет, живое движение */
.main::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(
            ellipse 40% 40% at 50% 50%,
            rgba(99, 102, 241, 0.22) 0%,
            rgba(99, 102, 241, 0.08) 35%,
            transparent 55%
        );
    background-size: 140% 140%;
    background-position: 10% 15%;
    background-repeat: no-repeat;
    animation: main-glow-move-1 7s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

.main::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(
            ellipse 35% 45% at 50% 50%,
            rgba(59, 130, 246, 0.18) 0%,
            rgba(59, 130, 246, 0.06) 30%,
            transparent 50%
        );
    background-size: 130% 130%;
    background-position: 85% 80%;
    background-repeat: no-repeat;
    animation: main-glow-move-2 9s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

.main > * {
    position: relative;
    z-index: 1;
}

@keyframes main-glow-move-1 {
    0%   { background-position: 10% 15%; }
    20%  { background-position: 85% 20%; }
    40%  { background-position: 75% 82%; }
    60%  { background-position: 15% 70%; }
    80%  { background-position: 50% 12%; }
    100% { background-position: 10% 15%; }
}

@keyframes main-glow-move-2 {
    0%   { background-position: 85% 80%; }
    25%  { background-position: 18% 25%; }
    50%  { background-position: 90% 55%; }
    75%  { background-position: 25% 88%; }
    100% { background-position: 85% 80%; }
}

.main-title {
    font-size: 22px;
    font-weight: 600;
    color: #fff;
    text-align: center;
    padding: 24px 24px 16px;
    flex-shrink: 0;
}

.main-title:empty {
    display: none;
}

.messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 42px 24px;
    min-height: 0;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: #2a3c64 #282A2E;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.messages::-webkit-scrollbar {
    width: 8px;
}

.messages::-webkit-scrollbar-track {
    background: #282A2E;
    border-radius: 4px;
}

.messages::-webkit-scrollbar-thumb {
    background: #2a3c64;
    border-radius: 4px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: #5a72c4;
}

.messages::-webkit-scrollbar-thumb:active {
    background: #3d4e8f;
}

.message {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 75%;
}

.message.user {
    background: #282a2e69;
    color: #fff;
    margin-left: auto;
    backdrop-filter: blur(1px);
}

.message.assistant {

    color: #E4E4E7;
}

.message-time {
    font-size: 11px;
    margin-top: 6px;
    opacity: 0.75;
}

.message-body h1,
.message-body h2 {
    margin: 0.75em 0 0.35em;
    font-weight: 600;
    line-height: 1.3;
}
.message-body h1 { font-size: 1.35em; }
.message-body h2 { font-size: 1.15em; }
.message-body h1:first-child,
.message-body h2:first-child { margin-top: 0; }

/* Поле ввода внизу */
.input-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 24px 24px;
    flex-shrink: 0;


    max-width: 830px;
    /* margin: 0 auto; */
    width: 100%;

}

.copyright {
    margin: 0 24px 16px;
    padding: 0;
    font-size: 12px;
    color: #6B7280;
    flex-shrink: 0;
}

.input-wrap input {
    flex: 1;
    padding: 12px 16px;
    background: #282A2E;
    border: 1px solid #35373B;
    border-radius: 12px;
    font-size: 15px;
    color: #E4E4E7;
}

.input-wrap input::placeholder {
    color: #6B7280;
}

.input-wrap input:focus {
    outline: none;
    border-color: #2a3c64;
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #2a3c64;
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.send-btn:hover {
    background: #5a72c4;
}

.send-btn:disabled {
    background: #35373B;
    color: #6B7280;
    cursor: not-allowed;
    opacity: 0.7;
}

.empty-state {
    text-align: center;
    color: #6B7280;
    padding: 32px 24px;
    font-size: 15px;
}

/* Модальное окно */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    background: #282A2E;
    padding: 24px;
    border-radius: 12px;
    width: 400px;
    border: 1px solid #35373B;
}

.modal-content h3 {
    color: #fff;
    margin-bottom: 16px;
    font-size: 18px;
}

.modal-content input {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: #17191C;
    border: 1px solid #35373B;
    border-radius: 8px;
    color: #E4E4E7;
    font-size: 14px;
}

.modal-content input:last-of-type {
    margin-bottom: 0;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.modal-buttons button {
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    border: none;
}

.modal-buttons button:first-child {
    background: #35373B;
    color: #E4E4E7;
}

.modal-buttons button:first-child:hover {
    background: #404245;
}

.modal-buttons button:last-child {
    background: #2a3c64;
    color: #fff;
}

.modal-buttons button:last-child:hover {
    background: #2a3c64;
}

/* ——— Модалка "AI думает" с нейро-анимацией ——— */
.modal-thinking {
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
}

.modal-thinking .thinking-content {
    background: linear-gradient(145deg, #1e2126 0%, #25282e 50%, #1a1d22 100%);
    padding: 32px 40px;
    border-radius: 20px;
    border: 1px solid #35373B;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(76, 98, 177, 0.15);
    text-align: center;
    max-width: 340px;
}

.neuro-canvas {
    width: 280px;
    height: 74px;
    margin: 0 auto 24px;
    position: relative;
}

.neuro-lines {
    width: 100%;
    height: 100%;
    display: block;
    stroke: rgba(76, 98, 177, 0.4);
    stroke-width: 1.5;
    fill: none;
}

.neuro-lines .line {
    stroke-dasharray: 80;
    stroke-dashoffset: 80;
    animation: neuro-draw 2s ease-in-out infinite;
}

/* Задержки линий по буквам: A */
.neuro-lines .line.la1 { animation-delay: 0s; }
.neuro-lines .line.la2 { animation-delay: 0.06s; }
.neuro-lines .line.la3 { animation-delay: 0.12s; }
.neuro-lines .line.la4 { animation-delay: 0.18s; }
.neuro-lines .line.la5 { animation-delay: 0.24s; }
.neuro-lines .line.la6 { animation-delay: 0.3s; }
.neuro-lines .line.la7 { animation-delay: 0.36s; }
.neuro-lines .line.la8 { animation-delay: 0.42s; }
.neuro-lines .line.la9 { animation-delay: 0.48s; }
.neuro-lines .line.la10 { animation-delay: 0.54s; }
/* I (AI) */
.neuro-lines .line.li1 { animation-delay: 0.08s; }
.neuro-lines .line.li2 { animation-delay: 0.16s; }
.neuro-lines .line.li3 { animation-delay: 0.24s; }
.neuro-lines .line.li4 { animation-delay: 0.14s; }
.neuro-lines .line.li5 { animation-delay: 0.22s; }
.neuro-lines .line.li6 { animation-delay: 0.3s; }
.neuro-lines .line.li7 { animation-delay: 0.38s; }
.neuro-lines .line.li8 { animation-delay: 0.2s; }
.neuro-lines .line.li9 { animation-delay: 0.32s; }
/* R, I, T, I, N — появляются после AI */
.neuro-lines .line.lr1 { animation-delay: 0.5s; }
.neuro-lines .line.lr2 { animation-delay: 0.58s; }
.neuro-lines .line.lr3 { animation-delay: 0.66s; }
.neuro-lines .line.lr4 { animation-delay: 0.74s; }
.neuro-lines .line.lr5 { animation-delay: 0.82s; }
.neuro-lines .line.lr6 { animation-delay: 0.9s; }
.neuro-lines .line.li2-1, .neuro-lines .line.li2-2, .neuro-lines .line.li2-3 { animation-delay: 0.6s; }
.neuro-lines .line.lt1 { animation-delay: 0.65s; }
.neuro-lines .line.lt2 { animation-delay: 0.73s; }
.neuro-lines .line.lt3 { animation-delay: 0.7s; }
.neuro-lines .line.lt4 { animation-delay: 0.78s; }
.neuro-lines .line.li3-1, .neuro-lines .line.li3-2, .neuro-lines .line.li3-3 { animation-delay: 0.72s; }
.neuro-lines .line.ln1 { animation-delay: 0.8s; }
.neuro-lines .line.ln2 { animation-delay: 0.88s; }
.neuro-lines .line.ln3 { animation-delay: 0.96s; }
.neuro-lines .line.ln4 { animation-delay: 0.84s; }
.neuro-lines .line.ln5 { animation-delay: 0.92s; }

@keyframes neuro-draw {
    0%, 100% { stroke-dashoffset: 80; stroke: rgba(76, 98, 177, 0.25); }
    50% { stroke-dashoffset: 0; stroke: rgba(120, 160, 255, 0.9); }
}

/* Точки (узлы) внутри SVG */
.neuro-lines .neuro-node {
    fill: #2a3c64;
    filter: drop-shadow(0 0 4px rgba(76, 98, 177, 0.8));
    animation: neuro-pulse 1.5s ease-in-out infinite;
}

.neuro-lines .letter-ai .neuro-node { animation-delay: 0s; }
.neuro-lines .letter-ai .neuro-node:nth-child(4n+1) { animation-delay: 0.1s; }
.neuro-lines .letter-ai .neuro-node:nth-child(4n+2) { animation-delay: 0.2s; }
.neuro-lines .letter-ai .neuro-node:nth-child(4n+3) { animation-delay: 0.15s; }
.neuro-lines .letter-ai .neuro-node:nth-child(4n) { animation-delay: 0.25s; }
.neuro-lines .letter-rest .neuro-node {
    opacity: 0;
    animation: letter-rest-node-in 0.8s ease-out 1.2s forwards, neuro-pulse 1.5s ease-in-out 2s infinite;
}

/* Сначала показываем только AI, потом остальные буквы */
.neuro-lines .letter-rest {
    opacity: 0;
    animation: letter-rest-show 0.7s ease-out 1.2s forwards;
}

.neuro-lines .letter-rest .line {
    stroke-dashoffset: 80;
    animation: neuro-draw-rest 2s ease-in-out 1.5s infinite;
}

@keyframes letter-rest-show {
    to { opacity: 1; }
}

@keyframes neuro-draw-rest {
    0%, 100% { stroke-dashoffset: 80; stroke: rgba(76, 98, 177, 0.25); }
    50% { stroke-dashoffset: 0; stroke: rgba(120, 160, 255, 0.9); }
}

@keyframes letter-rest-node-in {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

.neuro-lines .letter-ai .neuro-node {
    animation: neuro-pulse 1.5s ease-in-out infinite;
}

@keyframes neuro-pulse {
    0%, 100% {
        filter: drop-shadow(0 0 4px rgba(76, 98, 177, 0.6));
        opacity: 0.9;
    }
    50% {
        filter: drop-shadow(0 0 10px rgba(120, 160, 255, 0.95));
        opacity: 1;
    }
}

.thinking-title {
    font-size: 18px;
    font-weight: 600;
    color: #fff;
    margin-bottom: 8px;
}

.thinking-sub {
    font-size: 14px;
    color: #9CA3AF;
    line-height: 1.45;
}

/* ——— Адаптивность для мобильных устройств ——— */
/* Кнопка меню (сайдбар) — показывается только на мобильных */
.sidebar-toggle {
    display: none;
    width: 40px;
    height: 40px;
    border: none;
    background: #282A2E;
    color: #E4E4E7;
    font-size: 20px;
    cursor: pointer;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.sidebar-toggle:hover {
    background: #35373B;
    color: #fff;
}

.main-header {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    flex-shrink: 0;
    border-bottom: 1px solid #282A2E;
    min-height: 56px;
}
.main-header .brand-mobile {
    font-weight: 700;
    font-size: 18px;
    color: #fff;
    letter-spacing: 0.02em;
}

/* Оверлей при открытом сайдбаре на мобильных */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
@media (min-width: 769px) {
    .sidebar-overlay { display: none !important; }
}
.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

@media (max-width: 768px) {
    body {
        overflow: auto;
    }

    .app {
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        min-width: 280px;
        max-width: 85vw;
        z-index: 60;
        transform: translateX(-100%);
        transition: transform 0.25s ease-out;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
    }
    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: flex;
    }
    .main-header {
        width: 100%;
        display: flex;
    }

    .main {
        padding-top: 0;
    }

    .main-title {
        font-size: 18px;
        padding: 16px 16px 12px;
    }

    .messages {
        padding: 12px 16px 20px;
    }

    .message {
        max-width: 90%;
        padding: 10px 14px;
    }

    .input-wrap {
        padding: 12px 16px 20px;
        gap: 10px;
    }

    .copyright {
        margin: 0 16px 12px;
        font-size: 11px;
    }

    .input-wrap input {
        padding: 10px 14px;
        font-size: 16px; /* уменьшает зум на iOS при фокусе */
    }

    .send-btn {
        width: 44px;
        height: 44px;
    }

    .modal {
        padding: 16px;
        align-items: flex-end;
    }

    .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-thinking .thinking-content {
        padding: 24px 20px;
        max-width: 100%;
    }

    .neuro-canvas {
        width: 100%;
        max-width: 260px;
        height: 64px;
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 100%;
        max-width: 100%;
    }

    .main-title {
        font-size: 16px;
        padding: 12px 12px 8px;
    }

    .messages {
        padding: 10px 12px 16px;
    }

    .message {
        max-width: 95%;
    }

    .input-wrap {
        padding: 10px 12px 16px;
    }

    .copyright {
        margin: 0 12px 10px;
        font-size: 11px;
    }

    .empty-state {
        padding: 24px 16px;
        font-size: 14px;
    }

    .btn-new-chat {
        padding: 12px 14px;
    }

    .chat-item {
        padding: 12px 14px;
    }
}
