﻿:root {
    --bg-dark: #0a0a0f;
    --bg-panel: #1a1a2e;
    --bg-message-user: #2563eb;
    --bg-message-bot: #374151;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
    --error: #ef4444;
    --success: #22c55e;
    --shadow: rgba(0, 0, 0, 0.3);
    --gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

html, body {
    height: 100%;
    min-height: 0;
}

* {
    box-sizing: border-box;
}

.card {
    background: rgba(26, 26, 46, 0.9);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px var(--shadow),
    0 0 0 1px rgba(255, 255, 255, 0.05);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    opacity: 0.6;
}

#auth {
    padding: 40px 35px;
    width: 420px;
    max-width: 90vw;
}

#auth:hover {
    transform: translateY(-4px);
    box-shadow: 0 35px 60px -12px var(--shadow),
    0 0 0 1px rgba(255, 255, 255, 0.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
    background: linear-gradient(135deg, #0f0f23 0%, #1a1a2e 50%, #16213e 100%) fixed;
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: stretch;
    height: 100vh;
    overflow: hidden;
    margin: 0;
    padding: 20px;
    min-height: 0;
}

#chat {
    display: grid;
    grid-template-rows: 1fr auto auto;
    row-gap: 15px;
    height: 90vh;
    width: 90%;
    max-width: 95vw;
    padding: 25px;
    background: rgba(26,26,46,0.9);
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px var(--shadow);
    min-height: 0;
}

#messages {
    grid-row: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
    margin: 0;
    background: rgba(15,15,35,0.6);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 20px;
    backdrop-filter: blur(10px);
    scroll-behavior: smooth;
    min-height: 0;
}

.input-container {
    grid-row: 2;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-shrink: 0;
    min-height: 70px;
}

.logout-container {
    grid-row: 3;
    text-align: center;
    margin-top: 10px;
}

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

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

#messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

#chat h1 {
    flex-shrink: 0;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

h1 {
    margin: 0 0 30px;
    color: var(--text-primary);
    font-size: 2rem;
    font-weight: 700;
    text-align: center;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

input, textarea {
    width: 100%;
    margin: 0 0 20px;
    padding: 16px 20px;
    border: 2px solid transparent;
    background: rgba(15, 15, 35, 0.8);
    border-radius: 16px;
    color: var(--text-primary);
    outline: none;
    font-size: 16px;
    font-family: inherit;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    resize: none;
}

input::placeholder, textarea::placeholder {
    color: var(--text-muted);
}

input:focus, textarea:focus {
    border-color: var(--accent);
    background: rgba(15, 15, 35, 1);
    transform: translateY(-1px);
    box-shadow: 0 10px 25px rgba(59, 130, 246, 0.15);
}

button {
    background: var(--accent);
    color: white;
    padding: 14px 24px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 15px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

button:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(59, 130, 246, 0.3);
}

button:hover::before {
    left: 100%;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.msg {
    padding: 16px 20px;
    border-radius: 18px;
    line-height: 1.5;
    max-width: 80%;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    animation: fadeIn 0.3s ease;
    position: relative;
    white-space: pre-wrap;
    margin: 0;
    flex-shrink: 0;
}

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

.msg.user {
    background: var(--bg-message-user);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.msg.bot {
    background: var(--bg-message-bot);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.msg.user::before {
    position: absolute;
    right: -40px;
    top: 16px;
    font-size: 18px;
}

.msg.bot::before {
    position: absolute;
    left: -40px;
    top: 16px;
    font-size: 18px;
}

.msg.loading {
    background: var(--bg-message-bot);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    padding: 10px 14px;
    max-width: fit-content;
    display: flex;
    align-items: center;
    justify-content: center;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 16px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typingAnimation 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingAnimation {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

#authMsg {
    margin-top: 15px;
    font-size: 14px;
    text-align: center;
    min-height: 20px;
    padding: 10px;
    border-radius: 8px;
    transition: all 0.3s ease;
}

#authMsg.error {
    color: var(--error);
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

#authMsg.success {
    color: var(--success);
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.2);
}

#msgInput {
    flex: 1;
    margin: 0;
    border-radius: 20px;
    padding: 16px 24px;
    min-height: 56px;
    max-height: 120px;
    overflow-y: auto;
}

#send {
    background: var(--accent);
    border-radius: 50%;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 18px;
    flex-shrink: 0;
}

#send::after {
    content: "➤";
    font-weight: bold;
}

#send.loading::after {
    content: '';
}

#send.loading {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

#logout {
    background: linear-gradient(135deg, #6b7280, #4b5563);
    border-radius: 12px;
}

.auth-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 20px;
}

.logout-container {
    text-align: center;
    margin-top: 15px;
    flex-shrink: 0;
}

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

.model-select {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

.model-select select {
    background: rgba(15, 15, 35, 0.8);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
}

.model-select select:hover,
.model-select select:focus {
    border-color: var(--accent);
    background: rgba(15, 15, 35, 1);
}

@media (max-width: 768px) {
    #chat {
        width: 95vw;
        height: 95vh;
        max-height: 95vh;
        padding: 15px;
    }

    #auth {
        width: 95vw;
        padding: 30px 20px;
    }

    .msg {
        max-width: 85%;
    }

    .msg.user::before {
        right: -35px;
        font-size: 16px;
    }

    .msg.bot::before {
        left: -35px;
        font-size: 16px;
    }

    h1 {
        font-size: 1.8rem;
    }
}

@media (max-width: 480px) {
    .msg {
        max-width: 90%;
    }

    .msg.user::before,
    .msg.bot::before {
        display: none;
    }

    #chat {
        padding: 10px;
    }

    #messages {
        padding: 15px;
    }
}