/* ============================================================================
   Trading Signals — Public Statistics + Live-only Lock
   .plan/intergrate_api_live_signal_and_update_statistic_api.plan
   Statistics are public; only the live section has an inline promo lock card.
   ========================================================================== */

.ts-page { padding-top: 28px; padding-bottom: 48px; }

.ts-page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.ts-title { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.ts-subtitle { margin-top: 6px; font-size: 14px; color: var(--text-secondary); line-height: 1.5; }
.ts-change-code { flex-shrink: 0; }

/* ---------- Live lock card (inline promo form, live-only) ---------- */
.live-lock-card {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 36px 32px 28px;
  text-align: center;
}
.live-lock-card[hidden] { display: none !important; }
#liveContent[hidden] { display: none !important; }

/* Gate form elements shared by the live lock card */
.gate-icon {
  display: grid; place-items: center;
  width: 56px; height: 56px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  border: 1px solid rgba(252,213,53,0.18);
}
.gate-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.gate-desc { margin-top: 8px; font-size: 14px; color: var(--text-secondary); line-height: 1.6; }
.gate-form { margin-top: 24px; text-align: left; }
.gate-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.gate-field { position: relative; }
.gate-input {
  width: 100%;
  height: 46px;
  padding: 0 44px 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface-2);
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.gate-input::placeholder { color: var(--text-disabled); font-family: var(--font); letter-spacing: 0; }
.gate-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(252,213,53,0.15); }
.gate-input[aria-invalid="true"] { border-color: var(--down); box-shadow: 0 0 0 3px rgba(246,70,93,0.12); }
.gate-input-icon {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-disabled); pointer-events: none;
}
.gate-hint { margin-top: 8px; font-size: 12px; color: var(--text-disabled); line-height: 1.5; }
.gate-error {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--down-bg);
  border: 1px solid rgba(246,70,93,0.18);
  color: var(--down);
  font-size: 13px;
  line-height: 1.5;
}
.gate-error[hidden] { display: none !important; }
.gate-submit { width: 100%; margin-top: 18px; justify-content: center; position: relative; }
.gate-submit:disabled { opacity: 0.7; cursor: not-allowed; }
.btn-spinner { display: inline-flex; align-items: center; gap: 8px; }
.btn-spinner[hidden] { display: none !important; }
.spin { animation: ts-spin 0.8s linear infinite; }
@keyframes ts-spin { to { transform: rotate(360deg); } }
.gate-foot {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-disabled);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.gate-foot code { font-family: var(--font-mono); font-size: 11px; background: var(--bg-elevated); padding: 2px 6px; border-radius: 4px; color: var(--text-secondary); }

/* ---------- Stats (always visible — statistics are public) ---------- */
.ts-stats { display: flex; flex-direction: column; gap: 16px; }

/* summary */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.summary-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 18px 16px;
}
.summary-k {
  display: block;
  font-size: 12px; font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}
.summary-v {
  display: block;
  margin-top: 8px;
  font-size: 22px; font-weight: 700;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
}
.summary-v.up { color: var(--up); }
.summary-v.down { color: var(--down); }
.summary-sub { display: block; margin-top: 6px; font-size: 11px; color: var(--text-disabled); line-height: 1.4; }
.rr-badge {
  display: inline-grid; place-items: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 10px; font-weight: 700;
  vertical-align: middle; cursor: help;
}

