/* ==========================================================================
   Herramix (https://herramixpy.com) - Hoja de estilos principal
   Diseño limpio, minimalista, mobile-first, accesible y con modo claro/oscuro
   ========================================================================== */

:root {
  /* Variables del tema claro por defecto */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --text: #0f172a;
  --text-muted: #475569;
  --border: #cbd5e1;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #dbeafe;
  --success: #15803d;
  --success-bg: #dcfce7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --focus-ring: #3b82f6;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --radius: 10px;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* Detección automática del modo oscuro del sistema si el usuario no forzó el claro */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120;
    --surface: #111827;
    --surface-alt: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-soft: #1e3a8a;
    --success: #4ade80;
    --success-bg: #14532d;
    --danger: #f87171;
    --danger-bg: #7f1d1d;
    --warning: #fbbf24;
    --warning-bg: #78350f;
    --focus-ring: #60a5fa;
    --shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  }
}

/* Tema oscuro forzado manualmente con el botón */
:root[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-alt: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-soft: #1e3a8a;
  --success: #4ade80;
  --success-bg: #14532d;
  --danger: #f87171;
  --danger-bg: #7f1d1d;
  --warning: #fbbf24;
  --warning-bg: #78350f;
  --focus-ring: #60a5fa;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

/* Reset básico y accesibilidad */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-family: var(--font-sans);
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Enlace de salto al contenido para lectores de pantalla y teclado */
.skip-link {
  position: absolute;
  top: -100px;
  left: 1rem;
  background: var(--primary);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  z-index: 1000;
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: 0.75rem;
}

/* Foco visible accesible con teclado */
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

a:hover {
  color: var(--primary-hover);
}

/* Contenedor principal adaptable */
.container {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Cabecera del sitio */
.site-header {
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.5rem 0;
}

.logo {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.logo-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--primary);
  color: #ffffff;
  border-radius: 7px;
  font-size: 1rem;
  font-weight: 800;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.65rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.site-nav {
  display: none;
  width: 100%;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border);
}

.site-nav.is-open {
  display: block;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.35rem;
}

.nav-list a {
  display: block;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.92rem;
}

.nav-list a:hover,
.nav-list a[aria-current="page"] {
  background: var(--surface-alt);
  color: var(--primary);
  font-weight: 600;
}

/* Selector de idioma y botón de tema */
.lang-switch,
.theme-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  line-height: 1.2;
}

.lang-switch:hover,
.theme-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Contenido principal */
main {
  flex: 1;
  padding: 1.25rem 0 2.5rem;
}

h1 {
  font-size: clamp(1.5rem, 3.5vw, 2rem);
  line-height: 1.25;
  margin: 0 0 0.5rem;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  margin: 0 0 1rem;
  font-size: 1rem;
}

h2 {
  font-size: 1.3rem;
  margin: 1.75rem 0 0.75rem;
  letter-spacing: -0.01em;
}

h3 {
  font-size: 1.05rem;
  margin: 1rem 0 0.4rem;
}

/* Caja principal de la herramienta */
.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

/* Aviso de privacidad local */
.privacy-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.9rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 1rem 0;
}

/* Espacio reservado para anuncio (altura mínima fija para evitar CLS) */
.ad-slot {
  min-height: 100px;
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 1.25rem 0;
  padding: 0.5rem;
  text-align: center;
}

/* Controles de formulario */
.form-group {
  margin-bottom: 1rem;
}

label {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 0.35rem;
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  transition: border-color 0.15s ease;
}

textarea {
  resize: vertical;
  min-height: 170px;
  line-height: 1.5;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.92rem;
}

/* Botones */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--primary);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, transform 0.05s ease;
}

.btn:hover {
  background: var(--primary-hover);
  color: #ffffff;
}

.btn:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--border);
  color: var(--text);
}

/* Cuadrículas utilitarias */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
  margin-top: 0.85rem;
}

.stat-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.2;
  word-break: break-word;
}

.stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  display: block;
}

/* Resultados y alertas */
.result-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin-top: 0.75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.status-msg {
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  margin-top: 0.75rem;
}

.status-ok {
  background: var(--success-bg);
  color: var(--success);
}

.status-error {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Tablas de datos (ej. subredes) */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;
  font-size: 0.95rem;
}

.data-table th,
.data-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  width: 42%;
}

.data-table td {
  font-family: var(--font-mono);
  word-break: break-all;
}

/* Tarjetas de herramientas en portada y relacionadas */
.tools-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
  margin-top: 0.75rem;
}

.tool-link-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s ease, transform 0.1s ease;
  box-shadow: var(--shadow);
}

.tool-link-card:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.tool-link-card h3 {
  margin: 0 0 0.35rem;
  color: var(--primary);
  font-size: 1.05rem;
}

.tool-link-card p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Secciones informativas, ejemplo y preguntas frecuentes */
.content-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-top: 1.25rem;
}

.example-box {
  background: var(--surface-alt);
  border-left: 4px solid var(--primary);
  padding: 0.85rem 1rem;
  border-radius: 0 8px 8px 0;
  margin: 0.75rem 0;
}

details.faq-item {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
}

details.faq-item:last-child {
  border-bottom: none;
}

details.faq-item summary {
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

details.faq-item summary::after {
  content: "+";
  font-size: 1.2rem;
  color: var(--primary);
  font-weight: 800;
}

details.faq-item[open] summary::after {
  content: "−";
}

details.faq-item p {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
}

/* Pestañas (ej. calculadora de fechas) */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.6rem;
}

.tab-btn {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.85rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.tab-btn[aria-selected="true"] {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.tab-panel[hidden] {
  display: none;
}

/* Opciones en línea (checkboxes, sliders) */
.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  margin: 0;
}

.check-label input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--primary);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

/* Zona de carga y vista previa de imágenes */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  text-align: center;
  background: var(--surface-alt);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--primary);
}

.preview-wrap {
  margin-top: 1rem;
  text-align: center;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  overflow: hidden;
}

.preview-wrap img {
  max-width: 100%;
  max-height: 360px;
  height: auto;
  border-radius: 6px;
}

/* Barra de fortaleza de contraseña */
.strength-bar {
  height: 8px;
  background: var(--surface-alt);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.5rem;
  border: 1px solid var(--border);
}

.strength-fill {
  height: 100%;
  width: 0%;
  transition: width 0.2s ease, background-color 0.2s ease;
}

/* Pie de página */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  margin-top: auto;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.footer-inner {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  text-align: center;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Media queries para tablet y escritorio (Mobile-first) */
@media (min-width: 640px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .tools-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  .tool-card {
    padding: 1.5rem;
  }
  .footer-inner {
    flex-direction: row;
    text-align: left;
  }
}

@media (min-width: 900px) {
  .tools-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
