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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: #0d0d0d;
    color: #e0e0e0;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    overflow: hidden;
    position: fixed;
    width: 100%;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 900px;
    margin: 0 auto;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background-color: #1a1a1a;
    border-bottom: 1px solid #2a2a2a;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #fff;
}

.mode-selector {
    display: flex;
    gap: 4px;
    background-color: #252525;
    padding: 4px;
    border-radius: 8px;
}

.mode-btn {
    background: none;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    color: #888;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn:hover {
    color: #e0e0e0;
}

.mode-btn.active {
    background-color: #6366f1;
    color: #fff;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.model-selector label {
    font-size: 0.875rem;
    color: #888;
}

.model-selector select {
    background-color: #252525;
    color: #e0e0e0;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.875rem;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.model-selector select:hover {
    border-color: #505050;
}

.model-selector select:focus {
    border-color: #6366f1;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0; /* Important for flex scrolling */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.chat-container::-webkit-scrollbar {
    width: 6px;
}

.chat-container::-webkit-scrollbar-track {
    background: #1a1a1a;
}

.chat-container::-webkit-scrollbar-thumb {
    background: #3a3a3a;
    border-radius: 3px;
}

.welcome-message {
    text-align: center;
    color: #666;
    margin: auto;
    font-size: 0.95rem;
}

.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 0.95rem;
    animation: fadeIn 0.3s ease;
}

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

.message.user {
    background-color: #6366f1;
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    background-color: #1f1f1f;
    color: #e0e0e0;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid #2a2a2a;
}

.message.assistant pre {
    background-color: #0d0d0d;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.message.assistant code {
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.875rem;
}

.message.error {
    background-color: #3d1f1f;
    border: 1px solid #5c2d2d;
    color: #f87171;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 16px;
    align-self: flex-start;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background-color: #4a4a4a;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

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

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

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

.input-area {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 24px;
    background-color: #1a1a1a;
    border-top: 1px solid #2a2a2a;
    flex-shrink: 0; /* Prevent input area from shrinking */
}

.input-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.image-preview {
    position: relative;
    display: inline-block;
    max-width: 200px;
}

.image-preview img {
    max-width: 200px;
    max-height: 150px;
    border-radius: 8px;
    border: 1px solid #3a3a3a;
}

.remove-image {
    position: absolute;
    top: -8px;
    right: -8px;
    background-color: #ef4444;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.remove-image:hover {
    background-color: #dc2626;
}

.remove-image svg {
    color: #fff;
}

.attach-btn {
    background-color: #252525;
    border: 1px solid #3a3a3a;
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: #888;
}

.attach-btn:hover {
    border-color: #6366f1;
    color: #e0e0e0;
}

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

.attach-btn.has-image {
    border-color: #6366f1;
    color: #6366f1;
}

.input-area textarea {
    flex: 1;
    background-color: #252525;
    border: 1px solid #3a3a3a;
    border-radius: 8px;
    padding: 12px 16px;
    color: #e0e0e0;
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 150px;
    transition: border-color 0.2s;
}

.input-area textarea:focus {
    border-color: #6366f1;
}

.input-area textarea::placeholder {
    color: #666;
}

.input-area button {
    background-color: #6366f1;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.input-area button:hover {
    background-color: #5355d1;
}

.input-area button:disabled {
    background-color: #3a3a3a;
    cursor: not-allowed;
}

@media (max-width: 600px) {
    header {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 12px;
        align-items: center;
    }

    header h1 {
        font-size: 1rem;
        flex: 1;
    }

    .user-info {
        order: 0;
        gap: 8px;
    }

    .user-email {
        display: none; /* Hide email on mobile to save space */
    }

    .logout-btn {
        padding: 6px 10px;
    }

    .mode-selector {
        order: 1;
        width: 100%;
    }

    .mode-btn {
        flex: 1;
        padding: 8px 12px;
    }

    .model-selector {
        width: 100%;
        order: 2;
    }

    .model-selector label {
        display: none;
    }

    .model-selector select {
        width: 100%;
        padding: 8px 10px;
        font-size: 0.85rem;
    }

    .chat-container {
        padding: 12px;
        gap: 10px;
    }

    .message {
        max-width: 88%;
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    .message.assistant pre {
        padding: 8px;
        font-size: 0.75rem;
    }

    .message.assistant code {
        font-size: 0.75rem;
    }

    .input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        gap: 8px;
    }

    .input-row {
        gap: 8px;
    }

    .input-area textarea {
        padding: 10px 12px;
        font-size: 16px; /* Prevents iOS zoom */
        min-height: 44px;
    }

    .input-area button#sendBtn {
        padding: 10px 12px;
        min-width: 44px;
        min-height: 44px;
    }

    .attach-btn {
        padding: 10px;
        min-width: 44px;
        min-height: 44px;
    }

    .image-preview {
        max-width: 120px;
    }

    .image-preview img {
        max-width: 120px;
        max-height: 80px;
    }
}

/* Extra small devices */
@media (max-width: 380px) {
    header {
        padding: 8px 10px;
    }

    header h1 {
        font-size: 0.95rem;
    }

    .message {
        max-width: 92%;
        padding: 8px 10px;
        font-size: 0.85rem;
    }

    .chat-container {
        padding: 10px;
        gap: 8px;
    }

    .input-area {
        padding: 8px 10px;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
}
