/* ── CVM Tracker styles ── */
:root {
    --tr-navy:    #001F62;
    --tr-blue:    #195AB4;
    --tr-green:   #198754;
    --tr-green-bg:rgba(25,135,84,0.09);
    --tr-red:     #cf3e3e;
    --tr-red-bg:  rgba(207,62,62,0.09);
    --tr-yellow:  #c07a00;
    --tr-yellow-bg:rgba(245,166,35,0.12);
    --tr-bg:      #EFF2F8;
    --tr-surface: #FFFFFF;
    --tr-border:  #d9e0ea;
    --tr-text:    #0B1D3A;
    --tr-muted:   #6b7b96;
    --tr-faint:   #9BAABF;
    --tr-font:    'BTG Pactual', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

/* ── Initial sync banner ── */
.tr-sync-banner {
    background: #fff8e1;
    color: #7c5c00;
    border-bottom: 1px solid #f0d060;
    padding: 12px 24px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.tr-sync-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #f0d060;
    border-top-color: #7c5c00;
    border-radius: 50%;
    animation: tr-spin 0.8s linear infinite;
    display: inline-block;
    flex-shrink: 0;
}
@keyframes tr-spin { to { transform: rotate(360deg); } }

/* ── Hint bar ── */
.tr-hint-bar {
    background: #f0f4fb;
    border-bottom: 1px solid var(--tr-border);
    padding: 8px 24px;
    font-size: 12px;
    color: var(--tr-muted);
}
.tr-hint-bar-inline {
    background: #f0f4fb;
    border: 1px solid var(--tr-border);
    border-radius: 4px;
    padding: 7px 14px;
    font-size: 12px;
    color: var(--tr-muted);
    margin: 8px 0 4px;
}

/* ── Tab bar ── */
.tr-tab-bar {
    background: var(--tr-surface);
    border-bottom: 1px solid var(--tr-border);
    padding: 0 28px;
    display: flex;
    gap: 0;
}
.tr-tab {
    padding: 13px 24px;
    font-size: 14px;
    font-weight: 600;
    color: var(--tr-muted);
    cursor: pointer;
    border: none;
    border-bottom: 3px solid transparent;
    background: none;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.15s;
    font-family: var(--tr-font);
}
.tr-tab:hover { color: var(--tr-navy); }
.tr-tab.active { color: var(--tr-blue); border-bottom-color: var(--tr-blue); }

/* ── Filter bar ── */
.tr-filter-bar {
    background: var(--tr-surface);
    border-bottom: 1px solid var(--tr-border);
    padding: 10px 28px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.tr-filter-label {
    font-size: 12px;
    color: var(--tr-faint);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    white-space: nowrap;
    font-family: var(--tr-font);
}
.tr-filter-controls { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
#sectorFilter  { width: 140px; }
#companyFilter { width: 160px; }
.tr-sel {
    padding: 7px 14px;
    border: 1px solid var(--tr-border);
    border-radius: 20px;
    background: #fff;
    color: var(--tr-text);
    font-family: var(--tr-font);
    font-size: 13px;
    font-weight: 500;
    outline: none;
    cursor: pointer;
    transition: border-color 0.15s;
}
.tr-sel:focus { border-color: var(--tr-blue); }
.tr-sel-date {
    background: var(--tr-blue);
    color: #fff;
    border-color: var(--tr-blue);
    font-weight: 600;
}
.tr-sel-date:focus { border-color: var(--tr-navy); }
.tr-sel.tr-sel-active {
    border-color: var(--tr-blue);
    color: var(--tr-blue);
    font-weight: 600;
    background: rgba(25, 90, 180, 0.08);
    box-shadow: 0 0 0 2px rgba(25, 90, 180, 0.22);
}
.tr-sel-cta {
    border-color: var(--tr-blue);
    color: var(--tr-blue);
    font-weight: 600;
    background: rgba(25, 90, 180, 0.07);
    box-shadow: 0 0 0 2.5px rgba(25, 90, 180, 0.18);
}
.tr-sel-cta:focus { border-color: var(--tr-navy); box-shadow: 0 0 0 2.5px rgba(0, 31, 98, 0.18); }

/* ── Filter search box ── */
.tr-filter-search input,
.tr-history-search input {
    padding: 7px 14px;
    width: 220px;
    border: 1px solid var(--tr-border);
    border-radius: 20px;
    background: #fff;
    color: var(--tr-text);
    font-family: var(--tr-font);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.tr-filter-search input:focus,
.tr-history-search input:focus {
    border-color: var(--tr-blue);
    box-shadow: 0 0 0 2px rgba(25, 90, 180, 0.15);
}
.tr-filter-search input::placeholder,
.tr-history-search input::placeholder { color: #aaa; }

/* ── History company custom dropdown ── */
.tr-search-wrap {
    position: relative;
    display: inline-block;
}
.tr-search-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 200;
    background: #fff;
    border: 1px solid var(--tr-border);
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
    min-width: 220px;
    max-height: 220px;
    overflow-y: auto;
}
.tr-search-opt {
    padding: 8px 13px;
    font-size: 13px;
    cursor: pointer;
    color: var(--tr-text);
    border-bottom: 1px solid var(--tr-border);
}
.tr-search-opt:last-child { border-bottom: none; }
.tr-search-opt:hover {
    background: var(--tr-bg);
    color: var(--tr-blue);
}
.tr-filter-count {
    font-size: 12px;
    color: var(--tr-muted);
    white-space: nowrap;
    font-family: var(--tr-font);
}

/* ── Context badge ── */
.tr-reset-btn {
    margin-left: 8px; padding: 4px 12px; font-size: 12px; font-weight: 600;
    font-family: var(--tr-font); cursor: pointer; border-radius: 16px;
    border: 1.5px solid #c0392b; color: #c0392b; background: #fff8f7;
    white-space: nowrap; transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.tr-reset-btn:hover { background: #c0392b; color: #fff; }
.tr-context-badge {
    margin-left: auto;
    font-size: 11px;
    color: var(--tr-blue);
    background: rgba(25, 90, 180, 0.08);
    padding: 3px 8px;
    border-radius: 10px;
    white-space: nowrap;
    font-weight: 600;
    font-family: var(--tr-font);
}

/* ── Buyback sort toggle ── */
.tr-sort-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 14px 0 4px;
}

/* ── Market cap methodology note ── */
.tr-mcap-note {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 8px 0 0;
    padding: 9px 14px;
    background: #fffbf0;
    border-left: 3px solid #e6a800;
    border-radius: 0 4px 4px 0;
    font-size: 12px;
    color: #5a4200;
    line-height: 1.45;
}
.tr-mcap-note-icon {
    flex-shrink: 0;
    font-size: 13px;
    margin-top: 1px;
    color: #c07a00;
    font-style: normal;
}
.tr-toggle {
    padding: 5px 14px;
    border: 1px solid #c9d3e0;
    border-radius: 4px;
    background: #f5f7fa;
    color: #4a5568;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    font-family: var(--tr-font);
    transition: all 0.15s;
}
.tr-toggle:hover { border-color: var(--tr-blue); color: var(--tr-blue); }
.tr-toggle.active {
    background: var(--tr-blue);
    color: #fff;
    border-color: var(--tr-blue);
}

/* ── Market cap column highlight when sort by % Mkt Cap ── */
.tr-tbl td.mcap-active,
.tr-tbl th.mcap-active {
    background: rgba(25, 90, 180, 0.06) !important;
}
/* Keep row dividers visible against the tinted background */
.tr-tbl td.mcap-active {
    border-bottom-color: rgba(25, 90, 180, 0.14) !important;
}

/* ── Rolling window controls ── */
.tr-rolling-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0 4px;
    margin-top: -4px;
}
.tr-period-arrow {
    font-size: 14px;
    color: var(--tr-muted);
}

/* ── Tab content ── */
.tr-content { display: none; }
.tr-content.active { display: block; }

/* ── Main ── */
.tr-main { padding: 20px 28px 48px; background: var(--tr-bg); min-height: calc(100vh - 140px); }

/* ── Section titles ── */
.tr-section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--tr-navy);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding-bottom: 7px;
    border-bottom: 2px solid var(--tr-blue);
    margin: 26px 0 14px;
    font-family: var(--tr-font);
}
.tr-section-head {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}
.tr-section-head .tr-section-title { margin-bottom: 0; width: 100%; min-width: 0; }
.tr-section-inline-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 14px;
    justify-content: flex-start;
}
.tr-content > div:first-child .tr-section-title { margin-top: 0; }

/* ── KPI cards ── */
.tr-kpi-row { display: grid; gap: 13px; grid-template-columns: repeat(3, 1fr); }
.tr-kpi-row-5 { grid-template-columns: repeat(5, 1fr); }
.tr-mt14 { margin-top: 14px; }
.tr-mt8  { margin-top: 8px; }

.tr-kpi {
    background: var(--tr-surface); border: 1px solid var(--tr-border);
    border-radius: 10px; padding: 17px 20px; position: relative; overflow: hidden;
}
.tr-kpi.accent-blue  { border-left: 3px solid var(--tr-blue); }
.tr-kpi.accent-green { border-left: 3px solid var(--tr-green); }
.tr-kpi.accent-red   { border-left: 3px solid var(--tr-red); }
.tr-kpi.accent-yellow{ border-left: 3px solid var(--tr-yellow); }
.tr-kpi.accent-top::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: rgba(25,90,180,0.3);
}
.tr-kpi.accent-top-g::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: rgba(25,135,84,0.45);
}
.tr-kpi.accent-top-r::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: rgba(207,62,62,0.45);
}
.tr-kpi.accent-top-y::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
    background: rgba(192,122,0,0.5);
}
.tr-kpi-label {
    font-size: 12px; font-weight: 700; color: var(--tr-faint);
    text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 8px;
    font-family: var(--tr-font);
}
.tr-kpi-value {
    font-size: 24px; font-weight: 700; color: var(--tr-text); line-height: 1;
    font-variant-numeric: tabular-nums; font-family: var(--tr-font);
}
.tr-kpi-value.sm  { font-size: 18px; }
.tr-kpi-value.green { color: var(--tr-green); }
.tr-kpi-value.red   { color: var(--tr-red); }
.tr-kpi-sub { font-size: 13px; color: var(--tr-muted); margin-top: 7px; font-family: var(--tr-font); }
.tr-kpi-sub strong { color: #333; }

/* ── Grids ── */
.tr-g2  { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: stretch; }
.tr-g3  { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; align-items: stretch; }
.tr-glw { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tr-g3 > .tr-sc {
    min-height: 0;
    height: var(--tr-fill-card-height, auto);
    max-height: var(--tr-fill-card-height, none);
}
#inMonthlyBlock,
#inAccumBlock { --tr-fill-card-height: 500px; }

/* ── Equal-height table card in 2-col grid ── */
.tr-g2 > .tr-sc { display: flex; flex-direction: column; }
.tr-g2 > .tr-sc .tr-tbl-wrap { flex: 1; min-height: 0; overflow: hidden; max-height: none; height: 1px; }
.tr-g2 > .tr-sc .tr-tbl { height: 100%; }
.tr-g2 > .tr-sc .tr-tbl tbody tr { height: 1px; }

/* ── Equal-height table card in 3-col grid (insider monthly/accum blocks) ── */
/* Only target table cards (not chart cards which already manage their own flex layout) */
.tr-g3 > .tr-sc:not(.tr-sc-fill) { display: flex; flex-direction: column; }
.tr-g3 > .tr-sc:not(.tr-sc-fill) .tr-tbl-wrap { flex: 1; min-height: 0; overflow-y: auto; max-height: none; height: 1px; }

/* ── Section card ── */
.tr-sc {
    background: var(--tr-surface); border: 1px solid var(--tr-border);
    border-radius: 10px; overflow: hidden;
}
.tr-sh {
    padding: 12px 18px; border-bottom: 1px solid var(--tr-border);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.tr-st {
    font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.7px;
    display: flex; align-items: center; gap: 6px; color: var(--tr-text);
    font-family: var(--tr-font);
}
.tr-ss { font-size: 13px; color: var(--tr-muted); margin-top: 3px; font-family: var(--tr-font); }
.tr-sb {
    font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 4px;
    white-space: nowrap; flex-shrink: 0; font-family: var(--tr-font);
}
.tr-sb.blue  { background: rgba(25,90,180,0.10); color: var(--tr-blue); }
.tr-sb.green { background: var(--tr-green-bg); color: var(--tr-green); }
.tr-sb.red   { background: var(--tr-red-bg); color: var(--tr-red); }
.tr-sb.grey  { background: rgba(92,111,138,0.09); color: var(--tr-muted); }

.tr-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.tr-dot.blue  { background: var(--tr-blue); }
.tr-dot.green { background: var(--tr-green); }
.tr-dot.red   { background: var(--tr-red); }
.tr-dot.grey  { background: var(--tr-faint); }

/* ── Tables ── */
.tr-tbl { width: 100%; border-collapse: collapse; font-family: var(--tr-font); }
.tr-tbl th {
    background: #F7F9FC; padding: 10px 16px; text-align: center !important;
    font-size: 13px; font-weight: 700; color: var(--tr-faint);
    text-transform: uppercase; letter-spacing: 0.5px;
    border-bottom: 1px solid var(--tr-border); white-space: nowrap;
    font-family: var(--tr-font);
}
.tr-tbl td {
    padding: 12px 16px; border-bottom: 1px solid #F0F3F8;
    font-size: 15px; vertical-align: middle; text-align: center;
    font-family: var(--tr-font);
}
.tr-tbl td.r { text-align: center; }
/* Company column stays left-aligned */
.tr-tbl th:first-child { text-align: left; }
.tr-tbl td:first-child:not(.tr-organ-col) { text-align: left; }
.tr-comp-cell { text-align: left; }
.tr-tbl tr:last-child td { border-bottom: none; }
.tr-tbl tr:hover td { background: #FAFBFE; }

/* ── Compact table variant ── */
.tr-tbl-sm th { font-size: 11px; padding: 8px 12px; }
.tr-tbl-sm td { font-size: 13px; padding: 10px 12px; }

/* ── Insider company grouping ── */
/* Rows belonging to the same company (different insider groups) */
.tr-comp-cell { vertical-align: top; padding-top: 12px !important; }
.tr-comp-continuation td { border-top: none !important; }
.tr-comp-continuation .tr-organ-col { padding-top: 0 !important; }
/* Visible separator between different companies */
.tr-comp-first td { border-top: 2px solid var(--tr-border) !important; }

/* ── Table scrollable wrapper ── */
.tr-tbl-wrap { overflow: auto; max-height: 440px; }
.tr-tbl-wrap .tr-tbl thead th {
    position: sticky; top: 0; z-index: 2; background: #F7F9FC;
}
/* mcap-active uses rgba — must be opaque on sticky headers so content scrolling below is hidden */
.tr-tbl-wrap .tr-tbl thead th.mcap-active {
    background: #EAEFF8 !important;
}

/* ── Inline elements ── */
.tr-cn { font-weight: 600; color: var(--tr-text); font-family: var(--tr-font); }
.tr-tk {
    display: inline-block; background: rgba(25,90,180,0.08); color: var(--tr-blue);
    font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: 4px;
    margin-left: 5px; letter-spacing: 0.2px; font-family: var(--tr-font);
}
.tr-tk-muted {
    font-size: 12px; color: var(--tr-faint); font-weight: 500;
    margin-left: 5px; font-family: var(--tr-font);
}
.tr-mn { font-variant-numeric: tabular-nums; font-family: var(--tr-font); }
.tr-mn.green { color: var(--tr-green); }
.tr-mn.red   { color: var(--tr-red); }
.tr-mn.blue  { color: var(--tr-blue); }
.tr-mn.muted { color: var(--tr-faint); }
.tr-mn.lg    { font-size: 14px; font-weight: 600; }
.tr-pill {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 700;
    font-family: var(--tr-font);
}
.tr-pill.green { background: var(--tr-green-bg); color: var(--tr-green); }
.tr-pill.red   { background: var(--tr-red-bg); color: var(--tr-red); }

.tr-rt {
    display: inline-block; font-size: 12px; color: var(--tr-muted);
    background: var(--tr-bg); padding: 2px 8px; border-radius: 4px;
    font-family: var(--tr-font);
}
.tr-cnt {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 24px; height: 22px; padding: 0 5px; background: var(--tr-bg);
    border-radius: 10px; font-size: 11px; font-weight: 700; color: var(--tr-muted);
    font-family: var(--tr-font);
}

/* ── Horizontal bar chart ── */
.tr-bar-wrap { padding: 16px 18px; }
.tr-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.tr-bar-row:last-child { margin-bottom: 0; }
.tr-bar-label { width: 140px; flex-shrink: 0; }
.tr-bar-label-name { font-size: 13px; font-weight: 600; color: var(--tr-text); font-family: var(--tr-font); }
.tr-bar-label-sub  { font-size: 12px; color: var(--tr-faint); display: block; margin-top: 1px; font-family: var(--tr-font); }
.tr-bar-track { flex: 1; height: 24px; background: #EEF2F8; border-radius: 4px; display: flex; align-items: center; }
.tr-bar-fill {
    height: 100%; border-radius: 4px; display: flex; align-items: center;
    padding-left: 9px; flex-shrink: 0;
    font-size: 11px; font-weight: 600; color: #fff;
    background: var(--tr-blue);
    min-width: 4px; transition: width 0.4s ease;
    font-family: var(--tr-font);
}
.tr-bar-fill.label-end {
    justify-content: flex-end;
    padding-left: 0;
    padding-right: 9px;
}
.tr-bar-ext-val {
    font-size: 12px; font-weight: 600; color: var(--tr-blue);
    padding-left: 7px; white-space: nowrap; flex-shrink: 0;
    font-family: var(--tr-font);
}

/* ── Fill-height card (bar chart + net balance) ── */
.tr-sc-fill { display: flex; flex-direction: column; overflow: hidden; }
/* Bar chart: distribute rows to fill card height */
.tr-sc-fill .tr-bar-wrap { flex: 1; display: flex; flex-direction: column; justify-content: space-evenly; }
.tr-sc-fill .tr-bar-row { margin-bottom: 0; }
/* Net balance: distribute rows to fill card height */
.tr-sc-fill .tr-nb-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tr-sc-fill .tr-nb-rows { flex: 1; display: flex; flex-direction: column; justify-content: space-evenly; }
.tr-sc-fill .tr-nb-row { margin-bottom: 0; }
.tr-sc-fill .tr-nb-section-label,
.tr-sc-fill .tr-nb-section-divider { flex-shrink: 0; }

/* ── Net balance chart ── */
.tr-nb-wrap { padding: 14px 18px; }
.tr-nb-header { display: flex; margin-bottom: 9px; padding-left: 140px; }
.tr-nb-header span {
    flex: 1; text-align: center; font-size: 11px; color: var(--tr-faint);
    font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
    font-family: var(--tr-font);
}
.tr-nb-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.tr-nb-row:last-child { margin-bottom: 0; }
.tr-nb-label { width: 130px; flex-shrink: 0; }
.tr-nb-label-name { font-size: 12px; font-weight: 600; color: var(--tr-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--tr-font); }
.tr-nb-label-sub  { font-size: 10px; color: var(--tr-faint); font-family: var(--tr-font); }
.tr-nb-chart { flex: 1; height: 22px; position: relative; }
.tr-nb-axis  { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--tr-border); }
.tr-nb-bar   { height: 100%; position: absolute; top: 0; border-radius: 3px; display: flex; align-items: center; font-size: 11px; font-weight: 600; color: #fff; font-family: var(--tr-font); }
.tr-nb-bar.sell { background: var(--tr-red);   right: 50%; justify-content: flex-end; padding-right: 5px; }
.tr-nb-bar.buy  { background: var(--tr-green); left:  50%; padding-left: 5px; }
.tr-nb-ext-val {
    position: absolute; top: 50%; transform: translateY(-50%);
    font-size: 11px; font-weight: 600; white-space: nowrap; font-family: var(--tr-font);
}
.tr-nb-ext-val.sell { color: var(--tr-red); }
.tr-nb-ext-val.buy  { color: var(--tr-green); }

/* ── Empty ── */
.tr-empty { padding: 20px; text-align: center; color: var(--tr-muted); font-size: 13px; font-style: italic; font-family: var(--tr-font); }

/* ── Market separator rows in tables ── */
.tr-tbl .tr-market-sep td {
    background: #eaf0fb !important;
    color: var(--tr-navy); font-weight: 700; font-size: 12px;
    text-transform: uppercase; letter-spacing: 0.5px;
    padding: 7px 14px !important; border-top: 1px solid #c8d7ef;
    text-align: center !important; font-family: var(--tr-font);
}

/* ── Pivot (insider activity) table ── */
.tr-pivot-tbl { table-layout: auto; min-width: 600px; }
.tr-pivot-tbl thead th {
    background: var(--tr-navy) !important; color: #fff;
    border-bottom: 1px solid #16387f;
}
.tr-pivot-tbl thead tr.pivot-sub th { top: 36px; }
.tr-pivot-tbl tbody tr.pivot-divider td {
    padding: 0; height: 2px;
    background: linear-gradient(to right, transparent, var(--tr-border) 20%, var(--tr-border) 80%, transparent);
    border: none;
}

/* ── Net balance section labels ── */
.tr-nb-section-label {
    font-size: 10px; font-weight: 700; letter-spacing: 0.6px;
    text-transform: uppercase; padding: 4px 12px 2px; opacity: 0.75;
}
.tr-nb-section-label.sell { color: var(--tr-red); }
.tr-nb-section-label.buy  { color: var(--tr-green); }
.tr-nb-section-divider {
    height: 1px; margin: 4px 12px;
    background: var(--tr-border);
}

/* ── Timeline chart legend ── */
.tr-timeline-legend {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}
.tr-tl-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--tr-muted);
}
.tr-tl-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}
.tr-tl-item.buy  .tr-tl-dot { background: #22a463; }
.tr-tl-item.sell .tr-tl-dot { background: #d94040; }

/* ── Vertical timeline / history chart ── */
.tr-timeline-wrap { padding: 16px 18px; overflow-x: auto; }
.tr-timeline-bars {
    display: flex; align-items: flex-end; gap: 8px;
    height: 190px; border-bottom: 2px solid var(--tr-border);
    min-width: max-content;
}
.tr-timeline-col {
    flex: 1; min-width: 52px; display: flex; flex-direction: column;
    align-items: center; justify-content: flex-end;
}
.tr-timeline-bar-val {
    font-size: 13px; color: var(--tr-text); font-weight: 600;
    text-align: center; margin-bottom: 5px; white-space: nowrap;
    font-family: var(--tr-font);
}
.tr-timeline-bar {
    width: 58%; background: var(--tr-blue); border-radius: 3px 3px 0 0;
    min-height: 0;
}
.tr-timeline-bar.empty {
    width: 58%; background: var(--tr-border); border-radius: 3px 3px 0 0;
    min-height: 3px; opacity: 0.5;
}
.tr-timeline-bar.buy  { background: #22a463; }
.tr-timeline-bar.sell { background: #d94040; }
.tr-timeline-bar-val.buy  { color: #22a463; }
.tr-timeline-bar-val.sell { color: #d94040; }
.tr-timeline-lbl {
    font-size: 13px; color: var(--tr-faint); margin-top: 7px;
    white-space: nowrap; font-family: var(--tr-font);
}

/* ── Bidirectional insider history chart ── */
.tr-bi-wrap {
    display: flex; flex-direction: column; min-width: max-content;
}
.tr-bi-chart {
    display: flex; align-items: stretch; gap: 4px;
    height: 300px; min-width: max-content;
}
.tr-bi-col {
    flex: 1; min-width: 64px; max-width: 90px;
    display: flex; flex-direction: column; align-items: center;
}
.tr-bi-top {
    flex: 1; display: flex; flex-direction: column;
    justify-content: flex-end; align-items: center; width: 100%;
}
.tr-bi-bot {
    flex: 1; display: flex; flex-direction: column;
    justify-content: flex-start; align-items: center; width: 100%;
}
.tr-bi-axis-tick {
    width: 100%; height: 2px; background: var(--tr-border); flex-shrink: 0;
}
.tr-bi-bar {
    width: 60%; min-width: 28px; max-width: 52px; min-height: 0;
}
.tr-bi-bar.buy  { background: #22a463; border-radius: 3px 3px 0 0; }
.tr-bi-bar.sell { background: #d94040; border-radius: 0 0 3px 3px; }
.tr-bi-val {
    font-size: 11px; font-weight: 600; white-space: nowrap;
    height: 18px; line-height: 18px; font-family: var(--tr-font); flex-shrink: 0;
}
.tr-bi-val.buy  { color: #22a463; }
.tr-bi-val.sell { color: #d94040; }
.tr-bi-labels {
    display: flex; gap: 4px; margin-top: 6px; min-width: max-content;
}
.tr-bi-lbl {
    flex: 1; min-width: 64px; max-width: 90px;
    font-size: 11px; color: var(--tr-faint);
    text-align: center; white-space: nowrap; font-family: var(--tr-font);
}

/* ── Responsive — Notebook (1024px–1280px) ── */
@media (max-width: 1280px) {
    .tr-main { padding: 16px 18px 36px; }
    .tr-g2  { gap: 12px; }
    .tr-g3  { gap: 12px; }
    .tr-tbl-sm td { font-size: 13px; }
    /* Allow tables to scroll horizontally rather than overflow */
    .tr-tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ── Responsive — Tablet (≤960px) ── */
@media (max-width: 960px) {
    .tr-g2, .tr-g3, .tr-glw { grid-template-columns: 1fr; }
    #inMonthlyBlock,
    #inAccumBlock { --tr-fill-card-height: auto; }
    /* Cards stack vertically — no need to fill height, use natural spacing */
    .tr-sc-fill .tr-bar-wrap { justify-content: flex-start; gap: 6px; }
    .tr-sc-fill .tr-nb-rows  { justify-content: flex-start; gap: 6px; }
    .tr-kpi-row-5 { grid-template-columns: repeat(2, 1fr); }
    .tr-main { padding: 14px 16px 36px; }
    .tr-filter-bar { padding: 9px 16px; }
    /* On mobile, revert grid cards to block so table wraps scroll correctly */
    .tr-g2 > .tr-sc,
    .tr-g3 > .tr-sc:not(.tr-sc-fill) {
        display: block;
        overflow: hidden; /* restore border-radius clipping */
    }
    /* Restore scroll + height for table wraps */
    .tr-g2 > .tr-sc .tr-tbl-wrap,
    .tr-g3 > .tr-sc:not(.tr-sc-fill) .tr-tbl-wrap {
        flex: none;
        overflow-x: auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        max-height: 440px;
        height: auto;
    }
    .tr-tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* Force tables wide enough to trigger horizontal scroll */
    .tr-g2 .tr-tbl { min-width: 560px; }
    .tr-g3 .tr-tbl { min-width: 480px; }

    /* Freeze Company column (first col) in buyback + insider grid tables */
    .tr-g2 .tr-tbl thead th:first-child,
    .tr-g3 .tr-tbl thead th:first-child {
        position: sticky; left: 0; z-index: 3;
        background: #F7F9FC;
        box-shadow: 2px 0 6px rgba(0,31,98,0.07);
    }
    .tr-g2 .tr-tbl tbody td:first-child,
    .tr-g3 .tr-tbl tbody td:first-child {
        position: sticky; left: 0; z-index: 1;
        background: var(--tr-surface);
        box-shadow: 2px 0 6px rgba(0,31,98,0.07);
    }
    /* Keep hover background on sticky cell */
    .tr-g2 .tr-tbl tr:hover td:first-child,
    .tr-g3 .tr-tbl tr:hover td:first-child { background: #FAFBFE; }
    /* mcap-active sticky header stays opaque */
    .tr-g2 .tr-tbl thead th.mcap-active:first-child,
    .tr-g3 .tr-tbl thead th.mcap-active:first-child { background: #EAEFF8; }
}

@media (max-width: 760px) {
    .tr-organ-col { display: none; }
}

@media (max-width: 600px) {
    .tr-section-head { align-items: stretch; }
    .tr-section-head .tr-section-title { min-width: 0; }
    .tr-section-inline-controls {
        margin-bottom: 12px;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
    .tr-filter-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 10px 14px;
    }
    .tr-filter-controls {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "sector company"
            "search search"
            "year   month";
        gap: 6px;
    }
    #sectorFilter                        { grid-area: sector; }
    #companyFilter                       { grid-area: company; }
    .tr-filter-controls .tr-filter-search { grid-area: search; }
    #analyticsYearFilter                 { grid-area: year; }
    #analyticsMonthFilter                { grid-area: month; }
    .tr-filter-controls .tr-sel,
    .tr-filter-controls .tr-filter-search { width: 100%; box-sizing: border-box; }
    .tr-filter-controls .tr-filter-search input { width: 100%; box-sizing: border-box; }
    .tr-rolling-controls .tr-history-search { width: 100%; box-sizing: border-box; }
    .tr-rolling-controls .tr-history-search input { width: 100%; box-sizing: border-box; }
    .tr-filter-count { margin-left: 0; }
    .tr-reset-btn { margin-left: 0; }
    .tr-context-badge { margin-left: 0; }

    .tr-rolling-controls {
        flex-wrap: wrap;
        gap: 6px;
        padding: 4px 0;
    }
    .tr-rolling-controls .tr-sel { flex: 1; min-width: 110px; }

    .tr-tab-bar { padding: 0 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .tr-tab { padding: 10px 16px; font-size: 13px; white-space: nowrap; }

    .tr-main { padding: 10px 12px 32px; }

    .tr-section-title { font-size: 13px; margin: 20px 0 12px; }
    .tr-st { font-size: 11px; }
    .tr-ss { font-size: 11px; }

    .tr-bar-label { width: 100px; }
    .tr-bar-label-name { font-size: 12px; }
    .tr-bar-label-sub  { font-size: 11px; }

    .tr-nb-label { width: 64px; }
    .tr-nb-label-name { font-size: 12px; white-space: normal; overflow: visible; text-overflow: clip; }
    .tr-nb-row { align-items: flex-start; }
    .tr-nb-header { padding-left: 74px; } /* 64px label + 10px gap */

    .tr-timeline-col { min-width: 40px; }
    .tr-timeline-bar-val { font-size: 11px; }
    .tr-timeline-lbl    { font-size: 11px; }

    .tr-sh { padding: 10px 14px; }
    .tr-bar-wrap { padding: 12px 14px; }
    .tr-nb-wrap  { padding: 10px 14px; }
    .tr-tbl-sm td { font-size: 12px; padding: 9px 10px; }
    .tr-tbl-sm th { font-size: 10px; padding: 7px 10px; }

    .tr-sort-toggle { flex-wrap: wrap; }
}
