:root {
  --bg: #f3f6f6;
  --surface: #ffffff;
  --surface-2: #eef3f3;
  --text: #102326;
  --muted: #5b6b6e;
  --border: #d7e0e1;
  --accent: #0f766e;
  --accent-contrast: #ffffff;
  --accent-soft: #d5efec;
  --danger: #b42318;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(16 35 38 / 0.06), 0 4px 16px rgb(16 35 38 / 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1416;
    --surface: #132124;
    --surface-2: #1a2c30;
    --text: #e6eff0;
    --muted: #93a7aa;
    --border: #26393d;
    --accent: #2dd4bf;
    --accent-contrast: #062421;
    --accent-soft: #123a37;
    --danger: #f97066;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

button, input, select { font: inherit; color: inherit; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--bg);
}

.brand {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 1.1rem;
}

.install-btn {
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  cursor: pointer;
}

/* ---------- Categorías ---------- */
.categories {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 16px 12px;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.categories::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  white-space: nowrap;
  cursor: pointer;
  scroll-snap-align: start;
  font-size: 0.95rem;
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}

/* ---------- Contenido ---------- */
.content {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px 24px;
  display: grid;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.cat-title, .section-title {
  margin: 0 0 12px;
  font-size: 1.05rem;
  font-weight: 650;
}

.field { display: grid; gap: 6px; }

.field-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.value-input, .value-output {
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 1.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.value-input {
  border: 2px solid var(--border);
  background: var(--surface);
  outline: none;
}
.value-input:focus { border-color: var(--accent); }
.value-input[aria-invalid="true"] { border-color: var(--danger); }

.value-output {
  display: flex;
  align-items: center;
  background: var(--accent-soft);
  border: 2px solid transparent;
}

.unit-select {
  width: 100%;
  min-height: 48px;
  padding: 10px 40px 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background-color: var(--surface-2);
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.input-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.85rem;
}

.swap-row {
  display: flex;
  justify-content: center;
  margin: 10px 0;
}

.swap-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 1.4rem;
  cursor: pointer;
  transition: transform 0.2s ease;
}
.swap-btn:active { transform: rotate(180deg); }

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.formula {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.cat-note {
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.ghost-btn {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- Lista de equivalencias ---------- */
.hint {
  margin: -6px 0 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.all-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.all-list li + li { border-top: 1px solid var(--border); }

.all-item {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 4px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.all-item[aria-current="true"] .all-value { color: var(--accent); }

.all-name { color: var(--muted); font-size: 0.92rem; }

.all-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  overflow-wrap: anywhere;
}

.all-symbol { color: var(--muted); font-weight: 500; margin-left: 4px; }

.footer-note {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0;
}

/* ---------- Avisos ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 20;
}

.ios-hint {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: 528px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 15;
}
.ios-hint p { margin: 0; font-size: 0.9rem; }

/* ---------- Selector de sección ---------- */
.view-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 0 16px 8px;
  padding: 4px;
  max-width: 528px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
@media (min-width: 592px) { .view-switch { margin: 0 auto 8px; } }

.view-switch button {
  min-height: 40px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}
.view-switch button[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ---------- Herramientas eléctricas ---------- */
.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}
@media (min-width: 480px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.f, .mini {
  display: grid;
  gap: 4px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}
.f input, .f select, .mini input, .preset-select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-weight: 500;
}
.f input:focus, .f select:focus, .mini input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.f input:disabled { opacity: 0.5; }
.tool > .f { margin-top: 12px; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  grid-column: 1 / -1;
}
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.sub-title { margin: 18px 0 4px; font-size: 0.95rem; }

.results { margin-top: 16px; }
.res-list { margin: 0; display: grid; }
.res-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 10px 4px;
  border-top: 1px solid var(--border);
}
.res-row:first-child { border-top: 0; }
.res-row dt { color: var(--muted); font-size: 0.9rem; }
.res-row dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.res-row.highlight {
  background: var(--accent-soft);
  border-radius: 10px;
  border-top-color: transparent;
  padding: 12px;
}
.res-row.highlight + .res-row { border-top-color: transparent; }

.warn, .ok {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
}
.warn { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.ok { background: var(--surface-2); }

.rows { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}
.row-4 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) auto; }
.row-4 .mini:first-child { grid-column: 1 / -1; }
.empty { color: var(--muted); font-size: 0.9rem; padding: 8px 4px; }

.icon-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
}
.row-4 .icon-btn { grid-column: 4; grid-row: 2; }

.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.preset-select { width: auto; flex: 1 1 180px; min-height: 38px; border-radius: 999px; font-size: 0.9rem; }

.table-wrap { overflow-x: auto; margin: 8px 0; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; white-space: nowrap; }

.spaced { margin-top: 24px; }
.formula-list { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 0.9rem; }

.disclaimer {
  margin: 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px dashed var(--border);
  color: var(--muted);
  font-size: 0.82rem;
}

[hidden] { display: none !important; }

@media (min-width: 480px) {
  .field-row { grid-template-columns: minmax(0, 1fr) 190px; }
}

@media (prefers-reduced-motion: reduce) {
  .swap-btn { transition: none; }
}

#fUse { margin-top: 16px; }

.f-btn { display: flex; align-items: flex-end; }
.offgrid {
  grid-column: 1 / -1;
  margin: 4px 0 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  min-width: 0;
}
.offgrid legend { padding: 0 6px; font-weight: 650; font-size: 0.9rem; }
.hint-top { margin: 12px 0 0; }
.res-group { margin: 16px 0 4px; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