/* toolbar */
.ts-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  flex-wrap: wrap;
}
.toolbar-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.toolbar-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); white-space: nowrap; }
.ts-select, .ts-date {
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface-2);
  color: var(--text-primary);
  font-size: 13px;
}
.ts-select:focus, .ts-date:focus { outline: none; border-color: var(--brand); }
.custom-range { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.custom-range[hidden] { display: none !important; }
.range-sep { color: var(--text-disabled); }
.toolbar-info { font-size: 13px; color: var(--text-secondary); white-space: nowrap; }

/* alert */
.ts-alert {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  font-size: 13px;
}
.ts-alert[hidden] { display: none !important; }
.ts-alert--error { background: var(--down-bg); border-color: rgba(246,70,93,0.18); color: var(--down); }
.ts-alert--error .ts-alert-msg { color: var(--down); flex: 1; }
.ts-alert-icon { flex-shrink: 0; }

/* table */
.ts-table-card { overflow: hidden; }
.ts-table th { font-weight: 600; }
.ts-table td { font-size: 13px; }

/* Row-level status colors: all values in a row share one color,
   except the first (time) column which stays neutral. */
.ts-table .cell-time { color: var(--text-secondary); font-weight: 400; }
.ts-table .result-text { color: inherit; font-weight: 700; letter-spacing: 0.01em; white-space: nowrap; }
.ts-table tbody tr.row-tp > td:not(.cell-time) { color: var(--up); font-weight: 600; }
.ts-table tbody tr.row-tp > td:not(.cell-time) .result-text { color: var(--up); }
.ts-table tbody tr.row-loss > td:not(.cell-time) { color: var(--down); font-weight: 600; }
.ts-table tbody tr.row-loss > td:not(.cell-time) .result-text { color: var(--down); }
.ts-table tbody tr.row-pending > td:not(.cell-time) { color: var(--text-primary); font-weight: 500; }
.ts-table tbody tr.row-pending > td:not(.cell-time) .result-text { color: var(--text-primary); }

.result-pill {
  display: inline-flex; align-items: center;
  height: 22px; padding: 0 8px;
  border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.01em; white-space: nowrap;
}
.result-TP1, .result-TP2, .result-TP3 { background: var(--up-bg); color: var(--up); border: 1px solid rgba(14,203,129,0.18); }
.result-LOSS { background: var(--down-bg); color: var(--down); border: 1px solid rgba(246,70,93,0.18); }
.result-CHUA_KHOP, .result-unknown { background: var(--bg-elevated); color: var(--text-secondary); }
.profit-up { color: inherit; font-weight: inherit; font-family: var(--font-mono); }
.profit-down { color: inherit; font-weight: inherit; font-family: var(--font-mono); }
.profit-zero { color: inherit; font-family: var(--font-mono); }

.ts-skeleton-rows { display: flex; flex-direction: column; gap: 14px; padding: 16px 20px; }
.ts-skeleton-rows[hidden] { display: none !important; }

/* pagination */
.ts-pagination {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 0 4px;
  flex-wrap: wrap;
}
.ts-pagination[hidden] { display: none !important; }
.ts-pagination button {
  min-width: 36px; height: 36px;
  padding: 0 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13px; font-weight: 500;
}
.ts-pagination button:hover:not(:disabled) { border-color: var(--border-strong); background: var(--bg-surface-2); }
.ts-pagination button:disabled { opacity: 0.45; cursor: not-allowed; }
.ts-pagination button[aria-current="true"] { background: var(--brand); color: var(--brand-text); border-color: var(--brand); font-weight: 700; }
.page-ellipsis { color: var(--text-disabled); padding: 0 4px; }

/* skeleton overrides */
.summary-skeleton[hidden] { display: none !important; }
.summary-skeleton { display: grid; }

/* ---------- Live signal section (.plan/live-signal.plan §3-§7) ---------- */
.ts-section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 2px 0;
  flex-wrap: wrap;
}
.ts-section-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.ts-section-sub { margin-top: 4px; font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.ts-section-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ts-history-head { margin-top: 8px; }

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  background: rgba(246, 70, 93, 0.12);
  border: 1px solid rgba(246, 70, 93, 0.25);
  color: var(--down);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: live-pulse 1.6s ease-in-out infinite;
}
@keyframes live-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.live-auto { font-size: 12px; color: var(--text-disabled); white-space: nowrap; }

.ts-live-wrap { display: flex; flex-direction: column; gap: 12px; }
.ts-live-wrap.ts-live-card {
  background: transparent;
  border: none;
  box-shadow: none;
}
.ts-live-wrap.is-refreshing .live-grid { opacity: 0.6; }
.ts-live-error { margin: 0; }

.live-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.live-grid[hidden] { display: none !important; }
.live-empty { grid-column: 1 / -1; }

