﻿/* ═══════════════════════════════════════════════════════════════════════════
   SALES ANALYTICS — sa-modal-confirm.css (v3)
   Confirm Mapping Modal (Stage B). Loads after sa-shared.css.

   Owns:
     - Filter input row at the top of the modal body
     - Strong-match section: flat list, vendor pill on each row
     - Weak-match section: expandable, vendor-grouped, dimmer styling
     - Candidate row layout: checkbox + name + meta line
     - Vendor pill on flat strong rows
     - Vendor group headers (weak section only)
     - Empty-filter and empty-list states

   Does NOT own:
     - Modal shell (.sa-modal, .sa-modal-dialog, header/body/footer,
       loading/error/empty states, .sa-modal-intro) — sa-shared.css
     - .sa-btn.ghost-warn for the "no match" button — sa-shared.css

   Modal markup: Pages/SalesAnalytics/Partials/_ConfirmMappingModal.cshtml
   JS handlers: sales-analytics.js → openConfirmModal, renderConfirmPayload,
                                     handleConfirmSave, handleConfirmNoMatch
   ═══════════════════════════════════════════════════════════════════════════ */


/* ── FILTER INPUT ──────────────────────────────────────────────────────── */

.sa-confirm-filter {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .5rem .75rem;
    margin-bottom: .85rem;
    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);
}

    .sa-confirm-filter:focus-within {
        border-color: rgba(37, 99, 235, .55);
        box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
    }

.sa-confirm-filter-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}

.sa-confirm-filter-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: .88rem;
    font-family: inherit;
    color: var(--text-main);
    min-width: 0;
}

    .sa-confirm-filter-input::placeholder {
        color: var(--text-muted);
    }


/* ── STRONG MATCHES (flat list) ────────────────────────────────────────── */

.sa-confirm-strong-list {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
    border: 1px solid var(--glass-stroke);
    border-radius: 12px;
    background: rgba(255, 255, 255, .82);
    overflow: hidden;
}

    .sa-confirm-strong-list > li + li {
        border-top: 1px solid rgba(148, 163, 184, .14);
    }


/* ── WEAK MATCHES (expandable, grouped) ────────────────────────────────── */

.sa-confirm-weak {
    border-top: 1px solid rgba(148, 163, 184, .18);
    padding-top: .85rem;
}

.sa-confirm-weak-toggle {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .4rem .7rem;
    border-radius: 8px;
    border: 1px solid var(--glass-stroke);
    background: rgba(255, 255, 255, .72);
    font-size: .82rem;
    font-weight: 560;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}

    .sa-confirm-weak-toggle:hover {
        background: rgba(255, 255, 255, .92);
        border-color: rgba(37, 99, 235, .30);
        color: var(--text-main);
    }

    .sa-confirm-weak-toggle[aria-expanded="true"] .sa-confirm-weak-chevron {
        transform: rotate(90deg);
    }

.sa-confirm-weak-chevron {
    transition: transform var(--t-fast);
    color: var(--text-muted);
}

.sa-confirm-weak-body {
    margin-top: .85rem;
    display: flex;
    flex-direction: column;
    gap: .65rem;
    /* The weak section is intentionally dimmer — it's the long tail. */
    opacity: .92;
}

/* Vendor group inside the weak body. Strong list never uses these. */
.sa-confirm-vendor-group {
    border: 1px solid var(--glass-stroke);
    border-radius: 10px;
    background: rgba(255, 255, 255, .65);
    overflow: hidden;
}

.sa-confirm-vendor-name {
    margin: 0;
    padding: .55rem .75rem;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid rgba(148, 163, 184, .12);
    background: rgba(248, 250, 252, .85);
}

.sa-confirm-candidate-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

    .sa-confirm-candidate-list > li + li {
        border-top: 1px solid rgba(148, 163, 184, .10);
    }


/* ── CANDIDATE ROW (used in both strong and weak sections) ─────────────── */

.sa-confirm-candidate {
    /* Outer <li>; the clickable surface is .sa-confirm-candidate-row inside. */
}

.sa-confirm-candidate-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: .65rem;
    align-items: start;
    padding: .65rem .75rem;
    cursor: pointer;
    transition: background var(--t-fast);
}

    .sa-confirm-candidate-row:hover {
        background: rgba(219, 234, 254, .25);
    }

    .sa-confirm-candidate-row input[type="checkbox"] {
        margin-top: .25rem;
        flex-shrink: 0;
    }

        .sa-confirm-candidate-row input[type="checkbox"]:checked ~ .sa-confirm-candidate-main .sa-confirm-candidate-name {
            color: var(--accent-strong);
        }

.sa-confirm-candidate-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: .2rem;
}

