/* ============================================================
   COMPONENTES
   ============================================================ */

/* ---------- Panel ---------- */
.panel {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: clamp(16px, 3.4vw, 24px);
  box-shadow: var(--shadow);
}
.panel--key { border-color: var(--acc-line); }

.editbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 16px;
  border: 1px dashed var(--wood);
  border-radius: var(--r-sm);
  background: var(--wood-soft);
  font-size: 12.5px;
  color: var(--wood);
}
.editbar button {
  border: none;
  background: none;
  color: var(--wood);
  font-size: 12px;
  text-decoration: underline;
  padding: 0;
}

/* ---------- Campos ---------- */
.row { display: grid; gap: 12px; margin-bottom: 16px; }
.row--2 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.row--3 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

.field { display: block; min-width: 0; }
/* Dentro de una fila, el rótulo absorbe la diferencia de alto: así los
   campos quedan alineados aunque un rótulo ocupe dos líneas. */
.row .field { display: flex; flex-direction: column; }
.row .field > .field__lbl { flex: 1 0 auto; }
.field--block { display: block; margin-bottom: 16px; }
.field__lbl {
  display: block;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--ink-3);
  margin-bottom: 6px;
}
.field__lbl.mt { margin-top: 20px; }
/* Campo que el método activo no exige: se puede llenar igual y sirve
   para la comparación entre métodos. */
.field.is-opt .field__lbl { opacity: .55; }
.field.is-opt .field__lbl::after { content: " · opcional"; }
.field.is-opt input { border-style: dashed; }
.field__help {
  margin-top: 6px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--ink-3);
}

input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--raised);
  color: var(--ink);
  /* 16px evita que iOS haga zoom al enfocar */
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
  -webkit-appearance: none;
  appearance: none;
}
input::placeholder { color: var(--ink-3); opacity: .7; }
input:focus, select:focus {
  outline: none;
  border-color: var(--acc);
  box-shadow: 0 0 0 3px var(--acc-soft);
}
input[type="date"] { min-height: 42px; }
/* El icono nativo del calendario es negro: en tema oscuro se pierde. */
:root:not([data-theme="light"]) input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1) opacity(.55);
}
select {
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

.inline-add { display: flex; gap: 8px; }
.inline-add input { flex: 1; min-width: 0; }
.add-btn {
  flex-shrink: 0;
  width: 44px;
  border: 1px solid var(--acc-line);
  border-radius: var(--r-sm);
  background: var(--acc-soft);
  color: var(--acc);
  font-size: 20px;
  line-height: 1;
  transition: background var(--t), transform .12s var(--ease);
}
.add-btn:hover { background: color-mix(in srgb, var(--acc) 20%, transparent); }
.add-btn:active { transform: scale(.94); }

.linkbtn {
  margin-top: 6px;
  padding: 0;
  border: none;
  background: none;
  color: var(--acc);
  font-size: 11.5px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- Chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chips:empty { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 4px 3px 11px;
  border: 1px solid var(--line-2);
  border-radius: 99px;
  background: var(--raised);
  font-size: 12.5px;
}
.chip button {
  border: none;
  background: none;
  color: var(--ink-3);
  font-size: 13px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 99px;
  transition: color var(--t), background var(--t);
}
.chip button:hover { color: var(--alert); background: var(--alert-soft); }

/* ---------- Tags / presets ---------- */
.preset-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
.preset-row__lbl {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--ink-3);
  margin-right: 4px;
}
.tag {
  padding: 4px 11px;
  border: 1px solid var(--line-2);
  border-radius: 99px;
  background: transparent;
  color: var(--ink-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  transition: color var(--t), border-color var(--t), background var(--t);
}
.tag:hover { color: var(--acc); border-color: var(--acc-line); background: var(--acc-soft); }

/* ---------- Segmentado ---------- */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--raised);
  margin-bottom: 12px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg__btn {
  flex-shrink: 0;
  padding: 6px 15px;
  border: none;
  border-radius: 99px;
  background: transparent;
  color: var(--ink-3);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: color var(--t), background var(--t);
}
.seg__btn.is-active { background: var(--acc); color: var(--bg); font-weight: 600; }

.method-note {
  font-size: 12.5px;
  color: var(--ink-2);
  line-height: 1.55;
  margin-bottom: 16px;
  padding-left: 11px;
  border-left: 2px solid var(--acc-line);
}
.method-note strong { color: var(--ink); }

/* ---------- Lectura de resultados ---------- */
.readout {
  margin: 18px 0;
  padding: 16px 18px;
  border: 1px solid var(--acc-line);
  border-radius: var(--r);
  background: linear-gradient(135deg, var(--acc-soft), transparent 70%), var(--raised);
}
.readout__meta {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-3);
  margin-bottom: 12px;
}
.readout__nums {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 26px;
  align-items: baseline;
}
.num { display: flex; align-items: baseline; gap: 5px; }
.num b {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink-2);
}
.num span { font-size: 11px; color: var(--ink-3); }
.num--hero { margin-left: auto; }
.num--hero b { font-size: 30px; color: var(--acc); }
.num--hero span { color: var(--ink-2); font-size: 12px; }
@media (max-width: 560px) {
  .num--hero { margin-left: 0; width: 100%; }
}

