/* CSS Variables - Warm & Friendly Palette */
:root {
    /* Primary Colors */
    --sage-green: #7C9A82;
    --sage-light: #A8C5AE;
    --sage-dark: #5A7A60;

    /* Warm Neutrals */
    --cream: #FDF8F3;
    --warm-white: #FEFCFA;
    --beige: #F5EDE4;
    --warm-gray: #8B8178;
    --brown: #6B5B4F;

    /* Accent Colors */
    --coral: #E8A598;
    --coral-light: #F5D5CF;
    --amber: #E9B872;
    --amber-light: #F5DEB3;

    /* FODMAP Status Colors */
    --low-green: #7CB87C;
    --low-bg: #E8F5E8;
    --medium-amber: #E9A94B;
    --medium-bg: #FEF3E2;
    --high-coral: #E07B6B;
    --high-bg: #FDECEC;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(107, 91, 79, 0.08);
    --shadow-md: 0 4px 12px rgba(107, 91, 79, 0.1);
    --shadow-lg: 0 8px 24px rgba(107, 91, 79, 0.12);

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, var(--cream) 0%, var(--beige) 100%);
    color: var(--brown);
    line-height: 1.6;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 800px;
    margin: 0 auto;
    background: var(--warm-white);
    box-shadow: var(--shadow-lg);
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--sage-green) 0%, var(--sage-dark) 100%);
    padding: 12px 20px;
    flex-shrink: 0;
}

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

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

.logo-img {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

/* Header Install Button */
.header-install-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    cursor: pointer;
    transition: var(--transition-fast);
    margin-left: 4px;
}

.header-install-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: white;
    transform: scale(1.1);
}

.header-install-btn.visible {
    display: flex;
}

.logo h1 {
    font-family: 'Nunito', sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    color: white;
    letter-spacing: -0.02em;
}

/* Header Toggles Container */
.header-toggles {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Model & Length Toggle */
.model-toggle,
.length-toggle {
    display: flex;
    background: rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-full);
    padding: 3px;
    gap: 2px;
}

.toggle-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border: none;
    border-radius: var(--radius-full);
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
}

.toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.toggle-btn.active {
    background: white;
    color: var(--sage-dark);
    box-shadow: var(--shadow-sm);
}

.toggle-btn svg {
    flex-shrink: 0;
}

/* FODMAP Filter Bar */
.fodmap-filters {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.filter-label {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.filter-chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 2px;
}

.filter-chips::-webkit-scrollbar {
    display: none;
}

.filter-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border: 1.5px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-full);
    background: transparent;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
}

.filter-chip:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
}

.filter-chip.active {
    background: white;
    color: var(--sage-dark);
    border-color: white;
    box-shadow: var(--shadow-sm);
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Welcome Card */
.welcome-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-md);
    text-align: center;
    animation: fadeInUp 0.5s ease;
}

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

.welcome-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.welcome-card h2 {
    font-family: 'Nunito', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--sage-dark);
    margin-bottom: 12px;
}

.welcome-card > p {
    color: var(--warm-gray);
    font-size: 0.95rem;
    max-width: 400px;
    margin: 0 auto 24px;
}

/* FODMAP Legend */
.fodmap-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-bottom: 24px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    min-width: 150px;
}

.legend-item.low {
    background: var(--low-bg);
}

.legend-item.medium {
    background: var(--medium-bg);
}

.legend-item.high {
    background: var(--high-bg);
}

.legend-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: white;
    flex-shrink: 0;
}

.legend-item.low .legend-icon {
    background: var(--low-green);
}

.legend-item.medium .legend-icon {
    background: var(--medium-amber);
}

.legend-item.high .legend-icon {
    background: var(--high-coral);
}

.legend-text {
    text-align: left;
}

.legend-text strong {
    display: block;
    font-size: 0.85rem;
    color: var(--brown);
}

.legend-text span {
    font-size: 0.75rem;
    color: var(--warm-gray);
}

/* Quick Actions */
.quick-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.quick-btn {
    padding: 10px 18px;
    border: 2px solid var(--beige);
    border-radius: var(--radius-full);
    background: var(--cream);
    color: var(--brown);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
}

.quick-btn:hover {
    border-color: var(--sage-light);
    background: var(--sage-light);
    color: white;
    transform: translateY(-2px);
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: fadeInUp 0.3s ease;
}

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

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

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

.message.user .message-avatar {
    background: var(--coral-light);
}

.message-content {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    line-height: 1.5;
}

.message.assistant .message-content {
    background: white;
    box-shadow: var(--shadow-sm);
    border-bottom-left-radius: 4px;
}

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

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

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

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

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

.message-content strong {
    color: var(--sage-dark);
}

.message.user .message-content strong {
    color: white;
}

/* User Image in Message */
.message-image {
    max-width: 100%;
    max-height: 200px;
    border-radius: var(--radius-md);
    margin-bottom: 8px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 16px 18px;
}

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

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

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input Area */
.input-area {
    background: white;
    border-top: 1px solid var(--beige);
    padding: 16px 20px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    flex-shrink: 0;
}

.input-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.image-preview-container {
    display: none;
    position: relative;
    width: fit-content;
}

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

#imagePreview {
    max-height: 100px;
    max-width: 200px;
    border-radius: var(--radius-md);
    object-fit: cover;
}

.remove-image {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: var(--high-coral);
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.remove-image:hover {
    transform: scale(1.1);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--cream);
    border: 2px solid var(--beige);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
    transition: var(--transition-fast);
}

.input-wrapper:focus-within {
    border-color: var(--sage-light);
    box-shadow: 0 0 0 3px rgba(124, 154, 130, 0.15);
}

