/*
 * styles/tooltips.css — Trading Hub v2 portfolio-wide tooltip styles.
 * NEXUS COMMAND THv2 lane 37 — 2026-04-28.
 *
 * Two surfaces:
 *   .thv2-tip-bubble        — fast native-style hover bubble (≤140 char)
 *   .thv2-tip-modal-backdrop — modal explainer (formula/source/learn-more)
 *   .thv2-tip-chip          — inline ⓘ chip injected next to data-tip elems
 *
 * WCAG 2.2 AA:
 *   - focus-visible 2px outline on all interactive surfaces.
 *   - aria-describedby links anchor → bubble.
 *   - role=tooltip / role=dialog applied in JS.
 *   - prefers-reduced-motion: animations disabled.
 *
 * Mobile: bubble suppressed below 720px; tap → modal.
 * Theme: variables read from app.css; fallbacks safe for standalone pages.
 */

:root {
  --thv2-tip-bg: var(--bg-2);
  --thv2-tip-fg: var(--fg-0);
  --thv2-tip-fg-muted: var(--fg-2);
  --thv2-tip-border: var(--border);
  --thv2-tip-accent: var(--accent);
  --thv2-tip-shadow: 0 8px 32px rgba(0,0,0,0.45);
  --thv2-tip-radius: 8px;
  --thv2-tip-z: 10000;
}

/* ─── Native-style bubble ───────────────────────────────────────────── */

.thv2-tip-bubble {
  position: absolute;
  z-index: var(--thv2-tip-z);
  max-width: 320px;
  padding: 8px 10px;
  background: var(--thv2-tip-bg);
  color: var(--thv2-tip-fg);
  border: 1px solid var(--thv2-tip-border);
  border-radius: var(--thv2-tip-radius);
  box-shadow: var(--thv2-tip-shadow);
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
  opacity: 0;
  transition: opacity 100ms ease-out;
}

.thv2-tip-bubble .tip-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--thv2-tip-accent);
  margin-bottom: 2px;
}

.thv2-tip-bubble .tip-what {
  color: var(--thv2-tip-fg);
  font-size: 12px;
}

/* ─── data-tip affordance ───────────────────────────────────────────── */

[data-tip] {
  position: relative;
  cursor: help;
}

[data-tip]:focus-visible {
  outline: 2px solid var(--thv2-tip-accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ─── ⓘ chip ────────────────────────────────────────────────────────── */

.thv2-tip-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 4px;
  width: 16px;
  height: 16px;
  padding: 0;
  font-size: 11px;
  line-height: 1;
  color: var(--thv2-tip-fg-muted);
  background: transparent;
  border: 1px solid var(--thv2-tip-border);
  border-radius: 50%;
  cursor: pointer;
  vertical-align: middle;
  transition: background 120ms, color 120ms, border-color 120ms;
}

.thv2-tip-chip:hover,
.thv2-tip-chip:focus-visible {
  color: var(--thv2-tip-fg);
  background: var(--thv2-tip-bg);
  border-color: var(--thv2-tip-accent);
}

.thv2-tip-chip:focus-visible {
  outline: 2px solid var(--thv2-tip-accent);
  outline-offset: 2px;
}

/* ─── Modal explainer ───────────────────────────────────────────────── */

.thv2-tip-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: calc(var(--thv2-tip-z) + 100);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  padding: 16px;
  animation: thv2TipFade 160ms ease-out;
}

.thv2-tip-modal-backdrop[hidden] {
  display: none;
}

.thv2-tip-modal {
  width: 100%;
  max-width: 540px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--thv2-tip-bg);
  color: var(--thv2-tip-fg);
  border: 1px solid var(--thv2-tip-border);
  border-radius: 12px;
  box-shadow: var(--thv2-tip-shadow);
  padding: 24px;
  position: relative;
  animation: thv2TipPop 200ms ease-out;
}

.thv2-tip-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  font-size: 20px;
  line-height: 1;
  color: var(--thv2-tip-fg-muted);
  background: transparent;
  border: 1px solid var(--thv2-tip-border);
  border-radius: 6px;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}

.thv2-tip-modal-close:hover,
.thv2-tip-modal-close:focus-visible {
  color: var(--thv2-tip-fg);
  background: var(--thv2-tip-border);
}

.thv2-tip-modal-close:focus-visible {
  outline: 2px solid var(--thv2-tip-accent);
  outline-offset: 2px;
}

.thv2-tip-modal-title {
  margin: 0 32px 16px 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--thv2-tip-accent);
}

.thv2-tip-modal-body {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 16px;
  row-gap: 8px;
  font-size: 14px;
  line-height: 1.5;
}

.thv2-tip-modal-body dt {
  font-weight: 600;
  color: var(--thv2-tip-fg-muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.05em;
  padding-top: 2px;
}

.thv2-tip-modal-body dd {
  margin: 0;
  color: var(--thv2-tip-fg);
  word-break: break-word;
}

.thv2-tip-modal-body code {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  background: rgba(255,255,255,0.04);
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
}

.thv2-tip-modal-body a {
  color: var(--thv2-tip-accent);
  text-decoration: underline;
}

.thv2-tip-modal-body a:focus-visible {
  outline: 2px solid var(--thv2-tip-accent);
  outline-offset: 2px;
}

/* ─── Animations ────────────────────────────────────────────────────── */

@keyframes thv2TipFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes thv2TipPop {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ─── Mobile ────────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  .thv2-tip-bubble { display: none !important; }
  .thv2-tip-modal {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 12px 12px 0 0;
    margin-top: auto;
  }
  .thv2-tip-modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }
  .thv2-tip-chip {
    width: 22px;
    height: 22px;
    font-size: 13px;
  }
  [data-tip] {
    /* Larger touch targets on mobile */
    min-height: 28px;
  }
}

/* ─── Reduced motion ────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .thv2-tip-bubble,
  .thv2-tip-modal-backdrop,
  .thv2-tip-modal {
    animation: none !important;
    transition: none !important;
  }
}

/* ─── High contrast ─────────────────────────────────────────────────── */

@media (prefers-contrast: more) {
  .thv2-tip-bubble,
  .thv2-tip-modal {
    border-width: 2px;
    border-color: var(--thv2-tip-fg);
  }
}
