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

:root {
    --bg: #faf9f7;
    --bg-chat: #ffffff;
    --primary: #1a1a1a;
    --primary-light: #333;
    --accent: #c9a87c;
    --accent-light: #e8dcc8;
    --accent-subtle: #f5efe7;
    --text: #1a1a1a;
    --text-secondary: #6b6b6b;
    --text-muted: #999;
    --border: #e8e8e8;
    --border-light: #f0f0f0;
    --msg-user: #1a1a1a;
    --msg-assistant: #f5f0eb;
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-pill: 100px;
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}

/* App Layout */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 640px;
    margin: 0 auto;
    background: var(--bg-chat);
}

/* Header */
.app-header {
    padding: 16px 20px;
    background: var(--bg);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.app-header h1 {
    font-family: 'Instrument Serif', Georgia, serif;
    font-size: 1.5rem;
    font-weight: 400;
    letter-spacing: -0.02em;
    color: var(--primary);
}

/* Chat Area */
.chat-area {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.chat-messages {
    height: 100%;
    overflow-y: auto;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Messages */
.message {
    margin-bottom: 16px;
    display: flex;
    animation: messageIn 0.3s ease-out;
}

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

.message-content {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    line-height: 1.6;
}

.message.user .message-content {
    background: var(--msg-user);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--msg-assistant);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

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

.message-image {
    max-width: 200px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    display: block;
}

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

/* Typing Indicator */
.typing-dots {
    display: flex;
    gap: 5px;
    padding: 4px 0;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

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

/* Shopping List */
.shopping-list {
    margin-top: 12px;
    border-top: 1px solid rgba(0,0,0,0.08);
    padding-top: 8px;
}

.shopping-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    margin-top: 12px;
    margin-bottom: 4px;
}

.shopping-section-title:first-child {
    margin-top: 4px;
}

.shopping-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    cursor: pointer;
    transition: opacity 0.3s ease;
    user-select: none;
}

.shopping-item input[type="checkbox"] { display: none; }

.checkmark {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
    font-size: 12px;
    color: transparent;
}

.shopping-item.checked .checkmark {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.checkmark::after {
    content: '\2713';
    font-weight: 700;
}

.shopping-label {
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.shopping-item.checked .shopping-label {
    text-decoration: line-through;
    color: var(--text-muted);
}

.shopping-item.checked { opacity: 0.6; }

/* Meal Plan */
.meal-plan {
    margin-top: 12px;
    border-top: 1px solid rgba(0,0,0,0.08);
    padding-top: 8px;
}

.meal-plan-day {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(0,0,0,0.04);
}

.meal-plan-day:last-child { border-bottom: none; }

.meal-day-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent);
    min-width: 80px;
}

.meal-recipe-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
}

.meal-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    width: 100%;
    padding-left: 86px;
}

/* Drop Overlay */
.drop-overlay {
    position: absolute;
    inset: 0;
    background: rgba(250, 249, 247, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 10;
    border: 3px dashed var(--accent);
    border-radius: var(--radius-md);
    margin: 12px;
}

.drop-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.drop-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--accent);
}

.drop-content span {
    font-size: 1rem;
    font-weight: 500;
}

/* Copy Buttons */
.copy-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(0,0,0,0.06);
}

.copy-btn {
    padding: 5px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.copy-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-subtle);
}

.copy-btn.copied {
    border-color: #4caf50;
    color: #4caf50;
    background: rgba(76, 175, 80, 0.08);
}

/* Image Preview */
.image-preview {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    background: var(--bg);
    border-top: 1px solid var(--border-light);
}

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

.preview-thumbs {
    display: flex;
    gap: 6px;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex: 1;
}

.preview-thumbs::-webkit-scrollbar { display: none; }

.preview-thumb {
    position: relative;
    flex-shrink: 0;
}

.preview-thumb img {
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.remove-thumb {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    padding-left: 4px;
}

.remove-image {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: var(--border);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.2s;
}

.remove-image:hover {
    background: var(--text-muted);
    color: white;
}

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

.quick-actions {
    display: flex;
    gap: 8px;
    padding: 12px 20px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.quick-actions::-webkit-scrollbar { display: none; }

.quick-btn {
    flex-shrink: 0;
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-family: inherit;
}

.quick-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-subtle);
}

.quick-btn:active { transform: scale(0.97); }

.chat-form {
    display: flex;
    align-items: center;
    padding: 12px 12px 12px 8px;
    gap: 4px;
}

.attach-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.2s;
}

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

#user-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    background: var(--bg-chat);
    color: var(--text);
    transition: border-color 0.2s;
}

#user-input::placeholder { color: var(--text-muted); }
#user-input:focus { border-color: var(--accent); }

#send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

#send-btn:hover { background: var(--primary-light); }
#send-btn:active { transform: scale(0.95); }
#send-btn:disabled { background: var(--text-muted); cursor: not-allowed; }

/* Desktop */
@media (min-width: 640px) {
    .app {
        border-left: 1px solid var(--border-light);
        border-right: 1px solid var(--border-light);
    }
}

@media (min-width: 768px) {
    body { background: var(--bg); }

    .app {
        margin-top: 20px;
        margin-bottom: 20px;
        height: calc(100vh - 40px);
        border-radius: var(--radius-md);
        border: 1px solid var(--border);
        box-shadow: var(--shadow-md);
        overflow: hidden;
    }
}
