/*
 * Compatibility layer for migrated TvingHub interactive tools.
 *
 * This file intentionally owns no document, header, navigation, article, ad,
 * or footer styles. Every rule is rooted at Core's blank interactive mount so
 * legacy `.th-*` markup cannot restyle the WordPress or ToolForge shell.
 */

#tfg-interactive-root {
  --th-bg: var(--tfg-bg, #f8fafc);
  --th-surface: var(--tfg-surface, #fff);
  --th-bg-subtle: var(--tfg-bg-subtle, #f1f5f9);
  --th-text: var(--tfg-text, #172033);
  --th-text-muted: var(--tfg-text-muted, #5d687a);
  --th-border: var(--tfg-border, #dde3ea);
  --th-border-strong: var(--tfg-border-strong, #c8d1dc);
  --th-accent: var(--tfg-accent, #2457e6);
  --th-accent-hover: var(--tfg-accent-hover, #1944c7);
  --th-danger: var(--tfg-danger, #b42318);
  --th-accent-soft: var(--tfg-accent-soft, #edf2ff);
  --th-radius: 12px;
  --th-radius-lg: 18px;
  --th-shadow-md: 0 12px 32px rgb(23 32 51 / 8%);
  --th-space-label: 8px;
  --th-space-field: 16px;
  color: var(--th-text);
  font: inherit;
}

#tfg-interactive-root,
#tfg-interactive-root *,
#tfg-interactive-root *::before,
#tfg-interactive-root *::after {
  box-sizing: border-box;
}

#tfg-interactive-root button,
#tfg-interactive-root input,
#tfg-interactive-root select,
#tfg-interactive-root textarea {
  font: inherit;
}

#tfg-interactive-root .th-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

#tfg-interactive-root .th-panel {
  margin: 0 0 32px;
  padding: 28px;
  border: 1px solid var(--th-border-strong);
  border-radius: var(--th-radius-lg);
  background: var(--th-surface);
  box-shadow: var(--th-shadow-md);
}

#tfg-interactive-root .th-panel-label {
  margin: 0 0 22px;
  padding: 0 0 16px;
  border-bottom: 1px solid var(--th-border);
  color: var(--th-text);
  font-size: 17px;
  font-weight: 750;
  line-height: 1.4;
}

#tfg-interactive-root .th-hint-inline,
#tfg-interactive-root .th-hint,
#tfg-interactive-root .th-panel-empty-hint,
#tfg-interactive-root .th-ltv-places {
  color: var(--th-text-muted);
  font-size: 13px;
  font-weight: 400;
}

#tfg-interactive-root .th-field {
  margin-bottom: var(--th-space-field);
}

#tfg-interactive-root .th-field:last-child {
  margin-bottom: 0;
}

#tfg-interactive-root .th-field > label:not(.th-check),
#tfg-interactive-root .th-legend {
  display: block;
  margin: 0 0 var(--th-space-label);
  color: var(--th-text);
  font-size: 14px;
  font-weight: 650;
}

#tfg-interactive-root .th-field input[type="text"],
#tfg-interactive-root .th-field input[type="number"],
#tfg-interactive-root .th-field input[type="date"],
#tfg-interactive-root .th-field input[type="email"],
#tfg-interactive-root .th-field input[type="url"],
#tfg-interactive-root .th-field select,
#tfg-interactive-root .th-field textarea {
  width: 100%;
  padding: 0 14px;
  border: 1px solid var(--th-border);
  border-radius: var(--th-radius);
  background: var(--th-surface);
  color: var(--th-text);
  font-size: 16px;
  transition: border-color 160ms ease, background-color 160ms ease;
}

#tfg-interactive-root .th-field input[type="text"],
#tfg-interactive-root .th-field input[type="number"],
#tfg-interactive-root .th-field input[type="date"],
#tfg-interactive-root .th-field input[type="email"],
#tfg-interactive-root .th-field input[type="url"],
#tfg-interactive-root .th-field select {
  min-height: 50px;
}

#tfg-interactive-root .th-field textarea {
  min-height: 168px;
  padding: 14px;
  line-height: 1.6;
  resize: vertical;
}

#tfg-interactive-root .th-field input::placeholder,
#tfg-interactive-root .th-field textarea::placeholder {
  color: #8a8a90;
}

#tfg-interactive-root .th-field input:focus,
#tfg-interactive-root .th-field select:focus,
#tfg-interactive-root .th-field textarea:focus {
  border-color: var(--th-accent);
  outline: 3px solid rgb(36 87 230 / 14%);
  outline-offset: 0;
}

#tfg-interactive-root .th-field-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: var(--th-space-field);
}

#tfg-interactive-root .th-field-row-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

#tfg-interactive-root .th-field-row .th-field {
  min-width: 0;
  margin-bottom: 0;
}

#tfg-interactive-root .th-msg {
  margin: 12px 0 0;
  color: var(--th-text);
  font-size: 14px;
  line-height: 1.55;
}

