/* css/recents-collections.css — Recents rail + text-saving Collections.
   Additive, self-contained. Built by js/features/recents-collections.js via a
   copyObserver on #results-container (mirrors compatibility-checker's copyObserver).
   No innerHTML for styled/user text. Reuses main.css tokens; respects
   prefers-reduced-motion; >=44px touch targets; aria-driven disclosure. */

/* -- Shell -------------------------------------------------------------- */
.rc {
    position: relative;            /* anchor for the absolutely-positioned saver */
    margin-top: var(--s-xl);
    display: flex;
    flex-direction: column;
    gap: var(--s-md);
    /* Reserve height -> zero CLS (mirrors #compat-strip in css/compatibility.css).
     * JS ships this mount `hidden`, then removeAttribute('hidden') reveals it and
     * injects the recents header (~44px) + open-by-default empty body (~109px) +
     * the collections bar (~46px) + the 16px inter-section gap. Holding that height
     * here means the document settles ONCE and the results grid + page-intro /
     * how-it-works / FAQ below never jump as the shell hydrates or as recents fill.
     *   recents section .... ~155px (44 toggle + 109 open empty body + 2 border)
     *   gap ................ 16px (--s-md)
     *   collections section  ~46px (44 bar + 2 border, manager closed when empty)
     *   ── ≈ 217px; round to 224px for font-metric / line-wrap headroom ── */
    min-height: 224px;
}
.rc[hidden] { display: none; }

/* Shared panel surface (matches .compat-strip / .tool-panel glass language). */
.rc-recents,
.rc-collections {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--r-md);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    overflow: hidden;
}

/* -- Recents: header toggle -------------------------------------------- */
.rc-recents__toggle,
.rc-collections__manage,
.rc-col__toggle {
    /* disclosure buttons: full-width, >=44px row */
    display: flex;
    align-items: center;
    gap: var(--s-sm);
    width: 100%;
    min-height: 44px;
    padding: var(--s-sm) var(--s-md);
    background: transparent;
    color: var(--c-text);
    font-size: 0.92rem;
    font-weight: 700;
    text-align: left;
    transition: background var(--t-fast);
}
.rc-recents__toggle:hover { background: var(--c-surface-hover); }
.rc-recents__icon { font-size: 1.05rem; line-height: 1; }
.rc-recents__title { flex: 0 0 auto; }
.rc-recents__count {
    display: inline-flex;
    align-items: center;
    min-width: 22px;
    height: 20px;
    padding: 0 7px;
    border-radius: var(--r-full);
    font-size: 0.72rem;
    font-weight: 800;
    color: #fff;
    background: var(--grad-brand);
}
.rc-recents__count[hidden] { display: none; }
.rc-recents__chevron {
    margin-left: auto;
    transition: transform var(--t-base);
    color: var(--c-text-muted);
}
.rc-recents__toggle[aria-expanded="false"] .rc-recents__chevron { transform: rotate(-90deg); }

/* -- Recents: horizontal rail ------------------------------------------ */
.rc-recents__body {
    display: flex;
    gap: var(--s-sm);
    padding: 0 var(--s-md) var(--s-md);
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-snap-type: x proximity;
    /* right-edge fade hints "more this way" (mirrors compat-platforms mask) */
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
}
.rc-recents__body::-webkit-scrollbar { display: none; }
.rc-recents__body[hidden] { display: none; }

