/*
 * NepseIQ — Screener
 * ───────────────────────────────────────────────────────────────────────
 * A research terminal, not a marketing page. The rules here are restraint:
 * one border weight, one radius, one shadow (none), colour reserved for
 * direction and state. Density comes from tight line-height and small type,
 * readability from consistent alignment and a monospaced numeric column.
 *
 * Tokens come from style.css — nothing new is invented here.
 */

.scr {
    --scr-row: 38px;
    --scr-gap: 10px;
    display: flex;
    flex-direction: column;
    gap: var(--scr-gap);
    padding-bottom: 32px;
}

/* ── header ───────────────────────────────────────────────────────────── */
.scr-head {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    padding: 4px 0 10px;
    border-bottom: 1px solid var(--border-color);
}
.scr-title { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.scr-title h1 {
    margin: 0; color: var(--text-primary);
}
.scr-count {
    font-size: 12px; color: var(--text-muted);
    font-variant-numeric: tabular-nums; white-space: nowrap;
}
.scr-count b { color: var(--text-primary); font-family: var(--font-mono); font-weight: 700; }

.scr-search-wrap { position: relative; flex: 1 1 280px; min-width: 200px; }
.scr-search-ic {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    width: 14px; height: 14px; color: var(--text-dim); pointer-events: none;
}
#scr-search {
    width: 100%;
    height: 32px;
    padding: 0 10px 0 30px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 12.5px;
    outline: none;
    transition: border-color var(--duration-fast, .15s);
}
#scr-search::placeholder { color: var(--text-dim); }
#scr-search:focus { border-color: var(--accent-blue); }

.scr-tools { display: flex; gap: 4px; flex-wrap: wrap; }
.scr-tool {
    height: 32px;
    padding: 0 11px;
    display: inline-flex; align-items: center; gap: 5px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    font-family: var(--font-main);
    font-size: 12px; font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--duration-fast, .15s), color var(--duration-fast, .15s),
                border-color var(--duration-fast, .15s);
}
.scr-tool:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.scr-tool.active { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border-hover); }
.scr-tool:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 1px; }
.scr-tool-badge {
    min-width: 16px; height: 16px; padding: 0 4px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--accent-blue); color: #fff;
    border-radius: 8px;
    font-family: var(--font-mono); font-size: 10px; font-weight: 700;
}
.scr-tool-badge[hidden] { display: none; }

/* ── condition chips ──────────────────────────────────────────────────── */
.scr-chips { display: flex; flex-direction: column; gap: 6px; }
.scr-chips[hidden] { display: none; }
.scr-chip-row { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.scr-chip {
    display: inline-flex; align-items: center; gap: 5px;
    height: 24px; padding: 0 4px 0 9px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 11.5px; font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}
.scr-chip-preset { padding-right: 9px; border-color: var(--border-hover); color: var(--accent-blue-light); }
.scr-chip-x {
    width: 16px; height: 16px;
    display: inline-flex; align-items: center; justify-content: center;
    background: none; border: 0; border-radius: 3px;
    color: var(--text-muted); font-size: 14px; line-height: 1;
    cursor: pointer;
}
.scr-chip-x:hover { background: var(--market-down-bg); color: var(--market-down); }
.scr-chip-x:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 1px; }
.scr-join, .scr-chip-clear {
    height: 24px; padding: 0 9px;
    background: transparent;
    border: 1px dashed var(--border-color);
    border-radius: 4px;
    color: var(--text-muted);
    font-family: var(--font-mono); font-size: 11px; font-weight: 700;
    cursor: pointer;
}
.scr-join:hover, .scr-chip-clear:hover { color: var(--text-primary); border-color: var(--border-hover); }

.scr-note {
    font-size: 11.5px; line-height: 1.5;
    color: var(--text-muted);
    padding: 6px 10px;
    border-left: 2px solid var(--border-color);
    background: var(--bg-surface);
    border-radius: 0 4px 4px 0;
}
.scr-note.warn { border-left-color: var(--accent-yellow); color: var(--text-secondary); }
.scr-note.bad { border-left-color: var(--market-down); color: var(--text-secondary); }

/* ── panels ───────────────────────────────────────────────────────────── */
.scr-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 14px 14px;
}
.scr-panel[hidden] { display: none; }
.scr-panel-head {
    display: flex; align-items: center; justify-content: space-between;
    font-size: 11px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase;
    color: var(--text-muted);
    padding-bottom: 10px; margin-bottom: 12px;
    border-bottom: 1px solid var(--border-subtle);
}
.scr-panel-x {
    width: 22px; height: 22px;
    background: none; border: 0; border-radius: 4px;
    color: var(--text-muted); font-size: 16px; line-height: 1; cursor: pointer;
}
.scr-panel-x:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.scr-panel-foot { font-size: 11.5px; color: var(--text-muted); margin: 12px 0 0; line-height: 1.55; }