#tfg-interactive-root .th-swatch {
  height: 80px;
  margin-bottom: 16px;
  border: 1px solid var(--th-border);
  border-radius: var(--th-radius);
  background: #1a5cff;
}

#tfg-interactive-root .th-check,
#tfg-interactive-root .th-field label.th-check,
#tfg-interactive-root .th-radios label,
#tfg-interactive-root .th-field .th-radios label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  margin: 0;
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
}

#tfg-interactive-root .th-radios {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

#tfg-interactive-root .th-check input,
#tfg-interactive-root .th-radios input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--th-accent);
  flex-shrink: 0;
}

#tfg-interactive-root .th-check input:focus-visible,
#tfg-interactive-root .th-radios input:focus-visible {
  outline: 2px solid var(--th-accent);
  outline-offset: 2px;
}

#tfg-interactive-root .th-actions,
#tfg-interactive-root .th-ltv-apply-row,
#tfg-interactive-root .th-ltv-nav,
#tfg-interactive-root .th-ltv-cities,
#tfg-interactive-root .th-note-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

#tfg-interactive-root .th-actions {
  margin: 14px 0 0;
}

#tfg-interactive-root .th-btn,
#tfg-interactive-root .th-btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 0 24px;
  border-radius: var(--th-radius);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

#tfg-interactive-root .th-btn {
  min-width: 156px;
  border: 0;
  background: var(--th-accent);
  color: #fff;
}

#tfg-interactive-root .th-btn:hover {
  background: var(--th-accent-hover);
}

#tfg-interactive-root .th-btn-ghost {
  border: 0;
  background: transparent;
  color: var(--th-text-muted);
}

#tfg-interactive-root .th-btn-ghost:hover {
  background: var(--th-bg-subtle);
  color: var(--th-text);
}

#tfg-interactive-root .th-btn:disabled,
#tfg-interactive-root .th-btn-ghost:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

#tfg-interactive-root .th-btn:focus-visible,
#tfg-interactive-root .th-btn-ghost:focus-visible,
#tfg-interactive-root .th-ltv-nav-btn:focus-visible,
#tfg-interactive-root .th-ltv-chip:focus-visible {
  outline: 2px solid var(--th-accent);
  outline-offset: 2px;
}

#tfg-interactive-root .th-result {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--th-border);
}

#tfg-interactive-root .th-result[hidden] {
  display: none;
}

#tfg-interactive-root .th-panel-empty-hint {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--th-border);
}

#tfg-interactive-root .th-panel:has(.th-result:not([hidden])) .th-panel-empty-hint {
  display: none;
}

#tfg-interactive-root .th-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

#tfg-interactive-root .th-stat {
  display: flex;
  min-height: 112px;
  padding: 16px;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--th-border);
  border-radius: var(--th-radius);
  background: var(--th-bg-subtle);
}

#tfg-interactive-root .th-stat span {
  color: var(--th-text-muted);
  font-size: 12px;
  font-weight: 600;
}

#tfg-interactive-root .th-stat strong {
  margin-top: 10px;
  color: var(--th-text);
  font-size: 30px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

#tfg-interactive-root .th-hint {
  margin: 12px 0 0;
}

#tfg-interactive-root .th-badge {
  display: inline-block;
  margin: 12px 0 0;
  padding: 8px 12px;
  border-radius: var(--th-radius);
  background: var(--th-accent-soft);
  color: var(--th-accent);
  font-size: 13px;
  font-weight: 600;
}

#tfg-interactive-root .th-badge:empty {
  display: none;
}

#tfg-interactive-root .th-tool-ltv .th-field > .th-badge {
  margin-top: 0;
  font-size: 18px;
}

#tfg-interactive-root .th-ltv-nav {
  min-width: 200px;
  flex: 1;
}

#tfg-interactive-root .th-ltv-nav-btn,
#tfg-interactive-root .th-ltv-chip {
  display: inline-flex;
  padding: 8px 12px;
  border: 1px solid var(--th-border);
  border-radius: var(--th-radius);
  background: var(--th-surface);
  color: var(--th-text);
  text-decoration: none;
}

#tfg-interactive-root .th-ltv-nav-btn {
  min-height: 48px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  line-height: 1.3;
}

#tfg-interactive-root .th-ltv-nav-btn span {
  color: var(--th-text-muted);
  font-size: 12px;
}

#tfg-interactive-root .th-ltv-chip {
  min-height: 36px;
  align-items: center;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

#tfg-interactive-root .th-ltv-nav-btn:hover,
#tfg-interactive-root .th-ltv-chip:hover,
#tfg-interactive-root .th-ltv-nav-btn.is-current,
#tfg-interactive-root .th-ltv-chip.is-current {
  border-color: var(--th-accent);
  background: var(--th-accent-soft);
  color: var(--th-accent);
}

#tfg-interactive-root .th-table-wrap {
  margin-top: 20px;
  overflow-x: auto;
  border: 1px solid var(--th-border);
  border-radius: var(--th-radius);
  -webkit-overflow-scrolling: touch;
}

