/* Structural CSS for the furniture-search chat UI, shared by both themes unconditionally.
   Every color here is a variable (--bg/--surf/--rule/--rule2/--text/--text-sub/--media-radius)
   defined in theme.css, which supplies both the base theme's default values (:root) and the
   "Mara style" reskin's overrides (body.theme-mara) — this file never hardcodes a
   theme-specific color itself. */

:root {
    --media-radius: 8px; /* single source of truth for all image/card rounding, reused below as the "soft panel" radius tier too */
    --radius-tight: 4px; /* cards, badges, code blocks */
    --radius-pill: 999px; /* pill buttons, toggles */
    /* Text-size tiers for the small UI chrome (captions/labels/icons), not article-length prose —
       collapses what used to be ~10 near-identical values (0.65em-0.95em, 12px, 14px) into 3. */
    --fs-sm: 0.78em; /* captions, badges, uppercase labels, small notes */
    --fs-base: 0.9em; /* default readable size within these compact components */
    --fs-lg: 1.1em; /* icon glyphs, chevrons, section-heading accents */
    /* Sample-picker thumbnail size (image-search.js's initSamplePicker) — room photos are whole
       scenes needing more visible detail than an item crop, so they're 2x the item size, not an
       independently-picked value. */
    --item-thumb-min: 90px;
    --item-thumb-max: 120px;
}

img {
    border-radius: var(--media-radius);
}

.product-link {
    color: #3b82f6;
    text-decoration: none;
}

.product-link:hover {
    text-decoration: underline;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--bg);
    color: var(--text);
}

.header {
    position: relative;
    padding: 1rem 0;
    color: var(--text);
}

.chat-container {
    flex: 1;
    /* No overflow-y (was: auto) — forces overflow-x:auto too, clipping .results-panel's
       wider breakout. Page-level scroll (window.scrollTo) still works unaffected. */
    padding-bottom: 100px;
    max-width: 800px;
    margin: 0 auto;
}

.message-row {
    padding: 1rem;
    width: 100%;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.user-message .message-content {
    width: fit-content;
    max-width: 80%;
    padding: 1rem;
    border-radius: 1.5rem;
    background-color: var(--surf);
    margin-left: auto;
    position: relative;
}

.assistant-message .message-content {
    width: 100%;
    padding: 1rem;
    position: relative;
}

.input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1rem;
    /* Transparent, so the composer area doesn't block results behind it. Only the text box and
       the pill buttons are solid. */
    background-color: transparent;
    z-index: 100;
}

.centered-input-container {
    position: absolute;
    top: 68%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 900px; /* wide enough for the composer + .try-sidebar side by side */
    z-index: 100;
}

/* Composer + "Try one of these" side by side — stacks below on narrow screens (see the
   media query further down). */
.initial-layout {
    display: flex;
    gap: 36px;
    align-items: flex-start;
}

.initial-main {
    flex: 1;
    min-width: 0;
}

.try-sidebar {
    width: 260px;
    flex-shrink: 0;
}

/* Shared "section heading" pattern — small, uppercase, muted, underlined. Reused by
   .settings-group-header and .results-group-heading below; those two also layer on the
   "collapsible toggle" pattern (see further down) since they're clickable, unlike this one. */
.try-sidebar-heading,
.settings-group-header,
.results-group-heading {
    font-size: var(--fs-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-sub);
    border-bottom: 1px solid var(--rule);
}
.try-sidebar-heading {
    padding-bottom: 10px;
    margin-bottom: 2px;
}

.try-sidebar-list {
    display: flex;
    flex-direction: column;
}

.try-sidebar-row {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    border-bottom: 1px solid var(--rule);
    padding: 14px 0;
    cursor: pointer;
}

.try-sidebar-row:hover {
    border-bottom-color: var(--text);
}

.try-sidebar-q {
    display: block;
    font-size: var(--fs-base);
    color: var(--text);
    line-height: 1.4;
    margin-bottom: 6px;
}

.try-sidebar-cap {
    display: block;
    font-size: var(--fs-sm);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-sub);
}

/* The one row with a sample-item thumbnail (chat.js's TRY_SIDEBAR_PROMPTS) — image and
   text side by side instead of the plain stacked text block. */
.try-sidebar-row-img {
    display: flex;
    align-items: center;
    gap: 12px;
}

.try-sidebar-row-img img {
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: var(--media-radius);
    flex-shrink: 0;
}

.try-sidebar-text {
    display: block;
    min-width: 0;
}

