/* ==========================================================================
   NutriChat - CSS Design System & Theme Styles
   Theme: Fresh Emerald Health / Modern Glassmorphism
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CSS Variables & Theme Configuration
   -------------------------------------------------------------------------- */
:root {
    /* Color Palette - Light Mode */
    --primary-color: #10b981;
    --primary-hover: #059669;
    --primary-active: #047857;
    --primary-light: #ecfdf5;
    --primary-border: #a7f3d0;
    
    --accent-glow: rgba(16, 185, 129, 0.15);
    --accent-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --user-bubble-gradient: linear-gradient(135deg, #059669 0%, #10b981 100%);
    
    --bg-body: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-translucent: rgba(255, 255, 255, 0.85);
    --bg-chat-area: #f1f5f9;
    --bg-ai-bubble: #ffffff;
    --bg-input: #ffffff;
    --bg-badge: #e0e7ff;

    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --text-on-primary: #ffffff;
    --text-badge: #3730a3;

    --border-color: #e2e8f0;
    --border-focus: #10b981;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.08);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

/* Dark Mode Variables */
[data-theme="dark"] {
    --primary-color: #10b981;
    --primary-hover: #34d399;
    --primary-active: #059669;
    --primary-light: rgba(16, 185, 129, 0.12);
    --primary-border: rgba(16, 185, 129, 0.3);

    --accent-glow: rgba(16, 185, 129, 0.25);
    --user-bubble-gradient: linear-gradient(135deg, #059669 0%, #047857 100%);

    --bg-body: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-translucent: rgba(30, 41, 59, 0.88);
    --bg-chat-area: #0b1329;
    --bg-ai-bubble: #1e293b;
    --bg-input: #1e293b;
    --bg-badge: rgba(99, 102, 241, 0.2);

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-light: #64748b;
    --text-on-primary: #ffffff;
    --text-badge: #818cf8;

    --border-color: #334155;
    --border-focus: #34d399;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* --------------------------------------------------------------------------
   2. Reset & Global Styles
   -------------------------------------------------------------------------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    transition: background-color var(--transition-normal), color var(--transition-normal);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background-color: rgba(148, 163, 184, 0.3);
    border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
    background-color: rgba(148, 163, 184, 0.5);
}

/* --------------------------------------------------------------------------
   3. Main App Layout Structure
   -------------------------------------------------------------------------- */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1000px;
    margin: 0 auto;
    background-color: var(--bg-surface);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    position: relative;
}

/* --------------------------------------------------------------------------
   4. App Header Component
   -------------------------------------------------------------------------- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background-color: var(--bg-surface-translucent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    z-index: 10;
}

.brand-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    box-shadow: 0 4px 10px var(--accent-glow);
}

.brand-logo svg {
    width: 24px;
    height: 24px;
}

.brand-text {
    display: flex;
    flex-direction: column;
}

.brand-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.02em;
}

.brand-title .badge {
    font-size: 0.68rem;
    font-weight: 700;
    background-color: var(--primary-light);
    color: var(--primary-hover);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    border: 1px solid var(--primary-border);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.brand-subtitle {
    font-size: 0.81rem;
    color: var(--text-muted);
    font-weight: 500;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-surface);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
}

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

.icon-btn:hover {
    background-color: var(--primary-light);
    border-color: var(--primary-border);
    color: var(--primary-hover);
}

.danger-btn:hover {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

/* Theme Icon Visibility Switch */
.moon-icon {
    display: none;
}
[data-theme="dark"] .sun-icon {
    display: none;
}
[data-theme="dark"] .moon-icon {
    display: block;
}

/* --------------------------------------------------------------------------
   5. Main Chat Area Component
   -------------------------------------------------------------------------- */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background-color: var(--bg-chat-area);
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

/* Welcome Screen */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    margin: auto 0;
    padding: 30px 20px;
    max-width: 650px;
    align-self: center;
    animation: fadeIn 0.4s ease-out;
}

.welcome-badge {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary-hover);
    background-color: var(--primary-light);
    border: 1px solid var(--primary-border);
    padding: 6px 16px;
    border-radius: var(--radius-full);
    margin-bottom: 16px;
}

.welcome-title {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 10px;
    letter-spacing: -0.02em;
}

.welcome-desc {
    font-size: 1rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 28px;
}

.quick-prompts-section {
    width: 100%;
}

.quick-prompts-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 14px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.quick-prompts-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.quick-prompt-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
    text-align: left;
}

.quick-prompt-btn .prompt-icon {
    font-size: 1.1rem;
}

.quick-prompt-btn:hover {
    border-color: var(--primary-color);
    background-color: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.quick-prompt-btn:active {
    transform: translateY(0);
}

/* Chat Messages Layout */
.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: 100%;
}

.message-row {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: slideUp 0.3s ease-out;
}

