/* ════════════════════════════════════════════════════
   search-page.css — the shared search page surface
   ════════════════════════════════════════════════════
   Lifted verbatim out of apps/chat-features.css (AB#13493 P1), where these
   rules lived because Chat was the control's first and only mount.

   They are here, and under controls/, because chat-features.css is loaded by
   the CHAT APP ALONE (Apps/Chat/.../js/main.js, _loadCss 'chat-features-css').
   A second mount of controls/search-page.js would have rendered completely
   unstyled — not subtly wrong, entirely unstyled — and nothing would have said
   so, because a class with no rule throws nothing and fails no type check.

   Every app that mounts the search page loads THIS sheet. The class prefix is
   app-search-* for the same reason: the surface belongs to no one app.

   Order is the order they held in chat-features.css, so nothing that ties on
   specificity changed which declaration wins. Measured before the lift, not
   assumed: no rule here was nested in an @media, and no selector mixes a search
   class with an unrelated Chat class. */


/* ── Search page shell (rendered into .chat-content-view) ── */
.app-search-page {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
    background: var(--bg-primary);
}

.app-search-topbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    /* 12px, not 24: the gutter was eating width the results row wants — a Space cell,
       a title, a snippet and a time all compete on one line. Vertical rhythm unchanged. */
    padding: 16px 12px 0;
}
.app-search-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px 6px 6px;
    border: none;
    background: none;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: var(--fs-body-lg);
    font-family: inherit;
    cursor: pointer;
    transition: color 120ms ease, background 120ms ease;
}
.app-search-back:hover { color: var(--text-primary); background: var(--bg-hover); }

/* Names the Space/Project a scoped "All chats" opened from — mirrors the design
   reference's SearchPage taking a spaceName/spaceColor, so a scoped page never
   reads as "search everything" by mistake. */
.app-search-scope {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: var(--fs-ui);
    font-weight: 600;
}
.app-search-scope-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.app-search-inner {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    /* 1100, not 860. The ask was a narrower left and right margin, and the gutter above is
       only half of it: the column is centred, so most of the white space either side came
       from this cap rather than from padding. It also buys the pills row one line instead of
       two - six content pills plus a Space filter and a sort pill did not fit in 860. */
    max-width: 1100px;
    margin: 0 auto;
    /* Matches the topbar gutter above — the two must agree or the box and the rows
       below it sit on different left edges. */
    padding: 16px 12px 24px;
    box-sizing: border-box;
}

/* ── Search box ── */
.app-search-box {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.app-search-box-icon {
    position: absolute;
    left: 16px;
    display: inline-flex;
    color: var(--text-muted);
    pointer-events: none;
}
.app-search-input {
    width: 100%;
    padding: 14px 46px 14px 46px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-panel);
    color: var(--text-primary);
    font-size: var(--fs-subtitle);
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}
.app-search-input::placeholder { color: var(--text-muted); }
.app-search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.app-search-clear {
    position: absolute;
    right: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 120ms ease, background 120ms ease;
}
.app-search-clear:hover { color: var(--text-primary); background: var(--bg-hover); }
.app-search-clear[hidden] { display: none; }

/* ── Controls row: source tabs, then the filter + sort pair ── */
.app-search-controls {
    display: flex;
    align-items: center;
    /* NOT space-between. With three children it spread them evenly and left the Space pill
       stranded in the middle of the row, equidistant from the pills it is not part of and the
       sort it belongs beside. The filters block takes the slack instead (margin-left: auto
       below), so the two dropdowns sit together at the right with the row gap between them.
       An absent filter row is an empty div that still takes the slack, so a host with no
       filters - Chat - keeps its sort right-aligned exactly as before. */
    justify-content: flex-start;
    gap: 12px;
    margin: 16px 0 8px;
    flex-shrink: 0;
}
.app-search-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.app-search-tab {
    padding: 7px 16px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-panel);
    color: var(--text-secondary);
    font-size: var(--fs-body);
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.app-search-tab:hover { background: var(--bg-hover); color: var(--text-primary); }
.app-search-tab.active {
    background: var(--accent);
    border-color: transparent;
    color: #fff;
}
/* THE FILTER PILL IS THE SORT PILL. A host-supplied narrowing control (Chaos has one,
   for Spaces) sits on this row beside the sort, and two controls meant to read as a
   pair drift apart the moment they own separate rules. Grouped selectors rather than a
   rename: a Space filter is not a sort, and stamping sort classes on it would mislead
   the next reader more than the duplication costs. */
.app-search-sort,
.app-search-filter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-panel);
    color: var(--text-secondary);
    font-size: var(--fs-body);
    font-family: inherit;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.app-search-sort:hover,
.app-search-filter:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--text-muted); }
.app-search-sort svg,
.app-search-filter svg { flex-shrink: 0; }
/* The label inside the pill. Found by the second mount’s class pin (AB#13493): the span was
   stamped and no stylesheet anywhere defined it, so it took whatever the button gave it. That
   was survivable and not right — the longest option is "Oldest to newest", and in a
   fixed-width pill an unconstrained span wraps to two lines and pushes the caret out of the
   control. One line, ellipsised if it has to be. */
.app-search-sort-label,
.app-search-filter-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* A Space name is arbitrary text, unlike the fixed sort labels, so it is capped here
   rather than allowed to push the pills row out of shape. */
.app-search-filter-label { max-width: 180px; }