@media (max-width: 720px) {
    .initial-layout {
        flex-direction: column;
    }
    .try-sidebar {
        width: 100%;
    }
}

.input-box {
    resize: none;
    min-height: 80px;
    border-radius: var(--media-radius) !important;
    color: var(--text) !important;
    background-color: var(--surf) !important;
    border: 2px solid var(--rule2) !important;
}

.input-box:focus {
    box-shadow: none !important;
    border-color: var(--text) !important;
}

.input-box::placeholder {
    color: var(--text-sub) !important;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: var(--text-sub);
    border-radius: 50%;
    margin: 0 2px;
    opacity: 0.6;
    animation: typing 1.5s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

pre {
    background-color: var(--surf);
    border-radius: var(--radius-tight);
    padding: 1rem;
    overflow-x: auto;
    margin: 1rem 0;
    color: var(--text);
}

code {
    background-color: var(--surf);
    padding: 2px 4px;
    border-radius: var(--radius-tight);
    color: var(--text);
}

.message-content table {
    border-collapse: collapse;
    margin: 10px 0;
    color: var(--text);
    width: 100%;
}

.message-content th,
.message-content td {
    border: 1px solid var(--rule);
    padding: 8px;
}

.message-content th {
    background-color: var(--surf);
    text-align: left;
}

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

.message-content blockquote {
    border-left: 3px solid var(--rule2);
    padding-left: 10px;
    color: var(--text-sub);
    margin: 10px 0;
}

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

.message-content a {
    color: #3b82f6;
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-content img {
    max-width: 100%;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
    margin-top: 16px;
    margin-bottom: 10px;
    color: var(--text);
}

/* Top-left of the page header — app-level controls, not part of composing a message. */
.settings-icon {
    position: absolute;
    top: 1rem;
    left: 15px;
    font-size: var(--fs-lg);
    cursor: pointer;
    color: var(--text-sub);
    z-index: 1000;
}

.settings-icon:hover {
    color: var(--text);
}

/* Closed by default -- the panel is long enough that showing it put the whole app's tuning surface
   in front of the chat box before anyone asked for it. body.settings-open (soft state, see
   ui-state.js) opens it and survives a refresh. */
#settings-panel {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    padding: 6px 16px;
    margin-top: 6px;
}

/* The two env-aware visibility settings, applied by the inline script at the top of index.html so
   they take effect on the first paint rather than after chat.js runs. Kept as CSS on a body class
   (not per-element display writes) so an element created later still obeys them -- the bottom
   composer's attach button is cloned into existence well after that script runs. The panel is
   hidden too, since a panel left open in an earlier session would otherwise still show. */
body.settings-open #settings-panel {
    display: flex;
}

body.ui-settings-hidden #settings-button,
body.ui-settings-hidden #settings-panel,
body.image-search-hidden #attach-button,
body.image-search-hidden #bottom-attach-button {
    display: none;
}

.help-icon {
    position: absolute;
    top: 1rem;
    left: 42px;
    font-size: var(--fs-lg);
    cursor: pointer;
    color: var(--text-sub);
    z-index: 1000;
}

.help-icon:hover {
    color: var(--text);
}

/* Base (dark-theme) look of the theme toggle itself — the only chrome that must exist and
   be styled regardless of which theme is active. theme.css restyles it once on. */
.theme-toggle {
    position: absolute;
    top: 1rem;
    right: 15px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--fs-sm);
    letter-spacing: 0.02em;
    color: var(--text-sub);
    background: none;
    border: 1px solid var(--rule2);
    border-radius: var(--radius-pill);
    padding: 5px 12px;
    cursor: pointer;
    z-index: 1000;
}

.theme-toggle:hover {
    color: var(--text);
    border-color: var(--text);
}

.theme-toggle.active {
    color: #ccc;
    border-color: var(--text);
    background-color: var(--surf);
}

/* Icon rail + textarea side by side, vertically centered against however tall the
   (auto-growing) textarea currently is — overrides Bootstrap's own .input-group default
   (flex-wrap, align-items:stretch), which would otherwise stretch the rail to match. */
