/* =============================================================================
   History page — UI redesign (date-grouped transaction list + filters)
   Scoped to #historySection so Analytics keeps its current look.
   ============================================================================= */

#historySection { max-width: 1100px; padding: 28px 28px 48px; }
#historySection .page-section-header { align-items: flex-end; margin-bottom: 20px; }
#historySection .page-section-title { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.3px; margin-bottom: 6px; }
#historySection .page-section-subtitle { font-size: 0.8125rem; }
#historySection .btn-export {
    height: 38px; padding: 0 14px; border: 1px solid var(--border-color); border-radius: 10px;
    background: transparent; color: var(--text-primary); font-size: 0.8125rem; font-weight: 500;
    display: inline-flex; align-items: center; gap: 8px;
}
#historySection .btn-export:hover { border-color: #3A424C; background: var(--bg-tertiary); }

/* Model performance — KPI cards sit directly on the page */
#historySection > .page-section-header + .analytics-card { background: none; border: 0; padding: 0; margin-bottom: 8px !important; }
#historySection > .page-section-header + .analytics-card .analytics-card-title { font-size: 0.75rem; font-weight: 500; color: var(--text-secondary); }
#historySection > .page-section-header + .analytics-card > div:first-child { margin-bottom: 10px !important; }
#historySection .kpi-grid { margin-bottom: 0; }
#historySection .kpi-card { border: 1px solid var(--bg-tertiary); border-radius: 14px; padding: 18px; }
#historySection .kpi-label { font-size: 0.75rem; text-transform: none; letter-spacing: 0; color: var(--text-secondary); }
#historySection .kpi-value { font-size: 1.625rem; font-weight: 600; letter-spacing: -0.5px; margin: 6px 0 4px; }
#historySection .kpi-value.yellow, #historySection .kpi-value.blue { color: var(--text-primary); }
#historySection #histKpiWinRate { color: var(--green); }
#historySection .kpi-sub { font-size: 0.75rem; color: var(--text-secondary); }

/* Transactions */
.tx-section { display: flex; flex-direction: column; gap: 4px; margin-top: 28px; }
.tx-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.tx-head-title { display: flex; align-items: center; gap: 8px; }
.tx-head-title h2 { margin: 0; font-size: 1rem; font-weight: 600; color: var(--text-primary); }
.tx-summary { font-size: 0.75rem; color: var(--text-secondary); }
.tx-controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.tx-controls .seg[style*="display: none"] { display: none !important; }
/* Same font and size as the label so the two line up exactly; equal-width digits */
.tx-count { font-family: inherit; font-size: inherit; font-variant-numeric: tabular-nums; opacity: 0.6; }
.tx-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.tx-filter-btn {
    display: inline-flex; align-items: center; gap: 6px;
    height: 32px; padding: 0 12px; border-radius: 999px;
    border: 1px solid var(--border-color); background: transparent;
    color: var(--text-secondary); font: 500 0.75rem Inter, sans-serif; cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.tx-filter-btn:hover { border-color: #3A424C; color: var(--text-primary); }
.tx-filter-btn.active { border-color: var(--accent); background: rgba(240, 185, 11, 0.10); color: var(--accent); }
.tx-filter-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }

.tx-list { display: flex; flex-direction: column; gap: 18px; }
.tx-group-date { font-size: 0.75rem; font-weight: 500; color: var(--text-secondary); padding: 0 4px 8px; }
.tx-group-card { background: var(--bg-secondary); border: 1px solid var(--bg-tertiary); border-radius: 14px; padding: 0 16px; }
.tx-row {
    display: grid; grid-template-columns: minmax(0, 2.4fr) minmax(0, 1.6fr) minmax(0, 1.2fr);
    gap: 16px; align-items: center; min-height: 64px; padding: 10px 0;
    border-bottom: 1px solid rgba(43, 49, 57, 0.5);
}
.tx-row:last-child { border-bottom: 0; }
.tx-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.tx-icon { width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.tx-text { min-width: 0; }
.tx-title { font-size: 0.875rem; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-type { margin-left: 8px; font-size: 0.6875rem; font-weight: 400; color: var(--text-tertiary); }
.tx-meta { font-size: 0.75rem; color: var(--text-secondary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amounts { text-align: right; min-width: 0; }
.tx-qty { font-family: 'IBM Plex Mono', monospace; font-size: 0.8125rem; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-qty--in { color: var(--green); }
.tx-sub { font-family: 'IBM Plex Mono', monospace; font-size: 0.75rem; color: var(--text-secondary); margin-top: 2px; }
.tx-total { font-family: 'IBM Plex Mono', monospace; font-size: 0.875rem; font-weight: 600; color: var(--text-primary); text-align: right; }
.tx-empty { text-align: center; color: var(--text-tertiary); padding: 32px 16px; font-size: 0.8125rem; background: var(--bg-secondary); border: 1px solid var(--bg-tertiary); border-radius: 14px; }
.tx-empty a, .tx-empty .link-btn { color: var(--accent); }
.tx-empty .link-btn { text-decoration: underline; }

#historySection .load-more-wrap { border-top: 0; padding: 18px 0 0; }
#historySection .btn-load-more {
    height: 40px; padding: 0 18px; border: 1px solid var(--border-color); border-radius: 10px;
    background: transparent; color: var(--text-primary); font-size: 0.8125rem;
}
#historySection .btn-load-more:hover { border-color: var(--accent); color: var(--accent); }

@media (max-width: 900px) {
    #historySection .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    #historySection { padding: 20px 16px 40px; }
    /* nowrap: in a wrapping column the filter row took its full content width
       and pushed the whole page wider than the screen */
    .tx-controls { flex-direction: column; align-items: stretch; flex-wrap: nowrap; }
    .tx-filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
    .tx-filters::-webkit-scrollbar { display: none; }
    .tx-filter-btn { flex-shrink: 0; }
    .tx-group-card { padding: 0 14px; }
    /* Two columns: what + amounts; total folds under the quantity */
    .tx-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "main amounts" "main total"; gap: 2px 12px; }
    .tx-main { grid-area: main; }
    .tx-amounts { grid-area: amounts; }
    .tx-total { grid-area: total; font-size: 0.75rem; font-weight: 500; color: var(--text-secondary); }
    .tx-sub { display: none; }
    .tx-type { display: none; }
}

/* Apple HIG: every button and link can be tapped in a 44 × 44px area */
.tx-filter-btn, .btn-export, .btn-load-more { min-height: 44px; min-width: 44px; }
/* Filter buttons share one width: the widest one's */
.tx-filters { display: block; }
/* Phones: buttons stay on one line and the row scrolls sideways; the inner
   row is as wide as its buttons so every button can take the widest one's width */
.tx-filter-btn { white-space: nowrap; justify-content: center; }
.tx-filters { overflow-x: auto; scrollbar-width: none; }
.tx-filters::-webkit-scrollbar { display: none; }
.tx-filters-row { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; width: max-content; }
@media (max-width: 640px) {
    .tx-filters { display: block; }
    /* Exchange tabs: as wide as the widest tab, on the left (as on Portfolio) */
    .tx-controls > .seg { align-self: flex-start; }
}

/* Transactions couldn't load: message with Retry */
.tx-error { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.tx-error-title { font-size: 0.875rem; font-weight: 600; color: var(--text-primary); }
.tx-error-retry {
    min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid #474D57;
    background: transparent; color: var(--text-primary); font: 600 0.875rem Inter, -apple-system, BlinkMacSystemFont, sans-serif; cursor: pointer;
}
.tx-error-retry:hover { border-color: var(--text-secondary); }