#messageInput {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 1rem;
    color: var(--brown);
    resize: none;
    min-height: 24px;
    max-height: 120px;
    padding: 8px 0;
    line-height: 1.4;
}

#messageInput::placeholder {
    color: var(--warm-gray);
}

#messageInput:focus {
    outline: none;
}

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

.action-btn {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--warm-gray);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.action-btn:hover {
    background: var(--beige);
    color: var(--sage-dark);
}

.send-btn {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--sage-green);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

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

.send-btn:disabled {
    background: var(--beige);
    color: var(--warm-gray);
    cursor: not-allowed;
}

/* Install Banner */
.install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--sage-dark);
    color: white;
    padding: 12px 20px;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 1000;
}

.install-banner.visible {
    transform: translateY(0);
}

.install-content {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.install-btn {
    padding: 8px 20px;
    border: 2px solid white;
    border-radius: var(--radius-full);
    background: white;
    color: var(--sage-dark);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
}

.install-btn:hover {
    background: transparent;
    color: white;
}

.install-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    opacity: 0.7;
    padding: 4px;
}

.install-close:hover {
    opacity: 1;
}

/* Disclaimer Banner */
.disclaimer-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    background: linear-gradient(135deg, var(--amber-light) 0%, #FEF3E2 100%);
    border-top: 1px solid var(--beige);
    font-size: 0.8rem;
    color: var(--brown);
    line-height: 1.4;
    animation: slideIn 0.3s ease;
}

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

.disclaimer-banner.hidden {
    display: none;
}

.disclaimer-text {
    flex: 1;
}

.disclaimer-close {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: rgba(107, 91, 79, 0.1);
    color: var(--warm-gray);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition-fast);
}

.disclaimer-close:hover {
    background: rgba(107, 91, 79, 0.2);
    color: var(--brown);
}

/* Streaming Cursor */
.streaming-cursor {
    display: inline-block;
    color: var(--sage-green);
    animation: blink 1s infinite;
    margin-left: 2px;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Error State */
.error-message {
    background: var(--high-bg);
    border-left: 4px solid var(--high-coral);
    padding: 12px 16px;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    color: var(--brown);
    font-size: 0.9rem;
}

/* Mobile Install Button */
.mobile-install-btn {
    display: none;
    position: fixed;
    bottom: 100px;
    right: 16px;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: var(--sage-green);
    color: white;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    z-index: 100;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: var(--shadow-lg), 0 0 0 0 rgba(124, 154, 130, 0.4); }
    50% { box-shadow: var(--shadow-lg), 0 0 0 8px rgba(124, 154, 130, 0); }
}

.mobile-install-btn:hover {
    transform: scale(1.1);
    background: var(--sage-dark);
}

.mobile-install-btn.visible {
    display: flex;
}

/* Install Modal */
.install-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.install-modal-overlay.visible {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.install-modal {
    background: white;
    border-radius: var(--radius-lg);
    padding: 28px;
    max-width: 340px;
    width: 100%;
    text-align: center;
    position: relative;
    animation: slideUp 0.3s ease;
}

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

.install-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: var(--beige);
    color: var(--warm-gray);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.install-modal-close:hover {
    background: var(--coral-light);
    color: var(--brown);
}

.install-modal-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.install-modal h2 {
    font-family: 'Nunito', sans-serif;
    font-size: 1.3rem;
    color: var(--sage-dark);
    margin-bottom: 8px;
}

.install-modal > p {
    color: var(--warm-gray);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.install-instructions {
    display: none;
    text-align: left;
    margin-bottom: 20px;
}

.install-instructions.visible {
    display: block;
}

.install-step {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--beige);
}

.install-step:last-child {
    border-bottom: none;
}

.step-number {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--sage-light);
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.install-step span:last-child {
    font-size: 0.9rem;
    color: var(--brown);
    line-height: 1.4;
}

.ios-share-icon {
    display: inline-block;
    background: var(--beige);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
}

.android-menu-icon {
    display: inline-block;
    background: var(--beige);
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: bold;
}

.install-modal-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--sage-green);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
}

.install-modal-btn:hover {
    background: var(--sage-dark);
}

/* Responsive */
@media (max-width: 600px) {
    .header {
        padding: 10px 12px;
    }

    .header-content {
        margin-bottom: 8px;
        flex-wrap: wrap;
    }

    .logo h1 {
        font-size: 1rem;
    }

    .logo-img {
        width: 28px;
        height: 28px;
    }

    .header-toggles {
        gap: 4px;
    }

    .model-toggle,
    .length-toggle {
        padding: 2px;
    }

    .toggle-btn {
        padding: 5px 8px;
        font-size: 0.65rem;
    }

    .toggle-btn svg {
        width: 12px;
        height: 12px;
    }

    .fodmap-filters {
        gap: 6px;
        padding-top: 8px;
    }

    .filter-label {
        display: none;
    }

    .filter-chip {
        padding: 5px 8px;
        font-size: 0.65rem;
    }

    .chat-container {
        padding: 16px;
    }

    .welcome-card {
        padding: 20px;
    }

    .welcome-card h2 {
        font-size: 1.3rem;
    }

    .legend-item {
        min-width: 100%;
    }

    .message {
        max-width: 90%;
    }

    .input-area {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .input-wrapper {
        padding: 6px 10px;
    }

    .action-btn, .send-btn {
        width: 38px;
        height: 38px;
    }
}

/* Scrollbar Styling */
.chat-container::-webkit-scrollbar {
    width: 6px;
}

.chat-container::-webkit-scrollbar-track {
    background: transparent;
}

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

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

/* Print Styles */
@media print {
    .header, .input-area, .install-banner {
        display: none;
    }

    .chat-container {
        overflow: visible;
    }

    .app-container {
        box-shadow: none;
    }
}
