/* Active Trades — portfolio of decided trades
   Follows signal-log.css palette */

#page-active-trades { padding: 16px; }

/* ── Header ── */
.at-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.at-header-left h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--tv-text-primary);
  margin: 0 0 2px;
}
.at-meta-line { font-size: 0.73rem; color: var(--tv-text-secondary); }
.at-header-actions { display: flex; gap: 8px; }

/* ── Spinner ── */
.at-spin {
  display: inline-block;
  width: 10px; height: 10px;
  border: 2px solid var(--tv-border);
  border-top-color: var(--tv-accent);
  border-radius: 50%;
  animation: at-spin 0.7s linear infinite;
  margin-right: 5px;
  vertical-align: middle;
}
@keyframes at-spin { to { transform: rotate(360deg); } }

/* ── Dashboard ── */
.at-dashboard {
  background: var(--tv-bg);
  border: 1px solid var(--tv-border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
}

.at-stats-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.at-stat {
  flex: 1;
  min-width: 80px;
  background: var(--tv-bg-secondary);
  border: 1px solid var(--tv-border);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: center;
}
.at-stat-val {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--tv-text-primary);
  line-height: 1;
  margin-bottom: 4px;
}
.at-stat-label { font-size: 0.7rem; font-weight: 600; color: var(--tv-text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }
.at-stat-sub   { font-size: 0.65rem; color: var(--tv-text-tertiary); margin-top: 2px; }

/* ── Controls ── */
.at-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.at-tabs {
  display: flex;
  gap: 3px;
  background: var(--tv-border);
  border-radius: 7px;
  padding: 3px;
}
.at-tab {
  padding: 4px 12px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--tv-text-secondary);
  font-size: 0.76rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}