#tfg-interactive-root .th-panel table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

#tfg-interactive-root .th-panel th,
#tfg-interactive-root .th-panel td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--th-border);
  text-align: right;
  white-space: nowrap;
}

#tfg-interactive-root .th-panel th:first-child,
#tfg-interactive-root .th-panel td:first-child {
  text-align: left;
}

#tfg-interactive-root .th-panel th {
  background: var(--th-bg-subtle);
  color: var(--th-text-muted);
  font-weight: 600;
}

#tfg-interactive-root .th-panel tbody tr:last-child td {
  border-bottom: 0;
}

#tfg-interactive-root .th-error {
  color: var(--th-danger);
  font-size: 14px;
  font-weight: 600;
}

#tfg-interactive-root .th-kb-display,
#tfg-interactive-root .th-calc-display {
  width: 100%;
  min-height: 48px;
  padding: 12px;
  border: 1px solid var(--th-border);
  border-radius: var(--th-radius);
  background: var(--th-bg-subtle);
  color: var(--th-text);
  font-variant-numeric: tabular-nums;
}

#tfg-interactive-root .th-kb-status,
#tfg-interactive-root .th-kb-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#tfg-interactive-root .th-kb-key {
  display: inline-flex;
  min-width: 36px;
  min-height: 36px;
  padding: 0 6px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--th-border);
  border-radius: var(--th-radius);
  background: var(--th-bg-subtle);
  color: var(--th-text-muted);
  font-size: 12px;
  font-weight: 600;
  user-select: none;
}

#tfg-interactive-root .th-kb-key.wide {
  min-width: 56px;
}

#tfg-interactive-root .th-kb-key.space {
  min-width: 120px;
  flex: 1 1 120px;
}

#tfg-interactive-root .th-kb-key.active {
  border-color: var(--th-accent);
  background: var(--th-accent-soft);
  color: var(--th-accent);
}

#tfg-interactive-root .th-quiz-item {
  margin: 0 0 18px;
}

#tfg-interactive-root .th-quiz-item p {
  margin: 0 0 8px;
  font-weight: 600;
}

#tfg-interactive-root .th-calc-pad {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 16px;
}

#tfg-interactive-root .th-calc-pad button {
  min-height: 48px;
  border: 1px solid var(--th-border);
  border-radius: var(--th-radius);
  background: var(--th-surface);
  color: var(--th-text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

#tfg-interactive-root .th-calc-pad button:hover {
  background: var(--th-bg-subtle);
}

#tfg-interactive-root .th-calc-display {
  min-height: 56px;
  font-size: 22px;
  font-weight: 700;
  text-align: right;
}

#tfg-interactive-root .th-react-box,
#tfg-interactive-root .th-aim-stage {
  border: 1px solid var(--th-border);
  border-radius: var(--th-radius-lg);
  background: var(--th-bg-subtle);
}

#tfg-interactive-root .th-react-box {
  display: flex;
  min-height: 180px;
  padding: 20px;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  user-select: none;
}

#tfg-interactive-root .th-aim-stage {
  position: relative;
  height: 280px;
  overflow: hidden;
}

#tfg-interactive-root .th-color-plate {
  display: flex;
  width: min(280px, 100%);
  margin: 8px auto 16px;
  aspect-ratio: 1;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 72px;
  font-weight: 800;
  user-select: none;
}

#tfg-interactive-root .th-pdf-pages {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

#tfg-interactive-root .th-pdf-page img {
  display: block;
  width: 100%;
  border: 1px solid var(--th-border);
  border-radius: var(--th-radius);
  background: var(--th-surface);
}

#tfg-interactive-root .th-pdf-page a {
  display: inline-flex;
  margin-top: 8px;
}

@media (max-width: 800px) {
  #tfg-interactive-root .th-panel {
    padding: 22px;
    box-shadow: 0 8px 24px rgb(23 32 51 / 7%);
  }

  #tfg-interactive-root .th-kb-key {
    min-width: 44px;
    min-height: 44px;
    padding: 0 8px;
    font-size: 13px;
  }
}

@media (max-width: 520px) {
  #tfg-interactive-root .th-panel {
    padding: 20px;
    border-radius: 16px;
  }

  #tfg-interactive-root .th-field-row,
  #tfg-interactive-root .th-field-row-2,
  #tfg-interactive-root .th-stats {
    grid-template-columns: 1fr;
  }

  #tfg-interactive-root .th-btn,
  #tfg-interactive-root .th-btn-ghost {
    width: 100%;
    flex: 1 1 100%;
  }

  #tfg-interactive-root .th-kb-key.space {
    min-width: 100%;
    flex-basis: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  #tfg-interactive-root .th-btn,
  #tfg-interactive-root .th-field input,
  #tfg-interactive-root .th-field select,
  #tfg-interactive-root .th-field textarea {
    transition: none;
  }
}

/* Native file controls must shrink inside narrow phone cards. */
[data-tfg-interactive-root] input[type="file"] {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
