@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=DM+Sans:wght@300;400;500&display=swap');

:root {
    --bg: #0a0a0f;
    --surface: #111118;
    --surface2: #1a1a24;
    --border: #2a2a3a;
    --accent: #7c6aff;
    --accent-glow: rgba(124, 106, 255, 0.25);
    --text: #e8e8f0;
    --text-muted: #6a6a82;
    --user-bg: #7c6aff;
    --bot-bg: #1a1a24;
    --error: #ff4d6a;
    --success: #4dffb4;
}

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

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background-image:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(124, 106, 255, 0.12), transparent),
        radial-gradient(ellipse 60% 40% at 80% 100%, rgba(100, 80, 220, 0.08), transparent);
}

.chat-app {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    width: 100%;
    max-width: 720px;
    height: 88vh;
    max-height: 820px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow:
        0 0 0 1px rgba(124, 106, 255, 0.1),
        0 24px 80px rgba(0, 0, 0, 0.6),
        0 0 60px rgba(124, 106, 255, 0.05);
}

/* HEADER */
.header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.header::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent);
    animation: pulse 2s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 10px var(--accent); }
    50% { opacity: 0.5; box-shadow: 0 0 4px var(--accent); }
}

.header p {
    font-family: 'Space Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* LLM SELECTOR */
.llm-selector {
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
}

.llm-select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-family: 'Space Mono', monospace;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    appearance: none;
}

.llm-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* CHAT CONTAINER */
#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}

#chat-container::-webkit-scrollbar {
    width: 4px;
}
#chat-container::-webkit-scrollbar-track {
    background: transparent;
}
#chat-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* MESSAGES */
.message {
    padding: 12px 16px;
    border-radius: 16px;
    max-width: 78%;
    word-wrap: break-word;
    line-height: 1.6;
    font-size: 0.92rem;
    animation: fadeUp 0.25s ease-out;
}

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

.user-message {
    background: var(--user-bg);
    color: #fff;
    margin-left: auto;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 20px rgba(124, 106, 255, 0.3);
}

.bot-message {
    background: var(--bot-bg);
    color: var(--text);
    margin-right: auto;
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.error-message {
    background: rgba(255, 77, 106, 0.1);
    color: var(--error);
    border: 1px solid rgba(255, 77, 106, 0.3);
}

/* LOADING */
.loading {
    display: none;
    padding: 14px 18px;
    background: var(--bot-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    max-width: 78%;
    margin-right: auto;
    gap: 6px;
    align-items: center;
}

.loading[style*="block"] {
    display: flex !important;
}

.loading-dots {
    display: inline-block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent);
    animation: dots 1.2s infinite ease-in-out both;
}
.loading-dots:nth-child(1) { animation-delay: -0.32s; }
.loading-dots:nth-child(2) { animation-delay: -0.16s; }

@keyframes dots {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* RESPONSE TIME */
.response-time {
    font-family: 'Space Mono', monospace;
    font-size: 0.68rem;
    color: #39ff8f;
    text-shadow: 0 0 8px #39ff8f, 0 0 20px rgba(57, 255, 143, 0.5);
    padding: 4px 8px;
    margin-bottom: 8px;
    letter-spacing: 0.08em;
}

/* INPUT SECTION */
.input-section {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface2);
    display: flex;
    gap: 10px;
    align-items: center;
}

#message-input {
    flex: 1;
    padding: 12px 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 0.92rem;
    font-family: 'DM Sans', sans-serif;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
}

#message-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#message-input::placeholder {
    color: var(--text-muted);
}

#message-input:disabled {
    opacity: 0.5;
}

.send-button {
    padding: 12px 22px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-family: 'Space Mono', monospace;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-shadow: 0 4px 16px rgba(124, 106, 255, 0.4);
}

.send-button:hover:not(:disabled) {
    background: #9080ff;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(124, 106, 255, 0.5);
}

.send-button:active:not(:disabled) {
    transform: translateY(0);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* MOBILE */
@media (max-width: 600px) {
    body {
        padding: 0;
        justify-content: flex-start;
    }

    .chat-app {
        height: 100vh;
        max-height: none;
        border-radius: 0;
        border: none;
        box-shadow: none;
    }

    .header {
        padding: 16px 18px 12px;
    }

    #chat-container {
        padding: 16px;
    }

    .message {
        max-width: 88%;
        font-size: 0.88rem;
    }

    .input-section {
        padding: 12px 14px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        flex-wrap: wrap;
    }

    #message-input {
        font-size: 16px; /* prevent iOS zoom */
    }

    .send-button {
        width: 100%;
        padding: 13px;
        text-align: center;
    }
}
