:root {
    --primary-bg: #0a0a0a;
    --secondary-bg: #141414;
    --neon-purple: #9d24d3;
    --neon-orange: #ff7b00;
    --user-message-bg: rgba(157, 36, 211, 0.15);
    --assistant-message-bg: rgba(30, 30, 30, 0.7);
    --text-color: #ffffff;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--primary-bg);
    color: var(--text-color);
    line-height: 1.6;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: -webkit-fill-available;
}

.app-header {
    flex-shrink: 0;
    background-color: var(--secondary-bg);
    padding: 1rem;
    box-shadow: 0 2px 10px rgba(157, 36, 211, 0.2);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 1rem;
    max-width: 600px;
    margin: 0 auto;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--neon-purple);
    object-fit: cover;
    transition: all 0.3s ease;
}

.avatar:hover {
    transform: rotate(5deg) scale(1.1);
    border-width: 3px;
}

h1 {
    font-size: 1.5rem;
    background: linear-gradient(45deg, var(--neon-purple), var(--neon-orange));
    background-size: 200% 200%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 10px rgba(157, 36, 211, 0.3);
    animation: gradientText 5s ease infinite;
}

@keyframes gradientText {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    position: relative;
}

.messages {
    flex: 1;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
    will-change: transform;
}

.message {
    width: fit-content;
    max-width: 85%;
    padding: 0.8rem 1rem;
    border-radius: 1.2rem;
    backdrop-filter: blur(10px);
    word-break: break-word;
    white-space: pre-wrap;
    hyphens: auto;
    font-size: 0.95rem;
    line-height: 1.4;
    transition: transform 0.2s ease;
    opacity: 0;
    will-change: transform, opacity;
}

.message br {
    display: block;
    content: "";
    margin-top: 0.5em;
}

.message:hover {
    transform: translateY(-1px);
}

.user-message {
    background-color: var(--user-message-bg);
    align-self: flex-end;
    border-bottom-right-radius: 0.3rem;
    animation: slideInRight 0.3s ease forwards;
    background-image: linear-gradient(
        45deg,
        rgba(157, 36, 211, 0.15),
        rgba(157, 36, 211, 0.05)
    );
}

.assistant-message {
    background-color: var(--assistant-message-bg);
    align-self: flex-start;
    border-bottom-left-radius: 0.3rem;
    animation: slideInLeft 0.3s ease forwards;
    background-image: linear-gradient(
        45deg,
        rgba(255, 123, 0, 0.15),
        rgba(255, 123, 0, 0.05)
    );
}

.message img {
    max-width: 100%;
    border-radius: 0.8rem;
    margin-top: 0.5rem;
    animation: fadeIn 0.5s ease-out;
    transition: transform 0.3s ease;
}

.message img:hover {
    transform: scale(1.02);
}

