/* etf_screener — estilos (compact home + página /etf-screener/).
 * Depende de los tokens --bf-* que sirve el theme; fallbacks locales por si
 * el shortcode se usa fuera del theme. */

.escr-wrap {
    --escr-accent:   var(--bf-primary, #026580);
    --escr-bg:       #f9f9f9;
    --escr-panel-bg: #ffffff;
    --escr-border:   #e0e0e0;
    --escr-radius:   8px;
    --escr-shadow:   0 4px 12px rgba(0, 0, 0, 0.08);
    --escr-positive: var(--bf-buy, #27AE60);
    --escr-negative: var(--bf-sell, #E74C3C);
    --escr-neutral:  #6c757d;
    --escr-font:     'Roboto', system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
    font-family: var(--escr-font);
    box-sizing: border-box;
    max-width: 100%;
    position: relative;
}
.escr-wrap *, .escr-wrap *::before, .escr-wrap *::after { box-sizing: inherit; }

/* Guard load-bearing: el [hidden] del autocompletado no puede perder contra
 * reglas display de autor/theme (gotcha §8 de tool-plugin-pattern). */
.escr-wrap [hidden] { display: none !important; }

.escr-panel {
    background: var(--escr-panel-bg);
    border: 1px solid var(--escr-border);
    border-radius: var(--escr-radius);
    box-shadow: var(--escr-shadow);
    padding: 16px;
}

/* ── Cabecera ──────────────────────────────────────────────────────────── */
.escr-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--escr-border);
    padding-bottom: 10px;
    margin-bottom: 12px;
}
.escr-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #222;
    margin: 0;
    flex: 0 0 auto;
}
/* En la home el h2 del slot ya titula el bloque (tool-plugin-pattern §6) */
.escr-in-slot .escr-title { display: none; }

.escr-search-wrap { position: relative; flex: 1 1 200px; min-width: 150px; }
.escr-search {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.85rem;
    font-family: inherit;
}
.escr-search:focus { outline: none; border-color: var(--escr-accent); }
.escr-suggest {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--escr-border);
    border-radius: 4px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
    z-index: 30;
    max-height: 240px;
    overflow-y: auto;
}
.escr-suggest a {
    display: block;
    padding: 7px 10px;
    font-size: 0.8rem;
    color: #333;
    text-decoration: none;
    border-bottom: 1px solid #f1f1f1;
}
.escr-suggest a:last-child { border-bottom: none; }
.escr-suggest a:hover { background: rgba(2, 101, 128, 0.06); }

/* ℹ siempre último hijo, borde derecho (§3 plugin-ui-standards) */
.escr-controls .cpg-info-btn { margin-left: auto; }

.escr-select {
    padding: 7px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.8rem;
    font-family: inherit;
    background: #fff;
    color: #333;
    max-width: 170px;
}

