/* ==========================================================================
   Interactive PSA tools (loaded after styles.css on tool pages only)
   Chart series: --accent and --series-2 pass CVD and 3:1 contrast checks.
   ========================================================================== */

.tool-app {
  --series-2: #c2410c;
  --plot-line: var(--fg-2);
  font-size: var(--text-sm);
}

.tool-formula {
  margin-top: var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--muted);
}

.tool-app .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-width: 0;
}

.tool-app h2 {
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0;
}

.tool-app input[type="text"] {
  width: 100%;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}

.tool-app input::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

.tool-app input[aria-invalid="true"] {
  outline: 2px solid var(--danger-text);
  outline-offset: -2px;
}

.tool-app .errors {
  display: grid;
  gap: var(--space-1);
  font-size: var(--text-sm);
  color: var(--danger-text);
}

.tool-app .note {
  max-width: 78ch;
  font-size: var(--text-sm);
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   PSA Doubling Time Calculator: lab flowsheet feeds results and plot
   -------------------------------------------------------------------------- */

.dt-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-6);
  align-items: start;
}

@media (min-width: 900px) {
  .dt-workspace {
    grid-template-columns: minmax(290px, 340px) minmax(0, 1fr);
  }
}

.dt-form.panel {
  padding: var(--space-5);
  display: grid;
  gap: var(--space-3);
}

.flowsheet {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.flowsheet th {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  text-align: left;
  color: var(--muted);
  padding: 0 var(--space-2) var(--space-2);
  border-bottom: 1px solid var(--fg);
}

.flowsheet th:first-child,
.flowsheet td:first-child {
  width: 30px;
  padding-left: 0;
  padding-right: 0;
}

.flowsheet td {
  padding: 0;
  border-bottom: 1px solid var(--border-soft);
}

.flowsheet td:first-child {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.flowsheet input[type="text"] {
  height: 40px;
  padding: 0 var(--space-2);
  border: 0;
  border-radius: 4px;
  background: transparent;
}

.dt-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.dt-actions .btn-primary {
  grid-column: 1 / -1;
  order: 3;
}

.dt-actions .btn,
.tracker-actions .btn {
  font-size: var(--text-sm);
}

.dt-output,
.dt-report {
  display: grid;
  gap: var(--space-5);
  min-width: 0;
}

.dt-results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-5);
}

@media (max-width: 560px) {
  .dt-results {
    grid-template-columns: minmax(0, 1fr);
  }
}

.result {
  padding: var(--space-5);
  display: grid;
  gap: var(--space-1);
  align-content: start;
}

.tool-app .result h2 {
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.bracket-key {
  flex: none;
  width: 18px;
  height: 8px;
  border: 2px solid;
  border-bottom: 0;
}

.bracket-key.a { border-color: var(--accent); }
.bracket-key.b { border-color: var(--series-2); }

.result .value {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: var(--text-2xl);
  line-height: 1.1;
  letter-spacing: var(--tracking-display);
  font-variant-numeric: tabular-nums;
}

.result .value small {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 400;
  letter-spacing: 0;
  color: var(--muted);
}

.result .direction {
  font-size: var(--text-sm);
  font-weight: 600;
}

.result .detail {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.6;
  color: var(--muted);
}

.result .flag {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-warm);
  font-size: var(--text-xs);
  line-height: 1.5;
  color: var(--fg-2);
}

.result .flag b {
  font-weight: 600;
}

.plot {
  padding: var(--space-5) var(--space-5) var(--space-3);
  display: grid;
  gap: var(--space-2);
}

@media (max-width: 560px) {
  .plot {
    padding-inline: var(--space-3);
  }
}

.chart-wrap {
  position: relative;
  min-width: 0;
}

#chart {
  display: block;
  width: 100%;
  touch-action: pan-y;
}

#chart text {
  font-family: var(--font-mono);
  font-size: 11px;
  fill: var(--muted);
}

#chart .value-label {
  font-size: 12px;
  font-weight: 500;
  fill: var(--fg);
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 4px;
  stroke-linejoin: round;
}

#chart .bracket-label {
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  fill: var(--fg);
}

#chart .axis-title {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
}