/* ---------- Botones ---------- */
.primary {
  width: 100%;
  padding: 12px 18px;
  border: 1px solid var(--acc);
  border-radius: var(--r-sm);
  background: var(--acc);
  color: var(--bg);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: opacity var(--t), transform .12s var(--ease), background var(--t);
}
.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--acc) 88%, white); }
.primary:active:not(:disabled) { transform: scale(.99); }
.primary:disabled {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-3);
  cursor: not-allowed;
}
.primary--wa {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: auto;
  flex: 1 1 240px;
  border-color: #25D366;
  background: #25D366;
  color: #062A14;
}
.primary--wa:hover { background: #34e177; }

.ghost {
  padding: 11px 18px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 500;
  transition: color var(--t), border-color var(--t), background var(--t);
}
.ghost:hover { color: var(--ink); border-color: var(--ink-3); background: var(--raised); }
.ghost--danger:hover { color: var(--alert); border-color: var(--alert); background: var(--alert-soft); }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

/* ---------- Grilla JAS ---------- */
.gridwrap {
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: auto;
  max-height: 62vh;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 16px;
  background: var(--raised);
}
.jgrid {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 12.5px;
}
.jgrid th, .jgrid td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 5px 6px;
  text-align: center;
  white-space: nowrap;
}
.jgrid thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-2);
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 600;
}
.jgrid tbody td:first-child,
.jgrid thead th:first-child,
.jgrid tfoot th:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--bg-2);
  color: var(--ink-2);
  font-weight: 600;
  min-width: 74px;
}
.jgrid thead th:first-child { z-index: 4; }
.jgrid__hcell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.jgrid__rm {
  border: none;
  background: none;
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1;
  padding: 2px 3px;
  border-radius: 4px;
  transition: color var(--t), background var(--t);
}
.jgrid__rm:hover { color: var(--alert); background: var(--alert-soft); }
/* La celda tiene que leerse como celda: sin borde, en terreno no
   se ve dónde tocar. */
.cellcount {
  width: 48px;
  padding: 5px 2px;
  font-size: 13px;
  text-align: center;
  border-color: var(--line);
  background: var(--surface-s);
  border-radius: 5px;
}
.cellcount:focus { background: var(--bg-2); }
.cellcount.has-val { color: var(--acc); font-weight: 600; }
.jgrid .totcell {
  background: var(--acc-soft);
  color: var(--ink-2);
  font-weight: 600;
}
.jgrid tfoot th, .jgrid tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: var(--bg-2);
  color: var(--ink);
  font-weight: 700;
}
.jgrid tfoot .grandcell { color: var(--acc); }
.jgrid__empty {
  padding: 22px !important;
  color: var(--ink-3);
  font-size: 13px;
  border: none !important;
  text-align: left !important;
  white-space: normal !important;
}

/* ---------- Registro ---------- */
.log { margin-top: 20px; }
.log .empty {
  padding: 20px;
  border: 1px dashed var(--line-2);
  border-radius: var(--r);
  color: var(--ink-3);
  font-size: 13px;
  text-align: center;
}
.entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-s);
  margin-bottom: 8px;
  transition: border-color var(--t);
}
.entry:hover { border-color: var(--line-2); }
.entry__main { min-width: 0; }
.entry__title {
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.entry__tag {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-3);
  padding: 1px 7px;
  border: 1px solid var(--line-2);
  border-radius: 99px;
}
.entry__detail {
  font-size: 11.5px;
  color: var(--ink-3);
  margin-top: 3px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.entry__right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.entry__val {
  font-size: 16px;
  font-weight: 600;
  color: var(--acc);
  margin-right: 6px;
  white-space: nowrap;
}
.entry__val small { font-size: 10px; color: var(--ink-3); font-weight: 500; margin-left: 2px; }
.icon-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-3);
  font-size: 13px;
  transition: color var(--t), background var(--t);
}
.icon-btn:hover { color: var(--ink); background: var(--raised); }
.icon-btn--danger:hover { color: var(--alert); background: var(--alert-soft); }

/* En celular el registro no cabe en una línea: el valor y los botones
   bajan a su propia fila, con el área de toque más grande. */
