/* =====================================================================
   BASE: reset minimo, layout del shell, tipografia, foco y movimiento.
   ===================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
h3,
h4,
p,
figure,
ul,
ol {
  margin: 0;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

img,
svg {
  max-width: 100%;
  display: block;
}

a {
  color: var(--accent-text);
  text-decoration-color: color-mix(in srgb, var(--accent-text) 40%, transparent);
  text-underline-offset: 2px;
}

a:hover {
  text-decoration-color: currentColor;
}

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

/* Cualquier columna de cifras. Sin esto las tablas bailan al refrescar. */
.num,
td.num,
th.num,
.tabular {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.94em;
  font-variant-ligatures: none;
}

/* Variables de entorno, ids, rutas: SIEMPRE monoespaciada y en su forma real. */
.var,
.id,
.path {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--surface-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0 4px;
  white-space: nowrap;
}

.muted {
  color: var(--text-muted);
}
.faint {
  color: var(--text-faint);
}
.strong {
  font-weight: 620;
}
.tiny {
  font-size: var(--fs-xs);
}
.small {
  font-size: var(--fs-sm);
}
.nowrap {
  white-space: nowrap;
}
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* --- FOCO VISIBLE EN TODO LO INTERACTIVO ---------------------------- */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Nunca se quita el foco sin sustituirlo. */
:focus:not(:focus-visible) {
  outline: none;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--surface);
  color: var(--text);
  padding: var(--sp-4) var(--sp-5);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}

.skip-link:focus {
  left: var(--sp-5);
  top: var(--sp-5);
}

.noscript {
  max-width: 40rem;
  margin: var(--sp-8) auto;
  padding: var(--sp-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

/* --- SHELL ----------------------------------------------------------- */

.app-shell {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  padding: 0 var(--sp-6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

/* El contenedor alinea por linea base para que el nombre y la etiqueta de
   entorno compartan renglon. La marca no tiene texto, asi que con baseline
   quedaria colgando: se alinea al centro por su cuenta. */
.topbar__mark {
  display: flex;
  align-self: center;
  margin-right: calc(var(--sp-3) * -0.35);
  color: var(--text);
}

.topbar__brand {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  font-weight: 650;
  font-size: var(--fs-md);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.topbar__brand .env {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-faint);
}

.topbar__nav {
  display: flex;
  gap: var(--sp-2);
  margin-left: var(--sp-4);
  overflow: auto;
  scrollbar-width: none;
}

.topbar__nav::-webkit-scrollbar {
  display: none;
}

.topbar__nav a {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 var(--sp-5);
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: var(--fs-md);
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.topbar__nav a:hover {
  background: var(--surface-3);
  color: var(--text);
}

.topbar__nav a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.topbar__spacer {
  flex: 1;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.main {
  flex: 1;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: var(--sp-6);
  padding-block-end: var(--sp-8);
}

/* --- Rejillas y pilas ------------------------------------------------ */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.stack-xs {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.row-tight {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--sp-5);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--sp-5);
}

/* --- Cabeceras de seccion -------------------------------------------- */

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-4);
}

.section-head h2 {
  font-size: var(--fs-lg);
  font-weight: 650;
  letter-spacing: -0.01em;
}

.section-head h3 {
  font-size: var(--fs-md);
  font-weight: 650;
}

.page-head {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
}

.page-head h1 {
  font-size: var(--fs-2xl);
  font-weight: 660;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.crumb {
  font-size: var(--fs-sm);
}

.crumb a {
  color: var(--text-muted);
  text-decoration: none;
}

.crumb a:hover {
  color: var(--text);
  text-decoration: underline;
}

/* --- MOVIMIENTO: barra de progreso, pulso, 120 ms y nada mas --------- */

@keyframes nsh-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

@keyframes nsh-indeterminate {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(320%);
  }
}

.pulse {
  animation: nsh-pulse 1.8s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .pulse {
    opacity: 1;
    /* Sin animacion el estado "en curso" lo comunican icono + texto + color. */
  }
}

/* =====================================================================
   MOVIL DE VERDAD. Es donde el operador mira por la manana.
   ===================================================================== */

.tabbar {
  display: none;
}

@media (max-width: 780px) {
  .topbar__nav {
    display: none;
  }

  .topbar {
    padding: 0 var(--sp-5);
  }

  .main {
    padding: var(--sp-5);
    /* Hueco para la barra inferior + area segura del dispositivo. */
    padding-block-end: calc(var(--tabbar-h) + var(--sp-7) + env(safe-area-inset-bottom, 0px));
  }

  .tabbar {
    display: grid;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 30;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .tabbar a {
    min-height: var(--tabbar-h);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: var(--fs-xs);
  }

  .tabbar a .glyph {
    font-size: 16px;
    line-height: 1;
  }

  .tabbar a[aria-current="page"] {
    color: var(--accent-text);
    font-weight: 640;
  }

  .tabbar a[aria-current="page"] .glyph {
    color: var(--accent-text);
  }

  .grid-cards {
    grid-template-columns: 1fr;
  }
}