.at-tab.active {
  background: var(--tv-bg);
  color: var(--tv-text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ── Entries ── */
.at-entries { display: flex; flex-direction: column; gap: 6px; }

.at-entry {
  background: var(--tv-bg);
  border: 1px solid var(--tv-border);
  border-radius: 8px;
  padding: 10px 12px;
  transition: border-color 0.12s;
}
.at-entry:hover { border-color: var(--tv-accent); }
.at-entry.at-alert { border-left: 3px solid var(--tv-red); }
.at-entry.at-profit { border-left: 3px solid var(--tv-green); }

.at-entry-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.at-entry-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 150px;
}
.at-ticker {
  font-size: 1rem;
  font-weight: 800;
  color: var(--tv-text-primary);
  cursor: pointer;
  letter-spacing: 0.5px;
}
.at-ticker:hover { color: var(--tv-accent); }

.at-dir {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  text-transform: uppercase;
}
.at-dir.long  { background: #f0fdf4; color: #16a34a; }
.at-dir.short { background: var(--tv-red-bg-solid); color: var(--tv-red); }

.at-conviction {
  font-size: 0.62rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.at-conviction.high   { background: var(--tv-red-bg-solid); color: var(--tv-red); }
.at-conviction.medium { background: #fffbeb; color: var(--tv-orange); }
.at-conviction.low    { background: var(--tv-bg-tertiary); color: var(--tv-text-secondary); }

.at-date { font-size: 0.7rem; color: var(--tv-text-tertiary); }

.at-entry-mid {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  flex-wrap: wrap;
}
.at-levels {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.at-level-item {
  font-size: 0.72rem;
  color: var(--tv-text-primary);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 3px;
}
.at-lbl {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--tv-text-tertiary);
  text-transform: uppercase;
}

.at-entry-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.at-pnl {
  font-size: 0.85rem;
  font-weight: 800;
}
.at-pnl.positive { color: var(--tv-green); }
.at-pnl.negative { color: var(--tv-red); }

.at-eval-signal {
  font-size: 0.62rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.at-eval-signal.hold       { background: #eff6ff; color: #3b82f6; }
.at-eval-signal.add        { background: #f0fdf4; color: #16a34a; }
.at-eval-signal.trim       { background: #fffbeb; color: var(--tv-orange); }
.at-eval-signal.exit       { background: var(--tv-red-bg-solid); color: var(--tv-red); }
.at-eval-signal.stop_hit   { background: var(--tv-red-bg-solid); color: var(--tv-red); }
.at-eval-signal.target_hit { background: #f0fdf4; color: #16a34a; }

.at-status {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 3px;
  text-transform: uppercase;
}
.at-status.active  { background: #eff6ff; color: #3b82f6; }
.at-status.exited  { background: #f8f8f8; color: var(--tv-text-tertiary); }
.at-status.stopped { background: var(--tv-red-bg-solid); color: var(--tv-red); }

.at-eval-summary {
  font-size: 0.72rem;
  color: var(--tv-text-secondary);
  margin-top: 6px;
  line-height: 1.5;
  padding-top: 6px;
  border-top: 1px solid var(--tv-bg-tertiary);
}

.at-source {
  font-size: 0.62rem;
  color: var(--tv-text-tertiary);
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--tv-bg-tertiary);
}

.at-actions {
  display: flex;
  gap: 4px;
}

.at-btn {
  width: 22px; height: 22px;
  border-radius: 4px;
  border: 1px solid var(--tv-border);
  background: var(--tv-bg);
  color: var(--tv-text-tertiary);
  font-size: 0.7rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.12s;
  padding: 0;
}
.at-btn:hover { background: var(--tv-bg-tertiary); border-color: var(--tv-accent); color: var(--tv-accent); }
.at-btn.danger:hover { background: var(--tv-red-bg-solid); border-color: var(--tv-red); color: var(--tv-red); }

/* ── Add trade form ── */
.at-add-form {
  background: var(--tv-bg);
  border: 1px solid var(--tv-border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
  display: none;
}
.at-add-form.visible { display: block; }
.at-form-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.at-form-row:last-child { margin-bottom: 0; }
.at-input {
  padding: 5px 10px;
  border: 1px solid var(--tv-border);
  border-radius: 6px;
  font-size: 0.78rem;
  color: var(--tv-text-primary);
  background: var(--tv-bg);
  outline: none;
  flex: 1;
  min-width: 80px;
}
.at-input:focus { border-color: var(--tv-accent); }
.at-select {
  padding: 5px 10px;
  border: 1px solid var(--tv-border);
  border-radius: 6px;
  font-size: 0.78rem;
  color: var(--tv-text-primary);
  background: var(--tv-bg);
  outline: none;
  cursor: pointer;
}

/* ── Empty state ── */
.at-empty {
  padding: 40px;
  text-align: center;
  color: var(--tv-text-secondary);
  font-size: 0.85rem;
  background: var(--tv-bg);
  border: 1px solid var(--tv-border);
  border-radius: 8px;
}
.at-empty-icon { font-size: 2rem; margin-bottom: 8px; }

/* ── Exposure panel ── */
.at-exposure-panel {
  background: var(--tv-bg);
  border: 1px solid var(--tv-border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}
.at-exposure-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.at-exposure-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--tv-text-primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.at-exposure-dir {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}
.at-exposure-metrics {
  display: flex;
  gap: 16px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.at-exp-metric {
  font-size: 0.73rem;
  color: var(--tv-text-primary);
  font-weight: 600;
}
.at-exp-lbl {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--tv-text-tertiary);
  text-transform: uppercase;
  margin-right: 4px;
}
.at-sector-breakdown {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}
.at-sector-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.at-sector-name {
  font-size: 0.68rem;
  color: var(--tv-text-secondary);
  min-width: 120px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.at-sector-bar-container {
  flex: 1;
  display: flex;
  gap: 2px;
  height: 10px;
  background: var(--tv-bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}
.at-sector-bar {
  height: 100%;
  border-radius: 2px;
  min-width: 2px;
}
.at-sector-bar.long  { background: #10b981; }
.at-sector-bar.short { background: #ef4444; }
.at-sector-tickers {
  font-size: 0.62rem;
  color: var(--tv-text-tertiary);
  min-width: 80px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.at-warnings {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.at-warning-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  background: #fef3c7;
  color: #b45309;
  border: 1px solid #fde68a;
}

/* ── Positive / negative ── */
.positive { color: var(--tv-green); }
.negative { color: var(--tv-red); }

/* ── Mobile: < 768px ── */
@media (max-width: 768px) {
  #page-active-trades { padding: 10px; }

  .at-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .at-header-actions {
    width: 100%;
    display: flex;
  }
  .at-header-actions .btn { flex: 1; text-align: center; }

  .at-dashboard { padding: 10px; }

  .at-stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  .at-stat {
    min-width: 0;
    padding: 8px 6px;
  }
  .at-stat-val { font-size: 1.1rem; }
  .at-stat-label { font-size: 0.62rem; }
  .at-stat-sub { font-size: 0.58rem; }

  .at-tabs { width: 100%; }
  .at-tab { flex: 1; text-align: center; padding: 6px 8px; }

  /* Trade entries */
  .at-entry { padding: 10px; }
  .at-entry-main {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .at-entry-left { min-width: 0; width: 100%; }
  .at-entry-mid { width: 100%; }
  .at-entry-right {
    margin-left: 0;
    width: 100%;
    justify-content: space-between;
  }

  /* Add form */
  .at-add-form { padding: 10px; }
  .at-form-row { flex-direction: column; gap: 6px; }
  .at-input, .at-select { min-width: 0; width: 100%; }

  /* Exposure panel */
  .at-exposure-panel { padding: 10px; }
  .at-exposure-metrics { gap: 10px; }
  .at-sector-name { min-width: 80px; max-width: 80px; font-size: 0.6rem; }
  .at-sector-tickers { display: none; }
}

/* ── Small Mobile: < 480px ── */
@media (max-width: 480px) {
  .at-stats-row {
    grid-template-columns: repeat(2, 1fr);
  }
  /* Last stat spans full width when odd count */
  .at-stat:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
  .at-stat-val { font-size: 1rem; }

  .at-empty { padding: 24px 16px; font-size: 0.78rem; }
}