/* ── Filtros avanzados (solo full) ─────────────────────────────────────── */
.escr-filters { margin-bottom: 12px; }
.escr-filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
    align-items: flex-end;
}
.escr-filter-row .escr-select { flex: 1 1 150px; max-width: none; }
.escr-filter-row label {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 0.7rem;
    color: var(--escr-neutral);
    flex: 1 1 90px;
    min-width: 80px;
}
.escr-filter-row input[type="number"] {
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.8rem;
    font-family: inherit;
    width: 100%;
}
.escr-reset {
    flex: 0 0 auto;
    padding: 7px 14px;
    border: 1px solid var(--escr-border);
    border-radius: 4px;
    background: #f1f1f1;
    color: #333;
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s ease;
}
.escr-reset:hover { background: #e2e2e2; }

.escr-meta {
    font-size: 0.75rem;
    color: var(--escr-neutral);
    margin-bottom: 8px;
    min-height: 1em;
}

/* ── Tabla (full) ──────────────────────────────────────────────────────── */
.escr-table-scroll { overflow-x: auto; }
.escr-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
.escr-table th,
.escr-table td { padding: 8px 8px; text-align: left; }
.escr-table th {
    background: #f2f2f2;
    font-weight: 700;
    color: #333;
    white-space: nowrap;
    user-select: none;
}
.escr-table th.escr-sortable { cursor: pointer; }
.escr-table th.escr-sortable:hover { background: #e9ecef; }
.escr-table th.escr-sorted-desc::after { content: ' ▾'; color: var(--escr-accent); }
.escr-table th.escr-sorted-asc::after  { content: ' ▴'; color: var(--escr-accent); }
.escr-table td { border-bottom: 1px solid #eee; }
.escr-table tbody tr:hover { background: rgba(2, 101, 128, 0.05); }
.escr-table th.escr-num,
.escr-table td.escr-num { text-align: right; white-space: nowrap; }
.escr-table a { color: var(--escr-accent); text-decoration: none; font-weight: 500; }
.escr-table a:hover { text-decoration: underline; }
.escr-sym { color: var(--escr-neutral); font-size: 0.72rem; }

.escr-wrap .positive { color: var(--escr-positive) !important; font-weight: 500; }
.escr-wrap .negative { color: var(--escr-negative) !important; font-weight: 500; }
.escr-wrap .neutral  { color: var(--escr-neutral); }

.escr-loading, .escr-empty {
    text-align: center;
    color: var(--escr-neutral);
    padding: 18px 8px;
    font-size: 0.82rem;
}

/* ── Pager (full) ──────────────────────────────────────────────────────── */
.escr-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 10px;
    font-size: 0.8rem;
    color: var(--escr-neutral);
}
.escr-pager button {
    padding: 5px 12px;
    border: 1px solid var(--escr-border);
    border-radius: 4px;
    background: #fff;
    color: var(--escr-accent);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
}
.escr-pager button:hover:not(:disabled) { background: rgba(2, 101, 128, 0.06); }
.escr-pager button:disabled { opacity: 0.4; cursor: default; }

.escr-error {
    padding: 14px;
    border: 1px solid var(--escr-border, #e0e0e0);
    border-radius: 8px;
    color: #6c757d;
    font-size: 0.85rem;
}

/* ── Lista compact ─────────────────────────────────────────────────────── */
.escr-list { display: flex; flex-direction: column; }
.escr-item {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 6px 2px;
    border-bottom: 1px solid #f1f1f1;
    font-size: 0.8rem;
}
.escr-item:last-child { border-bottom: none; }
.escr-item-name {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.escr-item-name a { color: var(--escr-accent); text-decoration: none; font-weight: 500; }
.escr-item-name a:hover { text-decoration: underline; }
.escr-item-ter  { flex: 0 0 56px; text-align: right; color: var(--escr-neutral); }
.escr-item-aum  { flex: 0 0 64px; text-align: right; font-weight: 500; }
.escr-item-r1y  { flex: 0 0 70px; text-align: right; }

/* ── Cabecera compact: UNA fila garantizada (tool-plugin-pattern §5) ───── */
.escr-compact .escr-panel { padding: 12px; }
.escr-compact .escr-search-wrap { flex: 0 1 170px; }
.escr-compact .escr-select { flex: 0 1 auto; max-width: 120px; font-size: 0.75rem; padding: 6px 6px; }
.escr-compact .escr-controls { padding-bottom: 6px; margin-bottom: 8px; gap: 6px; }
.escr-compact .escr-meta { margin-bottom: 4px; }
@media (min-width: 768px) {
    .escr-compact .escr-controls { flex-wrap: nowrap; }  /* móvil sí envuelve */
}

/* ── Fit-to-height en la fila clampada de la home (tool-plugin-pattern §7) ─
 * Depende de --bft-row-max / bft-row-clamped / bft-slot-body y el breakpoint
 * 900px del theme: si el theme los cambia, actualizar aquí. */
@media (min-width: 901px) {
    .bft-row-clamped .bft-slot-body:has(.escr-wrap) { height: var(--bft-row-max, auto); }
    .bft-row-clamped .escr-wrap  { height: 100%; }
    .bft-row-clamped .escr-panel { height: 100%; display: flex; flex-direction: column; }
    .bft-row-clamped .escr-list  { flex: 1 1 auto; min-height: 0; overflow: hidden; }
    /* Ajustado al slot ya no hay truncado: fuera el degradado del theme */
    .bft-row-clamped .bft-slot-body:has(.escr-wrap)::after { display: none; }
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .escr-panel { padding: 10px; }
    .escr-table { font-size: 0.75rem; }
    .escr-table th, .escr-table td { padding: 6px 5px; }
    .escr-item-aum { display: none; }
}