/* -- Recents item ------------------------------------------------------- */
.rc-item {
    flex: 0 0 auto;
    scroll-snap-align: start;
    display: inline-flex;
    align-items: stretch;
    max-width: 240px;
    border: 1px solid var(--c-border);
    border-radius: var(--r-sm);
    background: rgba(255, 255, 255, 0.03);
    overflow: hidden;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.rc-item:hover { border-color: var(--c-border-hover); }

.rc-item__copy {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 2px;
    min-height: 44px;
    padding: 6px 10px;
    background: transparent;
    text-align: left;
    transition: background var(--t-fast);
}
.rc-item__copy:hover { background: var(--c-surface-hover); }
.rc-item__style {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--c-text-muted);
}
.rc-item__text {
    max-width: 180px;
    font-size: 1rem;
    color: var(--c-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.rc-item__save {
    flex: 0 0 auto;
    width: 44px;            /* >=44px touch target */
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-left: 1px solid var(--c-border);
    color: var(--c-text-secondary);
    background: transparent;
    transition: background var(--t-fast), color var(--t-fast);
}
.rc-item__save:hover { background: var(--grad-brand); color: #fff; }

/* fresh-copy entrance + cyan flash (one-shot) */
.rc-item--fresh { animation: rcItemIn var(--t-spring) both; }
.rc-item--copied,
.rc-saved--copied {
    border-color: var(--c-cyan);
    box-shadow: 0 0 0 1px var(--c-cyan), 0 0 16px rgba(6, 214, 160, 0.3);
}
@keyframes rcItemIn {
    from { opacity: 0; transform: translateX(-8px) scale(0.96); }
    to   { opacity: 1; transform: translateX(0) scale(1); }
}

/* -- Collections bar ---------------------------------------------------- */
.rc-collections__bar {
    display: flex;
    align-items: center;
    gap: var(--s-sm);
    min-height: 44px;
    padding: var(--s-sm) var(--s-md);
}
.rc-collections__title { font-weight: 700; }
.rc-collections__count { font-size: 0.78rem; color: var(--c-text-muted); }
.rc-collections__manage {
    margin-left: auto;
    width: auto;
    min-height: 44px;          /* >=44px touch target */
    padding: 6px 14px;
    border: 1px solid var(--c-border);
    border-radius: var(--r-sm);
    font-size: 0.8rem;
    color: var(--c-text-secondary);
}
.rc-collections__manage:hover {
    background: var(--c-surface-hover);
    border-color: var(--c-border-hover);
    color: var(--c-text);
}

/* -- Manager (disclosure) ----------------------------------------------- */
.rc-manager { padding: 0 var(--s-md) var(--s-md); display: flex; flex-direction: column; gap: var(--s-md); }
.rc-manager[hidden] { display: none; }

/* Trust footnote: local-only / no-account reassurance. */
.rc-note {
    margin: 0;
    font-size: 0.74rem;
    line-height: 1.4;
    color: var(--c-text-muted);
}

.rc-newcol { display: flex; gap: var(--s-sm); }
.rc-newcol__input {
    flex: 1 1 auto;
    min-height: 44px;
    padding: 8px 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--r-sm);
    background: rgba(255, 255, 255, 0.04);
    color: var(--c-text);
    font-size: 0.9rem;
}
.rc-newcol__input:focus-visible { outline: 2px solid var(--c-purple); outline-offset: 2px; }
.rc-newcol__add {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 8px 16px;
    border-radius: var(--r-sm);
    font-size: 0.82rem;
    font-weight: 700;
    color: #fff;
    background: var(--grad-brand);
    box-shadow: 0 4px 15px rgba(255, 45, 120, 0.25);
    transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.rc-newcol__add:hover { transform: translateY(-1px); box-shadow: 0 6px 22px rgba(255, 45, 120, 0.4); }

/* -- A collection ------------------------------------------------------- */
.rc-collist { display: flex; flex-direction: column; gap: var(--s-sm); }
.rc-col {
    border: 1px solid var(--c-border);
    border-radius: var(--r-sm);
    background: rgba(255, 255, 255, 0.02);
    overflow: hidden;
}
.rc-col__head { display: flex; align-items: center; }
.rc-col__toggle { flex: 1 1 auto; }
.rc-col__name { font-weight: 700; color: var(--c-text); }
.rc-col__count { font-size: 0.78rem; color: var(--c-text-muted); }
.rc-col__chevron { margin-left: auto; color: var(--c-text-muted); transition: transform var(--t-base); }
.rc-col__toggle[aria-expanded="false"] .rc-col__chevron { transform: rotate(-90deg); }
.rc-col__actions { flex: 0 0 auto; display: flex; padding-right: var(--s-xs); }
.rc-col__rename,
.rc-col__delete {
    width: 44px; min-height: 44px;     /* >=44px targets */
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--c-text-secondary);
    transition: color var(--t-fast), background var(--t-fast);
    border-radius: var(--r-sm);
}
.rc-col__rename:hover { color: var(--c-purple); background: var(--c-surface-hover); }
.rc-col__delete:hover { color: var(--c-pink); background: var(--c-surface-hover); }
.rc-col__delete--armed { color: #fff; background: var(--c-pink); }

.rc-col__name-input {            /* inline rename */
    min-height: 44px; padding: 6px 8px;
    border: 1px solid var(--c-border-hover); border-radius: var(--r-sm);
    background: var(--c-surface-solid); color: var(--c-text); font-weight: 700;
}

.rc-col__body { display: flex; flex-direction: column; gap: 4px; padding: var(--s-sm) var(--s-md); }
.rc-col__body[hidden] { display: none; }

/* -- A saved string ----------------------------------------------------- */
.rc-saved {
    display: flex; align-items: stretch;
    border: 1px solid var(--c-border); border-radius: var(--r-sm);
    background: rgba(255, 255, 255, 0.03);
    overflow: hidden;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.rc-saved__copy {
    flex: 1 1 auto; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
    min-height: 44px; padding: 6px 10px; text-align: left; background: transparent;
    transition: background var(--t-fast);
}
.rc-saved__copy:hover { background: var(--c-surface-hover); }
.rc-saved__label {
    font-size: 0.62rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.06em; color: var(--c-cyan);
}
.rc-saved__label[hidden] { display: none; }
.rc-saved__text {
    font-size: 1rem; color: var(--c-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.rc-saved__remove {
    flex: 0 0 auto; width: 44px; min-height: 44px;
    display: inline-flex; align-items: center; justify-content: center;
    border-left: 1px solid var(--c-border);
    color: var(--c-text-secondary); background: transparent;
    transition: background var(--t-fast), color var(--t-fast);
}
.rc-saved__remove:hover { background: rgba(255, 45, 120, 0.12); color: var(--c-pink); }

/* -- Empty states ------------------------------------------------------- */
.rc-empty {
    display: flex; align-items: flex-start; gap: var(--s-sm);
    padding: var(--s-md);
    font-size: 0.88rem; line-height: 1.45; color: var(--c-text-muted);
}
.rc-empty__icon { flex: 0 0 auto; font-size: 1.2rem; line-height: 1.45; opacity: 0.7; }
.rc-empty--mini { padding: var(--s-sm); font-size: 0.82rem; color: var(--c-text-muted); }

/* -- Save-to-collection popover ----------------------------------------- */
.rc-saver {
    position: absolute;       /* JS positions/anchors; z above cards (share=3) */
    z-index: 20;
    width: min(320px, calc(100vw - 2 * var(--s-md)));
    padding: var(--s-md);
    display: flex; flex-direction: column; gap: var(--s-sm);
    background: var(--c-surface-solid);
    border: 1px solid var(--c-border-hover);
    border-radius: var(--r-md);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}
.rc-saver[hidden] { display: none; }
.rc-saver__title {
    margin: 0;
    padding-right: 40px;          /* clear the close button */
    font-size: 0.78rem; font-weight: 800;
    text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--c-text-muted);
}
.rc-saver__preview {
    font-size: 1.05rem; color: var(--c-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    padding-bottom: var(--s-sm); border-bottom: 1px solid var(--c-border);
}
.rc-saver__label {
    min-height: 44px; padding: 8px 12px;
    border: 1px solid var(--c-border); border-radius: var(--r-sm);
    background: rgba(255, 255, 255, 0.04); color: var(--c-text); font-size: 0.9rem;
}
.rc-saver__targets { display: flex; flex-direction: column; gap: 4px; max-height: 200px; overflow-y: auto; }
.rc-saver__target,
.rc-saver__newtarget {
    display: flex; align-items: center; gap: var(--s-sm);
    min-height: 44px; padding: 8px 12px;
    border: 1px solid var(--c-border); border-radius: var(--r-sm);
    background: transparent; color: var(--c-text); font-size: 0.9rem; text-align: left;
    transition: background var(--t-fast), border-color var(--t-fast);
}
.rc-saver__target:hover,
.rc-saver__newtarget:hover { background: var(--c-surface-hover); border-color: var(--c-border-hover); }
.rc-saver__newtarget { color: var(--c-purple); font-weight: 700; }
.rc-saver__close {
    position: absolute; top: 2px; right: 2px;
    width: 44px; height: 44px;     /* >=44px touch target (glyph stays visually small) */
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--c-text-muted); border-radius: var(--r-sm);
}
.rc-saver__close:hover { color: var(--c-text); background: var(--c-surface-hover); }

/* -- Focus visibility (all interactive rc controls) -------------------- */
.rc button:focus-visible,
.rc input:focus-visible {
    outline: 2px solid var(--c-pink);
    outline-offset: 2px;
}

/* -- Mobile ------------------------------------------------------------- */
@media (max-width: 600px) {
    /* Narrow viewports wrap the open empty-state copy to ~4-5 lines, so the
     * reserved shell must grow too (mirrors #compat-strip's 132px -> 404px mobile
     * bump). recents ~196px (44 toggle + ~150 wrapped empty body + 2 border)
     * + 16px gap + ~46px collections bar -> ≈ 258px; round to 288px for ~320px
     * viewports that wrap one line more. Keeps the single-settle / zero-CLS goal. */
    .rc { margin-top: var(--s-lg); min-height: 288px; }
    .rc-item, .rc-item__text { max-width: 200px; }
    .rc-saver { position: fixed; left: var(--s-md); right: var(--s-md); bottom: var(--s-md); bottom: calc(var(--s-md) + env(safe-area-inset-bottom, 0px)); width: auto; }
}

/* Touch / no-hover: backdrop-filter is a compositor cost on long rails; soften. */
@media (hover: none) {
    .rc-recents, .rc-collections { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(18,18,32,0.72); }
}

/* -- Reduced motion ----------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .rc-recents__chevron, .rc-col__chevron { transition: none; }
    .rc-item--fresh { animation: none; }
    .rc-item--copied, .rc-saved--copied { box-shadow: 0 0 0 1px var(--c-cyan); }   /* keep confirm, drop glow motion */
}

/* light-mode: all tokens above (--c-surface, --c-border, --grad-brand, --c-cyan,
   --c-text*) already remap in html.light-mode (main.css), so no per-mode overrides
   are required. The popover uses --c-surface-solid (#fff in light mode) for opacity. */
