/* ==========================================================
   Estilos compartidos para todas las herramientas
   ========================================================== */

:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5a6675;
  --border: #dde3ea;
  --primary: #0b7a75;
  --primary-hover: #09625e;
  --primary-soft: #e3f3f2;
  --on-primary: #ffffff;
  --warn-bg: #fff6e0;
  --warn-border: #f0c96a;
  --danger: #b42318;
  --radius: 10px;
  --maxw: 860px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #171e26;
    --text: #e6ebf0;
    --muted: #9aa6b4;
    --border: #2a3440;
    --primary: #3fbab3;
    --primary-hover: #5fcfc8;
    --primary-soft: #16302f;
    --on-primary: #0f1419;
    --warn-bg: #2e2612;
    --warn-border: #7a6224;
    --danger: #f97066;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 16px;
}

a { color: var(--primary); }
a:hover { color: var(--primary-hover); }
a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

/* Enlace para saltar al contenido: solo aparece al navegar con teclado */
.skip-link {
  position: absolute;
  left: 16px;
  top: -100px;
  z-index: 10;
  background: var(--primary);
  color: var(--on-primary);
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: 8px; color: var(--on-primary); }

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px;
}

/* ---------- Encabezado ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  flex-wrap: wrap;
}
.logo {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--text);
}
.logo span { color: var(--primary); }
.site-nav a {
  margin-left: 16px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.95rem;
}
.site-nav a:first-child { margin-left: 0; }
.site-nav a:hover { color: var(--primary); }

/* ---------- Contenido ---------- */
main { padding: 32px 0 48px; }

.breadcrumb {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}
.breadcrumb a { color: var(--muted); }

h1 { font-size: 1.75rem; line-height: 1.25; margin: 0 0 8px; }
h2 { font-size: 1.3rem; margin: 36px 0 12px; }
h3 { font-size: 1.05rem; margin: 24px 0 8px; }

.lead { color: var(--muted); margin: 0 0 24px; }

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

/* ---------- Formularios ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.field label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
}
.field .hint {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.8rem;
}
.input-group { display: flex; }
.input-group input { border-radius: 8px 0 0 8px; flex: 1; min-width: 0; }
.input-group select,
.input-group .unit {
  border-radius: 0 8px 8px 0;
  border-left: none;
}
.input-group .unit {
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: none;
  color: var(--muted);
  font-size: 0.9rem;
}

input, select {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.input-group select { width: auto; }
input:focus, select:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.segmented label {
  position: relative;
  flex: 1;
  margin: 0;
  text-align: center;
  padding: 10px 8px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.95rem;
}
.segmented input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) {
  background: var(--primary);
  color: var(--on-primary);
}
/* El anillo de foco usa el color del texto: sobre la opción marcada (fondo turquesa) uno turquesa no se vería */
.segmented label:has(input:focus-visible) {
  outline: 2px solid var(--text);
  outline-offset: -4px;
}

/* ---------- Listas de opciones (escalas) ---------- */
.options {
  border: none;
  margin: 0 0 20px;
  padding: 0;
  min-width: 0;
}
.options legend {
  font-weight: 700;
  margin-bottom: 8px;
  padding: 0;
}
.options legend .hint { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
.options label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
}
.options label:hover { border-color: var(--primary); }
.options input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.options label b {
  flex: none;
  min-width: 32px;
  text-align: center;
  color: var(--muted);
}
.options label:has(input:checked) {
  background: var(--primary-soft);
  border-color: var(--primary);
}
.options label:has(input:checked) b { color: var(--primary); }
.options label:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 1px; }

.btn-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 0.9rem;
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- Resultados ---------- */
.results {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}
.result {
  background: var(--primary-soft);
  border-radius: var(--radius);
  padding: 16px;
}
.result-label {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}
.result-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 4px 0;
}
.result-value small { font-size: 0.9rem; font-weight: 500; color: var(--muted); }
.result-note { font-size: 0.85rem; color: var(--muted); }
.result-extra { font-size: 0.9rem; margin-top: 8px; }
.result-extra div { display: flex; justify-content: space-between; gap: 8px; }
.empty-msg { color: var(--muted); font-size: 0.95rem; margin: 16px 0 0; }
.error-msg { color: var(--danger); font-size: 0.9rem; margin: 12px 0 0; }

