/* Chat Page - Light Theme (Coherent with site) */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
    --sidebar-width: 260px;
    --sidebar-bg: #ffffff;
    --sidebar-hover: #f1f5f9;
    --sidebar-border: #e2e8f0;
    --chat-bg: #f8fafc;
    --message-user-bg: #0F172A;
    --message-bot-bg: #ffffff;
    --input-bg: #ffffff;
    --input-border: #e2e8f0;
    --text-primary: #0F172A;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --accent: #0D9488;
    --accent-hover: #0F766E;
    --accent-light: rgba(13, 148, 136, 0.1);
    --gradient-primary: #0F172A;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -1px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -2px rgba(15, 23, 42, 0.04);
    --border-radius: 12px;
    --border-radius-lg: 16px;
    --border-radius-xl: 24px;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body.chat-body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--chat-bg);
    color: var(--text-primary);
    display: flex;
    height: 100vh;
    height: 100dvh;
}

/* ==================== */
/* SIDEBAR              */
/* ==================== */
.chat-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
    height: 100dvh;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-logo {
    display: block;
    font-size: 1.5rem;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-decoration: none;
    margin-bottom: 1rem;
}

.new-chat-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--gradient-primary);
    border: none;
    border-radius: var(--border-radius);
    color: white;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.new-chat-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.new-chat-btn svg {
    width: 18px;
    height: 18px;
}

.sidebar-nav {
    padding: 0.75rem 0.75rem;
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
}

.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: var(--text-primary);
}

.sidebar-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sidebar-history {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

.history-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.25rem;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item:hover {
    background: var(--sidebar-hover);
    color: var(--text-primary);
}

.history-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.6;
}

.history-empty {
    padding: 1.5rem 0.75rem;
    color: var(--text-muted);
    font-size: 0.8125rem;
    text-align: center;
}

.sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid var(--sidebar-border);
}

.sidebar-login-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--border-radius);
    width: 100%;
    transition: all 0.2s ease;
}

.sidebar-login-btn:hover {
    background: var(--sidebar-hover);
    color: var(--text-primary);
}

.sidebar-login-btn svg {
    width: 18px;
    height: 18px;
}

/* ==================== */
/* MOBILE HEADER        */
/* ==================== */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--sidebar-border);
    padding: 0 1rem;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
}

.menu-toggle,
.new-chat-mobile {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--border-radius);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.2s ease;
}

.menu-toggle:hover,
.new-chat-mobile:hover {
    background: var(--sidebar-hover);
}

.menu-toggle svg,
.new-chat-mobile svg {
    width: 22px;
    height: 22px;
}

.mobile-title {
    font-weight: 700;
    font-size: 1.125rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ==================== */
/* MAIN CHAT AREA       */
/* ==================== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: var(--chat-bg);
}

/* ==================== */
/* WELCOME SCREEN       */
/* ==================== */
.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    padding-bottom: 0;
    overflow-y: auto;
}

.welcome-screen.hidden {
    display: none;
}

.welcome-content {
    max-width: 700px;
    width: 100%;
    text-align: center;
}

.welcome-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1.5rem;
    background: var(--gradient-primary);
    border-radius: var(--border-radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
}

.welcome-icon svg {
    width: 32px;
    height: 32px;
    color: white;
}

.welcome-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.welcome-subtitle {
    font-size: 1.0625rem;
    color: var(--text-secondary);
    margin-bottom: 3rem;
}

.prompt-suggestions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.suggestion-card {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.25rem;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--border-radius-lg);
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
}

.suggestion-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.suggestion-icon {
    width: 40px;
    height: 40px;
    background: var(--accent-light);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.suggestion-icon svg {
    width: 20px;
    height: 20px;
    color: var(--accent);
}

.suggestion-text {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.suggestion-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
}

.suggestion-desc {
    font-size: 0.8125rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==================== */
/* MESSAGES             */
/* ==================== */
.messages-container {
    flex: 1;
    overflow-y: auto;
    display: none;
}

.messages-container.active {
    display: block;
}

.messages-list {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1.5rem 2rem;
}

.message {
    display: flex;
    gap: 1rem;
    padding: 1.5rem 0;
    animation: messageIn 0.3s ease;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 600;
}

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

.message.assistant .message-avatar {
    background: var(--accent-light);
    color: var(--accent);
}

.message-avatar svg {
    width: 18px;
    height: 18px;
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-sender {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.message-text {
    font-size: 0.9375rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.message-text p {
    margin-bottom: 1rem;
}

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

.message-text code {
    background: var(--sidebar-hover);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, 'Consolas', monospace;
    font-size: 0.875rem;
    color: #e11d48;
}

.message-text pre {
    background: #1e293b;
    color: #e2e8f0;
    border-radius: var(--border-radius);
    padding: 1rem;
    overflow-x: auto;
    margin: 1rem 0;
}

.message-text pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

.message-image {
    max-width: 300px;
    border-radius: var(--border-radius);
    margin-top: 0.75rem;
    border: 1px solid var(--sidebar-border);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 0.5rem 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

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

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

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

/* ==================== */
/* INPUT AREA - FIXED   */
/* ==================== */
.input-area {
    flex-shrink: 0;
    padding: 1.5rem;
    background: var(--chat-bg);
    border-top: 1px solid var(--sidebar-border);
}

.input-container {
    max-width: 800px;
    margin: 0 auto;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    background: var(--input-bg);
    border: 2px solid var(--input-border);
    border-radius: var(--border-radius-xl);
    padding: 0.75rem 1rem;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-md);
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: var(--shadow-lg), 0 0 0 3px var(--accent-light);
}

.attach-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--sidebar-hover);
    border: none;
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.attach-btn:hover {
    background: var(--accent-light);
    color: var(--accent);
}

.attach-btn svg {
    width: 20px;
    height: 20px;
}

#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    max-height: 200px;
    min-height: 24px;
    padding: 0.5rem 0;
}

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

.send-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-primary);
    border: none;
    border-radius: var(--border-radius);
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

.send-btn:disabled {
    background: var(--sidebar-hover);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
}

.send-btn svg {
    width: 18px;
    height: 18px;
}

.send-btn.loading {
    background: #ef4444;
}

.input-disclaimer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.75rem;
}

/* Image Preview */
.image-preview {
    display: none;
    margin-bottom: 0.75rem;
}

.image-preview.active {
    display: block;
}

.preview-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.preview-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: var(--border-radius);
    overflow: hidden;
    border: 1px solid var(--sidebar-border);
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-remove:hover {
    background: #ef4444;
}

/* File preview for non-image files */
.preview-item.file-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--sidebar-hover);
    gap: 0.25rem;
}

