/* FTD Detector — scoped styles that reuse main site design tokens */
/* Load after ../css/styles.css; only page-specific layout & signal chrome */

.ftd-page {
  max-width: 1100px;
  padding: 0.75rem 0.85rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

/* —— Top row: hero + signal side by side —— */
.ftd-top-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
  align-items: stretch;
}

@media (min-width: 720px) {
  .ftd-top-row {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  }

  .ftd-top-row > .card {
    margin: 0;
    min-width: 0;
    height: 100%;
  }

  .ftd-hero-head {
    flex-direction: column;
    align-items: stretch;
  }

  .ftd-hero-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .ftd-updated {
    text-align: left;
  }

  .ftd-hero .seo-lead {
    max-width: none;
    font-size: 0.9rem;
  }

  .ftd-summary {
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
}

/* —— Hero —— */
.ftd-hero {
  padding: 1.1rem 1.15rem 1rem;
}

.ftd-hero-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.ftd-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
  margin: 0 0 0.5rem;
}

.ftd-title-row .seo-kicker {
  margin: 0;
}

.ftd-hero h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}

.ftd-hero .seo-lead {
  margin: 0;
  max-width: 52ch;
}

.ftd-hero-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem 0.75rem;
  flex-shrink: 0;
}

.ftd-updated {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  text-align: right;
  line-height: 1.3;
}

.ftd-hero-actions .btn {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  width: auto;
  flex: 0 0 auto;
  white-space: nowrap;
}

.ftd-btn-icon {
  display: inline-block;
  line-height: 1;
}

.ftd-hero-actions .btn.spinning .ftd-btn-icon {
  animation: ftd-spin 0.8s linear infinite;
}

@keyframes ftd-spin {
  to { transform: rotate(360deg); }
}

/* —— Signal summary —— */
.ftd-summary {
  padding: 1.15rem 1.2rem;
  position: relative;
  overflow: hidden;
  border-left: 4px solid var(--text-dim);
}

.ftd-summary.level-rally {
  border-left-color: var(--warning);
  background:
    linear-gradient(135deg, rgba(217, 119, 6, 0.08), transparent 55%),
    var(--bg-card);
}

.ftd-summary.level-ftd {
  border-left-color: var(--profit);
  background:
    linear-gradient(135deg, rgba(22, 163, 74, 0.1), transparent 55%),
    var(--bg-card);
}

.ftd-summary.level-watch {
  border-left-color: var(--primary);
  background:
    linear-gradient(135deg, var(--primary-soft), transparent 55%),
    var(--bg-card);
}

.ftd-summary.level-none {
  border-left-color: var(--text-dim);
}