.input-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* A vertical rail to the textarea's left, not floating inside it — a flex column, not
   each pill individually positioned by hand-computed pixel offsets. Hiding one
   (attach-button's own display:none, for imageSearchHidden) just lets its siblings
   reflow, no per-icon offset math to keep in sync. */
.input-icons {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
    z-index: 1000;
}

/* Labeled pills, not bare icons — "search by room"/"single-item search" don't read
   clearly from a glyph alone, so each spells out what it does. */
.attach-icon,
.room-search-icon {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border: 1px solid var(--rule2);
    border-radius: var(--radius-pill);
    font-size: var(--fs-sm);
    white-space: nowrap;
    cursor: pointer;
    color: var(--text-sub);
    background-color: var(--bg);
}

.attach-icon:hover,
.room-search-icon:hover {
    color: var(--text);
    border-color: var(--text);
}

.attach-badge {
    position: absolute;
    bottom: 100%;
    margin-bottom: 12px;
    left: 15px;
    max-height: 100px;
    border-radius: var(--media-radius);
    cursor: default;
    display: none;
}

/* No overflow:hidden on .attach-badge itself — it clipped .attach-remove, which pokes out
   past the image's own edge on purpose. object-fit:contain (not cover) so the full attached
   photo is visible, just capped by max-height, instead of zoomed/cropped to fill a fixed
   square. */
.attach-badge img {
    display: block;
    max-height: 100px;
    max-width: 160px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: var(--media-radius);
}

.attach-badge .attach-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: var(--surf);
    border: 1px solid var(--rule2);
    color: #ccc;
    font-size: var(--fs-sm);
    line-height: 20px;
    text-align: center;
    cursor: pointer;
}

.attach-badge:hover .attach-remove {
    color: #fff;
    border-color: var(--text);
}

.attach-badge .attach-mode-tag {
    position: absolute;
    bottom: 4px;
    left: 4px;
    padding: 1px 6px;
    border-radius: var(--radius-tight);
    background-color: var(--surf);
    color: #fff;
    font-size: var(--fs-sm);
    font-weight: 600;
    letter-spacing: 0.03em;
}

.message-content img.query-image-preview {
    display: block;
    max-width: 280px;
    max-height: 280px;
    width: 100%;
    object-fit: cover;
    margin-bottom: 6px;
}

.hidden {
    display: none !important;
}

/* Search tool call animation styles */
.search-indicator-container {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    padding: 10px 14px;
    background-color: var(--surf);
    border-radius: var(--media-radius);
    animation: fadeIn 0.4s ease-in-out;
    border-left: 3px solid var(--rule2);
    position: relative;
    overflow: hidden;
}

.search-indicator-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--text), transparent);
    animation: loading 1.5s infinite;
}

.search-pulse {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: var(--rule2);
    margin-right: 12px;
    animation: pulse 1.5s infinite ease-in-out;
    box-shadow: 0 0 0 rgba(119, 119, 119, 0.5);
    position: relative;
}

.search-pulse::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 50%;
    border: 3px solid var(--rule2);
    animation: ripple 1.5s infinite ease-out;
    opacity: 0;
}

.search-text {
    color: var(--text);
    font-weight: 400;
    font-size: var(--fs-base);
}

.search-params {
    margin-top: 3px;
    font-size: var(--fs-sm);
    color: var(--text-sub);
    font-family: system-ui, -apple-system, sans-serif;
}

.details {
    padding: 10px 0;
    background-color: var(--surf);
    border-radius: var(--media-radius);
    border-left: 3px solid var(--rule2);
    margin-bottom: 10px;
}

/* Header keeps its own inset padding; .details-content (below) stays full-width instead —
   the 20px .details used to take off both sides was exactly enough to drop .results-grid from
   4 columns to 3 (auto-fill needs ~768px for 4×180px+gaps), making cards render bigger than
   the un-wrapped search-only case for no real reason. Same .results-panel CSS either way now,
   just more room for it. */
/* Shared "collapsible toggle" pattern — a clickable row with a chevron (see further down),
   reused by .settings-group-header, .facet-coverage-toggle, .results-group-heading too. */
.details h4,
.settings-group-header,
.facet-coverage-toggle,
.results-group-heading {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
}
.details h4 {
    padding: 0 10px;
    margin-top: 0;
    margin-bottom: 0;
    color: var(--text);
    font-weight: 500;
    font-size: var(--fs-base);
}

.details h4::before {
    content: '';
    margin-right: 8px;
    width: 20px;
    height: 20px;
    background-color: var(--rule2);
    border-radius: 50%;
}

.details-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    margin-top: 0;
}