/* ---------- Tablas y avisos ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  background: var(--surface);
}
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
th { font-weight: 600; background: var(--bg); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }

.formula {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.9rem;
  overflow-x: auto;
  white-space: pre-wrap;
}

.disclaimer {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.9rem;
  margin-top: 32px;
}

.refs { font-size: 0.9rem; color: var(--muted); padding-left: 20px; }
.refs li { margin-bottom: 6px; }
.refs .ref-links { white-space: nowrap; font-size: 0.85rem; }

details { border-bottom: 1px solid var(--border); padding: 10px 0; }
summary { cursor: pointer; font-weight: 600; }

/* ---------- Listado de herramientas (inicio) ---------- */
.finder {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 8px;
  scroll-margin-top: 16px;
}
.finder input[type="search"] { font-size: 1rem; }
.cat h2 { margin-top: 32px; }
.cat .tool-grid { margin-top: 12px; }
.no-results {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
}
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.tool-card {
  display: block;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.tool-card:hover {
  border-color: var(--primary);
  color: var(--text);
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.08);
}
.tool-card:active { transform: translateY(0); }
.tool-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  .tool-card, .tool-card:hover { transition: none; transform: none; }
}
.tool-card strong { display: block; margin-bottom: 4px; }
.tool-card span { color: var(--muted); font-size: 0.9rem; }
.tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 999px;
  padding: 2px 8px;
  margin-bottom: 8px;
}

/* ---------- Acciones sobre el resultado ---------- */
.result-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 12px;
}
.btn-secondary {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--primary);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.btn-secondary:hover { border-color: var(--primary); background: var(--primary-soft); }
.btn-secondary:active { transform: translateY(1px); }
.btn-secondary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.result-actions-msg { font-size: 0.85rem; color: var(--muted); }

/* ---------- Fecha de actualización ---------- */
.updated { font-size: 0.85rem; color: var(--muted); margin: -16px 0 24px; }

/* ---------- Calculadoras relacionadas ---------- */
.related { margin-top: 36px; }
.related .tool-grid { margin-top: 12px; }

/* ---------- Espacios para anuncios ----------
   Quedan ocultos mientras estén vacíos. Al pegar el código de
   AdSense dentro del div, aparecen solos. */
.ad-slot { margin: 24px 0; min-height: 90px; text-align: center; }
.ad-slot:empty { display: none; }

/* ---------- Pie ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 24px 0;
  font-size: 0.85rem;
  color: var(--muted);
}
.site-footer nav a { margin-right: 16px; color: var(--muted); }
.site-footer p { margin: 8px 0 0; }

@media (max-width: 520px) {
  h1 { font-size: 1.45rem; }
  .result-value { font-size: 1.7rem; }
  /* Logo y menú en una sola fila también en el móvil */
  .site-header .container { flex-wrap: nowrap; gap: 8px; }
  .logo { font-size: 1rem; }
  .site-nav { display: flex; flex-shrink: 0; }
  .site-nav a { margin-left: 12px; font-size: 0.9rem; display: inline-flex; align-items: center; min-height: 44px; }
}
/* En pantallas muy estrechas no cabe todo: el buscador ya está en la portada */
@media (max-width: 360px) {
  .site-nav a[href="/#herramientas"] { display: none; }
}

/* ---------- Impresión: solo el título, los datos, el resultado y las referencias ---------- */
@media print {
  :root { --bg: #fff; --surface: #fff; --text: #000; --muted: #333; --border: #bbb; --primary: #000; --primary-soft: #f2f2f2; color-scheme: light; }
  body { font-size: 12pt; }
  .site-header, .site-footer, .skip-link, .ad-slot, .result-actions, .related, .breadcrumb, details { display: none !important; }
  main { padding: 0; }
  a { color: inherit; text-decoration: none; }
  .card, .result, table { break-inside: avoid; }
  .options label:not(:has(input:checked)) { display: none; }
}
