/* ── TES: Target Estimation Screener — v1.0.0 ─────────────────────────────── */
:root {
    --tes-bg:        #0d0f14;
    --tes-bg2:       #13161e;
    --tes-bg3:       #1a1e28;
    --tes-border:    #252a38;
    --tes-text:      #d4d8e8;
    --tes-muted:     #5a6080;
    --tes-accent:    #00d4aa;
    --tes-blue:      #4d9fff;
    --tes-green:     #00e676;
    --tes-yellow:    #ffd740;
    --tes-red:       #ff5252;
    --tes-orange:    #ff9800;
    --tes-long:      #00e676;
    --tes-short:     #ff5252;
    --tes-row-hover: #1e2333;
    --tes-radius:    8px;
    --tes-font:      'Inter','Segoe UI',system-ui,sans-serif;
}

#tes-wrap * { box-sizing: border-box; margin: 0; padding: 0; }

#tes-wrap {
    font-family: var(--tes-font);
    font-size: 13px;
    color: var(--tes-text);
    background: var(--tes-bg);
    border: 1px solid var(--tes-border);
    border-radius: var(--tes-radius);
    overflow: hidden;
}

/* ── Header ── */
.tes-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px 20px;
    background: linear-gradient(135deg, #0f1420 0%, #151b2a 100%);
    border-bottom: 1px solid var(--tes-border);
}
.tes-title {
    display: flex; align-items: center; gap: 10px;
    font-size: 17px; font-weight: 700;
    color: var(--tes-accent); letter-spacing: .5px;
}
.tes-title span:first-child { font-size: 22px; }
.tes-meta {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.tes-badge {
    font-size: 12px; font-weight: 700;
    padding: 3px 10px; border-radius: 10px;
}
.tes-badge-long  { background: rgba(0,230,118,.15); color: var(--tes-green); border: 1px solid rgba(0,230,118,.3); }
.tes-badge-short { background: rgba(255,82,82,.15);  color: var(--tes-red);   border: 1px solid rgba(255,82,82,.3); }
.tes-cache-time  { color: var(--tes-muted); font-size: 11px; }

/* ── Legend ── */
.tes-legend {
    display: flex; gap: 14px; flex-wrap: wrap;
    padding: 8px 20px;
    background: var(--tes-bg); border-bottom: 1px solid var(--tes-border);
}
.tes-leg {
    font-size: 11px; color: var(--tes-muted);
    padding: 2px 8px; border: 1px solid var(--tes-border); border-radius: 10px;
    cursor: default;
}
.tes-leg:hover { color: var(--tes-accent); border-color: var(--tes-accent); }

/* ── Sections ── */
.tes-section { border-bottom: 2px solid var(--tes-border); }
.tes-section:last-of-type { border-bottom: none; }
.tes-section-title {
    font-size: 14px; font-weight: 700;
    padding: 10px 20px; letter-spacing: .4px;
    border-bottom: 1px solid var(--tes-border);
    display: flex; align-items: baseline; gap: 10px;
}
.tes-section-title small { font-size: 11px; font-weight: 400; color: var(--tes-muted); }
.tes-long-title  { color: var(--tes-green); background: rgba(0,230,118,.04); }
.tes-short-title { color: var(--tes-red);   background: rgba(255,82,82,.04); }

/* ── Table ── */
.tes-table-wrap {
    overflow-x: auto;
    max-height: 600px;
    overflow-y: auto;
}
.tes-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.tes-table thead th {
    position: sticky; top: 0; z-index: 10;
    background: #0e1119;
    color: var(--tes-muted); text-align: center;
    padding: 7px 5px; font-size: 11px;
    text-transform: uppercase; letter-spacing: .3px;
    border-bottom: 1px solid var(--tes-border);
    white-space: nowrap; user-select: none;
}
.tes-table thead th.sortable { cursor: pointer; }
.tes-table thead th.sortable:hover { color: var(--tes-accent); }
.tes-table thead th.sort-asc::after  { content: ' ↑'; color: var(--tes-accent); }
.tes-table thead th.sort-desc::after { content: ' ↓'; color: var(--tes-accent); }

.tes-table tbody tr.tes-row {
    border-bottom: 1px solid var(--tes-border);
    cursor: pointer; transition: background .12s;
}
.tes-table tbody tr.tes-row:hover { background: var(--tes-row-hover); }
.tes-table tbody td { text-align: center; padding: 6px 5px; white-space: nowrap; }

/* Grade borders */
.tes-grade-green  { border-left: 3px solid var(--tes-green); }
.tes-grade-yellow { border-left: 3px solid var(--tes-yellow); }
.tes-grade-red    { border-left: 3px solid var(--tes-muted); }

/* Rank */
.tes-rank { color: var(--tes-muted); font-size: 11px; min-width: 24px; }

/* Ticker */
.tes-ticker { text-align: left !important; padding-left: 10px !important; }
.tes-ticker-link { color: var(--tes-blue); text-decoration: none; font-size: 13px; }
.tes-ticker-link:hover { color: var(--tes-accent); text-decoration: underline; }

/* Sector */
.tes-sector { text-align: left !important; color: var(--tes-muted); font-size: 11px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }

/* Score */
.tes-score { min-width: 75px; }
.tes-score-green  strong { color: var(--tes-green); }
.tes-score-yellow strong { color: var(--tes-yellow); }
.tes-score-red    strong { color: var(--tes-muted); }
.tes-bar { height: 3px; background: var(--tes-border); border-radius: 2px; margin-top: 3px; overflow: hidden; }
.tes-bar-fill { height: 100%; border-radius: 2px; transition: width .3s; }
.tes-bar-long  { background: linear-gradient(90deg, var(--tes-green), var(--tes-accent)); }
.tes-bar-short { background: linear-gradient(90deg, var(--tes-red), var(--tes-orange)); }

/* Factor cells */
.tes-f { font-size: 11px; font-weight: 600; }

/* Value helpers */
.tes-pos { color: var(--tes-green); }
.tes-neg { color: var(--tes-red); }
.tes-hi  { color: var(--tes-accent); font-weight: 600; }
.tes-na  { color: var(--tes-border); }

/* Empty state */
.tes-empty { text-align: center; padding: 40px 20px; color: var(--tes-muted); font-size: 14px; }

/* Button */
.tes-btn {
    background: var(--tes-bg3); border: 1px solid var(--tes-border);
    color: var(--tes-accent); border-radius: 5px;
    padding: 5px 12px; font-size: 12px; cursor: pointer; transition: all .15s;
}
.tes-btn:hover  { background: var(--tes-accent); color: var(--tes-bg); border-color: var(--tes-accent); }
.tes-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Win Rate ── */
.tes-th-wr, .tes-th-days { min-width: 62px; }
.tes-wr, .tes-days { min-width: 62px; font-weight: 600; text-align: center; }
.tes-wr  { cursor: pointer; }
.tes-wr:hover { text-decoration: underline; opacity: .85; }
.tes-wr small { font-size: 10px; opacity: .65; margin-left: 2px; font-weight: 400; }
.tes-wr-good { color: var(--tes-green); }
.tes-wr-mid  { color: var(--tes-yellow); }
.tes-wr-bad  { color: var(--tes-red); }
.tes-wr-na   { color: var(--tes-muted); font-weight: 400; }
.tes-days-fresh { color: var(--tes-green); }
.tes-days-mid   { color: var(--tes-yellow); }
.tes-days-old   { color: var(--tes-red); }
.tes-days-na    { color: var(--tes-muted); font-weight: 400; }

/* ── Detail Modal ── */
.tes-modal {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.75); z-index: 99999;
    align-items: center; justify-content: center;
}
.tes-modal.open { display: flex; }
.tes-modal-inner {
    background: var(--tes-bg2); border: 1px solid var(--tes-border);
    border-radius: 10px; padding: 26px 28px;
    max-width: 580px; width: 94%;
    position: relative; max-height: 88vh; overflow-y: auto;
}
.tes-modal-close {
    position: absolute; top: 12px; right: 14px;
    background: none; border: none; color: var(--tes-muted);
    font-size: 18px; cursor: pointer;
}
.tes-modal-close:hover { color: var(--tes-text); }
#tes-modal-title {
    font-size: 18px; font-weight: 700; color: var(--tes-accent);
    margin-bottom: 16px; letter-spacing: .5px;
}
.tes-modal-score-row {
    display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px;
}
.tes-modal-score-card {
    background: var(--tes-bg3); border: 1px solid var(--tes-border);
    border-radius: 6px; padding: 8px 12px; text-align: center; min-width: 70px;
}
.tes-modal-score-label { font-size: 10px; color: var(--tes-muted); text-transform: uppercase; margin-bottom: 3px; }
.tes-modal-score-val   { font-size: 18px; font-weight: 700; }
.tes-modal-detail      { font-size: 11px; color: var(--tes-muted); line-height: 1.7; margin-top: 10px; word-break: break-word; }