.gridline { stroke: var(--border-soft); stroke-width: 1; }
.baseline { stroke: var(--muted); stroke-width: 1; }
.psa-line { fill: none; stroke: var(--plot-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.psa-dot { fill: var(--plot-line); stroke: var(--surface); stroke-width: 2; }
.bracket { fill: none; stroke-width: 2; stroke-linejoin: round; }
.bracket.a { stroke: var(--accent); }
.bracket.b { stroke: var(--series-2); }
.label-bg { fill: var(--surface); }
.crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }

.tooltip {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  background: var(--fg);
  color: var(--surface);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.35;
  white-space: nowrap;
}

.dt-empty.panel {
  padding: 56px var(--space-6);
  text-align: center;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   PSA Kinetics Tracker: inputs on the left, the chart as the main sheet
   -------------------------------------------------------------------------- */

.tracker-sheet {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-6);
  align-items: start;
}

@media (min-width: 900px) {
  .tracker-sheet {
    grid-template-columns: minmax(0, 370px) minmax(0, 1fr);
  }
}

.tracker-sheet .panel {
  padding: var(--space-5);
  display: grid;
  gap: var(--space-4);
}

.tracker-sheet form.panel {
  gap: var(--space-5);
}

.tracker-sheet .group {
  display: grid;
  gap: var(--space-3);
}

.tracker-sheet .group > h2 {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-2);
}

.tracker-sheet .field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px 50px;
  align-items: center;
  gap: var(--space-2);
}

.tracker-sheet .field label {
  font-weight: 500;
}

.tracker-sheet .unit {
  color: var(--muted);
  font-size: var(--text-xs);
}

.tracker-sheet input[type="text"] {
  height: 38px;
  padding: 0 var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.tracker-sheet table {
  border-collapse: collapse;
  width: 100%;
  font-variant-numeric: tabular-nums;
}

.matrix th {
  text-align: left;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--fg-2);
  padding: 0 var(--space-2) var(--space-2) 0;
}

.matrix th span {
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 400;
}

.matrix td {
  padding: 0 var(--space-2) var(--space-2) 0;
}

.matrix th:last-child,
.matrix td:last-child {
  padding-right: 0;
}

.tracker-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.tracker-actions .btn-primary {
  flex: 1;
}

.chart-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2) var(--space-5);
  align-items: baseline;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  color: var(--fg-2);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.key {
  display: inline-block;
  flex: none;
}

.key-line { width: 20px; height: 2px; border-radius: 1px; background: var(--accent); }
.key-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--series-2); }
.key-band { width: 14px; height: 12px; border-radius: 2px; background: var(--surface-warm); border: 1px solid var(--border); }

.summary {
  font-size: var(--text-base);
}

.summary b {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 500;
}

.chart {
  position: relative;
  height: 420px;
  min-width: 0;
  touch-action: pan-y;
}

@media (max-width: 899px) {
  .chart {
    height: 340px;
  }
}

.chart svg {
  display: block;
  width: 100%;
  height: 100%;
}

.chart-empty {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
}

.axis { font-family: var(--font-mono); font-size: 11px; fill: var(--muted); }
.axis-title { font-family: var(--font-body); font-size: 12px; fill: var(--fg-2); }
.adt-band { fill: var(--surface-warm); }
.adt-label { font-family: var(--font-body); font-size: 12px; font-weight: 500; fill: var(--fg-2); }
.expected-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.expected-knot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.reading-dot { fill: var(--series-2); stroke: var(--surface); stroke-width: 2; }
.reading-value { font-family: var(--font-mono); font-size: 12px; font-weight: 500; fill: var(--fg); paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.hit { fill: transparent; }

.tip {
  position: absolute;
  top: 12px;
  z-index: 2;
  pointer-events: none;
  min-width: 150px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--elev-raised);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  display: grid;
  gap: 2px;
}

.tip strong {
  font-weight: 600;
}

.tip div {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  color: var(--fg-2);
}

.tip b {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--fg);
}

.schedule,
.table-wrap {
  overflow-x: auto;
}

.data th,
.data td {
  padding: var(--space-2) var(--space-3) var(--space-2) 0;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}

.data th {
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--fg-2);
}

.data td {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.data .num {
  text-align: right;
}

.data tr:last-child td,
.data tbody tr:last-child th {
  border-bottom: 0;
}

.data tbody th {
  font-weight: 500;
  color: var(--fg);
}
