/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #1a1a2e;
    color: #e2e8f0;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
}

/* Header Styles */
.header {
    background: linear-gradient(135deg, #16213e 0%, #1a1a2e 100%);
    padding: 12px 16px;
    border-bottom: 1px solid #2d3748;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    min-height: 56px;
}

.logo {
    font-size: 1.1rem;
    font-weight: 700;
    background: linear-gradient(135deg, #a855f7 0%, #c084fc 50%, #e879f9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Inter', sans-serif;
    letter-spacing: -0.02em;
}

.logo img {
    width: 32px;
    height: 32px;
    border-radius: 6px;
}

.clear-btn {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid #ef4444;
    color: #fca5a5;
    padding: 6px 12px;
    border-radius: 16px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.clear-btn:hover {
    background: rgba(239, 68, 68, 0.3);
    transform: translateY(-1px);
}

/* Chat Container */
.chat-container {
    flex: 1;
    padding: 16px;
    padding-bottom: 120px; /* Space for floating input */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    max-width: 100%;
    margin: 0 auto;
    width: 100%;
    /* Hide scrollbars */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

.chat-container::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 24px 20px;
    background: rgba(168, 85, 247, 0.05);
    border-radius: 12px;
    border: 1px solid rgba(168, 85, 247, 0.2);
    margin-bottom: 16px;
    max-width: 600px;
    margin: 0 auto 16px auto;
}

.welcome-message h2 {
    color: #a855f7;
    margin-bottom: 8px;
    font-size: 1.3rem;
}

.welcome-message p {
    opacity: 0.8;
    line-height: 1.5;
    font-size: 0.9rem;
}

.welcome-message kbd {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Message Styles */
.message {
    display: flex;
    margin-bottom: 12px;
    animation: slideIn 0.3s ease-out;
}

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

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

.message.ai {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 16px 20px;
    border-radius: 20px;
    position: relative;
    word-wrap: break-word;
    line-height: 1.5;
}

.message.user .message-bubble {
    background: linear-gradient(135deg, #a855f7, #8a2be2);
    color: white;
    border-bottom-right-radius: 8px;
    box-shadow: 0 4px 15px rgba(168, 85, 247, 0.3);
}

.message.ai .message-bubble {
    background: #4a5568;
    color: #e2e8f0;
    border-bottom-left-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* Avatar Styles */
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin: 0 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    flex-shrink: 0;
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.message.user .avatar {
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.message.ai .avatar {
    background: linear-gradient(135deg, #a855f7, #8a2be2);
    padding: 0;
}

/* Markdown Content Styles */
.message-bubble h1, .message-bubble h2, .message-bubble h3 {
    margin: 10px 0;
    color: inherit;
}

.message-bubble ul, .message-bubble ol {
    margin: 10px 0;
    padding-left: 20px;
}

.message-bubble li {
    margin: 5px 0;
}

.message-bubble pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 8px;
    margin: 10px 0;
    overflow-x: auto;
    border-left: 3px solid #a855f7;
}

.message-bubble code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}

.message-bubble pre code {
    background: none;
    padding: 0;
}

.message-bubble strong {
    color: #a855f7;
}

.message-bubble a {
    color: #60a5fa;
    text-decoration: none;
}

.message-bubble a:hover {
    text-decoration: underline;
}

/* Typing Indicator */
/* Typing indicator - horizontally aligned with avatar */
.external-typing-indicator {
    display: flex;
    align-items: center;
    height: 40px; /* Match avatar height */
}

.external-typing-indicator .typing-dots {
    display: flex;
    gap: 4px;
}

.external-typing-indicator .typing-dots span {
    width: 6px;
    height: 6px;
    background-color: #a855f7;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

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

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

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

.typing-indicator {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 16px 20px;
    min-height: 20px;
}

.typing-dots {
    display: flex;
    gap: 6px;
    align-items: center;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #a855f7;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
    opacity: 0.4;
}

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

.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.4;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* Loading message bubble specific styling */
.message.ai .message-bubble .typing-indicator {
    padding: 12px 16px;
    background: transparent;
}

/* Message Actions - under bubble, always visible */
.message-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.message-actions .copy-btn {
    background: rgba(45, 55, 72, 0.8);
    border: 1px solid rgba(74, 85, 104, 0.6);
    border-radius: 6px;
    color: #a855f7;
    cursor: pointer;
    padding: 6px;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

.message-actions .copy-btn:hover {
    background: rgba(55, 65, 82, 0.9);
    color: #c084fc;
}

.message-actions .copy-btn.copied {
    color: #10b981;
    border-color: rgba(16, 185, 129, 0.6);
}

.message-actions .copy-btn svg {
    width: 14px;
    height: 14px;
}

.message-actions .generation-time {
    font-size: 0.75rem;
    color: #a0aec0;
    font-weight: 500;
}

/* Input Container */
.input-container {
    background: transparent;
    padding: 20px;
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 40px);
    max-width: 800px;
    z-index: 50;
}

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: center;
    max-width: 100%;
    margin: 0 auto;
    background: rgba(45, 55, 72, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 24px;
    padding: 16px;
    border: 1px solid rgba(74, 85, 104, 0.6);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.input-field {
    flex: 1;
    background: rgba(26, 26, 46, 0.8);
    border: 1px solid rgba(74, 85, 104, 0.4);
    border-radius: 16px;
    padding: 12px 16px;
    color: #e2e8f0;
    font-size: 16px; /* 16px prevents iOS auto-zoom */
    resize: none;
    min-height: 20px;
    max-height: 200px;
    outline: none;
    transition: all 0.2s ease;
    font-family: inherit;
    line-height: 1.4;
}

.input-field:focus {
    border-color: rgba(168, 85, 247, 0.6);
    box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.1);
    background: rgba(26, 26, 46, 0.9);
}

.input-field::placeholder {
    color: #a0aec0;
}

.send-btn, .stop-btn {
    background: linear-gradient(135deg, #a855f7, #8a2be2);
    border: none;
    border-radius: 12px;
    width: 44px;
    height: 44px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease;
    box-shadow: 0 2px 8px rgba(168, 85, 247, 0.3);
    flex-shrink: 0;
}

.send-btn:hover, .stop-btn:hover {
    opacity: 0.9;
}

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

.stop-btn {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
    display: none;
}

/* Scroll to Bottom Button */
.scroll-to-bottom {
    position: fixed;
    right: 24px;
    bottom: 120px;
    width: 48px;
    height: 48px;
    background: rgba(45, 55, 72, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(74, 85, 104, 0.6);
    border-radius: 50%;
    color: #a855f7;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
    z-index: 40;
}

.scroll-to-bottom:hover {
    background: rgba(55, 65, 82, 0.95);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.scroll-to-bottom svg {
    width: 20px;
    height: 20px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .header {
        padding: 12px 16px;
    }

    .logo {
        font-size: 1.3rem;
    }

    .chat-container {
        padding: 16px;
        padding-bottom: 100px;
        max-width: none;
    }

    .message-bubble {
        max-width: 90%;
        padding: 14px 16px;
    }

    .avatar {
        width: 32px;
        height: 32px;
        margin: 0 8px;
        font-size: 1rem;
    }

    .input-container {
        position: fixed;
        bottom: 0;
        left: 0;
        transform: none;
        width: 100%;
        max-width: none;
        padding: 8px 12px 8px 12px; /* Reduced padding for smaller screens */
        background: #1a1a2e;
        border-top: 1px solid #2d3748;
    }

    .input-wrapper {
        background: transparent;
        backdrop-filter: none;
        border-radius: 0;
        padding: 0;
        border: none;
        box-shadow: none;
        gap: 8px; /* Smaller gap between input and buttons */
    }

    .input-field {
        background: #2d3748;
        border: 1px solid #4a5568;
        border-radius: 20px; /* Slightly smaller border radius */
        padding: 12px 16px; /* Reduced padding */
        font-size: 16px; /* Maintain 16px to prevent iOS zoom */
        line-height: 1.3; /* Tighter line height for mobile */
        min-height: 16px; /* Smaller min-height */
        max-height: 120px; /* Smaller max-height for mobile */
    }

    .send-btn, .stop-btn {
        width: 40px; /* Smaller buttons */
        height: 40px;
        border-radius: 10px; /* Smaller border radius */
    }

    .send-btn svg, .stop-btn svg {
        width: 18px; /* Smaller icons */
        height: 18px;
    }

    .welcome-message {
        padding: 30px 16px;
        max-width: none;
        margin: 0 0 20px 0;
    }

    .welcome-message h2 {
        font-size: 1.5rem;
    }

    .scroll-to-bottom {
        right: 16px;
        bottom: 100px;
        width: 44px;
        height: 44px;
    }

    .scroll-to-bottom svg {
        width: 18px;
        height: 18px;
    }
}

/* Desktop Responsive */
@media (min-width: 769px) {
    .header {
        padding: 16px 32px;
        height: 60px;
    }

    .logo {
        font-size: 1.5rem;
        font-weight: 700;
        letter-spacing: -0.03em;
    }

    .logo img {
        width: 38px;
        height: 38px;
    }

    .chat-container {
        padding: 24px 32px;
        padding-bottom: 110px;
        gap: 16px;
    }

    .message-bubble {
        max-width: 65%;
        padding: 16px 20px;
        font-size: 0.95rem;
        line-height: 1.6;
    }

    .avatar {
        width: 36px;
        height: 36px;
        margin: 0 12px;
        font-size: 1.1rem;
    }

    .input-container {
        bottom: 12px;
        max-width: 900px;
    }

    .input-field {
        padding: 14px 18px;
        font-size: 0.95rem;
        border-radius: 16px;
        max-height: 150px;
    }

    .send-btn, .stop-btn {
        width: 44px;
        height: 44px;
    }

    .welcome-message {
        padding: 24px 28px;
        max-width: 580px;
        margin: 12px auto;
    }

    .welcome-message h2 {
        font-size: 1.4rem;
        margin-bottom: 8px;
    }

    .welcome-message p {
        font-size: 0.9rem;
        max-width: 450px;
        margin: 0 auto;
    }

    .clear-btn {
        padding: 8px 16px;
        font-size: 0.85rem;
    }

    .desktop-shortcuts {
        display: block !important;
    }

    .scroll-to-bottom {
        right: 32px;
        bottom: 100px;
        width: 52px;
        height: 52px;
    }

    .scroll-to-bottom svg {
        width: 22px;
        height: 22px;
    }
}

/* Large Desktop */
@media (min-width: 1200px) {
    .chat-container {
        padding: 32px 64px;
        padding-bottom: 120px;
        max-width: 1400px;
        margin: 0 auto;
    }

    .input-container {
        bottom: 16px;
        max-width: 1000px;
    }

    .input-wrapper {
        max-width: 1200px;
        margin: 0 auto;
    }

    .message-bubble {
        max-width: 55%;
        padding: 18px 22px;
        font-size: 0.98rem;
    }

    .welcome-message {
        padding: 32px 36px;
        max-width: 650px;
    }

    .welcome-message h2 {
        font-size: 1.5rem;
    }

    .welcome-message p {
        font-size: 0.95rem;
    }
}

/* Extra small mobile devices */
@media (max-width: 480px) {
    .input-container {
        padding: 6px 8px; /* Even smaller padding for very small screens */
    }
    
    .input-field {
        padding: 10px 14px; /* Smaller padding */
        border-radius: 18px; /* Smaller border radius */
        font-size: 16px; /* Keep 16px to prevent zoom */
    }
    
    .send-btn, .stop-btn {
        width: 36px; /* Even smaller buttons */
        height: 36px;
        border-radius: 8px;
    }
    
    .send-btn svg, .stop-btn svg {
        width: 16px; /* Smaller icons */
        height: 16px;
    }
    
    .input-wrapper {
        gap: 6px; /* Smaller gap */
    }
}

/* Ultra-wide Desktop */
@media (min-width: 1600px) {
    .chat-container {
        padding: 40px 80px;
        padding-bottom: 130px;
        max-width: 1600px;
    }

    .input-container {
        bottom: 20px;
        max-width: 1200px;
    }

    .input-wrapper {
        max-width: 1400px;
    }

    .message-bubble {
        max-width: 50%;
        padding: 20px 24px;
    }
}
