/* ============================================================
   base.css — copia de meta/kb/templates/mobile-base.css
   Lo unico que se cambio son los tokens de marca del :root y el modo oscuro.
   Las escalas (spacing, tipografia, radios, breakpoints) NO se tocan: son el
   estandar compartido entre proyectos.
   ============================================================ */

/* ============================================================
   mobile-base.css — Base responsive mobile-first
   Estándares: Material Design 3 · Apple HIG · WCAG 2.2
   Copiar al proyecto y ajustar tokens de la sección :root
   ============================================================ */

/* ─── Reset mínimo ─────────────────────────────────────────── */

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

html {
  font-size: 100%;          /* base 16px, respeta preferencia del usuario */
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%; /* evita que iOS agrande texto en landscape */
  text-size-adjust: 100%;
}

img, video, svg, canvas {
  max-width: 100%;
  height: auto;
  display: block;
}

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

/* ─── Tokens del proyecto ───────────────────────────────────── */
/* Ajustar estos valores según el diseño de cada proyecto       */

:root {
  /* Colores — capa semantica de la maqueta. Las reglas estan en guia-estilo-hmi.md (ISA-101 /
     high performance HMI, JG 24/09): la pantalla es gris cuando todo anda, y el color es SOLO de
     las alarmas. Otro tema reasigna estos mismos tokens desde su propia hoja, sin tocar los usos. Todos los pares se miden con `node tools/contrast.mjs`, que los lee de aca. */
  --color-surface:        #e0e0e0;   /* fondo: gris de sala iluminada (Rockwell PlantPAx, ASM) */
  --color-surface-raised: #ededed;   /* panel: apenas mas claro, separa sin llamar la atencion */
  --color-on-surface:     #1f1f1f;
  --color-muted:          #4d4d4d;   /* rotulos y unidades */
  --color-border:         #c2c2c2;   /* divisores: no delimitan un control */
  --color-border-strong:  #6e6e6e;   /* bordes de controles: >= 3:1 contra el fondo */
  --color-live:           #475ca7;   /* el dato que cambia, distinto del rotulo fijo */
  --color-energized:      #ffffff;   /* equipo en servicio en un grafico: mas claro que el fondo */
  --color-outline:        #1f1f1f;   /* contorno de indicadores y del foco */
  --color-band:           #3f3f3f;   /* franja de datos generados: neutra a proposito */
  --color-on-band:        #ffffff;
  --color-p1:             #e22028;   /* alarma prioridad 1: rojo (Rockwell "urgente") */
  --color-p2:             #ec8629;   /* alarma prioridad 2: naranja (Rockwell "alta") */
  --color-p3:             #f5e11b;   /* alarma prioridad 3: amarillo (Rockwell "media") */
  /* El numero adentro del indicador lleno. Es el mismo en todos los temas: el relleno de la prioridad
     no cambia, asi que lo que se lee encima tampoco. */
  --color-on-p1:          #ffffff;
  --color-on-p2:          #1f1f1f;
  --color-on-p3:          #1f1f1f;
  --color-paper:          #ffffff;   /* lo que tiene que ser blanco en cualquier tema: el fondo del QR */
  --color-map-ground:     #e8e8e8;   /* el fondo del plano (img/mapa-ciudad-cordoba.svg): #home lo extiende a toda la pantalla */
  /* La portada (index.html) es la cara de Scadia, no una pantalla de operacion: lleva su marca. */
  --color-brand:          #2b5fa8;
  --color-brand-dark:     #1f4a87;
  --color-on-brand:       #ffffff;

  /* Tipografía fluida
     Fórmula: clamp(min, valor-ideal-en-vw, max)
     Escala base: 16px a 320px → 18px a 1280px
     Calcular en: https://clampgenerator.com */
  --text-xs:   clamp(0.75rem,  0.71rem + 0.19vw, 0.875rem);  /* 12→14px */
  --text-sm:   clamp(0.875rem, 0.83rem + 0.23vw, 1rem);       /* 14→16px */
  --text-base: clamp(1rem,     0.95rem + 0.26vw, 1.125rem);   /* 16→18px */
  --text-lg:   clamp(1.125rem, 1.06rem + 0.33vw, 1.25rem);    /* 18→20px */
  --text-xl:   clamp(1.25rem,  1.15rem + 0.52vw, 1.5rem);     /* 20→24px */
  --text-2xl:  clamp(1.5rem,   1.33rem + 0.83vw, 2rem);       /* 24→32px */
  --text-3xl:  clamp(1.875rem, 1.58rem + 1.46vw, 2.625rem);   /* 30→42px */
  --text-4xl:  clamp(2.25rem,  1.83rem + 2.08vw, 3.25rem);    /* 36→52px */
  /* Un escalón sobre 4xl, SOLO para un número protagonista (stat tile / KPI hero) — no para títulos
     ni prosa; 4xl sigue siendo el techo textual. Registrado en design-system.md (2026-08-27). */
  --text-display: clamp(2.75rem, 1.9rem + 4vw, 4.5rem);       /* 44→72px */

  /* Line-height */
  --leading-tight:  1.2;
  --leading-snug:   1.35;
  --leading-normal: 1.5;
  --leading-relaxed:1.7;

  /* Espaciado — escala de 4px */
  --space-1:  0.25rem;   /*  4px */
  --space-2:  0.5rem;    /*  8px */
  --space-3:  0.75rem;   /* 12px */
  --space-4:  1rem;      /* 16px */
  --space-5:  1.25rem;   /* 20px */
  --space-6:  1.5rem;    /* 24px */
  --space-8:  2rem;      /* 32px */
  --space-10: 2.5rem;    /* 40px */
  --space-12: 3rem;      /* 48px */
  --space-16: 4rem;      /* 64px */

  /* Layout */
  --container-max:   1280px;
  --gutter-mobile:   var(--space-4);   /* 16px */
  --gutter-tablet:   var(--space-6);   /* 24px */
  --gutter-desktop:  var(--space-8);   /* 32px */

  /* Touch targets — mínimos según Material Design 3 y Apple HIG */
  --touch-target: 3rem;   /* 48px — Material Design 3 mínimo */
  --touch-gap:    var(--space-2);  /* 8px mínimo entre targets */

  /* Bordes */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* Sombras */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.1);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);

  /* Transiciones */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;

  /* Z-index */
  --z-dropdown: 100;
  --z-sticky:   200;
  --z-modal:    300;
  --z-toast:    400;
}

