/* Manual overrides */


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

@media (min-width: 721px) {
    /* Page-scoped reset: apply only on chat page for wider screens */
    * {
        margin: 0;
        padding: 0;
    }
}

html, body {
    height: 100%;
    /* Prevent scroll chaining/bounce that can push content under the fixed header on first load */
    overscroll-behavior-y: auto;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
    color: var(--text);
    background: var(--bg-gradient, var(--bg));
    -webkit-text-size-adjust: 100%;
}

.app {
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    /* Use min-height so the page can scroll instead of forcing an inner scroller */
    min-height: 100dvh; /* fallback */
    min-height: 100svh; /* stable viewport on mobile */
    max-width: 820px;
    margin: 0 auto;
}


.chat {
    padding: 16px;
    /* Let the document/body be the scroller to avoid first-load under-header issues */
    overflow: visible;
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* Top spacing now inherited from shared .content to match other pages */
    margin-bottom: calc(69px + env(safe-area-inset-bottom));
}

/* Reduce inner padding to match other pages when using shared .content */
.chat.content {
    padding: 16px;
}

.bubble {
    max-width: 85%;
    padding: 12px 14px;
    border-radius: 14px;
    line-height: 1.35;
    white-space: normal;
    word-wrap: break-word;
}

.bubble.user {
    align-self: flex-end;
    background: var(--user);
    color: var(--user-text);
    border-bottom-right-radius: 4px;
}

.bubble.bot {
    align-self: flex-start;
    background: var(--bot);
    color: var(--bot-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

/* Ensure bot bubble has stronger contrast in dark mode */
:root[data-theme="dark"] .bubble.bot {
    background: #2b3541;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .bubble.bot {
        background: #2b3541;
    }
}

.bubble a {
    color: var(--link);
}

/* Embedded preview container */
.embed {
    display: block;
}

.embed iframe {
    width: 100%;
    height: 150px;
    border: 0;
    border-radius: 10px;
    background: #fff;
}

.controls {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--topbar-bg);
    position: fixed;
    bottom: calc(68px + env(safe-area-inset-bottom));
    left: 0;
    right: 0;
    max-width: 820px;
    margin: 0 auto;
    z-index: 9;
    max-height: 500px;
    overflow: hidden;
    transition: max-height 200ms ease, padding 200ms ease, opacity 180ms ease, transform 200ms ease, border-color 200ms ease;
}

.controls.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
    transform: translateY(4px);
    border-top-color: transparent;
    border-bottom-color: transparent;
}

.select-group {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0; /* allow flex shrink */
}

.select-group select {
    flex: 1 1 auto;
    min-width: 0;
}

.controls select, .controls button {
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--input-text);
    font-size: 16px; /* Prevent iOS zoom on focus */
}

.clear-select {
    width: 38px;
    max-width: 38px;
    height: 38px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--input-bg);
    color: var(--input-text);
    border: 1px solid var(--border);
}

.clear-select:hover,
.clear-select:focus {
    background: rgba(127, 127, 127, 0.08);
}

.controls .last5 {
    background: var(--primary);
    color: #fff;
    border: none;
}

.composer {
    display: flex;
    gap: 8px;
    padding: 12px;
    /* Add extra bottom padding for iOS home indicator */
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: var(--topbar-bg);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 820px;
    margin: 0 auto;
}

.composer input {
    flex: 1;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--input-text);
    font-size: 16px; /* Prevent iOS zoom on focus */
}

.composer button {
    width: 46px;
    border-radius: 12px;
    border: none;
    background: var(--primary);
    color: #fff;
    font-size: 18px;
}

.composer button:hover {
    background: var(--primary-dark);
}

/* Filters toggle button inside composer */
.filters-toggle {
    width: 46px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--input-text);
    font-size: 18px;
}

.filters-toggle:hover,
.filters-toggle:focus {
    background: rgba(127, 127, 127, 0.08);
}

.hint {
    font-size: 12px;
    opacity: 0.7;
    text-align: center;
    padding: 6px;
}

.loading {
    opacity: 0.7;
}

.loading .bubble-content::before {
    content: '';
    display: inline-block;
    width: 24px;
    height: 24px;
    margin-right: 8px;
    vertical-align: middle;
    background: url('/static/assets/loader-small-light.svg') center/contain no-repeat;
}

:root[data-theme="dark"] .loading .bubble-content::before {
    background: url('/static/assets/loader-small-dark.svg') center/contain no-repeat;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .loading .bubble-content::before {
        background: url('/static/assets/loader-small-dark.svg') center/contain no-repeat;
    }
}

.recipe {
    display: block;
}

.recipe-title {
    font-weight: 700;
    font-size: 16px;
    margin: 0 0 8px 0;
}

.recipe-section {
    margin-top: 10px;
}

.recipe-subtitle {
    font-weight: 600;
    margin: 6px 0;
}

.ingredients, .steps {
    margin: 6px 0 0 18px;
}

.steps {
    list-style: decimal;
}


/* Responsive adjustments for mobile: stack controls and make elements full width */
@media (max-width: 640px) {
    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .controls select,
    .controls button {
        width: 100%;
    }

    /* Slightly tighter spacing on small screens */
    .composer {
        padding: 10px;
        gap: 6px;
    }

    .chat {
        padding: 12px;
    }

    .chat.content {
        padding: 12px;
    }
}

@media (max-width: 640px) {
    /* Keep reset/clear buttons at a fixed size on mobile */
    .controls .clear-select {
        width: 38px;
        max-width: 38px;
        flex: 0 0 38px;
    }
}

@media (max-width: 768px) {
    /* Top spacing now inherited from shared .content on mobile as well */
}