.details-content.expanded {
    max-height: 500px;
    /* No margin-top here — .results-panel (or .details-timing) supplies its own top spacing
       already; stacking both double-margined every wrapped flow (room-search, /chats,
       llm-search) relative to image-search, which calls renderResultsGrid with no wrapper. */
    overflow-y: auto;
    /* Explicit, not left to default — an unpaired overflow-y:auto implicitly forces
       overflow-x to auto too (same coupling .chat-container hit above). Safe as hidden
       (never visible/auto) now that .results-panel's breakout is disabled below — nothing in
       here is ever wider than the box, so nothing needs to scroll or clip either way. */
    overflow-x: hidden;
}

/* Shared by room-search.js's two detail-table builders (buildRoomDetectionDetails,
   buildDesignStyleEmbeddingsDetails) — both build a <table> here via buildTableHead() +
   per-row <td>s, previously each with their own identical inline styles. */
.details-content table {
    width: 100%;
    border-collapse: collapse;
    color: var(--text);
    font-size: var(--fs-base);
}
.details-content th {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--rule);
}
.details-content td {
    padding: 8px;
    vertical-align: top;
}

/* .results-panel's 780px breakout (below) is for the un-wrapped case (search-only/
   image-search render it directly). Inside .details it'd be wider than the wrapper's own
   padded box, which is what forced the scroll/clip in the first place — disabled here so
   it just lays out at the wrapper's natural (narrower) width instead. */
.details-content .results-panel {
    position: static;
    left: auto;
    transform: none;
    width: 100%;
    max-width: 100%;
}

/* Shared "collapsible chevron" pattern — .details h4, .settings-group-header,
   .facet-coverage-toggle, .results-group-heading all reuse this; only font-size (and
   facet-coverage-toggle's margin-left) differ, set per-selector just below. */
.details h4::after,
.settings-group-header::after,
.facet-coverage-toggle::after,
.results-group-heading::after {
    content: '›';
    margin-left: auto;
    transition: transform 0.3s ease;
    transform: rotate(90deg);
}
.details h4.collapsed::after,
.settings-group-header.collapsed::after,
.facet-coverage-toggle.collapsed::after,
.results-group-heading.collapsed::after {
    transform: rotate(0deg);
}

/* A raw-search-query heading (no label or reply header to use instead) clamps to one line. Zero
   basis keeps it from widening the group past its cards; its own span keeps the chevron unclipped. */
.results-group-heading.clamped .results-group-heading-text {
    flex: 1 1 0;
    width: 0;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.details h4::after {
    font-size: var(--fs-base);
}

/* Plain, non-interactive stand-in for the real panel (room-search.js's
   showStagePlaceholder) — no collapse arrow, no pointer cursor, nothing to click. */
.stage-placeholder h4 {
    cursor: default;
}
.stage-placeholder h4::after {
    content: none;
}

.settings-group {
    flex-basis: 100%;
}

/* Reference/explanatory text blocks in the settings panel (chat.js's renderGroupTitleNotes,
   initCategoryFilterTextSourceNote) — width/text-align override .settings-group-body's
   flex-wrap row layout (built for side-by-side controls), so these stack as normal left-aligned
   paragraphs instead of shrinking to content width as flex items. */
.settings-note {
    width: 100%;
    text-align: left;
    font-size: var(--fs-sm);
    color: var(--text-sub);
    line-height: 1.5;
}
.settings-note ul {
    margin: 2px 0 0;
    padding-left: 18px;
}

/* Sub-heading above a run of .settings-note entries sharing the same group (renderGroupTitleNotes,
   chat.js) — the group name shown once, not repeated in every entry's own title. */
.settings-note-group-heading {
    width: 100%;
    text-align: left;
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text);
    margin: 10px 0 4px;
}
.settings-note-group-heading:first-child {
    margin-top: 0;
}

.settings-group-header {
    padding: 2px 0;
    margin-bottom: 5px;
}

.settings-group-header::after {
    font-size: var(--fs-lg);
}

.settings-group-body {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
    overflow: hidden;
    max-height: 500px;
    margin-bottom: 8px;
    transition: max-height 0.3s ease;
}

.settings-group-body.collapsed {
    max-height: 0;
    margin-bottom: 0;
}

.facet-coverage-toggle {
    justify-content: flex-start;
    text-align: left;
    font-size: var(--fs-sm);
    color: var(--text-sub);
    margin-top: 4px;
}

.facet-coverage-toggle::after {
    margin-left: 6px;
    font-size: var(--fs-lg);
}

.facet-coverage-body {
    width: 220px;
    text-align: left;
    font-size: var(--fs-sm);
    color: var(--text-sub);
    line-height: 1.5;
    overflow: hidden;
    max-height: 300px;
    margin-top: 4px;
    transition: max-height 0.3s ease, width 0.3s ease;
}

