/* =====================================================================
   Hierropar PWA — Base de diseño (temas Acero / Terreno / Automático)
   Un solo diseño; el tema cambia colores, tipografía y escala (--s).
   El tema efectivo lo pone <html data-tema="acero|terreno"> (ver layout_hp.html).
   ===================================================================== */

:root,
:root[data-tema="acero"] {
  --bg: #0F1115;
  --surface: #1A1D23;
  --surface-2: #23262E;
  --line: #2B2F38;
  --text: #F2F3F5;
  --muted: #9AA0AA;
  --head: #0F1115;
  --head-text: #F2F3F5;
  --head-muted: #9AA0AA;
  --head-chip: #1A1D23;
  --accent: #F0142D;
  --accent-hover: #FF2B42;
  --accent-soft: #2A1418;
  --accent-text: #FF7A86;
  --blue: #4B53F0;
  --warn: #FFB020;
  --on-warn: #111318;
  --ok: #3DDC97;
  --key: #1A1D23;
  --key-text: #F2F3F5;
  --nav: #14161B;
  --nav-line: #23262E;
  --nav-muted: #9AA0AA;
  --focus: #FF7A86;
  --fd: 'Space Grotesk', system-ui, sans-serif;
  --fb: Inter, system-ui, sans-serif;
  --up: none;
  --ls: -0.02em;
  --w-display: 700;
  --s: 1;
  color-scheme: dark;
}

:root[data-tema="terreno"] {
  --bg: #ECEEF2;
  --surface: #FFFFFF;
  --surface-2: #F1F2F5;
  --line: #C9CDD5;
  --text: #111318;
  --muted: #4A505C;
  --head: #111318;
  --head-text: #FFFFFF;
  --head-muted: #B4B9C3;
  --head-chip: #23262E;
  --accent: #D90F1F;
  --accent-hover: #B80C1A;
  --accent-soft: #FDE7E9;
  --accent-text: #A30A16;
  --blue: #1B1FB0;
  --warn: #F5B700;
  --on-warn: #111318;
  --ok: #0E7A47;
  --key: #FFFFFF;
  --key-text: #111318;
  --nav: #FFFFFF;
  --nav-line: #DADDE3;
  --nav-muted: #4A505C;
  --focus: #1B1FB0;
  --fd: 'Barlow Condensed', system-ui, sans-serif;
  --fb: Barlow, system-ui, sans-serif;
  --up: uppercase;
  --ls: 0.01em;
  --w-display: 800;
  --s: 1.15;
  color-scheme: light;
}

