/* public/css/app.css
 *
 * Design language: "dark autumn" colour typing + "Natural/Relaxed" style
 * typing, drawn directly from Christina's own wardrobe colour analysis
 * rather than a generic dark-mode template. Deep warm charcoal-brown
 * background (not near-black — near-black reads sleek/cold, which works
 * against "warm and earthed"). Antique gold as the primary accent,
 * mirroring the 8ct/14ct gold jewellery family that recurs throughout the
 * catalogue. Burgundy and deep teal as secondary interactive accents.
 * Organic, slightly irregular serif for headings (Natural/Relaxed argues
 * against rigid geometric sans); clean humanist sans for body/UI text.
 */

:root {
    --bg-base:           #1c1410;   /* deep warm charcoal-brown, not black */
    --bg-surface:        #261c16;   /* cards, panels */
    --bg-surface-raised: #2f2319;   /* sticky bars, hover states */
    --bg-pill:           #2a1f18;
    --bg-pill-active:    #3d2c1a;

    --border-subtle:     #3a2c20;
    --border-strong:     #4a3826;

    --text-primary:      #dad0c3;   /* warm muted cream, colour-matched from the original design reference */
    --text-secondary:    #b8a890;
    --text-tertiary:     #8a7a64;

    --accent-gold:       #c9a35c;   /* antique gold — primary accent */
    --accent-gold-bright: #e0bc7a;
    --accent-burgundy:   #8b3a42;
    --accent-teal:       #2f6b5e;

    --score-badge-bg:    #3d2c14;
    --score-badge-text:  #e0bc7a;
    --score-badge-border:#6b5128;

    --font-display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
    --font-body: 'Inter', -apple-system, 'Segoe UI', sans-serif;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-pill: 999px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
    font-family: var(--font-display);
    font-weight: 500;
    letter-spacing: 0.01em;
}

/* ---------------------------------------------------------------------
   Top navigation: main category pills (sticky, always visible)
   --------------------------------------------------------------------- */

.sticky-header-group {
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--bg-base);
}

.nav-categories {
    padding: calc(0.85rem + env(safe-area-inset-top)) 1rem 0.6rem;
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    scrollbar-width: none;
}
.nav-categories::-webkit-scrollbar { display: none; }

.nav-categories .pill {
    flex: 0 0 auto;
    padding: 0.3rem 0.1rem;
    background: none;
    color: var(--text-secondary);
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 0.88rem;
    font-family: var(--font-body);
    white-space: nowrap;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
    margin-right: 1.1rem;
    display: inline-flex;
    align-items: center;
}
.nav-categories .pill:hover { color: var(--text-primary); }
.nav-categories .pill.active {
    color: var(--accent-gold-bright);
    border-bottom-color: var(--accent-gold);
}
.nav-categories .favourite-pill svg { display: block; }

/* Back button for a pushed grid card (depth > 0 only — e.g. a tag tap
   from an item) — sits inline as the first item in the nav-categories
   flex row, to the left of the pills, rather than floating fixed over
   them the way an item card's back button does. Being a normal flex
   child means the pills naturally shift right to make room; no
   special positioning is needed, unlike .item-back-btn which has to
   solve the "stay pinned while content scrolls" problem this button
   doesn't have (the whole row it lives in is already sticky). */