.facet-coverage-body.collapsed {
    max-height: 0;
    width: 0;
    margin-top: 0;
}

.movie-item {
    margin-bottom: 6px;
    padding: 10px;
    background-color: var(--surf);
    border-radius: var(--radius-tight);
    transition: filter 0.2s ease;
    color: var(--text-sub);
    font-size: var(--fs-base);
}

.movie-item:hover {
    /* Theme-agnostic hover feedback — a fixed brighten works identically in both themes with no
       extra variable needed, unlike a hardcoded hover color that only one theme ever defined. */
    filter: brightness(1.15);
}

.movie-title {
    font-weight: 500;
    color: var(--text);
    margin-bottom: 4px;
}

.tool-message {
    animation: fadeIn 0.5s ease-in-out;
    margin-bottom: 12px;
}

.document-content {
    margin-top: 6px;
    font-size: var(--fs-base);
    line-height: 1.4;
    color: var(--text-sub);
}

.document-properties {
    margin-top: 6px;
    font-size: var(--fs-base);
    color: var(--text-sub);
}

.document-property-list {
    display: grid;
    grid-template-columns: max-content auto;
    grid-gap: 6px 12px;
    margin: 0;
}

.document-property-list dt {
    font-weight: bold;
    color: var(--text-sub);
    text-align: right;
}

.document-property-list dd {
    margin: 0;
    color: var(--text-sub);
    overflow-wrap: break-word;
    word-break: break-all;
}



@keyframes pulse {
    0% {
        transform: scale(0.9);
        opacity: 0.7;
    }
    50% {
        transform: scale(1.1);
        opacity: 1;
    }
    100% {
        transform: scale(0.9);
        opacity: 0.7;
    }
}

@keyframes ripple {
    0% {
        transform: scale(1);
        opacity: 0;
    }
    40% {
        opacity: 0.5;
    }
    100% {
        transform: scale(2.2);
        opacity: 0;
    }
}

@keyframes fadeIn {
    0% { opacity: 0; transform: translateY(10px); }
    70% { opacity: 0.7; transform: translateY(-2px); }
    100% { opacity: 1; transform: translateY(0); }
}

@keyframes loading {
    0% { left: -100%; }
    50% { left: 100%; }
    100% { left: 100%; }
}

.product-card { border-radius: var(--media-radius); overflow: hidden; transition: opacity 0.3s, outline 0.3s; }
.product-card.mentioned { outline: 2px solid var(--text); outline-offset: -2px; }
.product-card.not-mentioned { opacity: 0.35; }

/* --group-columns: min(groups.length, GROUP_MAX_COLUMNS), set by renderResultsGrid, caps the
   panel's width. Groups wrap in one row, each sized to its content, so short groups share a
   row. Re-centered via left:50%/translateX(-50%) against the already-centered .message-content
   parent. */
.results-panel {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: start;
    position: relative;
    left: 50%;
    transform: translateX(-50%);
    width: calc(var(--group-columns, 1) * 780px + (var(--group-columns, 1) - 1) * 16px);
    max-width: calc(100vw - 48px);
}
.results-group {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px; /* heading-to-grid spacing, since .results-panel's own gap only applies between groups */
}
.results-group-heading {
    padding: 8px 4px;
    gap: 8px;
}
.results-group-heading::after {
    font-size: var(--fs-lg);
}
.results-grid {
    display: grid;
    --card-width: 140px;
    grid-template-columns: repeat(auto-fill, minmax(var(--card-width), 1fr));
    gap: 8px;
}
.results-grid.collapsed {
    display: none;
}

.search-indicator-container.search-done::after {
    animation: none;
    display: none;
}
.search-indicator-container.search-done .search-pulse,
.search-indicator-container.search-done .search-pulse::after {
    animation: none;
    opacity: 0.4;
}

/* Sample-image picker (room-search + single-item search) — one shared popover per form,
   repositioned above whichever button opened it. See image-search.js's initSamplePicker().
   Subjects render as collapsible groups reusing settings.js's buildGroupSection()/
   .settings-group-* mechanism (same collapse/localStorage behavior, not reinvented here) —
   .image-picker-grid overrides just the body's layout (grid instead of flex-wrap). */
