﻿/* ═══════════════════════════════════════════════════════════════════════════
   SALES ANALYTICS — sa-search.css
   Cross-source search dropdown (Stage A). Loads after sa-day.css.

   Layout decision (current revision):
     Invoice rows are always-visible with a compact two-line layout. The
     click-to-expand pattern was removed — metadata is compact enough to
     show inline without a second interaction. Result panel:

       [•] Item name                       Vendor · code
           Mar 30 · 1 delivery · $34.53        View detail →

     POS and Pattern rows stay one-line (less metadata to surface).

   Owns:
     - Search input wrap inside .sa-divisions-toolbar
     - Search input + clear + icon
     - Results panel positioning (absolute, bounded width, scrollable)
     - Section headers (POS / Invoice / Pattern groupings)
     - Result row variants (POS / invoice / pattern)
     - Compact two-line invoice row (.sa-search-result-row + .sa-search-result-detail)
     - Mapped-to-POS context block (.sa-search-result-mapped)
     - Pip indicators (linked/kitchen)
     - Inline "View detail →" button

   Does NOT own:
     - Divisions toolbar layout — sa-day.css
     - Modal opened by "View detail →" — sa-modal-vendor-detail.css
     - Tokens/primitives — sa-shared.css

   Note: there's a cross-cutting [hidden] attribute issue. Several files
   (this one previously among them) declared display:flex/grid on classes
   that the JS toggles via the [hidden] attribute. Class display rules
   override the user-agent [hidden] { display: none } rule because they
   tie on specificity and win on cascade order. We work around this by
   scoping [hidden] explicitly per-class, plus a global guard in
   sa-shared.css. See "Visibility hardening" below.
   ═══════════════════════════════════════════════════════════════════════════ */


/* ── SEARCH INPUT WRAP ─────────────────────────────────────────────────── */

.sa-divisions-toolbar .sa-search-wrap {
    flex: 1 1 280px;
    max-width: 420px;
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .4rem .75rem;
    border: 1px solid var(--glass-stroke);
    border-radius: 10px;
    background: rgba(255, 255, 255, .82);
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
    max-height: 42px;
}

    .sa-divisions-toolbar .sa-search-wrap:focus-within {
        border-color: rgba(37, 99, 235, .55);
        box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
    }

.sa-search-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}

#saSearch {
    flex: 1;
    border: none;
    outline: none;
    font-size: .88rem;
    font-family: inherit;
    background: transparent;
    color: var(--text-main);
    min-width: 0;
}

.sa-search-clear {
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0 .25rem;
    line-height: 1;
    transition: color var(--t-fast);
}

    .sa-search-clear:hover {
        color: var(--text-main);
    }


/* ── RESULTS PANEL ─────────────────────────────────────────────────────── */

.sa-search-results {
    list-style: none;
    margin: 0;
    padding: .5rem 1rem;
    line-height:1.8;
    border: 1px solid var(--glass-stroke);
    border-radius: 10px;
    background: rgba(255, 255, 255, .98);
    backdrop-filter: blur(10px);
    max-height: 480px;
    overflow-y: auto;
    position: absolute;
    right: 1.15rem;
    top: calc(100% - .35rem);
    width: min(560px, calc(100% - 2.3rem));
    z-index: 20;
    box-shadow: 0 12px 30px rgba(15, 23, 42, .12);
    

}

    /* Visibility hardening: [hidden] must take effect even when child
       rules set display: flex/grid. */
    .sa-search-results[hidden] {
        display: none !important;
    }

    .sa-search-results > li {
        padding: 0; /* per-row variants set their own padding */
        cursor: pointer;
        transition: background var(--t-fast);
    }

        .sa-search-results > li:hover {
            background: rgba(219, 234, 254, .35);
        }

    .sa-search-results .sa-no-match {
        padding: .9rem .85rem;
        color: var(--text-muted);
        cursor: default;
        font-style: italic;
        text-align: center;
    }

        .sa-search-results .sa-no-match:hover {
            background: none;
        }


/* ── SECTION HEADERS ───────────────────────────────────────────────────── */