.grid-back-btn {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    margin-right: 0.6rem;
    padding: 0;
    border: none;
    background: none;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.grid-back-btn:hover { color: var(--text-primary); }

/* ---------------------------------------------------------------------
   Subcategory pills (sticky just below the main row, only when visible)
   --------------------------------------------------------------------- */

.nav-subcategories {
    padding: 0.5rem 1rem 0.6rem;
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    scrollbar-width: none;
}
.nav-subcategories::-webkit-scrollbar { display: none; }
.nav-subcategories.hidden { display: none; }

.pill.sub {
    flex: 0 0 auto;
    font-size: 0.78rem;
    padding: 0.35rem 0.85rem;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.pill.sub:hover { color: var(--text-primary); border-color: var(--border-strong); }
.pill.sub.active {
    background: var(--bg-pill);
    color: var(--accent-gold);
    border-color: var(--accent-gold);
}

/* ---------------------------------------------------------------------
   Toolbar row: sort / filter / ask (left) + item count (right).
   NOT sticky — it hides on scroll-down, reappears on scroll-up.
   --------------------------------------------------------------------- */

.toolbar {
    background: var(--bg-base);
    padding: 0.5rem 1rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    overflow: hidden;
    max-height: 100px; /* generous ceiling above the toolbar's natural content height, so normal state isn't clipped */
    transition: max-height 0.22s ease, opacity 0.22s ease, padding 0.22s ease;
}
/* Hide-on-scroll only applies on phone-width screens — desktop has
   plenty of vertical space, so the toolbar just stays visible there
   rather than adding animation complexity with no real benefit. */
@media (max-width: 480px) {
    .toolbar.scroll-hidden {
        max-height: 0;
        padding-top: 0;
        padding-bottom: 0;
        opacity: 0;
        pointer-events: none;
    }
}

.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.82rem;
    cursor: pointer;
}
.toolbar-btn:hover { color: var(--text-primary); border-color: var(--border-strong); }
.toolbar-btn.ask-btn {
    background: var(--bg-pill-active);
    color: var(--accent-gold-bright);
    border-color: var(--border-strong);
}

.item-count {
    margin-left: auto;
    font-size: 0.78rem;
    color: var(--text-tertiary);
    white-space: nowrap;
}

/* ---------------------------------------------------------------------
   Active filter pills row — appears below the toolbar only when at
   least one tag filter is selected. Lives inside .sticky-header-group
   as a sibling of .toolbar, so it scrolls/sticks with the rest of the
   header rather than needing its own positioning logic. Deliberately
   only covers tag selections (colour/style/pattern/material/occasion/
   season) — category/subcategory already have their own pill UI above
   and aren't duplicated here.
   --------------------------------------------------------------------- */

.active-filters-row {
    padding: 0 1rem 0.6rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}
.active-filters-row.hidden { display: none; }

.active-filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.5rem 0.25rem 0.65rem;
    border-radius: var(--radius-pill);
    background: var(--bg-pill-active);
    border: 1px solid var(--accent-gold);
    color: var(--accent-gold-bright);
    font-size: 0.75rem;
    cursor: pointer;
}
.active-filter-pill-x {
    font-size: 0.95rem;
    line-height: 1;
    opacity: 0.85;
}
.active-filter-pill:hover .active-filter-pill-x { opacity: 1; }

.active-filter-reset-btn {
    padding: 0.25rem 0.65rem;
    border-radius: var(--radius-pill);
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-tertiary);
    font-size: 0.75rem;
    cursor: pointer;
    margin-left: 0.2rem;
}
.active-filter-reset-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

/* ---------------------------------------------------------------------
   Item grid + cards
   --------------------------------------------------------------------- */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.9rem;
    padding: 0.5rem 1rem 3rem;
}

/* True desktop widths: fixed 8 columns, rather than letting
   auto-fill/minmax keep adding columns as the window gets wider — at
   typical desktop widths that was producing around 11 columns, which
   Christina felt was too many/too small to browse comfortably. Tablet
   widths (481px–1023px) still use the auto-fill behaviour above; only
   this wider band is fixed. */
@media (min-width: 1024px) {
    .grid {
        grid-template-columns: repeat(8, 1fr);
    }
}

/* Phone-width screens (iPhone 13 and similar: ~390px logical width):
   force exactly 2 columns with a small, deliberate gap, rather than
   relying on auto-fill/minmax which left noticeable dead space at this
   width. Wider screens keep the auto-fill behaviour above. */
@media (max-width: 480px) {
    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.4rem;
        padding: 0.5rem 0.5rem 3rem;
    }
}

.item-card {
    cursor: pointer;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    transition: border-color 0.15s ease, transform 0.15s ease;
}
.item-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-2px);
}

.item-photo-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    background: var(--bg-pill);
    overflow: hidden;
}
.item-photo-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.item-photo-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    font-size: 0.75rem;
    text-align: center;
    padding: 0.5rem;
}

.score-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(20, 14, 10, 0.55);
    border-radius: var(--radius-pill);
    padding: 0.15rem 0.5rem;
    border: none;
    color: var(--accent-gold-bright);
    font-size: 0.95rem;
    letter-spacing: 0.06em;
    text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.score-badge.zero-score {
    color: rgba(240, 230, 216, 0.75);
    font-size: 0.85rem;
}
.score-badge.no-score {
    color: rgba(240, 230, 216, 0.55);
    font-size: 0.85rem;
}

.favourite-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    background: rgba(20, 14, 10, 0.55);
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(240, 230, 216, 0.85);
    cursor: pointer;
    padding: 0;
}
.favourite-btn svg {
    width: 20px;
    height: 20px;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.55));
}
.favourite-btn.active { color: rgba(240, 230, 216, 0.95); }
.favourite-btn:not(.active) svg { fill: none; stroke: currentColor; stroke-width: 1.8; }

