/* ===== Tools page — trading calculators ==================================
   Re-skin of to-do/multi_toolkit_4_tabs.html into the app's design system.
   Uses the shared CSS variables (--surface/--text/--primary/--border …) and
   reuses existing components (.card, .field, .switch, .badge, table.data,
   .subtabs). Only calculator-specific bits live here. Scoped to the Tools
   panel so nothing leaks into the rest of the app. */

[data-tab="tools"] {
  /* Up/down accents for P&L (down reuses the app error colour). */
  --tool-up: #18a957;
  --tool-down: var(--error);
}

/* Center the single-column calculators (Profit) without stretching wide. */
.tool-narrow {
  max-width: 520px;
  margin: 0 auto;
}

.tool-card-title {
  text-align: center;
  margin-bottom: 18px;
}

/* ----- Tool sub-panes (switched by the .subtabs nav) ----- */
.tool-pane[hidden] {
  display: none !important;
}

/* ----- Range slider rows (themed native range) ----- */
.tool-range {
  margin-bottom: 16px;
}

.tool-range-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: .9rem;
  margin-bottom: 4px;
}

.tool-val {
  font-weight: 700;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  padding: 2px 9px;
  border-radius: 7px;
  font-variant-numeric: tabular-nums;
}

.tool-val.up { color: var(--tool-up); background: color-mix(in srgb, var(--tool-up) 14%, transparent); }
.tool-val.down { color: var(--tool-down); background: color-mix(in srgb, var(--tool-down) 14%, transparent); }

[data-tab="tools"] input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  outline: none;
  cursor: pointer;
}

[data-tab="tools"] input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
}

[data-tab="tools"] input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
}

/* ----- Multi-column input grids ----- */
.tool-two,
.tool-four {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
}

.tool-two { grid-template-columns: 1fr 1fr; }
.tool-four { grid-template-columns: repeat(4, 1fr); }

/* Range labels inside grids stack tighter. */
.tool-four .tool-range,
.tool-two .tool-range { margin-bottom: 0; }

.tool-two .field,
.tool-four .field { margin-bottom: 0; }

@media (max-width: 680px) {
  .tool-four { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 420px) {
  .tool-two { grid-template-columns: 1fr; }
}

/* ----- Result boxes ----- */
.tool-result {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 18px;
  text-align: center;
}

.tool-result.ok { border-color: color-mix(in srgb, var(--tool-up) 40%, var(--border)); }
.tool-result.bad { border-color: color-mix(in srgb, var(--tool-down) 40%, var(--border)); }
.tool-result.net {
  background: color-mix(in srgb, var(--primary) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
}

.tool-result-cap {
  font-size: .82rem;
  font-weight: 600;
}

.tool-result.ok .tool-result-cap { color: var(--tool-up); }
.tool-result.bad .tool-result-cap { color: var(--tool-down); }
.tool-result.net .tool-result-cap { color: var(--primary); }

.tool-result-num {
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 4px 0;
  font-variant-numeric: tabular-nums;
}

.tool-result-sub { font-size: .85rem; }

.tool-result-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid var(--border);
  margin-top: 10px;
  padding-top: 8px;
  font-size: .85rem;
}

.tool-results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.tool-results-grid .tool-result.net { grid-column: 1 / -1; }

@media (max-width: 480px) {
  .tool-results-grid { grid-template-columns: 1fr; }
}

.tool-up { color: var(--tool-up); }
.tool-down { color: var(--tool-down); }

/* ----- Segmented LONG / SHORT control ----- */
.tool-seg {
  display: flex;
  gap: 10px;
  margin-bottom: 22px;
}

.tool-seg input { position: absolute; opacity: 0; pointer-events: none; }

.tool-seg label {
  flex: 1;
  text-align: center;
  cursor: pointer;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 600;
  font-size: .92rem;
  color: var(--muted);
  background: var(--surface);
  transition: border-color .15s, color .15s, background .15s;
}

.tool-seg label small { display: block; font-weight: 400; font-size: .72rem; opacity: .8; }

.tool-seg input:checked + .tool-seg-long {
  border-color: var(--tool-up);
  color: var(--tool-up);
  background: color-mix(in srgb, var(--tool-up) 12%, transparent);
}

.tool-seg input:checked + .tool-seg-short {
  border-color: var(--tool-down);
  color: var(--tool-down);
  background: color-mix(in srgb, var(--tool-down) 12%, transparent);
}

.tool-switch { margin: 0 0 18px; }

/* ----- Averaging table ----- */
.tool-table { font-size: .82rem; min-width: 640px; }
.tool-table th,
.tool-table td { padding: 8px 10px; text-align: center; white-space: nowrap; }
.tool-table td .sub { display: block; font-size: .72rem; }

.tool-table .cell-accent {
  color: var(--primary);
  font-weight: 700;
  background: color-mix(in srgb, var(--primary) 8%, transparent);
}

.badge.bad {
  background: color-mix(in srgb, var(--tool-down) 18%, var(--surface));
  color: var(--tool-down);
}

.badge.good {
  background: color-mix(in srgb, var(--tool-up) 18%, var(--surface));
  color: var(--tool-up);
}

/* ----- Chart container (dependency-free canvas) ----- */
.tool-chart {
  position: relative;
  height: 280px;
  width: 100%;
  margin-top: 18px;
}

.tool-chart canvas { width: 100%; height: 100%; display: block; }

/* ----- Ladder builder ----- */
.tool-ladder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.tool-ladder-row {
  display: grid;
  grid-template-columns: 34px 1fr 1fr 44px;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border-radius: 10px;
  border-left: 3px solid transparent;
  transition: background .15s, border-color .15s;
}

.tool-ladder-row:hover {
  background: var(--surface-2);
  border-left-color: var(--primary);
}

.tool-ladder-row .field { margin-bottom: 0; }

.tool-ladder-no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
  font-size: .85rem;
}

.tool-ladder-list { display: flex; flex-direction: column; }

.tool-scenario {
  padding: 14px 0;
  border-bottom: 1px dashed var(--border);
}

.tool-scenario:last-child { border-bottom: none; }

.tool-scenario-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.tool-scenario-title { font-weight: 600; color: var(--primary); }

.tool-scenario-badges { text-align: right; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }

.tool-scenario-meta { font-size: .83rem; }

.tool-scenario-meta b { color: var(--text); }

/* ----- Native select (Ladder direction) themed like .field inputs ----- */
[data-tab="tools"] .field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

.tool-sub-h { margin: 0; font-size: 1rem; }