/* Headline row: item name + (optional) vendor pill */
.sa-confirm-candidate-headline {
    display: flex;
    align-items: baseline;
    gap: .55rem;
    flex-wrap: wrap;
    line-height: 1.3;
}

.sa-confirm-candidate-name {
    font-size: .9rem;
    font-weight: 600;
    color: var(--text-main);
}

.sa-confirm-candidate-vendor-pill {
    display: inline-block;
    padding: 1px 7px;
    border-radius: var(--r-pill);
    font-size: .68rem;
    font-weight: 650;
    letter-spacing: .04em;
    text-transform: uppercase;
    background: var(--accent-soft);
    color: var(--accent-strong);
    border: 1px solid rgba(37, 99, 235, .18);
    flex-shrink: 0;
}

/* Meta line: dates / frequency / price / code, separated by · */
.sa-confirm-candidate-meta {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0 .35rem;
    font-size: .76rem;
    line-height: 1.45;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.sa-confirm-meta-sep {
    color: rgba(148, 163, 184, .55);
    user-select: none;
}

.sa-confirm-candidate-price {
    color: var(--text-main);
    font-weight: 600;
}

.sa-confirm-candidate-code {
    color: rgba(148, 163, 184, .85);
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: .72rem;
    letter-spacing: .02em;
}


/* ── EMPTY STATES ──────────────────────────────────────────────────────── */

.sa-confirm-empty-filter {
    list-style: none;
    padding: 1rem .85rem;
    text-align: center;
    color: var(--text-muted);
    font-size: .82rem;
    font-style: italic;
}


/* ── COMPONENT-SCOPED RESPONSIVE ───────────────────────────────────────── */

@media (max-width: 640px) {
    .sa-confirm-candidate-row {
        padding: .55rem .65rem;
    }

    .sa-confirm-candidate-headline {
        gap: .35rem;
    }

    .sa-confirm-candidate-name {
        font-size: .88rem;
    }

    .sa-confirm-candidate-meta {
        font-size: .74rem;
    }

    /* On narrow screens, drop the code from the meta line — it's usually
       redundant with the item name, and meta wraps awkwardly otherwise. */
    .sa-confirm-candidate-code,
    .sa-confirm-candidate-code + .sa-confirm-meta-sep {
        display: none;
    }
}


/* =============================================================================
   sa-modal-confirm.css — RETAIL CATALOG ADDITIONS (v4 / Step 2 styles)

   Append these rules to your existing sa-modal-confirm.css (or wherever
   the .sa-confirm-* classes already live). All selectors here are NEW —
   no overrides of existing rules, so order within the file doesn't matter.

   Token references (--sa-*) match the variables defined in your existing
   sa-shared.css / sa-analytics.css. If a token isn't defined in your
   project, the rule will fall back to inherit/default and still render
   acceptably — but for the polished look, ensure these tokens exist:
     --sa-surface, --sa-surface-2, --sa-border, --sa-text, --sa-text-2,
     --sa-text-mut, --sa-accent-soft, --sa-pending, --sa-current,
     --sa-current-bg, --sa-current-bd, --sa-r-sm, --sa-r-md
   ============================================================================= */


/* ── Step transitions ───────────────────────────────────────────────────── */

.sa-confirm-step-hd {
    margin-bottom: 14px;
}

.sa-confirm-step-title {
    margin: 0 0 4px;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.005em;
}

.sa-confirm-step-sub {
    margin: 0;
    font-size: 13px;
    color: var(--sa-text-2);
    line-height: 1.45;
}

.sa-confirm-step-actions {
    margin-top: 14px;
    display: flex;
    gap: 8px;
}


/* ── Source cards (one per Step 1 selection) ────────────────────────────── */

.sa-sources-list {
    margin-top: 12px;
}

.sa-source-card {
    background: var(--sa-surface-2, #fafafa);
    border: 1px solid var(--sa-border, #e6e6e3);
    border-radius: var(--sa-r-md, 5px);
    padding: 14px 17px;
    margin-bottom: 10px;
    transition: background .12s ease, border-color .12s ease;
}

    .sa-source-card[data-units-confirmed="true"] {
        background: #f0fdf4;
        border-color: #86efac;
    }

.sa-source-card-hd {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--sa-border, #e6e6e3);
}

.sa-source-vendor {
    font-weight: 600;
    font-size: 15px;
    color: var(--sa-text, #0a0a0a);
    line-height: 1.3;
}

.sa-source-item {
    font-size: 13px;
    color: var(--sa-text-2, #525252);
    margin-top: 2px;
    line-height: 1.35;
}

.sa-preferred-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    color: var(--sa-text-2, #525252);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}


/* ── Form primitives (scoped to modal, won't conflict with page forms) ─── */

.sa-source-card-body .sa-form-group {
    margin-bottom: 12px;
}

    .sa-source-card-body .sa-form-group:last-child {
        margin-bottom: 0;
    }

.sa-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.sa-conversion-group {
    grid-column: 1 / -1;
}

.sa-conversion-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

    .sa-conversion-row .sa-combo-wrap {
        flex: 1;
    }

.sa-conversion-x {
    font-size: 18px;
    font-weight: 600;
    color: var(--sa-text-mut, #a3a3a3);
    flex-shrink: 0;
}

.sa-input-emph {
    font-size: 17px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    max-width: 120px;
    flex-shrink: 0;
}


/* ── Form labels and inputs ─────────────────────────────────────────────── */

.sa-source-card .sa-form-label,
.sa-confirm-step .sa-form-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--sa-text-2, #525252);
    margin-bottom: 5px;
}

.sa-form-label.sa-required::after {
    content: " *";
    color: #be123c;
}

.sa-source-card .sa-form-input,
.sa-confirm-step .sa-form-input {
    width: 100%;
    height: 36px;
    padding: 0 10px;
    font-family: inherit;
    font-size: 15px;
    border: 1px solid var(--sa-border, #e6e6e3);
    border-radius: var(--sa-r-sm, 3px);
    background: var(--sa-surface, #fff);
    color: var(--sa-text, #0a0a0a);
    transition: border-color .12s ease, box-shadow .12s ease;
}

    .sa-source-card .sa-form-input:focus,
    .sa-confirm-step .sa-form-input:focus {
        outline: none;
        border-color: #1f2937;
        box-shadow: 0 0 0 2px rgba(31, 41, 55, 0.08);
    }

    .sa-source-card .sa-form-input[readonly] {
        background: var(--sa-surface-2, #fafafa);
        color: var(--sa-text-2, #525252);
        cursor: not-allowed;
    }

.sa-confirm-step .sa-form-select {
    width: 100%;
    height: 36px;
    padding: 0 28px 0 10px;
    font-family: inherit;
    font-size: 15px;
    border: 1px solid var(--sa-border, #e6e6e3);
    border-radius: var(--sa-r-sm, 3px);
    background: var(--sa-surface, #fff);
    color: var(--sa-text, #0a0a0a);
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    background-image: linear-gradient(45deg, transparent 50%, var(--sa-text-2, #525252) 50%), linear-gradient(135deg, var(--sa-text-2, #525252) 50%, transparent 50%);
    background-position: calc(100% - 14px) center, calc(100% - 9px) center;
    background-size: 5px 5px;
    background-repeat: no-repeat;
}

    .sa-confirm-step .sa-form-select:focus {
        outline: none;
        border-color: #1f2937;
        box-shadow: 0 0 0 2px rgba(31, 41, 55, 0.08);
    }


/* ── Help text variants ─────────────────────────────────────────────────── */

.sa-source-card .sa-form-help,
.sa-confirm-step .sa-form-help {
    font-size: 12px;
    color: var(--sa-text-mut, #a3a3a3);
    margin: 5px 0 0;
    line-height: 1.45;
}

    .sa-source-card .sa-form-help code,
    .sa-confirm-step .sa-form-help code {
        font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
        font-size: 11.5px;
        background: var(--sa-accent-soft, #f1f1ee);
        padding: 1px 4px;
        border-radius: 2px;
        color: var(--sa-text, #0a0a0a);
    }

.sa-form-help-warn {
    color: var(--sa-pending, #b45309) !important;
}

.sa-form-help-info {
    color: var(--sa-current, #1d4ed8);
    background: var(--sa-current-bg, #eff6ff);
    border: 1px solid var(--sa-current-bd, #bfdbfe);
    padding: 6px 10px;
    border-radius: var(--sa-r-sm, 3px);
    margin-top: 6px !important;
}


/* The unconfirmed-warning paragraph is hidden when the chef ticks the
   confirmed checkbox. JS toggles via [data-units-confirmed] on the card. */
.sa-source-card[data-units-confirmed="true"] [data-source-unconfirmed-warning] {
    display: none;
}


/* ── Combo-box (input + datalist + resolution hint) ─────────────────────── */

.sa-combo-wrap {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sa-combo-input {
    flex: 1;
    min-width: 0; /* let it shrink inside flex container */
}

.sa-combo-resolved {
    font-size: 12px;
    color: var(--sa-text-mut, #a3a3a3);
    font-style: italic;
    white-space: nowrap;
    flex-shrink: 0;
}

    .sa-combo-resolved.sa-combo-unrecognized {
        color: var(--sa-pending, #b45309);
        font-style: normal;
        font-weight: 500;
    }


/* ── "I've verified" toggle ─────────────────────────────────────────────── */

.sa-confirm-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    margin-top: 10px;
    cursor: pointer;
    user-select: none;
    color: var(--sa-text, #0a0a0a);
}

    .sa-confirm-toggle input[type="checkbox"] {
        width: 16px;
        height: 16px;
        margin: 0;
        cursor: pointer;
        accent-color: #047857;
    }


/* ── Responsive: stack form rows on narrow modals ──────────────────────── */

@media (max-width: 640px) {
    .sa-form-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .sa-conversion-row {
        flex-wrap: wrap;
    }

    .sa-input-emph {
        max-width: 100%;
    }
}

/* =============================================================================
   sa-modal-confirm.css — STALE DETECTION STYLES
   
   Append these rules to your existing sa-modal-confirm.css (or wherever
   the existing .sa-velocity-pill / .sa-confirm-* classes live). All
   selectors here are NEW — no overrides of existing rules.
   ============================================================================= */


/* ── Stale velocity pill (replaces velocity number on stale rows) ───────── */

.sa-velocity-stale {
    /* Override the normal pill — stale takes its visual slot entirely. */
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fca5a5;
    border-radius: var(--sa-r-sm, 3px);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: background .12s ease, border-color .12s ease, transform .08s ease;
}

    .sa-velocity-stale:hover {
        background: #fee2e2;
        border-color: #f87171;
    }

    .sa-velocity-stale:active {
        transform: scale(0.97);
    }

    .sa-velocity-stale:focus-visible {
        outline: 2px solid #dc2626;
        outline-offset: 1px;
    }

    .sa-velocity-stale svg {
        flex-shrink: 0;
        color: #dc2626;
    }

.sa-velocity-stale-label {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
}


/* ── Stale banner (top of Step 2 in stale-edit mode) ────────────────────── */

.sa-stale-banner {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    padding: 14px 16px;
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-left: 3px solid #dc2626;
    border-radius: var(--sa-r-md, 5px);
}

.sa-stale-banner-icon {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #dc2626;
    margin-top: 1px;
}

.sa-stale-banner-body {
    flex: 1;
    min-width: 0;
}

.sa-stale-banner-title {
    font-size: 14px;
    font-weight: 600;
    color: #7f1d1d;
    margin-bottom: 8px;
    line-height: 1.3;
}

.sa-stale-banner-diff {
    list-style: none;
    margin: 0 0 8px;
    padding: 0;
}

.sa-stale-banner-diff-source {
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px dashed #fca5a5;
}

    .sa-stale-banner-diff-source:last-child {
        margin-bottom: 0;
        padding-bottom: 0;
        border-bottom: none;
    }

.sa-stale-banner-diff-vendor {
    font-size: 13px;
    font-weight: 600;
    color: #991b1b;
    margin-bottom: 5px;
}

.sa-stale-banner-diff-meta {
    font-size: 12px;
    color: #b45309;
    margin-bottom: 6px;
    font-style: italic;
}

.sa-stale-banner-diff-fields {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 3px 12px;
    font-size: 12.5px;
    color: #7f1d1d;
    font-variant-numeric: tabular-nums;
}

.sa-stale-banner-diff-label {
    font-weight: 500;
    color: #991b1b;
}

.sa-stale-banner-diff-value {
    font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
}

.sa-stale-banner-diff-value-old {
    text-decoration: line-through;
    color: #9ca3af;
    margin-right: 6px;
}

.sa-stale-banner-diff-value-new {
    color: #7f1d1d;
    font-weight: 600;
}

.sa-stale-banner-diff-delta {
    color: #b91c1c;
    font-weight: 600;
    margin-left: 6px;
    font-size: 11.5px;
}

/* The "Effective cost per consumer unit" summary line — emphasized
   because it's the load-bearing margin-impact number. */
.sa-stale-banner-diff-cost {
    margin-top: 6px;
    padding: 6px 10px;
    background: #ffffff;
    border: 1px solid #fca5a5;
    border-radius: 3px;
    font-size: 12.5px;
    color: #7f1d1d;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.sa-stale-banner-diff-cost-label {
    font-weight: 600;
}

.sa-stale-banner-diff-cost-values {
    font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-variant-numeric: tabular-nums;
}

.sa-stale-banner-note {
    margin: 8px 0 0;
    font-size: 12.5px;
    color: #991b1b;
    line-height: 1.45;
}


/* ── Mobile responsive ──────────────────────────────────────────────────── */

@media (max-width: 640px) {
    .sa-stale-banner {
        padding: 12px;
    }

    .sa-stale-banner-diff-fields {
        grid-template-columns: 1fr;
        gap: 2px;
    }

    .sa-stale-banner-diff-cost {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
}

.sa-history-remove-locked {
    color: #9ca3af;
    font-size: 14px;
    cursor: help;
    user-select: none;
}

