/* Reset y variables */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #1a73e8;
    --primary-hover: #1557b0;
    --secondary-color: #34a853;
    --background: #f8f9fa;
    --surface: #ffffff;
    --text-primary: #202124;
    --text-secondary: #5f6368;
    --border-color: #dadce0;
    --user-bubble: #1a73e8;
    --ai-bubble: #f1f3f4;
    --shadow-sm: 0 1px 2px 0 rgba(60, 64, 67, 0.3);
    --shadow-md: 0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15);
    --shadow-lg: 0 2px 4px -1px rgba(0, 0, 0, 0.2), 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --header-height: 64px;
    --footer-height: auto;
}

/* Base */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 100%;
    margin: 0 auto;
    background: var(--surface);
}

/* Header */
.chat-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 100;
    position: sticky;
    top: 0;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    height: var(--header-height);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-info h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}

.status {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ea4335;
}

.status.connected::before {
    background: var(--secondary-color);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.btn-new-chat {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-new-chat:hover {
    background: var(--background);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-new-chat:active {
    transform: scale(0.95);
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: var(--background);
    scroll-behavior: smooth;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 800px;
    margin: 0 auto;
}

/* Messages */
.message {
    display: flex;
    animation: slideIn 0.3s ease-out;
}

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

.message-content {
    display: flex;
    gap: 8px;
    max-width: 85%;
}

.user-message {
    justify-content: flex-end;
}

.user-message .message-content {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--background);
}

.user-message .message-avatar {
    background: var(--primary-color);
}

.user-message .message-avatar::after {
    content: '👤';
    font-size: 16px;
}

.message-bubble {
    border-radius: var(--radius-md);
    padding: 12px 16px;
    box-shadow: var(--shadow-sm);
}

.ai-message .message-bubble {
    background: var(--ai-bubble);
    border-bottom-left-radius: 4px;
}

.user-message .message-bubble {
    background: var(--user-bubble);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-text {
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message-text p {
    margin-bottom: 8px;
}

.message-text p:last-child {
    margin-bottom: 0;
}

.message-text ul {
    margin: 8px 0;
    padding-left: 20px;
}

.message-text li {
    margin: 4px 0;
}

.message-text strong {
    font-weight: 600;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    opacity: 0.7;
}

.user-message .message-time {
    color: rgba(255, 255, 255, 0.8);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 8px;
    align-items: center;
    max-width: 800px;
    margin: 0 auto;
}

.typing-dots {
    background: var(--ai-bubble);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    display: flex;
    gap: 4px;
    box-shadow: var(--shadow-sm);
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typing 1.4s infinite;
}

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

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Input Area */
.chat-input-area {
    background: var(--surface);
    border-top: 1px solid var(--border-color);
    padding: 12px 16px;
    box-shadow: var(--shadow-md);
}

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

#messageInput {
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    font-family: inherit;
    font-size: 15px;
    resize: none;
    max-height: 120px;
    min-height: 44px;
    transition: border-color 0.2s ease;
    background: var(--surface);
    color: var(--text-primary);
}

#messageInput:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}

#messageInput::placeholder {
    color: var(--text-secondary);
}

.btn-voice,
.btn-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    margin-left: 8px;
}

.btn-voice {
    background: var(--surface-color);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.btn-voice:hover {
    background: var(--background-color);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: scale(1.05);
}

.btn-voice.recording {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
    animation: pulse 1.5s ease-in-out infinite;
}

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

.btn-send:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.btn-send:active:not(:disabled) {
    transform: scale(0.95);
}

.btn-send:disabled {
    background: var(--border-color);
    cursor: not-allowed;
    opacity: 0.5;
}

.input-footer {
    text-align: center;
    margin-top: 8px;
}

.input-footer small {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: slideUp 0.3s ease-out;
}

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

.toast-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Responsive Design */

/* Tablets */
@media (min-width: 768px) {
    #app {
        max-width: 1200px;
        box-shadow: var(--shadow-md);
    }

    .chat-container {
        padding: 24px;
    }

    .message-content {
        max-width: 70%;
    }

    .header-info h1 {
        font-size: 20px;
    }
}

/* Desktop */
@media (min-width: 1024px) {
    .message-content {
        max-width: 60%;
    }

    .input-footer small {
        font-size: 13px;
    }
}

/* Mobile optimizations */
@media (max-width: 767px) {
    .chat-container {
        padding: 12px;
    }

    .message-content {
        max-width: 90%;
    }

    .message-bubble {
        padding: 10px 14px;
    }

    .message-text {
        font-size: 14px;
    }

    #messageInput {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .input-footer {
        display: none; /* Hide helper text on mobile */
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #202124;
        --surface: #292a2d;
        --text-primary: #e8eaed;
        --text-secondary: #9aa0a6;
        --border-color: #3c4043;
        --ai-bubble: #3c4043;
    }

    .user-message .message-bubble {
        background: #1967d2;
    }
}

/* Custom scrollbar */
.chat-container::-webkit-scrollbar {
    width: 8px;
}

.chat-container::-webkit-scrollbar-track {
    background: var(--background);
}

.chat-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Loading animation */
@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

.loading {
    background: linear-gradient(90deg, var(--ai-bubble) 0%, var(--border-color) 50%, var(--ai-bubble) 100%);
    background-size: 1000px 100%;
    animation: shimmer 2s infinite;
}