@media (max-width: 560px) {
  .entry { flex-direction: column; align-items: stretch; gap: 10px; }
  .entry__right {
    justify-content: flex-end;
    gap: 6px;
    padding-top: 9px;
    border-top: 1px dashed var(--line);
  }
  .entry__val { margin-right: auto; font-size: 18px; }
  .icon-btn { width: 38px; height: 38px; font-size: 15px; border: 1px solid var(--line); }
}

/* ---------- Comparación de métodos ---------- */
.compare {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--raised);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.compare__lbl {
  display: block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--ink-3);
  margin-bottom: 10px;
}
.compare__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 5px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 13px;
  color: var(--ink-2);
}
.compare__row:last-of-type { border-bottom: none; }
.compare__row b {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 600;
}
.compare__row.is-sel b { color: var(--acc); }
.compare__note {
  margin-top: 10px;
  font-size: 11.5px;
  color: var(--ink-3);
  line-height: 1.5;
}

/* ---------- Medidor de calibración ---------- */
.gauge { margin: 18px 0 4px; }
.gauge__scale {
  position: relative;
  display: flex;
  height: 8px;
  border-radius: 99px;
  overflow: hidden;
  background: var(--raised);
}
/* Las proporciones son la escala real: −10..−7 / −7..−3 / −3..+3 / +3..+7 / +7..+10 */
.gauge__zone--bad  { flex: 3; background: color-mix(in srgb, var(--alert) 45%, transparent); }
.gauge__zone--warn { flex: 4; background: color-mix(in srgb, var(--wood) 45%, transparent); }
.gauge__zone--ok   { flex: 6; background: color-mix(in srgb, var(--acc) 60%, transparent); }
.gauge__needle {
  position: absolute;
  top: -4px;
  left: 50%;
  width: 3px;
  height: 16px;
  border-radius: 2px;
  background: var(--ink);
  box-shadow: 0 0 0 2px var(--bg);
  transform: translateX(-50%);
  transition: left .5s var(--ease);
}
.gauge__ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 7px;
  font-size: 10px;
  color: var(--ink-3);
}

.verdict {
  margin: 14px 0 18px;
  padding: 11px 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--ink-2);
}
.verdict:empty { display: none; }
.verdict.is-ok   { border-color: var(--acc-line);  background: var(--acc-soft);   color: var(--ink); }
.verdict.is-warn { border-color: var(--wood);      background: var(--wood-soft);  color: var(--ink); }
.verdict.is-bad  { border-color: var(--alert);     background: var(--alert-soft); color: var(--ink); }

.factorbox {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  padding: 16px 20px;
  border: 1px solid var(--acc-line);
  border-radius: var(--r);
  background: var(--acc-soft);
}
.factorbox__lbl {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--ink-3);
}
.factorbox__note { font-size: 12.5px; color: var(--ink-2); margin-top: 4px; max-width: 46ch; }
.factorbox__val b {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 30px;
  font-weight: 600;
  color: var(--acc);
}

/* ---------- Totales ---------- */
.totals {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  margin-bottom: var(--gap);
  background: var(--surface);
}
.totals__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--line);
}
.tot {
  background: var(--bg-2);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tot__lbl {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--ink-3);
}
.tot__val { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.tot__unit { font-size: 11px; color: var(--ink-3); }
.tot--hero { background: var(--acc-soft); }
.tot--hero .tot__val { color: var(--acc); font-size: 28px; }

.totals__break { padding: 0; }
.totals__break:not(:empty) { border-top: 1px solid var(--line); padding: 14px 18px; }
.kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  font-size: 12.5px;
  color: var(--ink-2);
  border-bottom: 1px dashed var(--line);
}
.kv:last-child { border-bottom: none; }
.kv b { color: var(--ink); font-weight: 600; }
/* En pantalla angosta el par no cabe en una línea: se apila en vez de
   partir el rótulo por la mitad. */
@media (max-width: 520px) {
  .kv { flex-direction: column; gap: 1px; padding: 7px 0; }
  .kv b { align-self: flex-start; }
}

/* ---------- Vista previa ---------- */
.preview-box {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--raised);
  overflow: hidden;
}
.preview-box summary {
  padding: 11px 14px;
  font-size: 12.5px;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.preview-box summary::-webkit-details-marker { display: none; }
.preview-box summary::before { content: "▸ "; color: var(--ink-3); }
.preview-box[open] summary::before { content: "▾ "; }
.preview-box pre {
  margin: 0;
  padding: 0 14px 14px;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--ink-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 44vh;
  overflow-y: auto;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 90;
  transform: translate(-50%, 20px);
  padding: 11px 20px;
  border: 1px solid var(--acc-line);
  border-radius: 99px;
  background: var(--raised);
  color: var(--ink);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .28s var(--ease), transform .28s var(--ease);
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
