/* ==========================================================================
   NutriChat - CSS Design System & Layout
   Theme: Modern Fresh Green, White & Soft Mint
   ========================================================================== */

:root {
    /* Color Palette */
    --primary-green: #10b981;
    --primary-green-hover: #059669;
    --primary-green-dark: #047857;
    --primary-green-light: #ecfdf5;
    --primary-green-subtle: #d1fae5;
    
    --bg-main: #f8fafc;
    --bg-white: #ffffff;
    --bg-sidebar: #064e3b;
    --bg-sidebar-hover: #047857;
    
    --text-dark: #0f172a;
    --text-medium: #334155;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --text-white: #ffffff;
    
    --border-color: #e2e8f0;
    --border-color-light: #f1f5f9;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(16, 185, 129, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-soft: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 10px 10px -5px rgba(0, 0, 0, 0.02);
    
    /* Layout Variables */
    --sidebar-width: 280px;
    --header-height: 70px;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 9999px;
    
    --font-family: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
}

/* Reset & Global Settings */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-family);
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-main);
    color: var(--text-dark);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    line-height: 1.5;
}

/* Main App Layout */
.app-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    position: relative;
}

/* ==========================================================================
   SIDEBAR (KIRI)
   ========================================================================== */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    color: var(--text-white);
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 24px 18px;
    z-index: 100;
    transition: transform var(--transition-normal);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.08);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

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

.brand-icon {
    width: 42px;
    height: 42px;
    background: var(--primary-green);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-white);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

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

.brand-text h2 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.brand-text .tagline {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.7);
    display: block;
}

.mobile-close-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-white);
    cursor: pointer;
    padding: 4px;
}

.new-chat-btn {
    width: 100%;
    background-color: var(--primary-green);
    color: var(--text-white);
    border: none;
    border-radius: var(--radius-md);
    padding: 12px 18px;
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.25);
    margin-bottom: 24px;
}

.new-chat-btn:hover {
    background-color: var(--primary-green-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(16, 185, 129, 0.35);
}

.new-chat-btn:active {
    transform: translateY(0);
}

/* Sidebar Menu Navigation */
.sidebar-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
}

.menu-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.45);
    font-weight: 700;
    margin-bottom: 8px;
    padding-left: 10px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: all var(--transition-fast);
}

.menu-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-white);
}

.menu-item.active {
    background-color: var(--bg-sidebar-hover);
    color: var(--text-white);
    font-weight: 600;
}

.menu-item svg {
    opacity: 0.85;
}

/* Sidebar Footer */
.sidebar-footer {
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.gemini-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.75);
    background: rgba(255, 255, 255, 0.08);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
}

.gemini-sparkle {
    color: #fbbf24;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 90;
}

/* ==========================================================================
   MAIN CONTENT AREA
   ========================================================================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: var(--bg-main);
    position: relative;
    overflow: hidden;
}

/* Header */
.chat-header {
    height: var(--header-height);
    background-color: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    z-index: 10;
}

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

.menu-toggle-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-dark);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
}

.menu-toggle-btn:hover {
    background-color: var(--bg-main);
}

.header-info .header-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-dark);
    line-height: 1.2;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    background-color: var(--primary-green);
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
    animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5); }
    70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.action-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.action-btn:hover {
    background-color: #fee2e2;
    color: #ef4444;
    border-color: #fca5a5;
}

/* Chat Messages Scroll Container */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
}

.chat-messages {
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Welcome Container */
.welcome-container {
    background: var(--bg-white);
    border: 1px solid var(--border-color-light);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-soft);
    margin-bottom: 12px;
    animation: fadeIn 0.4s ease;
}

.welcome-badge {
    width: 44px;
    height: 44px;
    background-color: var(--primary-green-light);
    color: var(--primary-green-dark);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.welcome-container h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 8px;
}

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

/* Quick Action Cards Grid */
.quick-actions-section {
    margin-bottom: 28px;
}

.quick-actions-section h3,
.suggested-section h3 {
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 14px;
}