/* ---------- Base ---------- */
html, body { margin: 0; }
body.hp {
  background: var(--bg);
  color: var(--text);
  font-family: var(--fb);
  font-size: calc(15px * var(--s));
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
.hp *, .hp *::before, .hp *::after { box-sizing: border-box; }
/* :where() = prioridad mínima: los enlaces con clase (.hp-btn, .hp-icon-btn, tarjetas) usan su propio color */
:where(.hp) a { color: var(--accent-text); }
.hp :focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.hp button { font: inherit; cursor: pointer; }
.hp-sr { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Columna de la app: mobile-first, centrada en pantallas grandes */
.hp-app {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.hp-app--con-nav { padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }

/* ---------- Tipografía ---------- */
.hp-display {
  font-family: var(--fd);
  font-weight: var(--w-display);
  text-transform: var(--up);
  letter-spacing: var(--ls);
  line-height: 1;
  margin: 0;
}
.hp-h1 { font-size: calc(32px * var(--s)); }
.hp-h2 { font-size: calc(19px * var(--s)); }
.hp-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.hp-muted { color: var(--muted); }

/* ---------- Cabecera ---------- */
.hp-head {
  background: var(--head);
  color: var(--head-text);
  padding: calc(18px + env(safe-area-inset-top, 0px)) 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.hp-head-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hp-brand { display: flex; align-items: center; gap: 10px; }
.hp-brand-name { font-family: var(--fd); font-weight: 800; font-size: 19px; letter-spacing: 0.12em; }
.hp-icon-btn {
  width: 44px; height: 44px;
  border-radius: 14px;
  border: 0;
  background: var(--head-chip);
  color: var(--head-text);
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none;
}

/* ---------- Campos "chip" (cabecera del login) ---------- */
.hp-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.hp-field {
  background: var(--head-chip);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px;
  cursor: text;
  box-shadow: inset 0 0 0 2px transparent;
  transition: box-shadow .15s ease;
  min-height: calc(70px * var(--s));
}
.hp-field.is-activo { box-shadow: inset 0 0 0 2px var(--accent); }
.hp-field .hp-label { color: var(--head-muted); }
.hp-field input[type="text"] {
  border: 0; outline: 0; background: transparent; padding: 0; width: 100%;
  color: var(--head-text);
  font-family: var(--fd);
  font-size: calc(22px * var(--s));
  font-weight: 700;
  letter-spacing: 0.02em;
}
.hp-field input::placeholder { color: var(--head-muted); opacity: .7; }
.hp-dots { display: flex; gap: 6px; align-items: center; min-height: calc(26px * var(--s)); }
.hp-dot {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--head-muted);
  transition: background .12s ease, border-color .12s ease;
}
.hp-dot.is-lleno { background: var(--head-text); border-color: var(--head-text); }

/* ---------- Teclado numérico ---------- */
.hp-keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 16px 20px 0;
}
.hp-key {
  height: calc(60px * var(--s));
  border: 0;
  border-radius: 14px;
  background: var(--key);
  color: var(--key-text);
  font-family: var(--fd);
  font-size: calc(26px * var(--s));
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 0 rgba(0,0,0,.06);
  transition: transform .06s ease, filter .12s ease;
  user-select: none;
  touch-action: manipulation;
}
.hp-key:active { transform: scale(.96); filter: brightness(1.15); }
.hp-key--ghost { background: transparent; color: var(--muted); box-shadow: none; }
.hp-key--ok { background: var(--accent); color: #FFFFFF; }

/* ---------- Botones ---------- */
.hp-btn {
  min-height: 52px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 0 18px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  font-family: var(--fd);
  font-size: calc(16px * var(--s));
  font-weight: 700;
  text-transform: var(--up);
  text-decoration: none;
}
.hp-btn--primary { background: var(--accent); border-color: var(--accent); color: #FFFFFF; }
.hp-btn--primary:hover { background: var(--accent-hover); }
.hp-btn--block { width: 100%; }
.hp-btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Checkbox ---------- */
.hp-check { display: flex; align-items: center; gap: 12px; min-height: 44px; font-weight: 600; cursor: pointer; }
.hp-check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.hp-check-box {
  width: 26px; height: 26px; border-radius: 7px;
  border: 2px solid var(--line);
  background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.hp-check-box svg { opacity: 0; }
.hp-check input:checked + .hp-check-box { background: var(--accent); border-color: var(--accent); }
.hp-check input:checked + .hp-check-box svg { opacity: 1; }
.hp-check input:focus-visible + .hp-check-box { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- Tarjetas / opciones ---------- */
.hp-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; }
.hp-option {
  width: 100%;
  min-height: 84px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 12px 14px;
  display: flex; align-items: center; gap: 14px;
  text-align: left;
  color: var(--text);
}
.hp-option[aria-pressed="true"] { border: 2px solid var(--accent); padding: 11px 13px; }
.hp-option-swatch {
  width: 58px; height: 58px; border-radius: 14px; overflow: hidden;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line); flex-shrink: 0;
}
.hp-option-body { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.hp-option-radio {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--muted);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.hp-option[aria-pressed="true"] .hp-option-radio { border-color: var(--accent); }
.hp-option[aria-pressed="true"] .hp-option-radio::after {
  content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--accent);
}

/* ---------- Formularios ---------- */
.hp .d-none, .hp [hidden] { display: none !important; }
.hp-form { display: flex; flex-direction: column; gap: 16px; }
.hp-campo { display: flex; flex-direction: column; gap: 6px; }
.hp-campo > label, .hp-campo > .hp-campo-label { font-weight: 700; font-size: calc(14px * var(--s)); }
.hp-campo-ayuda { font-size: 12px; color: var(--muted); }
.hp-input, .hp-textarea {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
  font-size: calc(16px * var(--s));
}
.hp-textarea { min-height: 84px; resize: vertical; }
.hp-input::placeholder, .hp-textarea::placeholder { color: var(--muted); opacity: .75; }
.hp-input:focus, .hp-textarea:focus { outline: 0; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 30%, transparent); }
.hp-input--numero {
  min-height: calc(72px * var(--s));
  font-family: var(--fd);
  font-weight: 800;
  font-size: calc(34px * var(--s));
  letter-spacing: .04em;
  text-align: center;
}
.hp-input-grupo { display: flex; gap: 8px; }
.hp-input-grupo .hp-input { flex: 1; min-width: 0; }

/* Selector segmentado (radios) */
.hp-seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; }
.hp-seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.hp-seg label {
  min-height: 56px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  display: flex; align-items: center; justify-content: center; text-align: center; padding: 6px 10px;
  font-family: var(--fd); font-weight: var(--w-display); text-transform: var(--up); font-size: calc(15px * var(--s));
  cursor: pointer;
}
.hp-seg input:checked + label { background: var(--text); color: var(--bg); border-color: var(--text); }
.hp-seg input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }

.hp-seg--vertical { grid-auto-flow: row; grid-auto-columns: auto; }
.hp-seg--vertical label { justify-content: flex-start; text-align: left; padding: 10px 16px; }

/* Select */
.hp-select {
  width: 100%; min-height: 52px; border-radius: 14px; border: 1px solid var(--line);
  background-color: var(--surface); color: var(--text);
  padding: 12px 44px 12px 14px; font: inherit; font-size: calc(16px * var(--s));
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
.hp-select:focus { outline: 0; border-color: var(--focus); }

/* Fila de 2 campos que se apila en pantallas angostas */
.hp-fila2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 360px) { .hp-fila2 { grid-template-columns: minmax(0, 1fr); } }

/* Mensajes en línea */
.hp-msg { font-weight: 700; font-size: 14px; border-radius: 12px; padding: 10px 12px; }
.hp-msg:empty { display: none; }
.hp-msg.is-ok    { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--text); border-left: 5px solid var(--ok); }
.hp-msg.is-error { background: var(--accent-soft); color: var(--accent-text); border-left: 5px solid var(--accent); }