/* ── Sort dropdown menu ── */
.app-search-sort-wrap,
.app-search-filter-wrap { position: relative; flex-shrink: 0; }
.app-search-filters { display: flex; align-items: center; gap: 8px; flex-shrink: 0; margin-left: auto; }
.app-search-sort-menu,
.app-search-filter-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 210px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
    z-index: 30;
}
.app-search-sort-menu[hidden],
.app-search-filter-menu[hidden] { display: none; }
/* The filter sits LEFT of the sort rather than at the row’s right edge, so its menu
   hangs from the left or it reaches back across the pills it belongs to. */
.app-search-filter-menu { right: auto; left: 0; }
.app-search-sort-option,
.app-search-filter-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 9px 12px;
    border: none;
    background: none;
    border-radius: 7px;
    color: var(--text-primary);
    font-size: var(--fs-body-lg);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 120ms ease;
}
.app-search-sort-option:hover,
.app-search-filter-option:hover { background: var(--bg-hover); }
.app-search-sort-option.selected,
.app-search-filter-option.selected { font-weight: 600; }
.app-search-sort-check,
.app-search-filter-check { color: var(--accent); flex-shrink: 0; }

/* ── Results ── */
.app-search-results {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    margin-top: 8px;
    /* Thin, light scrollbar matching the left sidebar (.sidebar-list). */
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.app-search-results::-webkit-scrollbar { width: 6px; }
.app-search-results::-webkit-scrollbar-track { background: transparent; }
.app-search-results::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.app-search-results::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
/* Top scroll-fade — results dissolve into the tabs/sort row as they scroll up.
   Applied only while scrolled (is-scrolled, set in chat-search-page.js) so the
   first row stays crisp at rest. Mask fades to transparent (theme-agnostic). */
.app-search-results.is-scrolled {
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 32px);
    mask-image: linear-gradient(to bottom, transparent 0, #000 32px);
}
.app-search-group { margin-bottom: 18px; }
.app-search-group-header {
    font-size: var(--fs-meta);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: var(--ls-caps);
    color: var(--text-muted);
    padding: 6px 4px;
}
.app-search-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    background: none;
    border-radius: 10px;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    color: var(--text-primary);
    transition: background 120ms ease;
}
.app-search-row:hover { background: var(--bg-hover); }
.app-search-row:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}
.app-search-row-icon {
    display: inline-flex;
    flex-shrink: 0;
    color: var(--text-muted);
}
.app-search-row-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.app-search-row-title {
    font-size: var(--fs-body-lg);
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.app-search-row-snippet {
    font-size: var(--fs-ui);
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* The Space column, between the body and the time.
   A fixed lane rather than a shrink-to-fit cell: the names line up down the
   list, which is what makes the column scannable — a ragged left edge reads as
   scattered metadata rather than as a column. 140px fits the names in practice
   and ellipsises the rest, with the full name on the element title.
   `flex-shrink: 1` keeps it yielding before the title does, so a long Space
   name still cannot squeeze what the row is called. */
.app-search-row-space {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    /* 160, not 140. A Chaos row names Space AND project when the content is in one, and
       "Teams > Lani Project" measures 129px against the 126px a 140px cell leaves after
       its 8px dot and 6px gap — it clipped by three pixels, which is the worst width to
       pick, because three pixels reads as a bug and not as a long name.

       The extra 20px comes from the TITLE, which is the row's only flexible column and
       gives it up out of several hundred. It could not come from the time column beside
       this one: see the measurement there — that column has no surplus to give. Chat's
       cells are ~45px and simply gain whitespace. Anything genuinely longer than this
       still ellipsises, with the full value on the title attribute. */
    flex: 0 1 160px;
    min-width: 0;
    font-size: var(--fs-ui);
    color: var(--text-secondary);
}
/* The same 8px dot the page's own scope header uses (.app-search-scope-dot
   above) — one convention for "which Space is this", not two. Its colour is
   inline because it is per-Space data, not a style. */
.app-search-row-space-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.app-search-row-space-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* A COLUMN, not a label. Sized to its content this pushed everything to its left by
   whatever its own text happened to measure — "just now" against "2h ago" moved the
   Space cell beside it 7px per row (measured), so a column of dots that should read as
   a straight line wandered instead. A fixed basis lines the two right-hand columns up on
   every row; the Chat page looks aligned already only because its rows all carry the same
   shape of text.

   88, AND ITS SLACK IS NOT SLACK. The common forms are short — "2h ago" is 51px, "just
   now" 52, "29m ago" 55 — so this column LOOKS over-wide on a fresh workspace. It is not:
   relativeSearchTime answers with a DATE past thirty days, and "Sep 30, 2026" measures 83.
   A first cut at 76px fitted everything a new workspace can show and would have overflowed
   the first row older than a month, which is the kind of defect that waits a month to
   appear. Measured rather than eyeballed: 88 clears the longest form the function can
   produce. There is nothing here to lend the Space column. */
.app-search-row-time {
    flex: 0 0 88px;
    text-align: right;
    font-size: var(--fs-ui);
    color: var(--text-muted);
    white-space: nowrap;
}
/* Not in the design reference — added on top of it. Same hover-only reveal
   convention as the sidebar's own "⋯" (.ch-tree-item-action). */
.app-search-row-action {
    display: inline-grid;
    place-items: center;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 0;
    border-radius: 7px;
    background: none;
    color: var(--text-muted);
    opacity: 0;
    cursor: pointer;
}
.app-search-row:hover .app-search-row-action,
.app-search-row-action:focus-visible {
    opacity: 1;
}
.app-search-row-action:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}
.app-search-row-action:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
}
.app-search-empty {
    padding: 48px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: var(--fs-body-lg);
}