.image-picker-popover {
    display: none;
    flex-direction: column;
    position: absolute;
    bottom: calc(100% + 10px);
    left: 0;
    width: min(760px, calc(100vw - 48px)); /* grows past the old fixed 640px when the viewport allows it */
    max-height: min(640px, calc(100vh - 140px)); /* never taller than the viewport allows above the input bar */
    background-color: var(--surf);
    border: 1px solid var(--rule);
    border-radius: var(--media-radius);
    padding: 10px;
    z-index: 1100;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* Added by image-search.js's toggle() when there's genuinely more room below the button
   than above it — flips the anchor edge instead of leaving the popover's top rendered
   above the scrollable document. */
.image-picker-popover.open-below {
    bottom: auto;
    top: calc(100% + 10px);
}

/* Scrolls independently of .image-picker-upload-row below, which stays pinned in view —
   min-height:0 is required for a flex child to actually scroll instead of just growing
   its flex parent past max-height. */
.image-picker-groups {
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    padding-right: 14px; /* clearance so items/chevron don't sit flush against the scrollbar */
}

.image-picker-upload-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--rule);
    cursor: pointer;
    color: var(--text);
    flex-shrink: 0;
    font-size: var(--fs-base);
}

.image-picker-upload-row:hover {
    background-color: var(--surf);
    border-radius: var(--media-radius);
}

.image-picker-grid.settings-group-body {
    display: grid;
    /* Capped, not minmax(..., 1fr) — thumbnails here stay small and consistent regardless
       of how many items are in a group; a sparse group just leaves blank space to the
       right instead of stretching its few cards to fill the row. */
    grid-template-columns: repeat(auto-fit, minmax(var(--item-thumb-min), var(--item-thumb-max)));
    gap: 8px;
    max-height: 2000px; /* generous cap so a full subject group (up to ~17 items) never clips */
}

/* Room photos are whole-room scenes — 2x the item picker's own thumbnail size above (see
   --item-thumb-min/-max), so enough of the room is actually visible to judge by. */
#room-picker-popover .image-picker-grid.settings-group-body,
#bottom-room-picker-popover .image-picker-grid.settings-group-body {
    grid-template-columns: repeat(auto-fit, minmax(calc(var(--item-thumb-min) * 2), calc(var(--item-thumb-max) * 2)));
}

/* .settings-group-body.collapsed (max-height:0) and the grid rule above have equal
   specificity (2 classes each) — without this, whichever is later in the stylesheet always
   wins regardless of collapsed state. This 3-class rule outranks both, so collapse always
   applies to the grid too. */
.image-picker-grid.settings-group-body.collapsed {
    max-height: 0;
}

.image-picker-item {
    cursor: pointer;
    text-align: center;
    min-width: 0;
}

.image-picker-item img {
    width: 100%;
    height: auto; /* keeps each image's real aspect ratio (room photos square, item crops
                     vary) — grows both dimensions with the column instead of a fixed
                     height cropping/distorting it */
    display: block;
    border: 2px solid transparent;
}

.image-picker-item:hover img {
    border-color: var(--text);
}

.image-picker-item span {
    display: block;
    font-size: var(--fs-sm);
    color: var(--text-sub);
    margin-top: 3px;
    line-height: 1.2;
    overflow-wrap: break-word;
}

/* Tutorial modal — explains whichever attach icons are actually visible (/image-search
   included only when MEILI_CONFIG.defaults.imageSearchHidden is false). Built dynamically
   in chat.js's initTutorial() rather than hardcoded here, so it never drifts from what's
   actually on screen. */
.tutorial-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.tutorial-modal {
    background-color: var(--surf);
    border: 1px solid var(--rule);
    border-radius: var(--media-radius);
    padding: 24px;
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    overflow-y: auto;
    color: var(--text);
}

.tutorial-modal h4 {
    margin-top: 0;
    margin-bottom: 16px;
}

.tutorial-item {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding: 10px 0;
    border-bottom: 1px solid var(--rule);
}

.tutorial-item:last-child {
    border-bottom: none;
}

.tutorial-item i {
    font-size: var(--fs-lg);
    color: var(--text-sub);
    width: 24px;
    text-align: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.tutorial-item-title {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}

.tutorial-item-desc {
    font-size: var(--fs-base);
    color: var(--text-sub);
}

.tutorial-close {
    margin-top: 18px;
    text-align: right;
}

.tutorial-close button {
    background-color: var(--surf);
    color: #ccc;
    border: 1px solid var(--rule2);
    border-radius: var(--media-radius);
    padding: 6px 14px;
    cursor: pointer;
}

.tutorial-close button:hover {
    border-color: var(--text);
}