/* ─── Tipografía base ───────────────────────────────────────── */

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-on-surface);
  background-color: var(--color-surface);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1 { font-size: var(--text-4xl); line-height: var(--leading-tight); }
h2 { font-size: var(--text-3xl); line-height: var(--leading-tight); }
h3 { font-size: var(--text-2xl); line-height: var(--leading-snug); }
h4 { font-size: var(--text-xl);  line-height: var(--leading-snug); }
h5 { font-size: var(--text-lg);  line-height: var(--leading-snug); }
h6 { font-size: var(--text-base);line-height: var(--leading-snug); }

/* ─── Contenedor ────────────────────────────────────────────── */

.container {
  width: 100%;
  padding-inline: var(--gutter-mobile);
  margin-inline: auto;
}

@media (min-width: 768px) {
  .container { padding-inline: var(--gutter-tablet); }
}

@media (min-width: 1024px) {
  .container {
    padding-inline: var(--gutter-desktop);
    max-width: var(--container-max);
  }
}

/* ─── Touch target helper ───────────────────────────────────── */
/* Elemento visualmente chico que necesita área de toque grande */

.touch-target {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
}

/* Expand area without affecting layout */
.touch-target-expand::after {
  content: '';
  position: absolute;
  inset: -50%;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
}

/* ─── Botón base (touch-safe) ───────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
  font-weight: 500;
  line-height: 1;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: background-color var(--transition-fast),
              transform var(--transition-fast),
              box-shadow var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background-color: var(--color-brand);
  color: #fff;
}

.btn-primary:hover {
  background-color: var(--color-brand-dark);
}

/* ─── Inputs base (touch + iOS-safe) ───────────────────────── */

.input {
  display: block;
  width: 100%;
  min-height: var(--touch-target);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base); /* ≥ 16px para evitar zoom en iOS */
  line-height: var(--leading-normal);
  color: var(--color-on-surface);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  appearance: none;
  -webkit-appearance: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input:focus {
  outline: none;
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-brand) 20%, transparent);
}

/* ─── Breakpoints como media queries reutilizables ─────────── */
/* Usar en CSS del proyecto: @media (--sm) { ... }             */
/* Requiere PostCSS custom-media o copiar los valores directo  */

/* sm:  @media (min-width: 480px)  */
/* md:  @media (min-width: 768px)  */
/* lg:  @media (min-width: 1024px) */
/* xl:  @media (min-width: 1280px) */
/* 2xl: @media (min-width: 1440px) */

/* ─── Utilidades responsivas comunes ────────────────────────── */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

.hidden-mobile  { display: none; }
.visible-mobile { display: block; }

@media (min-width: 768px) {
  .hidden-mobile  { display: block; }
  .visible-mobile { display: none; }
}

/* ─── Hasta que el tema este puesto, la pagina no se ve ─────────
   web/js/theme.js pone data-tema en <html> antes de dibujar; hasta ahi, nada (si no, un tema que baja su
   hoja se veia un instante con los colores del otro). Si el JavaScript no corre, la pagina aparece igual a
   los 2 segundos: nunca queda en blanco. */
html:not([data-tema]) body:is(.proyeccion, .telefono) { visibility: hidden; animation: aparecer-sin-tema 0s 2s forwards; }
@keyframes aparecer-sin-tema { to { visibility: visible; } }

/* ─── Reducir movimiento (accesibilidad) ────────────────────── */

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