/* ==========================================================================
   tools.css — styling for the standalone utility pages.

   These pages reuse the main site's tokens (colours, radii, typography) so they
   read as part of the same product rather than as bolt-on widgets. Anything
   shared with the app belongs in app.css; only tool-specific layout lives here.
   ========================================================================== */

.tool-page {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 24px 96px;
}

.tool-head { margin-bottom: 26px; }
.tool-title {
  font-family: var(--serif);
  font-size: 30px;
  letter-spacing: .3px;
  margin: 0 0 8px;
}
.tool-lede { color: var(--ink-muted); font-size: 15px; line-height: 1.75; margin: 0; }

/* A single card is the unit of layout on these pages. */
.tool-card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 16px;
}
.tool-card h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 14px;
  color: var(--ink);
}
.tool-hint { font-size: 13px; color: var(--ink-faint); line-height: 1.7; margin: 10px 0 0; }

/* ── controls ───────────────────────────────────────────────────────────── */

.tool-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.tool-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
/* A field that should take the remaining width, but never force the row wider
   than the screen. The flex-basis is a hint, not a floor: `min-width: 0` is what
   lets it shrink below the basis on a narrow screen.
   Written as a class rather than an inline style because an inline
   `min-width: 200px` outranks this stylesheet, including its media queries — that
   is exactly how the search row came to overflow on a phone. */
.tool-field.grow { flex: 1 1 200px; min-width: 0; }
.tool-field.grow input { width: 100%; }
.tool-row.center { justify-content: center; }
.tool-row.spaced { margin-top: 14px; }
.tool-choice.spaced { margin-bottom: 14px; }
.tool-steps { padding-left: 20px; margin: 0; }
/* Results area: a plain block that the page fills with its own rows. */
.tool-results:not(:empty) { margin-top: 12px; }
.tool-field > span { font-size: 12.5px; color: var(--ink-muted); }
.tool-field input,
.tool-field select {
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--bg);
  outline: 0;
  font-size: 14px;
}
.tool-field input:focus,
.tool-field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }

.tool-btn {
  padding: 11px 20px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--bg-raised);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.tool-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.tool-btn:disabled { opacity: .5; cursor: default; }
.tool-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.tool-btn.primary:hover:not(:disabled) { color: #fff; filter: brightness(1.05); }

/* Radio-style strategy picker: one choice, visible current selection. */
.tool-choice { display: flex; flex-wrap: wrap; gap: 8px; }
.tool-choice button {
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--bg-raised);
  color: var(--ink-soft);
  font-size: 13.5px;
  cursor: pointer;
}
.tool-choice button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── tuner ──────────────────────────────────────────────────────────────── */

.tuner-readout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 0 4px;
}
.tuner-note {
  font-family: var(--serif);
  font-size: 76px;
  line-height: 1;
  color: var(--ink);
}
.tuner-note.idle { color: var(--ink-faint); }
.tuner-sub { font-size: 13.5px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

/* The needle: a fixed track with a marker that translates by cents. */
.tuner-meter { width: 100%; max-width: 460px; margin: 18px auto 4px; }
.tuner-track {
  position: relative;
  height: 46px;
  border-radius: 10px;
  background: linear-gradient(
    to right,
    var(--bg-side) 0%, var(--bg-side) 20%,
    var(--bg-raised) 20%, var(--bg-raised) 80%,
    var(--bg-side) 80%, var(--bg-side) 100%
  );
  border: 1px solid var(--line);
  overflow: hidden;
}
/* The in-tune band, drawn at the centre. */
.tuner-track::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 12%;
  transform: translateX(-50%);
  background: var(--accent-wash);
}
.tuner-track::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: var(--line-strong);
}
.tuner-needle {
  position: absolute;
  top: 5px;
  bottom: 5px;
  width: 4px;
  border-radius: 2px;
  background: var(--ink-faint);
  left: 50%;
  transform: translateX(-50%);
  transition: left .09s linear, background .15s;
}
.tuner-needle.in-tune { background: var(--ok); }
.tuner-scale {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--ink-faint);
  margin-top: 5px;
}

.tuner-strings { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.tuner-string {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 14px;
  min-width: 68px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  cursor: pointer;
}
.tuner-string b { font-size: 17px; font-weight: 600; }
.tuner-string small { font-size: 11.5px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.tuner-string.active { border-color: var(--accent); color: var(--accent); }
.tuner-string.active small { color: var(--accent); }
.tuner-string.done { border-color: var(--ok); }
.tuner-string.done b { color: var(--ok); }

.tuner-level {
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
  margin-top: 16px;
}
.tuner-level i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .08s linear; }

/* ── backtest ───────────────────────────────────────────────────────────── */

.bt-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(122px, 1fr));
  gap: 10px;
}
.bt-stat {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.bt-stat span { display: block; font-size: 12px; color: var(--ink-faint); margin-bottom: 5px; }
.bt-stat b { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bt-stat b.up { color: var(--ok); }
.bt-stat b.down { color: var(--err); }

.bt-chart { width: 100%; height: 260px; display: block; }
.bt-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-muted); margin-top: 8px; }
.bt-legend i { display: inline-block; width: 16px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

.bt-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.bt-table th {
  text-align: left;
  font-weight: 500;
  color: var(--ink-faint);
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.bt-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.bt-table tr:last-child td { border-bottom: 0; }
.bt-table .num { text-align: right; }
.bt-table tbody tr:hover { background: var(--bg); }

.bt-note {
  font-size: 12.5px;
  color: var(--ink-faint);
  line-height: 1.75;
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.tool-empty { color: var(--ink-faint); font-size: 14px; padding: 18px 0; text-align: center; }

/* Cross-link back to the main product, present on every tool page. */
.tool-cta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  margin-top: 22px;
  padding: 18px 20px;
  border-radius: 14px;
  background: var(--accent-wash);
  border: 1px solid var(--line);
}
.tool-cta p { margin: 0; font-size: 14px; color: var(--ink-soft); line-height: 1.7; }
.tool-cta a {
  padding: 11px 18px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  white-space: nowrap;
}

@media (max-width: 860px) {
  .tool-page { padding: 18px 16px 80px; }
  .tool-title { font-size: 25px; }
  .tuner-note { font-size: 62px; }
  .tool-btn, .tool-choice button, .tool-cta a { min-height: 44px; display: inline-flex; align-items: center; }
  .tuner-string { min-height: 58px; }
  input, select { font-size: 16px; }
  .bt-chart { height: 200px; }

  /* Stack the control rows instead of letting them wrap into a ragged jumble.
     A row of four controls cannot fit 360px, and wrapping alone leaves inputs
     at odd widths. */
  .tool-row { flex-direction: column; align-items: stretch; }
  .tool-row .tool-field,
  .tool-row .tool-field.grow { flex: 1 1 auto; width: 100%; }
  .tool-row .tool-btn { width: 100%; }
  .tool-row.center { flex-direction: row; justify-content: center; }
  .tool-row.center .tool-btn { width: auto; }

  /* Options in a picker keep flowing rather than stacking: five tuning buttons
     one-per-row would push the actual tuner far below the fold. */
  .tool-choice { gap: 7px; }
  .tool-choice button { padding: 8px 12px; font-size: 13px; }

  .bt-stats { grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); }
  .bt-table { font-size: 12px; }
  .bt-table th, .bt-table td { padding: 6px 4px; }
  /* The trades table is wider than a phone; let it scroll rather than squash. */
  .tool-card.table-scroll { overflow-x: auto; }
}
