/* Trade History page */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg, #090b0f);
  color: var(--ink, #e8eaed);
  font: 13px/1.5 var(--font-sans, system-ui, sans-serif);
}

.th-wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 24px 48px;
}

.th-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line, #1e2430);
  margin-bottom: 20px;
}

.th-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.th-by {
  color: var(--ink-3, #6a7280);
  font-size: 13px;
  font-weight: 500;
  margin-left: 8px;
}

.th-sub {
  margin: 6px 0 0;
  color: var(--ink-3, #6a7280);
  font-size: 12px;
  max-width: 520px;
}

.th-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.th-btn {
  appearance: none;
  border: 1px solid var(--line, #1e2430);
  background: var(--surface-2, #12151c);
  color: var(--ink-2, #b8bcc4);
  font: 600 10px/1 var(--font-mono, ui-monospace, monospace);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
}

.th-btn:hover { color: var(--ink); border-color: var(--line-strong, #2a3140); }
.th-btn.danger { color: #e85d5d; border-color: rgba(232, 93, 93, 0.35); }
.th-btn.danger:hover { background: rgba(232, 93, 93, 0.08); }

.th-kpis {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

@media (max-width: 900px) {
  .th-kpis { grid-template-columns: repeat(3, 1fr); }
}

.th-kpi {
  background: var(--surface, #0f1218);
  border: 1px solid var(--line, #1e2430);
  border-radius: 4px;
  padding: 10px 12px;
}

.th-kpi .lbl {
  font: 600 9px/1 var(--font-mono, ui-monospace, monospace);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3, #6a7280);
  margin-bottom: 6px;
}

.th-kpi .val {
  font: 700 20px/1.1 var(--font-mono, ui-monospace, monospace);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.th-kpi .val.good { color: var(--take, #3eb987); }
.th-kpi .val.bad { color: var(--stop, #e85d5d); }
.th-kpi .val.flat { color: var(--wait, #d3ad67); }

.th-kpi .sub {
  margin-top: 4px;
  font-size: 10px;
  color: var(--ink-3, #6a7280);
}

.th-data-status {
  margin: -8px 0 14px;
  font-size: 11px;
  color: var(--ink-3, #6a7280);
}

.th-report {
  background: var(--surface, #0f1218);
  border: 1px solid var(--line, #1e2430);
  border-radius: 4px;
  padding: 16px 18px;
  margin-bottom: 14px;
}

.th-report-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.th-report-head h2 {
  margin: 0;
  font: 600 9px/1 var(--font-mono, ui-monospace, monospace);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3, #6a7280);
}

.th-report-period {
  font: 500 10px/1 var(--font-mono, ui-monospace, monospace);
  color: var(--ink-3, #6a7280);
}

.th-report-title {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.th-report-body p {
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-2, #b8bcc4);
  max-width: 72ch;
}

.th-report-body p:last-child { margin-bottom: 0; }

.th-report-bullets {
  margin: 12px 0 0;
  padding: 0 0 0 18px;
  color: var(--ink-2, #b8bcc4);
  font-size: 12px;
  line-height: 1.5;
}

.th-report-bullets li { margin-bottom: 6px; }
.th-report-bullets li:last-child { margin-bottom: 0; }

.th-charts-pie {
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 10px;
}

@media (max-width: 960px) {
  .th-charts-pie { grid-template-columns: 1fr; }
}

.th-chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line, #1e2430);
}

.th-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 500 10px/1 var(--font-mono, ui-monospace, monospace);
  color: var(--ink-3, #6a7280);
}

.th-legend-item .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.th-legend-item strong {
  color: var(--ink-2, #b8bcc4);
  font-weight: 600;
}

.th-chart-card-stats { display: flex; flex-direction: column; }

.th-quick-stats {
  flex: 1;
  display: grid;
  gap: 6px;
  padding: 4px 0 8px;
}

.th-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 11px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(30, 36, 48, 0.6);
}

.th-stat-row:last-child { border-bottom: none; }

.th-stat-row .k {
  color: var(--ink-3, #6a7280);
  font: 600 9px/1 var(--font-mono, ui-monospace, monospace);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.th-stat-row .v {
  font: 600 12px/1 var(--font-mono, ui-monospace, monospace);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.th-charts {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.th-charts-sm { grid-template-columns: 1fr 1fr; margin-bottom: 16px; }

@media (max-width: 760px) {
  .th-charts, .th-charts-sm { grid-template-columns: 1fr; }
}

.th-chart-card {
  background: var(--surface, #0f1218);
  border: 1px solid var(--line, #1e2430);
  border-radius: 4px;
  padding: 10px 12px 8px;
}

.th-chart-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font: 600 9px/1 var(--font-mono, ui-monospace, monospace);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3, #6a7280);
}

.th-chart-toggle {
  display: flex;
  gap: 4px;
}

.th-chart-toggle button {
  appearance: none;
  border: 1px solid var(--line, #1e2430);
  background: transparent;
  color: var(--ink-3);
  font: 600 9px/1 var(--font-mono, ui-monospace, monospace);
  padding: 3px 8px;
  border-radius: 3px;
  cursor: pointer;
}

.th-chart-toggle button.active {
  color: var(--ink);
  border-color: var(--accent, #8bb8e8);
  background: rgba(139, 184, 232, 0.08);
}

.th-chart-card canvas {
  display: block;
  width: 100%;
  height: 160px;
  border-radius: 2px;
}

.th-charts-sm .th-chart-card canvas { height: 140px; }

.th-insights {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.th-insight {
  font: 500 11px/1.4 var(--font-sans, system-ui, sans-serif);
  color: var(--ink-2, #b8bcc4);
  background: rgba(139, 184, 232, 0.06);
  border: 1px solid rgba(139, 184, 232, 0.15);
  border-radius: 4px;
  padding: 8px 10px;
  max-width: 360px;
}

.th-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 14px;
  padding: 12px;
  background: var(--surface, #0f1218);
  border: 1px solid var(--line, #1e2430);
  border-radius: 4px;
}

.th-controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font: 600 9px/1 var(--font-mono, ui-monospace, monospace);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3, #6a7280);
}

.th-controls select,
.th-controls input {
  background: var(--bg, #090b0f);
  border: 1px solid var(--line, #1e2430);
  color: var(--ink);
  padding: 7px 10px;
  border-radius: 4px;
  font: inherit;
  min-width: 110px;
}

.th-search-wrap { flex: 1; min-width: 160px; }
.th-search-wrap input { width: 100%; min-width: 0; }

.th-list { display: grid; gap: 8px; }

.th-trade {
  background: var(--surface, #0f1218);
  border: 1px solid var(--line, #1e2430);
  border-radius: 4px;
  border-left: 3px solid var(--line, #1e2430);
  overflow: hidden;
}

.th-trade.won { border-left-color: var(--take, #3eb987); }
.th-trade.lost { border-left-color: var(--stop, #e85d5d); }
.th-trade.be { border-left-color: var(--wait, #d3ad67); }

.th-trade summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 88px 72px 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  font-size: 12px;
}

.th-trade summary::-webkit-details-marker { display: none; }

.th-trade .dt {
  font: 500 10px/1.3 var(--font-mono, ui-monospace, monospace);
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.th-trade .asset {
  font: 700 10px/1 var(--font-mono, ui-monospace, monospace);
  letter-spacing: 0.04em;
}

.th-trade .dir-long { color: var(--take, #3eb987); }
.th-trade .dir-short { color: var(--stop, #e85d5d); }

.th-trade .title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-2);
}

.th-trade .levels {
  font: 500 10px/1.3 var(--font-mono, ui-monospace, monospace);
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.th-trade .pnl {
  font: 700 11px/1 var(--font-mono, ui-monospace, monospace);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.th-trade .pnl.good { color: var(--take, #3eb987); }
.th-trade .pnl.bad { color: var(--stop, #e85d5d); }

.th-trade .badge {
  font: 700 9px/1 var(--font-mono, ui-monospace, monospace);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 7px;
  border-radius: 3px;
  background: rgba(255,255,255,0.04);
  color: var(--ink-3);
}

.th-trade .body {
  padding: 0 14px 12px;
  border-top: 1px solid var(--line, #1e2430);
  font-size: 12px;
  color: var(--ink-2);
}

.th-trade .body .row { margin-top: 8px; }
.th-trade .body .lbl {
  font: 600 9px/1 var(--font-mono, ui-monospace, monospace);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 4px;
}

.th-outcome-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line, #1e2430);
}

.th-outcome-row .lbl {
  margin-bottom: 0;
  margin-right: 4px;
}

.th-out-btn {
  appearance: none;
  border: 1px solid var(--line, #1e2430);
  background: var(--surface-2, #12151c);
  color: var(--ink-2, #b8bcc4);
  font: 600 10px/1 var(--font-mono, ui-monospace, monospace);
  padding: 5px 8px;
  border-radius: 3px;
  cursor: pointer;
}

.th-out-btn:hover { border-color: var(--line-strong, #2a3140); color: var(--ink); }
.th-out-btn.active { border-color: var(--take, #3eb987); color: var(--take, #3eb987); }
.th-out-btn.lost.active { border-color: var(--stop, #e85d5d); color: var(--stop, #e85d5d); }
.th-out-btn.be.active { border-color: var(--wait, #d3ad67); color: var(--wait, #d3ad67); }

.th-trade.open { border-left-color: var(--ink-3, #6a7280); }

.th-empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--ink-3);
  background: var(--surface, #0f1218);
  border: 1px dashed var(--line, #1e2430);
  border-radius: 4px;
}

.th-dialog {
  border: 1px solid var(--line, #1e2430);
  border-radius: 3px;
  background: var(--surface, #0f1218);
  color: var(--ink);
  padding: 20px;
  max-width: 420px;
  z-index: 75;
}

.th-dialog::backdrop { background: rgba(0,0,0,0.65); }
.th-dialog h2 { margin: 0 0 10px; font-size: 16px; }
.th-dialog p { margin: 0 0 16px; font-size: 13px; color: var(--ink-2); line-height: 1.5; }
.th-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.th-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 10px 14px;
  background: #0c1015;
  border: 1px solid var(--take, #3eb987);
  color: var(--take, #3eb987);
  border-radius: 4px;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.th-toast.show { opacity: 1; }
.th-toast.err { border-color: var(--stop); color: var(--stop); }

/* ── Floor modal shell (Trade History desk) ── */
.thd-modal {
  position: fixed;
  inset: 0;
  z-index: 65;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(4, 6, 10, 0.58);
}
.thd-modal.hidden { display: none; }

.thd-dialog {
  width: min(1120px, 100%);
  max-height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line-strong, #2a3140);
  border-radius: 3px;
  background: var(--bg, #090b0f);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.58);
}

.thd-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line, #1e2430);
  background: linear-gradient(180deg, rgba(139, 184, 232, 0.08) 0%, var(--surface-2, #12151c) 100%);
  flex-shrink: 0;
}

.thd-title { flex: 1; min-width: 0; }
.thd-title strong {
  display: block;
  font: 700 14px var(--font-sans, system-ui, sans-serif);
  color: var(--ink, #e8eaed);
}
.thd-title span {
  display: block;
  margin-top: 2px;
  font: 500 11px var(--font-sans, system-ui, sans-serif);
  color: var(--ink-3, #6a7280);
}

.thd-top-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.thd-close {
  appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 3px;
  border: 1px solid var(--line, #1e2430);
  background: transparent;
  color: var(--ink-3, #6a7280);
  font: 700 16px/1 var(--font-sans, system-ui, sans-serif);
  cursor: pointer;
  flex-shrink: 0;
}
.thd-close:hover { color: var(--ink); border-color: var(--line-strong, #2a3140); }

.thd-scroll {
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.th-wrap.thd-in-floor {
  max-width: none;
  margin: 0;
  padding: 16px 18px 28px;
}

.th-header-compact {
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: none;
}

.thd-modal .th-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 80;
}

@media (max-width: 700px) {
  .th-trade summary {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
  }
}
