/* Calculator components — inputs, results, charts, compare mode */

.calc-layout { display: grid; gap: var(--s4); grid-template-columns: minmax(0, 1fr); }

.calc-panel {
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--s3);
  box-shadow: var(--shadow-card);
}

.calc-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--s2); flex-wrap: wrap; margin-bottom: var(--s3);
}
.calc-head h2 { font-size: 1.25rem; margin: 0; }
.calc-head .btn-ghost { flex-shrink: 0; }

/* Field rows */
.field-grid { display: grid; gap: var(--s2); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: .875rem; font-weight: 500; color: var(--text-strong); }
.field .hint { font-size: .75rem; color: var(--text-muted); }

.input-shell {
  display: flex; align-items: center;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--bg-surface); overflow: hidden;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.input-shell:focus-within {
  border-color: var(--c-primary-mid);
  box-shadow: 0 0 0 3px var(--c-primary-tint);
}
.input-shell .prefix, .input-shell .suffix {
  padding: 0 12px; font-size: .875rem; color: var(--text-muted);
  background: var(--bg-sunken); align-self: stretch; display: grid; place-items: center;
  flex-shrink: 0;
}
.input-shell input, .input-shell select {
  flex: 1; min-width: 0; height: 48px; padding: 0 12px;
  border: 0; background: transparent; color: var(--text-strong);
  font-family: var(--font-mono); font-size: 1rem;
}
.input-shell select { font-family: var(--font-body); cursor: pointer; }
.input-shell input:focus, .input-shell select:focus { outline: none; }
.input-shell.invalid { border-color: var(--c-error); }
.input-shell.invalid:focus-within { box-shadow: 0 0 0 3px var(--c-error-tint); }

.field-error { font-size: .8125rem; color: var(--c-error); min-height: 0; }
.field-error:empty { display: none; }

/* Segmented toggle */
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.segmented button {
  min-height: 40px; padding: 0 var(--s2); border: 0; cursor: pointer;
  background: var(--bg-surface); color: var(--text-body);
  font-family: inherit; font-size: .8125rem; font-weight: 500;
}
.segmented button + button { border-left: 1px solid var(--line-strong); }
.segmented button[aria-pressed="true"] { background: var(--c-primary-mid); color: #FFFFFF; }

/* Quick-pick chips */
.chips { display: flex; flex-wrap: wrap; gap: var(--s1); }
.chips button {
  min-height: 40px; padding: 0 var(--s2);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--bg-surface); color: var(--text-body);
  font-family: inherit; font-size: .875rem; cursor: pointer;
}
.chips button:hover { border-color: var(--c-primary-mid); color: var(--c-primary-mid); }
.chips button[aria-pressed="true"] { background: var(--c-primary-tint); border-color: var(--c-primary-mid); color: var(--text-on-tint); }

.calc-actions { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s3); }
.calc-actions .btn-primary { flex: 1 1 200px; }