.quick-cards-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.quick-card {
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.quick-card .card-icon {
    font-size: 1.5rem;
    background-color: var(--bg-white);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.quick-card h4 {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 4px;
}

.quick-card p {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Suggested Questions Chips */
.suggested-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.chip-btn {
    background-color: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    padding: 8px 16px;
    font-size: 0.85rem;
    color: var(--text-medium);
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
    font-weight: 500;
}

.chip-btn:hover {
    border-color: var(--primary-green);
    color: var(--primary-green-dark);
    background-color: var(--primary-green-light);
    transform: translateY(-1px);
}

/* Message Bubbles */
.chat-row {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: messageSlideIn 0.3s ease forwards;
}

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

.chat-row.user-row {
    margin-left: auto;
    flex-direction: row-reverse;
}

.chat-row.ai-row {
    margin-right: auto;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-avatar {
    background-color: var(--text-dark);
    color: var(--text-white);
}

.bot-avatar {
    background-color: var(--primary-green);
    color: var(--text-white);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

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

.user-row .message-bubble {
    background-color: var(--primary-green);
    color: var(--text-white);
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

.ai-row .message-bubble {
    background-color: var(--bg-white);
    color: var(--text-dark);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-color-light);
    box-shadow: var(--shadow-sm);
}

/* Formatted Markdown inside AI Message */
.message-content p {
    margin-bottom: 10px;
}

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

.message-content strong {
    font-weight: 700;
    color: inherit;
}

.message-content ul,
.message-content ol {
    margin: 8px 0 12px 20px;
}

.message-content li {
    margin-bottom: 4px;
}

.message-content h1,
.message-content h2,
.message-content h3 {
    font-weight: 700;
    margin: 14px 0 8px 0;
    line-height: 1.3;
}

.message-content h3 {
    font-size: 1.05rem;
}

.message-content code {
    background-color: rgba(15, 23, 42, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.85em;
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.88rem;
}

.message-content th,
.message-content td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}

.message-content th {
    background-color: var(--bg-main);
    font-weight: 600;
}

.message-content tr:nth-child(even) {
    background-color: #fafafa;
}

/* Typing Indicator */
.typing-indicator-container {
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 10px;
}

.typing-indicator-container.hidden {
    display: none;
}

.typing-bubble {
    background-color: var(--bg-white);
    border: 1px solid var(--border-color-light);
    padding: 10px 16px;
    border-radius: var(--radius-md);
    border-bottom-left-radius: 4px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-sm);
}

.typing-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

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

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

.typing-dots .dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dots .dot:nth-child(2) { animation-delay: -0.16s; }

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

/* Error Message Bubble */
.error-bubble {
    background-color: #fef2f2 !important;
    border-color: #fca5a5 !important;
    color: #991b1b !important;
}

/* ==========================================================================
   INPUT AREA (BOTTOM)
   ========================================================================== */
.chat-input-area {
    padding: 16px 28px 20px;
    background-color: var(--bg-white);
    border-top: 1px solid var(--border-color);
}

.input-container {
    max-width: 860px;
    margin: 0 auto;
    background-color: var(--bg-main);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 8px 12px 8px 16px;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.input-container:focus-within {
    border-color: var(--primary-green);
    background-color: var(--bg-white);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.chat-textarea {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    resize: none;
    font-size: 0.95rem;
    color: var(--text-dark);
    max-height: 140px;
    min-height: 24px;
    padding: 6px 0;
    line-height: 1.5;
}

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

.input-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.icon-action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.icon-action-btn:hover {
    background-color: rgba(15, 23, 42, 0.05);
    color: var(--text-dark);
}

.send-btn {
    background-color: var(--primary-green);
    color: var(--text-white);
    border: none;
    border-radius: var(--radius-md);
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
    height: 38px;
}

.send-btn:hover:not(:disabled) {
    background-color: var(--primary-green-hover);
    transform: translateY(-1px);
}

.send-btn:disabled {
    background-color: var(--text-light);
    cursor: not-allowed;
    box-shadow: none;
    opacity: 0.7;
}

.input-footer-note {
    max-width: 860px;
    margin: 8px auto 0;
    font-size: 0.73rem;
    color: var(--text-muted);
    text-align: center;
}

/* ==========================================================================
   RESPONSIVE DESIGN (TABLET & MOBILE)
   ========================================================================== */
@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

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

    .mobile-close-btn {
        display: block;
    }

    .menu-toggle-btn {
        display: flex;
    }

    .quick-cards-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .chat-header {
        padding: 0 16px;
    }

    .chat-messages {
        padding: 0 14px;
    }

    .welcome-container {
        padding: 20px 16px;
    }

    .welcome-container h2 {
        font-size: 1.25rem;
    }

    .suggested-chips {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 6px;
        -webkit-overflow-scrolling: touch;
    }

    .chip-btn {
        white-space: nowrap;
        flex-shrink: 0;
    }

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

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

    .send-btn span {
        display: none;
    }

    .send-btn {
        padding: 8px;
        width: 38px;
        justify-content: center;
    }

    .input-footer-note {
        display: none;
    }
}