.message::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: inherit;
    padding: 2px;
    background: linear-gradient(45deg, 
        rgba(157, 36, 211, 0.5), 
        rgba(255, 123, 0, 0.5)
    );
    -webkit-mask: 
        linear-gradient(#fff 0 0) content-box, 
        linear-gradient(#fff 0 0);
    mask: 
        linear-gradient(#fff 0 0) content-box, 
        linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0.5;
    animation: borderGlow 3s infinite;
}

@keyframes borderGlow {
    0% {
        opacity: 0.3;
    }
    50% {
        opacity: 0.6;
    }
    100% {
        opacity: 0.3;
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

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

.input-area {
    flex-shrink: 0;
    background-color: var(--secondary-bg);
    padding: 1rem;
    width: 100%;
    box-shadow: 0 -2px 10px rgba(157, 36, 211, 0.2);
    backdrop-filter: blur(10px);
    z-index: 100;
}

.input-container {
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

textarea {
    flex: 1;
    background-color: var(--primary-bg);
    border: 1px solid rgba(157, 36, 211, 0.3);
    border-radius: 1.5rem;
    padding: 0.8rem 1rem;
    color: var(--text-color);
    resize: none;
    max-height: 100px;
    font-size: 1rem;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
}

textarea:focus {
    outline: none;
    border-color: var(--neon-purple);
    background-color: rgba(157, 36, 211, 0.1);
}

.attach-button {
    background: rgba(157, 36, 211, 0.15);
    border: 1px solid rgba(157, 36, 211, 0.3);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(5px);
}

.attach-button:hover {
    transform: scale(1.05);
    background: rgba(157, 36, 211, 0.25);
}

.attach-button:active {
    transform: scale(0.9);
}

.attach-button.has-file {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

.attach-button svg {
    fill: rgba(255, 255, 255, 0.7);
    width: 20px;
    height: 20px;
}

.attach-button.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.send-button {
    background: rgba(157, 36, 211, 0.3);
    border: 1px solid rgba(157, 36, 211, 0.5);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(5px);
}

.send-button:hover {
    transform: scale(1.05);
    background: rgba(157, 36, 211, 0.4);
}

.send-button:active {
    transform: scale(0.9);
}

.send-button svg {
    fill: rgba(255, 255, 255, 0.9);
    width: 20px;
    height: 20px;
}

.error-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 0, 0, 0.1);
    border: 1px solid #ff0000;
    border-radius: 8px;
    padding: 15px 25px;
    color: #ff3333;
    z-index: 1000;
    backdrop-filter: blur(5px);
    display: none;
    animation: fadeIn 0.3s ease;
    box-shadow: 0 0 15px rgba(255, 0, 0, 0.2);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

/* Scrollbar styling */
.messages::-webkit-scrollbar {
    width: 8px;
}

.messages::-webkit-scrollbar-track {
    background: var(--primary-bg);
}

.messages::-webkit-scrollbar-thumb {
    background: var(--neon-purple);
    border-radius: 4px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: var(--neon-orange);
}

/* Стили для markdown */
.message code.inline-code {
    background: rgba(157, 36, 211, 0.1);
    padding: 0.2em 0.4em;
    border-radius: 0.3em;
    font-family: 'Fira Code', monospace;
    font-size: 0.9em;
    white-space: pre-wrap;
}

.message pre.code-block {
    background: rgba(0, 0, 0, 0.8);
    padding: 1em;
    border-radius: 0.5em;
    margin: 0.5em 0;
    overflow-x: auto;
    position: relative;
}

.message pre.code-block code {
    font-family: 'Fira Code', monospace;
    font-size: 0.9em;
    line-height: 1.5;
    display: block;
    color: #f8f8f2;
}

/* Подсветка синтаксиса */
.code-keyword { color: #ff79c6; }
.code-string { color: #f1fa8c; }
.code-number { color: #bd93f9; }
.code-comment { color: #6272a4; }
.code-function { color: #50fa7b; }
.code-variable { color: #8be9fd; }

.message strong {
    color: var(--neon-purple);
    font-weight: 600;
}

.message em {
    color: var(--neon-orange);
    font-style: italic;
}

.message a {
    color: var(--neon-purple);
    text-decoration: none;
    border-bottom: 1px solid rgba(157, 36, 211, 0.3);
    transition: all 0.2s ease;
}

.message a:hover {
    color: var(--neon-orange);
    border-bottom-color: var(--neon-orange);
}

/* Мобильные стили для markdown */
@media (max-width: 768px) {
    .message code.inline-code {
        font-size: 0.85em;
        padding: 0.15em 0.3em;
    }

    .message pre.code-block {
        padding: 0.8em;
        font-size: 0.85em;
        margin: 0.4em 0;
    }
    
    .message a {
        border-bottom-width: 2px;
    }
}

/* Стили для мобильных устройств */
@media (max-width: 768px) {
    .app-container {
        background: linear-gradient(
            to bottom,
            var(--primary-bg),
            var(--secondary-bg)
        );
    }

    .chat-container {
        padding: 0.5rem;
    }

    .messages {
        gap: 0.8rem;
    }

    .message {
        max-width: 90%;
        padding: 0.8rem 1rem;
        font-size: 1rem;
        line-height: 1.5;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    }

    .input-area {
        background: rgba(20, 20, 20, 0.95);
        backdrop-filter: blur(20px);
        border-top: 1px solid rgba(157, 36, 211, 0.2);
        padding: 0.8rem;
    }

    .input-container {
        background: rgba(255, 255, 255, 0.05);
        border-radius: 1.5rem;
        padding: 0.5rem;
        gap: 0.5rem;
    }

    textarea {
        background: transparent;
        font-size: 1rem;
        padding: 0.5rem 0.8rem;
        line-height: 1.4;
        min-height: 44px;
    }

    .send-button, .attach-button {
        width: 44px;
        height: 44px;
        padding: 0.7rem;
        background: rgba(157, 36, 211, 0.2);
        border-radius: 50%;
        transition: all 0.2s ease;
    }

    .send-button:active, .attach-button:active {
        transform: scale(0.95);
        background: rgba(157, 36, 211, 0.3);
    }

    /* Улучшенные градиенты для сообщений */
    .user-message {
        background: linear-gradient(
            135deg,
            rgba(157, 36, 211, 0.2),
            rgba(157, 36, 211, 0.1)
        );
        border: 1px solid rgba(157, 36, 211, 0.2);
    }

    .assistant-message {
        background: linear-gradient(
            135deg,
            rgba(255, 123, 0, 0.2),
            rgba(255, 123, 0, 0.1)
        );
        border: 1px solid rgba(255, 123, 0, 0.2);
    }
}

/* Специальные стили для iOS */
@supports (-webkit-touch-callout: none) {
    .message {
        border: 1px solid rgba(157, 36, 211, 0.2);
        box-shadow: 
            0 2px 8px rgba(0, 0, 0, 0.1),
            0 0 0 1px rgba(157, 36, 211, 0.1);
    }

    .user-message {
        border-color: rgba(157, 36, 211, 0.3);
    }

    .assistant-message {
        border-color: rgba(255, 123, 0, 0.3);
    }

    .input-area {
        backdrop-filter: blur(20px);
    }

    /* Улучшенный скроллинг */
    .messages {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        padding-bottom: calc(env(safe-area-inset-bottom) + 1rem);
    }

    /* Фикс для кнопок */
    .send-button, .attach-button {
        -webkit-tap-highlight-color: transparent;
    }
}

/* Убираем лишние эффекты на мобильных */
@media (hover: none) {
    .messages {
        scroll-behavior: auto;
    }
    
    .message::before {
        /* Облегченная версия рамки для мобильных */
        opacity: 0.3;
        animation: none;
        background: linear-gradient(45deg, 
            var(--neon-purple),
            var(--neon-orange)
        );
    }

    /* Уменьшаем интенсивность свечения */
    .message {
        box-shadow: 0 0 10px rgba(157, 36, 211, 0.1);
    }
}

/* Темные темы и OLED экраны */
@media (prefers-color-scheme: dark) {
    :root {
        --primary-bg: #000000;
        --secondary-bg: #0a0a0a;
        --text-color: #ffffff;
    }
}