/* Results */
.results[hidden] { display: none; }
.results {
  margin-top: var(--s3);
  animation: reveal .3s ease both;
}
@keyframes reveal {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.result-primary {
  background: var(--c-primary-tint);
  border-left: 4px solid var(--c-primary);
  padding: var(--s3);
  margin-bottom: var(--s2);
}
.result-primary .label { font-size: .875rem; color: var(--text-on-tint); margin: 0 0 4px; }
.result-primary .value {
  font-family: var(--font-mono); font-size: 2.25rem; font-weight: 600;
  color: var(--text-on-tint); line-height: 1.15; margin: 0;
  overflow-wrap: anywhere;
}
.result-primary .sub { font-size: .875rem; color: var(--text-on-tint); margin: 6px 0 0; opacity: .85; }

.result-stats { display: grid; gap: var(--s1); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat { background: var(--bg-sunken); border-radius: var(--radius); padding: var(--s2); }
.stat .label { font-size: .8125rem; color: var(--text-muted); margin: 0 0 2px; }
.stat .value { font-family: var(--font-mono); font-size: 1.25rem; font-weight: 600; color: var(--text-strong); margin: 0; overflow-wrap: anywhere; }

/* Chart */
.chart-box { margin-top: var(--s3); }
.chart-box canvas { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s1); font-size: .8125rem; color: var(--text-muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* Working / formula panel */
.working {
  margin-top: var(--s3); border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-surface);
}
.working summary {
  cursor: pointer; padding: var(--s2) var(--s3); font-weight: 600; font-size: .9375rem;
  color: var(--text-strong); list-style: none;
  display: flex; justify-content: space-between; align-items: center; gap: var(--s2);
}
.working summary::-webkit-details-marker { display: none; }
.working summary::after { content: "+"; color: var(--c-primary-mid); font-size: 1.25rem; }
.working[open] summary::after { content: "\2212"; }
.working .body { padding: 0 var(--s3) var(--s3); }
.working code, .working .eq {
  display: block; font-family: var(--font-mono); font-size: .875rem;
  background: var(--bg-sunken); padding: var(--s2); border-radius: var(--radius-sm);
  margin-bottom: var(--s1); overflow-x: auto; color: var(--text-strong);
}

/* Data tables */
.table-scroll { overflow-x: auto; margin-top: var(--s3); border: 1px solid var(--line); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data th, table.data td { padding: 10px var(--s2); text-align: right; white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th {
  background: var(--bg-sunken); color: var(--text-strong); font-weight: 600;
  position: sticky; top: 0; font-size: .8125rem;
}
table.data td { border-top: 1px solid var(--line); font-family: var(--font-mono); }
table.data td:first-child { font-family: var(--font-body); }
table.data tbody tr:hover { background: var(--bg-sunken); }
.table-tools { display: flex; gap: var(--s1); flex-wrap: wrap; margin-top: var(--s2); }

/* Compare mode */
.compare-grid { display: grid; gap: var(--s2); grid-template-columns: 1fr 1fr; }
.compare-col { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s2); background: var(--bg-sunken); }
.compare-col h3 { font-size: .9375rem; margin-bottom: var(--s2); color: var(--text-muted); }
.compare-col .field-grid { grid-template-columns: 1fr; }
.compare-col-b { border-top: 3px solid var(--c-accent); }
.compare-col-a { border-top: 3px solid var(--c-primary-mid); }
.diff-good { color: var(--c-success); font-weight: 600; }
.diff-bad { color: var(--c-error); font-weight: 600; }

@media (max-width: 640px) {
  .compare-grid { grid-template-columns: 1fr; }
}

/* Sticky mobile result bar */
.sticky-result {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
  background: var(--c-primary); color: #FFFFFF;
  padding: 10px var(--s2);
  display: none; align-items: center; justify-content: space-between; gap: var(--s2);
  box-shadow: 0 -2px 12px rgba(31, 35, 64, .18);
}
.sticky-result .label { font-size: .75rem; opacity: .85; margin: 0; }
.sticky-result .value { font-family: var(--font-mono); font-size: 1.125rem; font-weight: 600; margin: 0; }
.sticky-result button {
  background: rgba(255,255,255,.16); color: #FFFFFF; border: 0;
  border-radius: var(--radius-sm); min-height: 36px; padding: 0 12px;
  font-family: inherit; font-size: .8125rem; cursor: pointer; flex-shrink: 0;
}
@media (max-width: 767px) {
  .sticky-result.show { display: flex; }
  body.has-sticky { padding-bottom: 68px; }
}

/* Gauge / scale visual for health tools */
.gauge { margin-top: var(--s3); }
.gauge-track { display: flex; height: 14px; border-radius: 7px; overflow: hidden; }
.gauge-track i { display: block; height: 100%; }
.gauge-marker { position: relative; height: 22px; }
.gauge-marker span {
  position: absolute; transform: translateX(-50%);
  font-size: .75rem; color: var(--text-strong); font-weight: 600; white-space: nowrap;
  top: 2px;
}
.gauge-marker span::before {
  content: ""; position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-bottom: 6px solid var(--text-strong);
}
.gauge-labels { display: flex; justify-content: space-between; font-size: .6875rem; color: var(--text-muted); margin-top: 4px; }

.verdict { display: inline-block; padding: 6px 14px; border-radius: 999px; font-size: .875rem; font-weight: 600; }
.verdict-good { background: var(--c-success-tint); color: var(--c-success); }
.verdict-warn { background: var(--c-warn-tint); color: var(--c-warn); }
.verdict-bad { background: var(--c-error-tint); color: var(--c-error); }