/* ── Trade History Modal ── */
.tes-th-overlay { z-index: 100000; }
.tes-th-inner {
    background: var(--tes-bg2); border: 1px solid var(--tes-border);
    border-radius: 12px; padding: 26px 28px;
    width: 96%; max-width: 860px;
    max-height: 90vh; overflow-y: auto; position: relative;
}
.tes-th-title {
    font-size: 18px; font-weight: 700; color: var(--tes-accent);
    margin-bottom: 14px; letter-spacing: .4px;
}
.tes-th-side-badge {
    display: inline-block; padding: 2px 8px; border-radius: 8px;
    font-size: 11px; font-weight: 700; margin-left: 8px; vertical-align: middle;
}
.tes-th-side-long  { background: rgba(0,230,118,.15); color: var(--tes-green); }
.tes-th-side-short { background: rgba(255,82,82,.15);  color: var(--tes-red); }
.tes-th-summary { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.tes-th-card {
    background: var(--tes-bg3); border: 1px solid var(--tes-border);
    border-radius: 8px; padding: 10px 14px; text-align: center; min-width: 85px;
}
.tes-th-card-label { font-size: 10px; color: var(--tes-muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 3px; }
.tes-th-card-value { font-size: 20px; font-weight: 700; }
.tes-th-card-value.good { color: var(--tes-green); }
.tes-th-card-value.bad  { color: var(--tes-red); }
.tes-th-card-value.mid  { color: var(--tes-yellow); }
.tes-th-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.tes-th-table thead th {
    background: #0e1119; color: var(--tes-muted); text-align: center;
    padding: 7px 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .3px;
    border-bottom: 1px solid var(--tes-border); white-space: nowrap;
    position: sticky; top: 0; z-index: 5;
}
.tes-th-table tbody td {
    text-align: center; padding: 6px 8px;
    border-bottom: 1px solid var(--tes-border); white-space: nowrap;
}
.tes-th-table tbody tr:hover { background: var(--tes-row-hover); }
.tes-outcome { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.tes-outcome-tp    { background: rgba(0,230,118,.15); color: var(--tes-green); }
.tes-outcome-sl    { background: rgba(255,82,82,.15);  color: var(--tes-red); }
.tes-outcome-twin  { background: rgba(0,212,170,.12); color: var(--tes-accent); }
.tes-outcome-tloss { background: rgba(255,152,0,.15);  color: var(--tes-orange); }
.tes-outcome-open  { background: rgba(77,159,255,.15); color: var(--tes-blue); }
.tes-pnl-pos { color: var(--tes-green); font-weight: 600; }
.tes-pnl-neg { color: var(--tes-red);   font-weight: 600; }
.tes-pnl-neu { color: var(--tes-muted); }
.tes-th-loading { text-align: center; padding: 40px; color: var(--tes-muted); font-size: 14px; }
.tes-th-loading::before {
    content: ''; display: block; width: 32px; height: 32px;
    border: 3px solid var(--tes-border); border-top-color: var(--tes-accent);
    border-radius: 50%; animation: tes-spin .7s linear infinite; margin: 0 auto 12px;
}
@keyframes tes-spin { to { transform: rotate(360deg); } }

/* ── Toast ── */
.tes-toast {
    display: none; position: fixed; bottom: 30px; right: 30px;
    background: var(--tes-bg2); border: 1px solid var(--tes-accent);
    color: var(--tes-text); border-radius: 8px;
    padding: 12px 20px; font-size: 13px;
    z-index: 999999; box-shadow: 0 4px 20px rgba(0,0,0,.5);
}
.tes-toast.show { display: block; animation: tes-slide-in .25s ease; }
@keyframes tes-slide-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Scrollbar ── */
#tes-wrap ::-webkit-scrollbar       { width: 6px; height: 6px; }
#tes-wrap ::-webkit-scrollbar-track { background: var(--tes-bg); }
#tes-wrap ::-webkit-scrollbar-thumb { background: var(--tes-border); border-radius: 3px; }
#tes-wrap ::-webkit-scrollbar-thumb:hover { background: var(--tes-muted); }