.live-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 3px solid var(--border-strong);
  min-width: 0;
}
.live-card[data-status="RUNNING"] {
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.12), var(--bg-surface) 48%);
  border-color: rgba(59, 130, 246, 0.5);
  border-top-color: #3b82f6;
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.18), 0 8px 24px rgba(59, 130, 246, 0.18);
  opacity: 1;
  filter: none;
}
.live-card[data-status="RUNNING"] .live-card-product { color: #93c5fd; }
.live-card[data-status="RUNNING"] .live-price {
  background: rgba(59, 130, 246, 0.08);
  border-color: rgba(59, 130, 246, 0.28);
}
/* Blue status pill — scoped to the RUNNING card only so other
   .status-running usages keep the gold style. */
.live-card[data-status="RUNNING"] .status-running {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.45);
}
.live-card[data-status="RUNNING"] .status-running .status-dot { background: #fff; }
.live-card[data-status="RUNNING"] .live-card-note {
  background: rgba(59, 130, 246, 0.1);
  border-color: rgba(59, 130, 246, 0.25);
}
.live-card[data-status="RUNNING"] .live-card-note-icon,
.live-card[data-status="RUNNING"] .live-card-note-title { color: #60a5fa; }
.live-card[data-status="PENDING"] {
  border-top-color: var(--brand);
  border-color: rgba(252, 213, 53, 0.35);
  box-shadow: 0 0 0 1px rgba(252, 213, 53, 0.12), var(--shadow-sm);
}
.live-card[data-status="TP1_HIT"],
.live-card[data-status="TP2_HIT"],
.live-card[data-status="TP3_HIT"] { border-top-color: var(--up); }
.live-card[data-status="STOPPED"] { border-top-color: var(--down); }
.live-card[data-status="CANCELLED"] {
  border-top-color: var(--text-disabled);
  background: var(--bg-surface-2);
  opacity: 0.55;
  filter: grayscale(0.7);
  cursor: not-allowed;
}
.live-card[data-status="CANCELLED"] .live-card-product,
.live-card[data-status="CANCELLED"] .live-price dd,
.live-card[data-status="CANCELLED"] .live-card-code { color: var(--text-disabled); }
.live-card[data-status="CANCELLED"] .live-price { background: var(--bg-surface); }
.live-card[data-status="CANCELLED"] .live-card-note { opacity: 0.6; filter: grayscale(0.7); }
.live-card[data-status="EXPIRED"] { border-top-color: transparent; }

.live-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; min-width: 0; }
.live-card-id { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.live-card-product { font-size: 14px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-card-code { font-size: 11px; color: var(--text-secondary); font-family: var(--font-mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-card-head-right { flex-shrink: 0; max-width: 100%; }
.live-card-head-right .status-pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }

.live-card-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 11px; color: var(--text-secondary); min-width: 0; }
.live-card-date { display: inline-flex; align-items: center; gap: 5px; }
.live-card-sep { color: var(--text-disabled); }

.live-card-prices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
}
.live-price {
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  margin: 0;
  min-width: 0;
}
.live-price dt { font-size: 10px; color: var(--text-secondary); font-weight: 500; margin-bottom: 3px; white-space: nowrap; }
.live-price dd { margin: 0; font-family: var(--font-mono); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-price .is-hit { color: var(--up); font-weight: 700; }
.live-price--sl .live-price-v { color: var(--down); }

.live-card-note {
  display: flex; gap: 8px; align-items: flex-start;
  background: var(--brand-soft);
  border: 1px solid rgba(252, 213, 53, 0.22);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.live-card-note-icon { color: var(--brand-hover); flex-shrink: 0; margin-top: 1px; }
.live-card-note-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--brand-hover); margin-bottom: 3px; }
.live-card-note-text { font-size: 13px; line-height: 1.55; color: var(--text-primary); margin: 0; }

.live-card--skeleton { gap: 10px; border-top-color: var(--border); }

.ts-live-table { min-width: 1280px; }
.ts-live-table th.ta-center,
.ts-live-table td.ta-center { text-align: center; }
.ts-live-table .cell-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ts-live-table .cell-contract,
.ts-live-table .cell-tf {
  font-family: var(--font-mono);
  white-space: nowrap;
}
.ts-live-table .cell-hit { color: var(--up); font-weight: 700; }

/* Sticky context columns for horizontal scroll */
.ts-live-table thead th.cell-sticky-left,
.ts-live-table thead th.cell-sticky-left-2,
.ts-live-table thead th.cell-sticky-right {
  background: var(--bg-surface);
  z-index: 3;
}
.ts-live-table tbody td.cell-sticky-left,
.ts-live-table tbody td.cell-sticky-left-2,
.ts-live-table tbody td.cell-sticky-right {
  background: var(--bg-surface);
  z-index: 2;
}
.ts-live-table tbody tr:hover td.cell-sticky-left,
.ts-live-table tbody tr:hover td.cell-sticky-left-2,
.ts-live-table tbody tr:hover td.cell-sticky-right { background: var(--bg-surface-2); }
.ts-live-table .cell-sticky-left {
  position: sticky;
  left: 0;
  min-width: 104px;
  box-shadow: 1px 0 0 var(--border);
}
.ts-live-table .cell-sticky-left-2 {
  position: sticky;
  left: 104px;
  min-width: 92px;
  box-shadow: 1px 0 0 var(--border);
}
.ts-live-table .cell-sticky-right {
  position: sticky;
  right: 0;
  min-width: 140px;
  box-shadow: -1px 0 0 var(--border);
}

/* Position pills — always pill, never plain text */
.pos-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  height: 22px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.pos-long { background: var(--up-bg); color: var(--up); border: 1px solid rgba(14, 203, 129, 0.18); }
.pos-short { background: var(--down-bg); color: var(--down); border: 1px solid rgba(246, 70, 93, 0.18); }

/* Timeframe badge */
.tf-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* Status pills — only colored element in a live row */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid transparent;
}
.status-pending { background: var(--brand); color: var(--brand-text); border-color: var(--brand); }
.status-running { background: var(--brand-soft); color: var(--brand-hover); border-color: rgba(252, 213, 53, 0.25); }
.status-running .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: live-pulse 1.6s ease-in-out infinite;
}
.status-tp1 { background: transparent; color: var(--up); border-color: rgba(14, 203, 129, 0.4); }
.status-tp2 { background: var(--up-bg); color: var(--up); border-color: rgba(14, 203, 129, 0.25); }
.status-tp3 { background: var(--up-bg); color: var(--up); border-color: rgba(14, 203, 129, 0.25); }
.status-stopped { background: var(--down-bg); color: var(--down); border-color: rgba(246, 70, 93, 0.25); }
.status-cancelled { background: var(--bg-elevated); color: var(--text-disabled); border-color: var(--border-strong); }
.status-expired { background: var(--bg-elevated); color: var(--text-disabled); text-decoration: line-through; }
.status-unknown { background: var(--bg-elevated); color: var(--text-secondary); }