.scr-btn {
    height: 28px; padding: 0 11px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    color: var(--text-secondary);
    font-family: var(--font-main); font-size: 12px; font-weight: 600;
    cursor: pointer;
}
.scr-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.scr-btn:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 1px; }
.scr-btn-primary { background: var(--accent-blue); border-color: var(--accent-blue); color: #fff; }
.scr-btn-primary:hover { background: #1d4ed8; color: #fff; }
.scr-btn-primary:disabled { opacity: .45; cursor: not-allowed; }

/* presets */
.scr-preset-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 6px;
}
.scr-preset {
    display: flex; flex-direction: column; gap: 3px;
    padding: 9px 11px;
    text-align: left;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    cursor: pointer;
    transition: border-color var(--duration-fast, .15s), background var(--duration-fast, .15s);
}
.scr-preset:hover { border-color: var(--border-hover); background: var(--bg-card-hover); }
.scr-preset.active { border-color: var(--accent-blue); background: var(--bg-elevated); }
.scr-preset b { font-size: 12.5px; font-weight: 700; color: var(--text-primary); }
.scr-preset span { font-size: 11px; line-height: 1.45; color: var(--text-muted); }

/* condition list + builder */
.scr-cond-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.scr-cond {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 6px 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 5px;
}
.scr-cond-text { font-size: 12.5px; font-weight: 600; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.scr-cond-x {
    background: none; border: 0; padding: 2px 6px; border-radius: 4px;
    color: var(--text-muted); font-size: 11px; font-weight: 600; cursor: pointer;
}
.scr-cond-x:hover { color: var(--market-down); background: var(--market-down-bg); }
.scr-cond-empty { font-size: 12px; color: var(--text-muted); padding: 8px 2px; }

.scr-builder { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.scr-builder select, .scr-builder input {
    height: 30px; padding: 0 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    color: var(--text-primary);
    font-family: var(--font-main); font-size: 12.5px;
    outline: none;
}
.scr-builder input { width: 110px; font-family: var(--font-mono); }
.scr-builder select:focus, .scr-builder input:focus { border-color: var(--accent-blue); }
.scr-builder #scr-b-metric { min-width: 190px; }
.scr-builder #scr-b-values { display: inline-flex; gap: 6px; }
.scr-sr { display: inline-flex; font-size: 0; }   /* label text is for screen readers */
.scr-b-help { flex: 1 1 100%; font-size: 11px; line-height: 1.5; color: var(--text-dim); }

/* unavailable metrics */
.scr-na { margin-top: 14px; border-top: 1px solid var(--border-subtle); padding-top: 10px; }
.scr-na summary {
    font-size: 11.5px; font-weight: 600; color: var(--text-muted);
    cursor: pointer; list-style: none;
}
.scr-na summary::-webkit-details-marker { display: none; }
.scr-na summary::before { content: '▸ '; color: var(--text-dim); }
.scr-na[open] summary::before { content: '▾ '; }
.scr-na-body { padding: 10px 0 0 14px; display: flex; flex-direction: column; gap: 5px; }
.scr-na-row { display: flex; gap: 10px; font-size: 11.5px; }
.scr-na-row b { min-width: 92px; color: var(--text-secondary); font-weight: 600; }
.scr-na-row span { color: var(--text-dim); }
.scr-na-body p { font-size: 11.5px; line-height: 1.6; color: var(--text-muted); margin: 6px 0 0; max-width: 62ch; }

/* columns */
.scr-col-wrap { display: grid; grid-template-columns: 1fr 230px; gap: 20px; }
.scr-col-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.scr-col-group h4, .scr-col-order h4 {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    font-size: 10px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
    color: var(--text-dim); margin: 0 0 6px;
}
.scr-col-item { display: flex; align-items: center; gap: 6px; padding: 2px 0; cursor: pointer; font-size: 12px; }
.scr-col-item input { accent-color: var(--accent-blue); }
.scr-col-item input:disabled + span { color: var(--text-dim); }
.scr-col-order ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.scr-col-order li {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 4px 8px; font-size: 12px;
    background: var(--bg-surface); border-radius: 4px;
}
.scr-col-move button {
    width: 20px; height: 20px; background: none; border: 1px solid var(--border-subtle);
    border-radius: 3px; color: var(--text-muted); cursor: pointer; font-size: 10px;
}
.scr-col-move button:hover:not(:disabled) { color: var(--text-primary); border-color: var(--border-hover); }
.scr-col-move button:disabled { opacity: .3; cursor: default; }

/* saved screens */
.scr-save-form { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
#scr-save-name {
    flex: 1 1 200px; height: 30px; padding: 0 9px;
    background: var(--bg-input); border: 1px solid var(--border-color);
    border-radius: 5px; color: var(--text-primary); font-size: 12.5px; outline: none;
}
#scr-save-name:focus { border-color: var(--accent-blue); }
.scr-saved-list { display: flex; flex-direction: column; gap: 4px; }
.scr-saved {
    display: flex; align-items: stretch; gap: 6px;
    background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: 5px;
}
.scr-saved-open {
    flex: 1; display: flex; align-items: baseline; gap: 10px;
    padding: 8px 11px; background: none; border: 0; text-align: left; cursor: pointer;
}
.scr-saved-open b { font-size: 12.5px; color: var(--text-primary); }
.scr-saved-open span { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.scr-saved:hover { border-color: var(--border-hover); }
.scr-saved-x {
    padding: 0 11px; background: none; border: 0; border-left: 1px solid var(--border-subtle);
    color: var(--text-dim); font-size: 11px; font-weight: 600; cursor: pointer;
}
.scr-saved-x:hover { color: var(--market-down); }

/* ── table ────────────────────────────────────────────────────────────── */
.scr-table-wrap {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: auto;
    background: var(--bg-card);
    /* Vertical room for a dense list without the page itself scrolling away
       from the toolbar. */
    max-height: calc(100vh - 220px);
}
.scr-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
}
.scr-table thead th {
    position: sticky; top: 0; z-index: 3;
    background: var(--bg-secondary);
    padding: 0 10px;
    height: 34px;
    text-align: right;
    white-space: nowrap;
    font-size: 12.5px; font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    user-select: none;
}
.scr-table thead th.left { text-align: left; }
.scr-table thead th:hover { color: var(--text-primary); }
.scr-table thead th.sorted { color: var(--text-primary); }
.scr-table thead th i { font-style: normal; font-size: 8px; margin-left: 3px; color: var(--accent-blue); }
.scr-table thead th:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: -2px; }

.scr-table tbody td {
    padding: 0 10px;
    height: var(--scr-row);
    text-align: right;
    white-space: nowrap;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    border-bottom: 1px solid var(--border-subtle);
}
.scr-table tbody td.left { text-align: left; font-family: var(--font-main); }
.scr-table tbody td.dim { color: var(--text-muted); font-size: 11.5px; }
/* The sector cell filters to that sector, the same action every sector tile
   elsewhere in the app now performs. */
.scr-sector-link {
    background: none; border: 0; padding: 0;
    color: inherit; font: inherit;
    cursor: pointer;
    border-bottom: 1px dotted transparent;
}
.scr-sector-link:hover { color: var(--accent-blue-light); border-bottom-color: currentColor; }
.scr-sector-link:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; border-radius: 2px; }
.scr-table tbody td.bold { font-weight: 700; }
.scr-table tbody td.na { color: var(--text-dim); }
.scr-table tbody td.up { color: var(--market-up); }
.scr-table tbody td.down { color: var(--market-down); }
.scr-table tbody td.hot { color: var(--accent-orange); font-weight: 700; }

.scr-table tbody tr { cursor: pointer; transition: background var(--duration-fast, .12s); }
.scr-table tbody tr:hover > td { background: var(--bg-card-hover); }
.scr-table tbody tr.expanded > td { background: var(--bg-elevated); }
.scr-table tbody tr:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: -2px; }