/* Badge de estado */
.hp-badge {
  display: inline-flex; align-items: center; min-height: 28px; padding: 2px 12px; border-radius: 999px;
  font-family: var(--fd); font-weight: 800; font-size: 13px; letter-spacing: .04em; text-transform: uppercase;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
}
.hp-badge[data-estado="OBRA"]     { background: var(--warn); color: var(--on-warn); border-color: var(--warn); }
.hp-badge[data-estado="DEPOSITO"] { background: var(--ok); color: #FFFFFF; border-color: var(--ok); }

/* Badges de estado del contenedor (por clase, para no chocar con filtros data-estado) */
.hp-badge--ELIMINADO { background: #3B0A0A; color: #FFFFFF; border-color: #3B0A0A; }
.hp-badge--TALLER    { background: var(--warn); color: var(--on-warn); border-color: var(--warn); }
.hp-badge--OPERABLE  { background: var(--ok); color: #FFFFFF; border-color: var(--ok); }
:root[data-tema="acero"] .hp-badge--ELIMINADO { background: #5A1218; border-color: #7A1A22; }

/* Alerta destacada */
.hp-alerta { background: color-mix(in srgb, var(--warn) 20%, transparent); border-left: 5px solid var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 14px; font-weight: 600; }

/* Interruptor (checkbox con aspecto de switch) */
.hp-switch {
  appearance: none; -webkit-appearance: none; flex-shrink: 0; margin: 0; cursor: pointer;
  width: 52px; height: 30px; border-radius: 999px; background: var(--line); position: relative;
  transition: background .15s ease;
}
.hp-switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #FFFFFF; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s ease;
}
.hp-switch:checked { background: var(--ok); }
.hp-switch:checked::after { transform: translateX(22px); }
.hp-switch:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.hp-switch:disabled { opacity: .5; cursor: not-allowed; }

/* Pantallas de administración: más anchas en PC */
@media (min-width: 900px) { .hp-app--ancho { max-width: 1040px; } }

/* Aviso suave */
.hp-aviso { display: flex; gap: 10px; align-items: center; padding: 14px 16px; border: 2px dashed var(--line); border-radius: 18px; color: var(--muted); font-weight: 600; }

/* Botones chicos / secundarios */
.hp-btn--sm { min-height: 44px; padding: 0 14px; font-size: calc(14px * var(--s)); }
.hp-btn--ghost { background: transparent; }
.hp-btn--azul { background: var(--blue); border-color: var(--blue); color: #FFFFFF; }
.hp-btn--warn { background: var(--warn); border-color: var(--warn); color: var(--on-warn); }
.hp-btn--ok   { background: var(--ok); border-color: var(--ok); color: #FFFFFF; }
.hp-btn--grande { min-height: calc(60px * var(--s)); font-size: calc(18px * var(--s)); }
.hp-msg.is-info { background: var(--surface-2); color: var(--muted); }

/* Chips de valores agregados */
.hp-chips { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 0; padding: 0; }
.hp-chip-item {
  display: inline-flex; align-items: center; gap: 4px; padding-left: 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-family: var(--fd); font-weight: 800; font-size: calc(18px * var(--s));
}
.hp-chip-item button {
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}

/* Cabecera de pantalla interna */
.hp-titulo { display: flex; align-items: center; gap: 12px; }
.hp-titulo-sup { font-size: 13px; font-weight: 600; color: var(--head-muted); }
.hp-body { padding: 18px 16px 24px; display: flex; flex-direction: column; gap: 16px; }
.hp-card-pad { padding: 16px; }

/* Diálogo nativo */
.hp-dialog {
  border: 0; padding: 0; border-radius: 22px; width: min(calc(100% - 32px), 440px);
  background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.hp-dialog::backdrop { background: rgba(10, 12, 16, .6); }
.hp-dialog-head { padding: 18px 18px 0; }
.hp-dialog-body { padding: 14px 18px; display: flex; flex-direction: column; gap: 10px; }
.hp-dialog-foot { padding: 0 18px 18px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.hp-kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.hp-kv:first-child { border-top: 0; }
.hp-kv dt { color: var(--muted); font-weight: 600; }
.hp-kv dd { margin: 0; font-weight: 700; text-align: right; overflow-wrap: anywhere; }

/* ---------- Barra inferior ---------- */
.hp-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 50;
  background: var(--nav);
  border-top: 1px solid var(--nav-line);
  padding: 6px 6px calc(10px + env(safe-area-inset-bottom, 0px));
}
.hp-nav-inner { max-width: 480px; margin: 0 auto; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
.hp-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 58px;
  color: var(--nav-muted);
  text-decoration: none;
  font-family: var(--fd);
  font-size: calc(12px * var(--s));
  font-weight: 700;
  text-transform: var(--up);
  border-top: 3px solid transparent;
}
.hp-nav a[aria-current="page"] { color: var(--accent-text); border-top-color: var(--accent); }

/* ---------- Toasts (showToast de app.js) ---------- */
.hp #toast-container {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  z-index: 2000; padding: 12px; width: min(100%, 420px);
  display: flex; flex-direction: column; gap: 8px;
}
.hp .custom-toast {
  display: flex; align-items: center;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-left: 6px solid var(--muted);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  opacity: 0; transform: translateY(-8px);
  transition: opacity .2s ease, transform .2s ease;
}
.hp .custom-toast.show { opacity: 1; transform: translateY(0); }
.hp .custom-toast .toast-body { padding: 12px 14px; flex: 1; font-weight: 600; }
.hp .custom-toast .close-btn { border: 0; background: none; color: var(--muted); font-size: 22px; width: 44px; height: 44px; }
.hp .toast-error   { border-left-color: var(--accent); }
.hp .toast-success { border-left-color: var(--ok); }
.hp .toast-info    { border-left-color: var(--blue); }
.hp .toast-warning { border-left-color: var(--warn); }

@media (prefers-reduced-motion: reduce) {
  .hp * { transition: none !important; animation: none !important; }
}