/* responsive — live grid scales 5 → 4 → 3 → 2 → 1 */
@media (max-width: 1360px) {
  .live-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 1120px) {
  .live-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .live-card-prices { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .ts-live-table .cell-sticky-left-2 { left: 104px; }
}
@media (max-width: 860px) {
  .live-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
}
@media (max-width: 640px) {
  .ts-page-head { flex-direction: column; }
  .live-lock-card { padding: 28px 20px 22px; }
  .summary-grid { grid-template-columns: 1fr; }
  .ts-toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-right { margin-left: 0; justify-content: space-between; }
  .ts-section-head { align-items: flex-start; flex-direction: column; }
  .ts-section-title { font-size: 16px; }
  .ts-section-actions { width: 100%; justify-content: space-between; }
}
@media (max-width: 580px) {
  .ts-page { padding-top: 20px; padding-bottom: 36px; }
  /* Gutters rieng cho mobile: container global chi co 16px, man hinh nay can
     thoang hon vi card xep 1 cot. max() giu gutter khi co tai thoai iOS. */
  .ts-page.container {
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
  }
  .live-grid { grid-template-columns: minmax(0, 1fr); }
  .live-card { padding: 14px 14px 12px; }
  .live-card-prices { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .live-card-note-text { font-size: 12.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .live-dot,
  .status-running .status-dot { animation: none; }
}