/* The symbol column stays put while the rest scrolls — the one thing a wide
   table must never lose is which row you are reading. */
.scr-table .sticky { position: sticky; left: 0; z-index: 2; background: var(--bg-card); }
.scr-table thead .sticky { z-index: 4; background: var(--bg-secondary); }
.scr-table tbody tr:hover > .sticky { background: var(--bg-card-hover); }
.scr-table tbody tr.expanded > .sticky { background: var(--bg-elevated); }
.scr-sym { display: inline-flex; align-items: center; gap: 7px; }
.scr-sym b { font-family: var(--font-mono); font-size: 12px; font-weight: 700; color: var(--text-primary); }

.scr-w52 {
    display: inline-block; vertical-align: middle;
    width: 46px; height: 3px; margin-right: 6px;
    background: var(--surface-2, var(--bg-input)); border-radius: 2px; overflow: hidden;
}
.scr-w52 > i { display: block; height: 100%; background: var(--accent-blue); }
.scr-w52-n { font-size: 11px; color: var(--text-muted); }

.scr-state {
    text-align: center !important;
    padding: 40px 20px !important;
    height: auto !important;
    display: table-cell;
    font-family: var(--font-main) !important;
    white-space: normal !important;
}
.scr-state b { display: block; font-size: 13px; color: var(--text-primary); margin-bottom: 5px; }
.scr-state span { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }

.scr-more {
    width: 100%; height: 34px;
    background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 6px;
    color: var(--text-secondary); font-size: 12px; font-weight: 600; cursor: pointer;
}
.scr-more:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.scr-more[hidden] { display: none; }

.scr-foot { font-size: 11px; line-height: 1.6; color: var(--text-dim); margin: 2px 0 0; max-width: 78ch; }

/* ── row detail ───────────────────────────────────────────────────────── */
#scr-detail-row > td { padding: 0 !important; height: auto !important; white-space: normal !important; background: var(--bg-elevated); }
.scr-detail {
    /* The detail cell spans a table that is wider than the viewport, so its
       content has to be pinned to the visible edge — otherwise the action
       button sits off-screen to the right and you have to scroll a horizontal
       bar to find the button that opens the stock. */
    position: sticky;
    left: 0;
    width: min(100%, calc(100vw - 40px));
    box-sizing: border-box;
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 24px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    font-family: var(--font-main);
    text-align: left;
}
.scr-detail-col h4 {
    font-size: 10px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
    color: var(--text-dim); margin: 0 0 8px;
}
.scr-why-row, .scr-cmp-row {
    display: grid;
    grid-template-columns: 1fr auto auto 16px;
    align-items: baseline; gap: 10px;
    padding: 4px 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 12px;
}
.scr-cmp-row { grid-template-columns: 1fr auto auto; }
.scr-why-row:last-child, .scr-cmp-row:last-child { border-bottom: 0; }
.scr-why-label, .scr-cmp-row > span:first-child { color: var(--text-secondary); }
.scr-why-row b, .scr-cmp-row b { font-family: var(--font-mono); font-weight: 700; font-variant-numeric: tabular-nums; }
.scr-why-rule { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); }
.scr-why-tick { text-align: center; font-weight: 700; }
.scr-cmp-row .dim { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }
.scr-detail .up { color: var(--market-up); }
.scr-detail .down { color: var(--market-down); }
.scr-detail-act { display: flex; align-items: flex-start; }

/* ── responsive ───────────────────────────────────────────────────────── */
/* Desktop is the primary surface for a data tool, so the table keeps its
   density everywhere and scrolls sideways rather than collapsing into cards.
   What changes on a phone is the chrome around it. */
@media (max-width: 1000px) {
    .scr-col-wrap { grid-template-columns: 1fr; }
    .scr-detail { grid-template-columns: 1fr; gap: 16px; }
    .scr-detail-act { justify-content: stretch; }
    .scr-detail-act .scr-btn { width: 100%; }
}
@media (max-width: 720px) {
    .scr-head { gap: 8px; padding-bottom: 8px; }
    .scr-title { width: 100%; justify-content: space-between; }
    .scr-search-wrap { flex-basis: 100%; order: 3; }
    .scr-tools { width: 100%; order: 4; }
    .scr-tool { flex: 1; justify-content: center; padding: 0 6px; }
    .scr-table-wrap { max-height: none; border-radius: 6px; }
    .scr-table { font-size: 12px; }
    /* If the company name column is on, it must not eat the screen before a
       single price is visible. */
    .scr-table tbody td.left { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
    .scr-preset-grid { grid-template-columns: 1fr; }
    .scr-builder #scr-b-metric,
    .scr-builder #scr-b-op { flex: 1 1 100%; min-width: 0; }
    .scr-builder input { flex: 1; width: auto; }
}

@media (prefers-reduced-motion: reduce) {
    .scr-tool, .scr-preset, .scr-table tbody tr { transition: none; }
}

/* Light theme: the table is the page, so its surfaces must follow the theme
   rather than staying dark against a light shell. */
:root[data-theme="light"] .scr-table thead th,
:root[data-theme="light"] .scr-table thead .sticky { background: var(--bg-secondary); }
:root[data-theme="light"] .scr-table .sticky { background: var(--bg-card); }
