/* ───────────────────────────────────────────────
   Lead Engine — v8 Premium Styles
   ─────────────────────────────────────────────── */

/* ── Layout ─────────────────────────────────── */
.lead-engine-container {
    display: flex;
    gap: 0;
    min-height: calc(100vh - 64px);
    background: #f8fafc;
    overflow-x: hidden;
}

/* ── Filter Panel (Slide-out) ── */
.btn-icon-sm {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s ease;
}

.btn-icon-sm:hover {
    background: #f1f5f9;
    color: var(--text-main);
}

.filter-backdrop {
    position: fixed;
    top: 64px;
    left: 0;
    width: 100vw;
    height: calc(100vh - 64px);
    background: rgba(15, 23, 42, 0.4);
    z-index: 1999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.filter-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

.filter-panel {
    position: fixed;
    top: 64px;
    right: -680px;
    width: 640px;
    height: calc(100vh - 64px);
    background: #ffffff;
    box-shadow: -4px 0 24px rgba(0,0,0,0.1);
    z-index: 2000;
    overflow-y: auto;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.filter-panel.panel-open {
    right: 0;
}

.panel-content {
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* Advanced toggle — hidden, all filters always visible */
.btn-toggle-advanced {
    display: none;
}

/* ── Two-column filter grid inside wider panel ── */
.filter-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
}
.filter-columns > .filter-col {
    display: flex;
    flex-direction: column;
}
/* Right column gets a left border for visual separation */
.filter-columns > .filter-col:last-child {
    border-left: 1px solid var(--border-color);
}

@media (max-width: 700px) {
    .filter-panel {
        width: 100vw !important;
        right: -100vw;
    }
    .filter-columns {
        grid-template-columns: 1fr;
    }
    .filter-columns > .filter-col:last-child {
        border-left: none;
        border-top: 1px solid var(--border-color);
    }
}

/* ── Accordions ────────────────────────────── */
.filter-accordion {
    border-bottom: 1px solid var(--border-color);
}
.filter-accordion summary {
    padding: 18px 20px;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--primary);
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #ffffff;
    transition: background 0.2s;
}
.filter-accordion summary::-webkit-details-marker { display: none; }
.filter-accordion summary:hover { background: #f8fafc; }
.filter-accordion summary i {
    color: var(--text-muted);
    transition: transform 0.3s ease;
    font-size: 0.8rem;
}
.filter-accordion[open] summary i {
    transform: rotate(-180deg);
}
.accordion-body {
    padding: 4px 20px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Slider Readouts ───────────────────────── */
.filter-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.slider-readout {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent-dark);
    background: #eff6ff;
    padding: 2px 8px;
    border-radius: 12px;
}
.dual-slider {
    position: relative;
    width: 100%;
    height: 30px;
    display: flex;
    align-items: center;
}
.dual-slider input[type="range"] {
    position: absolute;
    width: 100%;
    pointer-events: none;
    appearance: none;
    background: transparent;
}
.dual-slider input[type="range"]::-webkit-slider-thumb {
    pointer-events: auto;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.filter-group label {
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 4px;
}

/* ── Checkboxes ─────────────────────────────── */
.checkbox-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.cb-container {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    color: var(--text-main);
    cursor: pointer;
    font-weight: 500;
}
.cb-container .checkmark {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    transition: all 0.2s;
    flex-shrink: 0;
}
.cb-container input:checked ~ .checkmark {
    background: var(--accent);
    border-color: var(--accent);
}
.cb-container input:checked ~ .checkmark::after {
    content: '\f00c';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    color: white;
    font-size: 10px;
}
.cb-container input {
    display: none;
}

/* ── Active Filters Bar ─────────────────────── */
.active-filters-bar {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}
.active-filters-scroll {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex: 1;
}
.active-filter-tag {
    background: #f1f5f9;
    color: var(--text-main);
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid #e2e8f0;
}
.active-filter-tag .tag-remove {
    cursor: pointer;
    color: #94a3b8;
    transition: color 0.2s;
}
.active-filter-tag .tag-remove:hover {
    color: #ef4444;
}
.btn-clear-active {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    transition: color 0.2s;
}
.btn-clear-active:hover { color: var(--primary); }

/* ── Results Area ───────────────────────────── */
.lead-results {
    flex-grow: 1;
    min-width: 0;
    padding: 24px;
    transition: padding 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: #f8fafc;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: var(--spacing-xl);
    flex-wrap: wrap;
    gap: 12px;
}

.results-meta h2 {
    font-size: 1.8rem;
    font-weight: 900;
    color: var(--primary);
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

/* ── Grid ───────────────────────────────────── */
.leads-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
    align-items: stretch;
}

/* Cards never shrink below a readable width */
.leads-grid > .lead-card {
    min-width: 0;
}

@media (max-width: 1200px) {
    .leads-grid {
        grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    }
}

/* ── Card Base ──────────────────────────────── */
.lead-card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px; /* Increased internal gap for breathing room */
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    cursor: pointer;
    position: relative;
    height: 100%; /* Force consistent height in grid */
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.lead-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
    border-color: var(--primary-color);
}

/* Tier accent bar — neutral, lead type is the primary color driver */
.lead-card.tier-A { border-top: 3px solid #cbd5e1; }
.lead-card.tier-B { border-top: 3px solid #cbd5e1; }
.lead-card.tier-C { border-top: 3px solid #e2e8f0; }
.lead-card.tier-D { border-top: 3px solid #e2e8f0; }


/* ── Lead-type subtle card background tints ── */
.lt-card-renewal    { background: linear-gradient(135deg, #ffffff 80%, #f0fdf4 100%); }
.lt-card-shopper    { background: linear-gradient(135deg, #ffffff 80%, #fffbeb 100%); }
.lt-card-mixed      { background: linear-gradient(135deg, #ffffff 80%, #fff7ed 100%); }
.lt-card-distressed { background: linear-gradient(135deg, #ffffff 80%, #fef2f2 100%); }
.lt-card-low        { background: var(--surface); }

/* ── Card Header Row ────────────────────────── */
.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.card-title { flex: 1; min-width: 0; }

.card-title h4 {
    font-size: 1rem;
    font-weight: 800;
    color: var(--primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
    line-height: 1.3;
}

.card-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: 'SF Mono', ui-monospace, monospace;
}

.card-badges {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    flex-shrink: 0;
}

/* Tier badge — neutral now; lead type badge is the primary color signal */
.tier-badge {
    padding: 2px 7px;
    border-radius: 8px;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    white-space: nowrap;
    background: #f1f5f9;
    color: #94a3b8;
    border: 1px solid #e2e8f0;
}
.tier-badge.A { color: #64748b; }
.tier-badge.B { color: #64748b; }
.tier-badge.C { color: #94a3b8; }
.tier-badge.D { color: #94a3b8; }

/* ── Lead Type Badge ────────────────────────── */
.lt-badge {
    padding: 3px 9px;
    border-radius: 10px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.2px;
    white-space: nowrap;
}
.lt-badge.lt-renewal    { background: #dcfce7; color: #166534; }
.lt-badge.lt-shopper    { background: #fef3c7; color: #92400e; }
.lt-badge.lt-mixed      { background: #ffedd5; color: #c2410c; }
.lt-badge.lt-distressed { background: #fee2e2; color: #991b1b; }
.lt-badge.lt-low        { background: #f1f5f9; color: #64748b; }

/* ── Lead Type Tagline ──────────────────────── */
.lt-tagline {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: -8px;
    letter-spacing: 0.1px;
}

/* ── Scores Section ──────────────────────── */
.card-scores-section {
    display: flex;
    align-items: center;
    gap: 12px;               /* tighter gap so sub-metrics have more room */
    background: var(--background);
    border-radius: 10px;
    padding: 12px 14px;
    overflow: hidden;        /* prevent score block from ever overflowing card */
}

/* ── Hero Opp Score ─────────────────────────── */
.opp-score-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    position: relative;
}

.opp-score-main {
    display: flex;
    flex-direction: column;
    align-items: center;  /* Center number + qual-label + lead-score-label */
    text-align: center;
}

.opp-score-val {
    font-size: 2.6rem;       /* slightly smaller so it doesn't dominate narrow cards */
    font-weight: 900;
    line-height: 1;
    letter-spacing: -1.5px;
    display: inline-flex;
    align-items: flex-start;
    gap: 2px;
    white-space: nowrap;
}

/* Info icon inside the big hero number — small superscript-style */
.opp-score-val .risk-tooltip-icon {
    font-size: 0.6rem;
    margin-top: 4px;
    color: #cbd5e1;
    vertical-align: super;
    flex-shrink: 0;
}
.opp-score-val .risk-tooltip-icon:hover { color: #64748b; }

.opp-qual-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

.band-high-opp   { color: #166534; }
.band-strong-opp { color: #1e40af; }
.band-mod-opp    { color: #92400e; }
.band-low-pri    { color: #64748b; }


.opp-score-max {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-top: -2px;
}

.opp-score-label {
    font-size: 0.58rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-top: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
}

.opp-high .opp-score-val { color: #16a34a; }
.opp-mid  .opp-score-val { color: #2563eb; }
.opp-fair .opp-score-val { color: #d97706; }
.opp-low  .opp-score-val { color: #94a3b8; }

/* ── Sub Metrics ──────────────────────── */
.sub-metrics-row {
    flex: 1;
    min-width: 0;            /* critical: lets sub-metrics shrink in flex */
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 4px 6px;
    border-left: 1px solid var(--border);
    padding-left: 12px;
    overflow: hidden;
}

.sub-metric {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 2px;
}

.sub-metric-val {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-muted);
    line-height: 1.1;
}


.sub-metric-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.4px;
    white-space: nowrap;
}

/* Info icon inline next to the value number */
.sub-metric-val .risk-tooltip-icon {
    font-size: 0.65rem;
    margin-left: 2px;
    vertical-align: middle;
    color: #cbd5e1;
}
.sub-metric-val .risk-tooltip-icon:hover { color: #64748b; }

/* Lead score label info icon */
.opp-score-label .risk-tooltip-icon {
    font-size: 0.65rem;
    margin-left: 2px;
    vertical-align: middle;
    color: #cbd5e1;
}
.opp-score-label .risk-tooltip-icon:hover { color: #64748b; }

.metric-success { color: #16a34a; }
.metric-warn    { color: #d97706; }
.metric-danger  { color: #dc2626; }

/* ── Band Pills ─────────────────────────────── */
.band-pill {
    display: inline-block;
    font-size: 0.58rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-top: 1px;
}

/* Timing band pills */
.band-now       { background: #fee2e2; color: #991b1b; }
.band-active    { background: #fef3c7; color: #92400e; }
.band-soon      { background: #eff6ff; color: #1e40af; }
.band-early     { background: #f1f5f9; color: #64748b; }
.band-disrupted { background: #fdf4ff; color: #7c3aed; }
/* Placability band pills */
.band-easy      { background: #dcfce7; color: #166534; }
.band-standard  { background: #fef3c7; color: #92400e; }
.band-review    { background: #ffedd5; color: #c2410c; }
.band-hard      { background: #fee2e2; color: #991b1b; }
/* Risk band pills */
.band-strong    { background: #dcfce7; color: #166534; }
.band-caution   { background: #fef3c7; color: #92400e; }
.band-high-risk { background: #ffedd5; color: #c2410c; }
.band-severe    { background: #fee2e2; color: #991b1b; }
.band-elevated  { background: #ffedd5; color: #c2410c; }
.band-low       { background: #f0fdf4; color: #166534; }
.band-none      { background: #f1f5f9; color: #94a3b8; }
.band-mild      { background: #fefce8; color: #a16207; }
.band-warm      { background: #fff7ed; color: #c2410c; }
/* Legacy aliases (backward compat) */
.band-hot       { background: #fee2e2; color: #991b1b; }
.band-warm      { background: #fef3c7; color: #92400e; }
.band-moderate  { background: #eff6ff; color: #1e40af; }
.band-cold      { background: #f1f5f9; color: #64748b; }
.band-excellent { background: #dcfce7; color: #166534; }
.band-good      { background: #d1fae5; color: #065f46; }
.band-fair      { background: #fef3c7; color: #92400e; }
.band-poor      { background: #fee2e2; color: #991b1b; }

/* Info icon — larger and clickable */
.risk-tooltip-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 4px;
    cursor: pointer;
    color: #94a3b8;
    font-size: 0.75rem;
    vertical-align: middle;
    line-height: 1;
    flex-shrink: 0;
}
.risk-tooltip-icon:hover { color: var(--primary-color); }

/* ── Popovers ── */
.popover-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    z-index: 1000;
    pointer-events: none;
}

.lead-popover {
    position: absolute;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    padding: 16px;
    width: 260px;
    pointer-events: auto;
    z-index: 1001;
    animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.15);
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.popover-header {
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.popover-body {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-main);
}

.popover-arrow {
    position: absolute;
    width: 10px;
    height: 10px;
    background: white;
    border-left: 1px solid #e2e8f0;
    border-top: 1px solid #e2e8f0;
    transform: rotate(45deg);
}


/* ── Ops Snapshot ───────────────────────────── */
.ops-snapshot {
    display: flex;
    gap: 16px;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
}

.ops-snapshot span {
    display: flex;
    align-items: center;
    gap: 5px;
}

.ops-snapshot i { color: var(--text-muted); font-size: 0.7rem; }

/* ── Reason Bullets ─────────────────────────── */
.card-body-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex-grow: 1;
}

.card-reasons {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 84px;
}

.reason-bullet {
    display: flex;
    gap: 8px;
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--text-main);
}

.contact-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-main);
    margin-bottom: 4px;
}

.reason-bullet i {
    color: var(--accent);
    font-size: 0.55rem;
    margin-top: 4px;
    flex-shrink: 0;
}

.reason-bullet.text-muted { color: var(--text-muted); }

/* ── Contact ────────────────────────────────── */
.card-contact {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.82rem;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.contact-row {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-main);
}

.contact-row i {
    width: 14px;
    color: var(--text-muted);
    text-align: center;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.contact-link {
    color: var(--accent-dark);
    text-decoration: none;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
    display: inline-block;
}

.contact-link:hover { text-decoration: underline; }

.no-contact { font-style: italic; font-size: 0.78rem; }

.reach-row {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.reach-row i { font-size: 0.7rem; }
.reach-row strong { color: var(--text-main); }

/* ── CTAs ───────────────────────────────────── */
.card-actions {
    margin-top: auto;
    display: flex;
    gap: 8px;
}

.btn-score-breakdown,
.btn-analyze-risk {
    flex: 1;
    padding: 9px 8px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.8rem;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-score-breakdown {
    background: transparent;
    color: var(--text-muted);
    border: none;
}

.btn-score-breakdown:hover {
    background: var(--background);
    color: var(--text-main);
}

.btn-analyze-risk {
    background: var(--accent);
    color: white;
    border: none;
}

.btn-analyze-risk:hover {
    background: var(--accent-dark, #2563eb);
}

/* ── Pagination ─────────────────────────────── */
.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-top: auto;
    padding-top: var(--spacing-xl);
}

.pagination-controls .btn-outline {
    padding: 8px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
}

.pagination-controls .btn-outline:disabled { opacity: 0.5; cursor: not-allowed; }
.pagination-controls .btn-outline:not(:disabled):hover { background: var(--background); }

#page-indicator { font-weight: 700; font-size: 0.9rem; }

/* ── Form / Util overrides ──────────────────── */
.btn-primary {
    background: var(--accent-dark);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-primary:hover { background: var(--accent); }

.w-full { width: 100%; }
.mt-4   { margin-top: 16px; }

.form-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    background: var(--surface);
    color: var(--text-main);
}
.form-input:focus { outline: none; border-color: var(--accent); }