.preview-item .file-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.preview-item .file-name {
    font-size: 0.625rem;
    color: var(--text-secondary);
    text-align: center;
    word-break: break-all;
    line-height: 1.2;
}

.message-file-tag {
    display: inline-block;
    padding: 0.375rem 0.75rem;
    background: var(--sidebar-hover);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--border-radius);
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin: 0.25rem 0.25rem 0.25rem 0;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 199;
    backdrop-filter: blur(4px);
}

.sidebar-overlay.active {
    display: block;
}

/* ==================== */
/* RESPONSIVE           */
/* ==================== */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
    }

    .chat-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 200;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        width: var(--sidebar-width);
    }
    
    .chat-sidebar.open {
        transform: translateX(0);
    }
    
    .mobile-header {
        display: flex;
    }
    
    .chat-main {
        padding-top: 56px;
    }
    
    .welcome-screen {
        padding: 1.5rem 1rem;
        align-items: flex-start;
    }
    
    .welcome-content {
        padding: 0;
    }

    .welcome-icon {
        width: 56px;
        height: 56px;
        margin-bottom: 1rem;
    }

    .welcome-icon svg {
        width: 28px;
        height: 28px;
    }
    
    .welcome-title {
        font-size: 1.375rem;
    }

    .welcome-subtitle {
        font-size: 0.9375rem;
        margin-bottom: 2rem;
    }
    
    .prompt-suggestions {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .suggestion-card {
        padding: 1rem;
    }

    .suggestion-icon {
        width: 36px;
        height: 36px;
    }

    .suggestion-icon svg {
        width: 18px;
        height: 18px;
    }

    .suggestion-title {
        font-size: 0.875rem;
    }

    .suggestion-desc {
        font-size: 0.75rem;
    }
    
    .messages-list {
        padding: 1rem 0.75rem;
    }
    
    .message {
        gap: 0.625rem;
        padding: 0.875rem 0;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
    }

    .message-sender {
        font-size: 0.8125rem;
    }

    .message-text {
        font-size: 0.875rem;
        line-height: 1.6;
    }

    .message-text pre {
        padding: 0.75rem;
        font-size: 0.8125rem;
    }
    
    .input-area {
        padding: 0.5rem 0.75rem;
        padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
    }

    .input-disclaimer {
        display: none;
    }
    
    .input-wrapper {
        padding: 0.5rem 0.625rem;
        border-radius: var(--border-radius-lg);
    }

    .attach-btn,
    .send-btn {
        width: 36px;
        height: 36px;
    }

    .attach-btn svg,
    .send-btn svg {
        width: 18px;
        height: 18px;
    }

    #messageInput {
        font-size: 16px !important;
        padding: 0.375rem 0;
    }

    .input-disclaimer {
        font-size: 0.6875rem;
        margin-top: 0.5rem;
    }

    .preview-item {
        width: 60px;
        height: 60px;
    }

    /* Safe area for notched phones */
    .mobile-header {
        padding-top: env(safe-area-inset-top);
    }
}

@media (max-width: 380px) {
    .welcome-title {
        font-size: 1.25rem;
    }

    .welcome-subtitle {
        font-size: 0.875rem;
    }

    .suggestion-card {
        padding: 0.875rem;
        gap: 0.75rem;
    }

    .suggestion-icon {
        width: 32px;
        height: 32px;
    }

    .message-text {
        font-size: 0.8125rem;
    }

    .input-wrapper {
        padding: 0.375rem 0.5rem;
    }

    .attach-btn,
    .send-btn {
        width: 32px;
        height: 32px;
    }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--sidebar-border);
    border-radius: 3px;
}

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