.item-meta {
    padding: 0.55rem 0.7rem 0.7rem;
}
.item-code {
    font-size: 0.68rem;
    color: var(--text-tertiary);
    letter-spacing: 0.03em;
}
.item-title {
    font-size: 0.85rem;
    color: var(--text-primary);
    margin-top: 0.1rem;
    line-height: 1.3;
}

/* ---------------------------------------------------------------------
   Filter panel — desktop inline, mobile bottom sheet
   --------------------------------------------------------------------- */

.filter-panel {
    position: fixed;
    z-index: 50;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    display: none;
}
.filter-panel.open { display: block; }

@media (min-width: 769px) {
    .filter-panel {
        top: 150px;
        left: 0;
        right: 0;
        width: auto;
        max-height: 70vh;
        overflow-y: auto;
        border-radius: 0;
        border-left: none;
        border-right: none;
        padding: 1.3rem 2rem;
    }
    .filter-panel .filter-tags { max-width: 1100px; }
    .filter-panel .filter-section-label { max-width: 1100px; }
}

@media (max-width: 768px) {
    .filter-panel {
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        padding: 1rem 1rem 1.5rem;
        max-height: 75vh;
        overflow-y: auto;
        transform: translateY(100%);
        transition: transform 0.25s ease;
    }
    .filter-panel.open { transform: translateY(0); }
}

.filter-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 7, 5, 0.55);
    z-index: 49;
    display: none;
}
.filter-overlay.open { display: block; }

.filter-section-label {
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    margin: 1rem 0 0.45rem;
}
.filter-section-label:first-child { margin-top: 0; }

.filter-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.filter-tag {
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-pill);
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
}
.filter-tag.selected {
    background: var(--bg-pill-active);
    border-color: var(--accent-gold);
    color: var(--accent-gold-bright);
}

/* Greyed-out / disabled state for a filter chip that would produce
   zero results if selected, given the currently active filters
   (computed client-side in grid-card.js against api/items_tags_lite.php's
   snapshot). Uses opacity rather than overriding background/border/
   color directly, since .filter-tag-colour chips already have those
   three properties set inline via JS for colour-matching — opacity
   composites over whatever's underneath regardless of whether that's
   the plain .filter-tag style or an inline colour-matched one, so this
   one rule correctly dims either chip type without needing two
   separate empty-state rules. pointer-events removed as a second guard
   alongside the chip's own `disabled` attribute (set in JS) — belt and
   suspenders, since a disabled button already doesn't fire clicks in
   standard browsers, but this also prevents any hover-state flicker. */
.filter-tag-empty {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

/* Sub-headers within a section (Hero / Neutrals / Other under Colour;
   category names under Style) — smaller and less prominent than the
   main section label, so the visual hierarchy reads as
   SECTION > sub-group > chips, not three equally-weighted levels. */
.filter-section-sublabel {
    font-size: 0.64rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    opacity: 0.75;
    margin: 0.7rem 0 0.35rem 0.1rem;
}
.filter-section-sublabel:first-of-type { margin-top: 0.3rem; }

/* Colour-matched chips: background/border/text colour are set inline
   via JS (one hex per colour, plus an auto dark/light text colour based
   on that hex's luminance — see colour-map.js), since they're
   necessarily per-value rather than expressible as a single CSS rule.
   Inline styles already take precedence over .filter-tag.selected's
   background/border/color rules, so a selected colour chip keeps its
   colour-match automatically — no override needed for those three
   properties. The only thing added here is a visible ring, layered on
   top via box-shadow, to show selection state without touching the
   colour-match itself. */
.filter-tag-colour.selected {
    box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 4px var(--accent-gold-bright);
}

/* ---------------------------------------------------------------------
   Ask / chat drawer — slides in from the right
   --------------------------------------------------------------------- */

.chat-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 380px;
    max-width: 92vw;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-subtle);
    z-index: 60;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
}
.chat-drawer.open { transform: translateX(0); }

.chat-drawer-header {
    padding: 1rem 1.1rem;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.chat-drawer-close {
    color: var(--text-tertiary);
    cursor: pointer;
    background: none;
    border: none;
    font-size: 1.1rem;
}

.chat-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 7, 5, 0.45);
    z-index: 59;
    display: none;
}
.chat-drawer-overlay.open { display: block; }
