/* PipAtlas tools. Everything is scoped under .tool and uses the site's CSS variables with fallbacks. */
.tool {
  --fx-bg: var(--bg, #0b1020);
  --fx-panel: var(--panel, #131a2e);
  --fx-panel2: var(--panel2, #1a2340);
  --fx-line: var(--line, #27314f);
  --fx-text: var(--text, #e8ecf6);
  --fx-muted: var(--muted, #97a3c0);
  --fx-accent: var(--accent, #ffc857);
  --fx-good: var(--good, #4ade80);
  --fx-bad: var(--bad, #f87171);
  --fx-radius: var(--radius, 14px);
  background: var(--fx-panel);
  border: 1px solid var(--fx-line);
  border-radius: var(--fx-radius);
  color: var(--fx-text);
  padding: 20px;
  margin: 24px 0;
  font: inherit;
  line-height: 1.5;
  max-width: 100%;
  min-width: 0;
}
.tool:empty { display: none; }
.tool *, .tool *::before, .tool *::after { box-sizing: border-box; }
.tool [hidden] { display: none !important; }

/* form */
.tool .fx-form { margin: 0; }
.tool .fx-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
  gap: 14px 16px;
  align-items: start;
}
.tool .fx-grid + .fx-grid, .tool .fx-set, .tool .fx-grid + .fx-set { margin-top: 16px; }
.tool .fx-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tool .fx-field.fx-wide { grid-column: 1 / -1; }
.tool label { font-size: 0.875rem; font-weight: 600; color: var(--fx-text); }
.tool input, .tool select, .tool textarea {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px; /* stops iOS zooming on focus */
  color: var(--fx-text);
  background: var(--fx-bg);
  border: 1px solid var(--fx-line);
  border-radius: calc(var(--fx-radius) * 0.6);
  font-variant-numeric: tabular-nums;
}
.tool textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; line-height: 1.45; resize: vertical; white-space: pre; overflow: auto; }
.tool select { appearance: auto; }
.tool input::placeholder, .tool textarea::placeholder { color: var(--fx-muted); opacity: 0.7; }
.tool input:focus-visible, .tool select:focus-visible, .tool textarea:focus-visible, .tool button:focus-visible, .tool .fx-scroll:focus-visible {
  outline: 2px solid var(--fx-accent);
  outline-offset: 2px;
  border-color: var(--fx-accent);
}
.tool input[readonly] { background: var(--fx-panel2); color: var(--fx-muted); cursor: default; }
.tool [aria-invalid="true"] { border-color: var(--fx-bad); box-shadow: 0 0 0 1px var(--fx-bad); }
.tool .fx-hint { font-size: 0.78rem; color: var(--fx-muted); min-height: 0; }
.tool .fx-hint:empty { display: none; }
.tool .fx-set { border: 1px solid var(--fx-line); border-radius: calc(var(--fx-radius) * 0.8); padding: 12px 14px 14px; min-width: 0; }
.tool .fx-set legend { padding: 0 8px; font-size: 0.8rem; font-weight: 700; color: var(--fx-accent); text-transform: uppercase; letter-spacing: 0.04em; }
.tool .fx-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.tool .fx-btn {
  min-height: 44px;
  padding: 10px 16px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--fx-text);
  background: var(--fx-panel2);
  border: 1px solid var(--fx-line);
  border-radius: calc(var(--fx-radius) * 0.6);
  cursor: pointer;
}
.tool .fx-btn:hover { border-color: var(--fx-accent); color: var(--fx-accent); }

/* notices */
.tool .fx-notice {
  margin: 0 0 16px;
  padding: 10px 14px;
  font-size: 0.875rem;
  color: var(--fx-text);
  background: var(--fx-panel2);
  border: 1px solid var(--fx-line);
  border-left: 4px solid var(--fx-accent);
  border-radius: calc(var(--fx-radius) * 0.5);
}
.tool .fx-h { margin: 22px 0 10px; font-size: 1rem; font-weight: 700; color: var(--fx-text); }
.tool .fx-results { background: var(--fx-bg); border: 1px solid var(--fx-line); border-radius: calc(var(--fx-radius) * 0.8); padding: 16px; min-width: 0; }
.tool .fx-form + .fx-results { margin-top: 18px; }
.tool .fx-results > :first-child { margin-top: 0; }
.tool .fx-results > :last-child { margin-bottom: 0; }
.tool .fx-msg { color: var(--fx-text); border-left: 4px solid var(--fx-bad); padding: 4px 0 4px 14px; }
.tool .fx-msg strong { color: var(--fx-bad); }
.tool .fx-msg ul { margin: 6px 0 0; padding-left: 18px; font-size: 0.92rem; }
.tool .fx-note { margin: 12px 0 0; font-size: 0.84rem; color: var(--fx-muted); }
.tool .fx-note.fx-warn { color: var(--fx-accent); }
.tool .fx-note.fx-bad { color: var(--fx-bad); font-weight: 700; margin: 0 0 12px; }
.tool .fx-formula { margin: 14px 0 0; font-size: 0.84rem; color: var(--fx-muted); }
.tool .fx-formula strong { color: var(--fx-text); }

/* stats */
.tool .fx-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 10px; }
.tool .fx-stat { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; background: var(--fx-panel); border: 1px solid var(--fx-line); border-radius: calc(var(--fx-radius) * 0.6); min-width: 0; }
.tool .fx-k { font-size: 0.76rem; color: var(--fx-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.tool .fx-v { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tool .fx-stat.fx-big { grid-column: 1 / -1; border-color: var(--fx-accent); }
.tool .fx-stat.fx-big .fx-v { font-size: 1.6rem; color: var(--fx-accent); }
.tool .fx-pos, .tool .fx-stat.fx-pos .fx-v, .tool .fx-stat.fx-big.fx-pos .fx-v { color: var(--fx-good); }
.tool .fx-neg, .tool .fx-stat.fx-neg .fx-v, .tool .fx-stat.fx-big.fx-neg .fx-v { color: var(--fx-bad); }
.tool .fx-acc, .tool .fx-stat.fx-acc .fx-v { color: var(--fx-accent); }

/* tables */
.tool .fx-scroll { overflow-x: auto; margin-top: 14px; border: 1px solid var(--fx-line); border-radius: calc(var(--fx-radius) * 0.6); -webkit-overflow-scrolling: touch; }
.tool .fx-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.tool .fx-table caption { caption-side: top; text-align: left; padding: 10px 12px; font-size: 0.8rem; font-weight: 700; color: var(--fx-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.tool .fx-table th, .tool .fx-table td { padding: 9px 12px; text-align: right; border-top: 1px solid var(--fx-line); white-space: nowrap; }
.tool .fx-table th:first-child, .tool .fx-table td:first-child { text-align: left; }
.tool .fx-table thead th { background: var(--fx-panel2); color: var(--fx-muted); font-size: 0.78rem; font-weight: 600; white-space: normal; }
.tool .fx-table tbody th { font-weight: 600; color: var(--fx-text); }
.tool .fx-table tr.fx-hl th, .tool .fx-table tr.fx-hl td { background: var(--fx-panel2); color: var(--fx-accent); font-weight: 700; }
.tool .fx-table tr.fx-rowneg td { color: var(--fx-bad); }
.tool .fx-table tr.fx-rowpos td { color: var(--fx-good); }
.tool .fx-scroll:has(.fx-tall) { max-height: 360px; overflow-y: auto; }
.tool .fx-tall thead th { position: sticky; top: 0; }
.tool .fx-matrix th, .tool .fx-matrix td { text-align: center; }
.tool .fx-matrix td { font-weight: 700; color: var(--fx-text); min-width: 64px; }
.tool .fx-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 10px 0 0; font-size: 0.8rem; color: var(--fx-muted); }
.tool .fx-sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--fx-line); }
.tool .fx-sw-neg { background: rgba(248, 113, 113, 0.55); }
.tool .fx-sw-zero { background: transparent; }
.tool .fx-sw-pos { background: rgba(74, 222, 128, 0.55); }

/* chart */
.tool .fx-chart { margin: 14px 0 0; padding: 12px; background: var(--fx-panel); border: 1px solid var(--fx-line); border-radius: calc(var(--fx-radius) * 0.6); }
.tool .fx-chart svg { display: block; width: 100%; height: auto; }
.tool .fx-chart figcaption { margin-top: 8px; font-size: 0.8rem; color: var(--fx-muted); }
.tool .fx-axis { stroke: var(--fx-muted); stroke-width: 1; }
.tool .fx-gridline { stroke: var(--fx-line); stroke-width: 1; stroke-dasharray: 3 4; }
.tool .fx-line1 { fill: none; stroke: var(--fx-accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.tool .fx-line2 { fill: none; stroke: var(--fx-muted); stroke-width: 2; stroke-dasharray: 6 5; vector-effect: non-scaling-stroke; }
.tool .fx-key { display: inline-block; width: 18px; height: 0; border-top: 3px solid var(--fx-accent); vertical-align: middle; margin: 0 6px 0 0; }
.tool .fx-key2 { border-top: 2px dashed var(--fx-muted); margin-left: 10px; }

/* session timeline */
.tool .fx-tl { margin-top: 16px; }
.tool .fx-tl-title { margin: 0 0 8px; font-size: 0.8rem; font-weight: 700; color: var(--fx-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.tool .fx-tl-row { display: grid; grid-template-columns: 68px minmax(0, 1fr); gap: 8px; align-items: center; margin-bottom: 6px; }
.tool .fx-tl-name { font-size: 0.8rem; font-weight: 600; color: var(--fx-text); }
.tool .fx-tl-track { position: relative; height: 22px; background: var(--fx-panel2); border-radius: 6px; overflow: hidden; }
.tool .fx-tl-seg { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.tool .fx-s-syd { background: #60a5fa; }
.tool .fx-s-tok { background: #f472b6; }
.tool .fx-s-lon { background: var(--fx-good); }
.tool .fx-s-nyc { background: #a78bfa; }
.tool .fx-s-ov { background: var(--fx-accent); }
.tool .fx-tl-now { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--fx-text); box-shadow: 0 0 0 1px var(--fx-bg); }
.tool .fx-tl-axis { position: relative; height: 18px; font-size: 0.72rem; color: var(--fx-muted); font-variant-numeric: tabular-nums; }
.tool .fx-tl-axis span { position: absolute; top: 0; padding-left: 4px; border-left: 1px solid var(--fx-line); }

@media (max-width: 480px) {
  .tool { padding: 14px; margin: 18px 0; }
  .tool .fx-results { padding: 12px; }
  .tool .fx-stat.fx-big .fx-v { font-size: 1.3rem; }
  .tool .fx-table th, .tool .fx-table td { padding: 8px 9px; font-size: 0.84rem; }
  .tool .fx-tl-row { grid-template-columns: 58px minmax(0, 1fr); gap: 6px; }
  .tool .fx-tl-name { font-size: 0.74rem; }
  .tool .fx-btn { width: 100%; }
}
@media (prefers-reduced-motion: no-preference) {
  .tool input, .tool select, .tool textarea, .tool .fx-btn { transition: border-color 0.15s ease; }
}