.user-row {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ai-row {
    align-self: flex-start;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.ai-avatar {
    background: var(--accent-gradient);
    color: #ffffff;
}

.user-avatar {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--primary-color);
    font-weight: 700;
}

.message-bubble-wrapper {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 100%;
}

.user-row .message-bubble-wrapper {
    align-items: flex-end;
}

.message-bubble {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    font-size: 0.95rem;
    line-height: 1.6;
    position: relative;
    word-break: break-word;
    box-shadow: var(--shadow-sm);
}

.user-bubble {
    background: var(--user-bubble-gradient);
    color: var(--text-on-primary);
    border-bottom-right-radius: 4px;
}

.ai-bubble {
    background-color: var(--bg-ai-bubble);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

/* AI Message Content Formatting */
.ai-bubble p {
    margin-bottom: 10px;
}
.ai-bubble p:last-child {
    margin-bottom: 0;
}

.ai-bubble ul, .ai-bubble ol {
    margin-top: 6px;
    margin-bottom: 12px;
    padding-left: 22px;
}

.ai-bubble li {
    margin-bottom: 4px;
}

.ai-bubble strong {
    font-weight: 700;
    color: var(--primary-hover);
}

.ai-bubble h3, .ai-bubble h4 {
    margin-top: 14px;
    margin-bottom: 6px;
    font-weight: 700;
    color: var(--text-main);
}

.ai-bubble blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 12px;
    margin: 8px 0;
    font-style: italic;
    color: var(--text-muted);
}

.ai-bubble code {
    background-color: var(--primary-light);
    color: var(--primary-hover);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: monospace;
    font-size: 0.88rem;
}

/* Message Meta & Action Bar */
.message-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.72rem;
    color: var(--text-light);
    margin-top: 2px;
    padding: 0 4px;
}

.copy-btn {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 0.75rem;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    transition: color var(--transition-fast), background-color var(--transition-fast);
}

.copy-btn svg {
    width: 13px;
    height: 13px;
}

.copy-btn:hover {
    color: var(--primary-color);
    background-color: var(--primary-light);
}

/* Loading Indicator Bubble */
.loading-row {
    margin-top: 4px;
}

.loading-bubble {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 500;
}

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

.typing-dots .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: var(--primary-color);
    animation: bounceDot 1.4s infinite ease-in-out both;
}

.typing-dots .dot:nth-child(1) { animation-delay: 0s; }
.typing-dots .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dots .dot:nth-child(3) { animation-delay: 0.4s; }

/* --------------------------------------------------------------------------
   6. Input Area Component
   -------------------------------------------------------------------------- */
.input-area {
    padding: 16px 24px;
    background-color: var(--bg-surface-translucent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 10;
}

.input-form {
    width: 100%;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 8px 12px 8px 18px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

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

textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-main);
    resize: none;
    max-height: 120px;
    min-height: 24px;
    line-height: 1.5;
    padding: 4px 0;
}

textarea::placeholder {
    color: var(--text-light);
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: var(--accent-gradient);
    border: none;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    box-shadow: 0 2px 8px var(--accent-glow);
}

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

.send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px var(--accent-glow);
}

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

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(40%);
}

.keyboard-hint {
    font-size: 0.72rem;
    color: var(--text-light);
    text-align: right;
    padding-right: 4px;
}

.keyboard-hint span {
    font-weight: 600;
    background-color: var(--primary-light);
    color: var(--primary-hover);
    padding: 1px 5px;
    border-radius: 4px;
    border: 1px solid var(--primary-border);
}

/* Disclaimer Banner */
.disclaimer-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.74rem;
    color: var(--text-muted);
    background-color: var(--primary-light);
    border: 1px solid var(--primary-border);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    text-align: center;
    line-height: 1.4;
}

.disclaimer-banner .info-icon {
    width: 14px;
    height: 14px;
    color: var(--primary-hover);
    flex-shrink: 0;
}

/* Utility Helpers */
.hidden {
    display: none !important;
}

/* --------------------------------------------------------------------------
   7. Keyframes & Animations
   -------------------------------------------------------------------------- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

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

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

/* --------------------------------------------------------------------------
   8. Responsive Media Queries
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .app-container {
        height: 100vh;
        border-radius: 0;
        box-shadow: none;
    }

    .app-header {
        padding: 10px 16px;
    }

    .brand-title {
        font-size: 1.1rem;
    }

    .brand-subtitle {
        font-size: 0.75rem;
    }

    .btn-text {
        display: none;
    }

    .icon-btn {
        padding: 8px;
    }

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

    .message-row {
        max-width: 92%;
    }

    .welcome-title {
        font-size: 1.4rem;
    }

    .welcome-desc {
        font-size: 0.9rem;
    }

    .quick-prompts-grid {
        flex-direction: column;
    }

    .quick-prompt-btn {
        width: 100%;
    }

    .input-area {
        padding: 12px 14px;
    }

    .keyboard-hint {
        display: none;
    }
}