.ftd-summary-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.ftd-summary h2 {
  margin: 0 0 0.35rem;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.ftd-summary p {
  margin: 0;
  color: var(--text-muted);
  max-width: 56ch;
  font-size: 0.92rem;
}

.ftd-summary.skeleton h2 {
  color: var(--text-dim);
}

/* —— Rules accordion —— */
.ftd-rules {
  padding: 0;
  overflow: hidden;
}

.ftd-rules details {
  padding: 0.9rem 1.1rem;
}

.ftd-rules summary {
  cursor: pointer;
  font-weight: 650;
  font-size: 0.92rem;
  color: var(--text-muted);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.ftd-rules summary::-webkit-details-marker {
  display: none;
}

.ftd-rules summary::before {
  content: "▸";
  color: var(--primary);
  font-size: 0.75rem;
  transition: transform 0.15s;
}

.ftd-rules details[open] summary::before {
  transform: rotate(90deg);
}

.ftd-rules ol {
  margin: 0.85rem 0 0.65rem;
  padding-left: 1.2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.ftd-rules li {
  margin-bottom: 0.4rem;
}

.ftd-rules strong {
  color: var(--text);
  font-weight: 650;
}

.ftd-rules-note {
  margin: 0;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

/* —— Index cards —— */
.ftd-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.ftd-index-card {
  padding: 1rem 1.05rem 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ftd-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.65rem;
}

.ftd-card-name {
  font-weight: 700;
  font-size: 0.98rem;
}

.ftd-card-ticker {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
}

.ftd-badge {
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.28rem 0.5rem;
  border-radius: 6px;
  white-space: nowrap;
  flex-shrink: 0;
}

.ftd-badge-CORRECTION {
  background: var(--loss-soft);
  color: var(--loss);
}

.ftd-badge-RALLY_ATTEMPT {
  background: rgba(217, 119, 6, 0.12);
  color: var(--warning);
}

.ftd-badge-FOLLOW_THROUGH {
  background: var(--profit-soft);
  color: var(--profit);
}

.ftd-badge-UPTREND {
  background: var(--primary-soft);
  color: var(--primary);
}

.ftd-badge-UNKNOWN {
  background: var(--control-hover-bg);
  color: var(--text-muted);
}

.ftd-price-row {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.ftd-price {
  font-family: var(--mono);
  font-size: 1.45rem;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.ftd-dd {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
}

.ftd-dd.neg {
  color: var(--loss);
}

.ftd-dd.pos {
  color: var(--profit);
}

.ftd-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.ftd-metric {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem;
}

.ftd-metric-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 650;
}

.ftd-metric-value {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 500;
  margin-top: 0.15rem;
}

.ftd-metric-value.ok {
  color: var(--profit);
}

.ftd-metric-value.bad {
  color: var(--loss);
}

/* Day timeline */
.ftd-timeline {
  display: flex;
  gap: 0.25rem;
}

.ftd-day-dot {
  flex: 1;
  height: 28px;
  border-radius: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--text-dim);
}

.ftd-day-dot.window {
  border-color: rgba(22, 163, 74, 0.35);
  background: var(--profit-soft);
  color: var(--profit);
}

.ftd-day-dot.late {
  border-color: rgba(217, 119, 6, 0.35);
  background: rgba(217, 119, 6, 0.1);
  color: var(--warning);
}

.ftd-day-dot.current {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  color: var(--text);
  font-weight: 700;
}

.ftd-day-dot.past {
  opacity: 0.55;
}

.ftd-card-msg {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.45;
}

.ftd-rally-box {
  border: 1px dashed rgba(217, 119, 6, 0.4);
  background: rgba(217, 119, 6, 0.08);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  font-size: 0.82rem;
}

.ftd-rally-box strong {
  color: var(--warning);
  font-weight: 650;
}

.ftd-rally-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 0.75rem;
  margin-top: 0.5rem;
  font-family: var(--mono);
  font-size: 0.78rem;
}

.ftd-rally-grid span {
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.7rem;
  display: block;
  margin-bottom: 0.1rem;
}

/* —— Panels / tabs / chart —— */
.ftd-panel {
  padding: 1rem 1.05rem 0.95rem;
}

.ftd-panel .table-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.ftd-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.ftd-tab {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  min-height: 34px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.ftd-tab:hover {
  border-color: var(--btn-hover-border);
  background: var(--btn-hover-bg);
  color: var(--text);
}

.ftd-tab.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.ftd-chart-wrap {
  position: relative;
  height: 260px;
  margin-top: 0.25rem;
}

/* —— History table —— */
.ftd-hist-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.ftd-hist-table th {
  text-align: left;
  font-weight: 700;
  color: var(--text-dim);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.5rem 0.55rem;
  border-bottom: 1px solid var(--border);
  background: var(--matrix-head);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.ftd-hist-table td {
  padding: 0.55rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.78rem;
  white-space: nowrap;
  vertical-align: middle;
}

.ftd-hist-table tbody tr:hover td {
  background: var(--control-hover-bg);
}

.ftd-hist-table tr:last-child td {
  border-bottom: none;
}

.ftd-status-pill {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 5px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.ftd-status-FTD {
  background: var(--profit-soft);
  color: var(--profit);
}

.ftd-status-FAIL {
  background: var(--loss-soft);
  color: var(--loss);
}

.ftd-status-OPEN {
  background: rgba(217, 119, 6, 0.12);
  color: var(--warning);
}

.ftd-note-cell {
  font-family: var(--font) !important;
  color: var(--text-muted);
  white-space: normal !important;
  max-width: 220px;
}

.ftd-empty {
  color: var(--text-dim);
  font-size: 0.9rem;
  padding: 1.25rem;
  text-align: center;
  margin: 0;
}

.ftd-params {
  margin: 0.15rem 0 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.45;
}

/* Toast — align with site, keep fixed placement for FTD reloads */
.ftd-toast {
  position: fixed;
  bottom: calc(1.25rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(90vw, 22rem);
  padding: 0.65rem 1rem;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  text-align: center;
}

.ftd-toast.hidden,
.ftd-toast[hidden] {
  display: none !important;
}

@media (min-width: 640px) {
  .ftd-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .ftd-hero h1 {
    font-size: 1.65rem;
  }
}

@media (min-width: 960px) {
  .ftd-cards {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 640px) {
  .ftd-hero-actions {
    justify-content: space-between;
    width: 100%;
  }

  .ftd-updated {
    text-align: left;
    flex: 1 1 auto;
    min-width: 0;
  }

  .ftd-price {
    font-size: 1.25rem;
  }

  .ftd-chart-wrap {
    height: 200px;
  }

  .ftd-summary h2 {
    font-size: 1.1rem;
  }
}