.sa-search-section-header {
    display: flex !important;
    align-items: center;
    gap: .45rem;
    padding: .45rem .85rem !important;
    cursor: default !important;
    background: rgba(248, 250, 252, .82);
    color: var(--text-muted) !important;
    font-size: .68rem !important;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    border-top: 1px solid rgba(148, 163, 184, .14);
    border-bottom: 1px solid rgba(148, 163, 184, .10);
}

    .sa-search-section-header:first-child {
        border-top: none;
    }

    .sa-search-section-header:hover {
        background: rgba(248, 250, 252, .82) !important;
    }

.sa-search-section-icon {
    opacity: .8;
    font-size: .85rem;
}

.sa-search-section-label {
    flex: 1;
    min-width: 0;
}

.sa-search-section-count {
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    font-weight: 700;
}


/* ── POS RESULT ROW (single-line, compact) ─────────────────────────────── */
/* Layout: [name ──────────────────] [code] [division] */

.sa-search-result-pos {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: .65rem;
    align-items: center;
    padding: .5rem .85rem;
}

    .sa-search-result-pos .sa-result-desc {
        color: var(--text-main);
        font-size: .88rem;
        font-weight: 560;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .sa-search-result-pos .sa-result-meta {
        display: inline-flex;
        align-items: center;
        gap: .55rem;
        flex-shrink: 0;
        font-size: .78rem;
        font-variant-numeric: tabular-nums;
    }


/* ── INVOICE RESULT ROW (two-line, always visible) ─────────────────────── */
/*
   Outer <li> is a vertical stack (flex column).
   Line 1: .sa-search-result-row    — name (left) + vendor/code (right)
   Line 2 (optional): .sa-search-result-mapped  — "Sold as ..." block
   Line 3: .sa-search-result-detail — metadata + "View detail →"

   The "always visible" decision means [hidden] is never applied to
   .sa-search-result-detail by JS for invoice rows. We harden against
   accidental hide-via-attribute below anyway.
*/

.sa-search-result-invoice {
    display: flex;
    flex-direction: column;
    gap: .2rem;
    padding: .55rem .85rem;
}

/* Line 1: name on left, vendor + code on right */
.sa-search-result-row {
    display: flex;
    align-items: baseline;
    gap: .85rem;
    width: 100%;
    min-width: 0;
}

    .sa-search-result-row > .sa-result-desc {
        flex: 1;
        min-width: 0;
        font-size: .88rem;
        font-weight: 560;
        color: var(--text-main);
        line-height: 1.35;
        /* Allow the item name to wrap onto a second visual line if very long.
           Most names will fit on one. */
    }

    .sa-search-result-row > .sa-result-meta {
        flex-shrink: 0;
        display: inline-flex;
        align-items: baseline;
        gap: .55rem;
        font-size: .78rem;
        max-width: 45%;
        overflow: hidden;
    }

        .sa-search-result-row > .sa-result-meta .sa-result-vendor {
            color: var(--text-main);
            font-weight: 560;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 200px;
        }

        .sa-search-result-row > .sa-result-meta .sa-result-code {
            color: var(--text-muted);
            font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
            font-size: .72rem;
            font-variant-numeric: tabular-nums;
            white-space: nowrap;
            flex-shrink: 0;
        }

/* Pip indicators — small dots before the item name */
.sa-search-result-pip {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: .5rem;
    vertical-align: middle;
    text-indent: -9999px;
    overflow: hidden;
    flex-shrink: 0;
}

    .sa-search-result-pip.sa-pip-linked {
        background: var(--positive);
        box-shadow: 0 0 0 2px rgba(22, 163, 74, .18);
    }

    .sa-search-result-pip.sa-pip-kitchen {
        background: var(--warn);
        box-shadow: 0 0 0 2px rgba(249, 115, 22, .18);
    }

/* "Sold as ..." block — appears only on mapped invoice items */
.sa-search-result-mapped {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .35rem .55rem;
    margin-top: .15rem;
    padding: .3rem .5rem;
    border-radius: 6px;
    background: rgba(22, 163, 74, .05);
    border-left: 2px solid rgba(22, 163, 74, .40);
    font-size: .74rem;
}

.sa-search-result-mapped-label {
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .10em;
    text-transform: uppercase;
    color: var(--positive);
    margin-right: .15rem;
}

.sa-search-result-mapped-item {
    color: var(--text-muted);
}

    .sa-search-result-mapped-item strong {
        color: var(--text-main);
        font-weight: 600;
    }

.sa-search-result-mapped-more {
    color: var(--text-muted);
    font-style: italic;
    font-size: .70rem;
}

/* Line 2: detail row — always visible, compact metadata + button on right */
.sa-search-result-detail {
    display: flex;
    align-items: baseline;
    gap: .55rem;
    flex-wrap: wrap;
    width: 100%;
    min-width: 0;
    margin-top: .1rem;
}

    /* Visibility hardening: even though we don't toggle [hidden] anymore for
       the always-visible layout, this guards against future markup that
       might reintroduce it. Without this, [hidden] is a no-op when display
       is set to flex. */
    .sa-search-result-detail[hidden] {
        display: none !important;
    }

.sa-search-result-detail-item {
    color: var(--text-muted);
    font-size: .74rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.4;
    /* Inline-flex so each metadata segment stays on its own visual unit
       and the gap on the parent does the spacing. */
}

    /* Subtle separator dots between metadata segments using ::before.
       Skips the first item so the line starts cleanly. */
    .sa-search-result-detail-item + .sa-search-result-detail-item::before {
        content: "·";
        margin-right: .55rem;
        color: rgba(148, 163, 184, .55);
    }

    .sa-search-result-detail-item strong {
        color: var(--text-main);
        font-weight: 600;
    }

/* "View detail →" button — pushed to the right with margin-left: auto */
.sa-search-result-detail-btn {
    margin-left: auto;
    padding: .22rem .6rem;
    border-radius: var(--r-pill);
    border: 1px solid var(--glass-stroke);
    background: rgba(255, 255, 255, .85);
    color: var(--accent-strong);
    font-size: .72rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}

    .sa-search-result-detail-btn:hover {
        background: rgba(219, 234, 254, .55);
        border-color: rgba(37, 99, 235, .40);
        box-shadow: 0 2px 8px rgba(37, 99, 235, .12);
    }

/* Removed: .sa-search-result.sa-expanded styles. The expand-on-click
   behavior was retired with the always-visible layout. The JS still
   toggles the class but it has no visual effect. Cleanup pass can
   delete the JS toggle later. */


/* ── PATTERN RESULT ROW (single-line, like POS) ────────────────────────── */
/* Layout: [name ──────────────] [vendor] [code] [price (optional)] */

.sa-search-result-pattern {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: .65rem;
    align-items: center;
    padding: .5rem .85rem;
}

    .sa-search-result-pattern .sa-result-desc {
        color: var(--text-main);
        font-size: .88rem;
        font-weight: 560;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .sa-search-result-pattern .sa-result-meta {
        display: inline-flex;
        align-items: center;
        gap: .55rem;
        flex-shrink: 0;
        font-size: .78rem;
        font-variant-numeric: tabular-nums;
    }

    .sa-search-result-pattern .sa-result-vendor {
        color: var(--text-main);
        font-weight: 560;
        max-width: 160px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .sa-search-result-pattern .sa-result-code {
        color: var(--text-muted);
        font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
        font-size: .72rem;
    }

.sa-result-pattern-price {
    color: var(--text-main);
    font-weight: 700;
    font-size: .76rem;
    font-variant-numeric: tabular-nums;
}


/* ── COMPONENT-SCOPED RESPONSIVE ───────────────────────────────────────── */

@media (max-width: 1024px) {
    .sa-search-results {
        right: 1.15rem;
        left: 1.15rem;
        width: auto;
    }
}

@media (max-width: 640px) {
    /* On narrow screens, drop the max-width caps on vendor names and let
       things wrap. Better than horizontal truncation. */
    .sa-search-result-row > .sa-result-meta .sa-result-vendor {
        max-width: none;
    }

    .sa-search-result-row {
        flex-wrap: wrap;
    }

        .sa-search-result-row > .sa-result-meta {
            max-width: 100%;
        }

    /* Detail line: button drops below if metadata is wide. */
    .sa-search-result-detail {
        gap: .35rem .55rem;
    }

    .sa-search-result-detail-btn {
        margin-left: 0;
    }

    /* Pattern price gets dropped to its own visual line. */
    .sa-search-result-pattern .sa-result-meta {
        flex-wrap: wrap;
    }
}
