/* ===== RYVAL · Sistema de Gestión de Activos =====
   Identidad corporativa oficial:
   Navy Industrial #001F3F · Electric Orange #FF851B · Steel Grey #AAAAAA */
:root {
  /* Colores de marca */
  --navy:       #001F3F;   /* Azul Corporativo */
  --orange:     #FF851B;   /* Naranja Activo (acentos / acción) */
  --orange-600: #E9740C;   /* naranja hover */
  --steel:      #AAAAAA;   /* Gris Técnico (divisores y detalles) */

  /* Roles (alias usados por los componentes) */
  --tinta:      #001F3F;
  --azul:       #001F3F;   /* navy: títulos, bordes, nav activo */
  --azul-claro: #EAF1F7;   /* tinte navy claro */
  --acento:     #FF851B;
  --acento-bg:  #FFF1E2;   /* tinte naranja muy claro */
  --verde:      #1A6A3A;  --verde-bg: #E8F4EC;  /* éxito / criticidad baja */
  --rojo:       #B42318;  --rojo-bg:  #FDECEA;  /* error / criticidad alta */
  --ambar:      #B7791F;  --ambar-bg: #FCF3DE;  /* aviso / criticidad media */
  --gris-bg:    #F3F5F8;   /* fondo de la app */
  --gris-linea: #DCE1E8;   /* bordes suaves */
  --texto:      #001F3F;   /* texto principal = navy */
  --texto-suave:#51607A;   /* texto secundario (AA ~5:1 sobre blanco) */
  --blanco:     #FFFFFF;
  --radio:      12px;
  --sombra:     0 1px 3px rgba(0,31,63,.08), 0 1px 2px rgba(0,31,63,.05);
}

* { box-sizing: border-box; }

/* Garantiza que el atributo `hidden` siempre oculte, aunque la clase
   del elemento defina display (ej. .activo-sel { display:flex }). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--gris-bg);
  color: var(--texto);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

/* ===== Encabezado ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--blanco);
  color: var(--navy);
  border-bottom: 3px solid var(--orange);
}
.brand { display: flex; align-items: center; }
.brand-logo { height: 52px; width: auto; display: block; }
/* Wordmark de respaldo (si el logo no carga) */
.brand-mark { font-weight: 800; font-size: 22px; letter-spacing: 1px; color: var(--navy); }
.brand-mark-accent { color: var(--orange); }
.brand-sub {
  font-size: 12px;
  letter-spacing: .5px;
  color: var(--texto-suave);
  text-transform: uppercase;
  margin-top: 2px;
}

/* Indicador de conexión */
.estado-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.estado-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
}
.estado-pill--cargando { background: #EEF1F5;        color: #51607A; }
.estado-pill--ok       { background: var(--verde-bg); color: var(--verde); }
.estado-pill--error    { background: var(--rojo-bg);  color: var(--rojo); }

/* ===== Aviso superior ===== */
.aviso {
  margin: 12px 16px 0;
  padding: 12px 14px;
  border-radius: var(--radio);
  font-size: 14px;
  border: 1px solid transparent;
}
.aviso--info  { background: var(--azul-claro); border-color: #C5D6F2; color: var(--azul); }
.aviso--error { background: var(--rojo-bg);    border-color: #F3C0BB; color: var(--rojo); }
.aviso--warn  { background: var(--ambar-bg);   border-color: #EBD9A6; color: var(--ambar); }

/* ===== Contenido / formulario ===== */
.contenido {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 120px; /* espacio para la barra inferior */
}

.grupo {
  background: var(--blanco);
  border: 1px solid var(--gris-linea);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 16px;
  margin-bottom: 14px;
}
.grupo-titulo {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--azul);
}

.campo { margin-bottom: 14px; }
.campo:last-child { margin-bottom: 0; }
.campo label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--texto);
}
.req { color: var(--rojo); }

/* Dos columnas en pantallas con espacio */
.fila { display: flex; gap: 12px; }
.fila .campo { flex: 1; }

input[type="text"],
input[type="date"],
input[type="number"],
select,
textarea {
  width: 100%;
  font: inherit;
  color: var(--texto);
  background: var(--blanco);
  border: 1px solid var(--gris-linea);
  border-radius: 10px;
  padding: 12px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235A6478' d='M6 8.5 1.5 4h9z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 34px;
}
textarea { resize: vertical; min-height: 64px; }

input:focus, select:focus, textarea:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(0,31,63,.16);
}
input.invalido, select.invalido {
  border-color: var(--rojo);
  box-shadow: 0 0 0 3px rgba(180,35,24,.12);
}

/* Código GTC 62 generado automáticamente */
.codigo-auto {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: .5px;
  color: var(--navy);
  background: var(--acento-bg);
  border-color: #F3D5B5;
}
.codigo-auto::placeholder {
  font-family: "Segoe UI", system-ui, sans-serif;
  font-weight: 400;
  font-size: 14px;
  letter-spacing: 0;
  color: var(--texto-suave);
}

/* ===== Foto ===== */
.foto-boton {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  border: 1.5px dashed var(--gris-linea);
  border-radius: 10px;
  background: var(--gris-bg);
  color: var(--azul);
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.foto-boton:active { background: #E9EDF5; }
.foto-preview { position: relative; margin-top: 10px; }
.foto-preview img {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}
.foto-quitar {
  position: absolute;
  top: 8px; right: 8px;
  width: 32px; height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(10,13,20,.7);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

/* ===== Barra inferior fija ===== */
.barra-guardar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--blanco);
  border-top: 1px solid var(--gris-linea);
  box-shadow: 0 -2px 10px rgba(10,13,20,.06);
}
.contador {
  font-size: 13px;
  font-weight: 600;
  color: var(--texto-suave);
  white-space: nowrap;
}
.btn-guardar {
  flex: 1;
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  color: var(--navy);
  background: var(--orange);
  border: none;
  border-radius: 10px;
  padding: 14px 18px;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn-guardar:hover { background: var(--orange-600); }
.btn-guardar:disabled { opacity: .55; cursor: progress; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%) translateY(8px);
  z-index: 40;
  max-width: 90%;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  box-shadow: 0 6px 20px rgba(10,13,20,.25);
  opacity: 0;
  transition: opacity .2s, transform .2s;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast--ok    { background: var(--verde); }
.toast--error { background: var(--rojo); }

/* ===== Navegación entre pantallas ===== */
.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px 0;
}
.app-nav a {
  flex: 1 1 88px;
  text-align: center;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  color: var(--texto-suave);
  background: var(--blanco);
  border: 1px solid var(--gris-linea);
  border-radius: 10px;
  padding: 10px 6px;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.app-nav a.actual {
  color: #fff;
  background: var(--azul);
  border-color: var(--azul);
}

/* ===== Selector de activo (intervenciones) ===== */
.activo-sel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1.5px solid var(--azul);
  background: var(--azul-claro);
  border-radius: 10px;
}
.activo-sel-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.activo-sel-info strong { color: var(--azul); }
.activo-sel-info small { color: var(--texto-suave); }
.btn-cambiar {
  flex-shrink: 0;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  color: var(--azul);
  background: #fff;
  border: 1px solid var(--azul);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

.resultados-cab {
  margin: 4px 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--texto-suave);
}
.resultados {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 340px;
  overflow-y: auto;
  border: 1px solid var(--gris-linea);
  border-radius: 10px;
}
.resultados:empty { display: none; }
.resultado {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 12px;
  background: #fff;
  border: none;
  border-bottom: 1px solid var(--gris-linea);
  cursor: pointer;
  font: inherit;
}
.resultado:hover { background: var(--gris-bg); }
.resultados li:last-child .resultado { border-bottom: none; }
.resultado-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.resultado-cod { font-weight: 700; color: var(--texto); }
.resultado-meta {
  font-size: 12px;
  color: var(--texto-suave);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}
.badge--Alta  { background: var(--rojo-bg);  color: var(--rojo); }
.badge--Media { background: var(--ambar-bg); color: var(--ambar); }
.badge--Baja  { background: var(--verde-bg); color: var(--verde); }
.vacio {
  padding: 20px;
  text-align: center;
  color: var(--texto-suave);
  font-size: 14px;
}

/* ===== Ayuda y evidencia fotográfica (galería múltiple) ===== */
.ayuda { margin: -4px 0 12px; font-size: 13px; color: var(--texto-suave); }
.fotos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin-top: 10px; }
.foto-thumb { position: relative; aspect-ratio: 1 / 1; border-radius: 10px; overflow: hidden; border: 1px solid var(--gris-linea); }
.foto-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.foto-thumb .foto-quitar { top: 4px; right: 4px; width: 26px; height: 26px; font-size: 13px; }

/* ===== Inicio / Dashboard ERP ===== */
.accesos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.acceso {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 16px 8px; text-decoration: none;
  background: var(--blanco); border: 1px solid var(--gris-linea);
  border-radius: 12px; box-shadow: var(--sombra);
  color: var(--azul); font-weight: 700; font-size: 13px; text-align: center;
}
.acceso:hover { background: var(--gris-bg); }
.acceso .ico { font-size: 24px; line-height: 1; }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kpi {
  background: var(--blanco); border: 1px solid var(--gris-linea);
  border-radius: 12px; padding: 14px; box-shadow: var(--sombra);
}
.kpi-num { font-size: 24px; font-weight: 800; color: var(--navy); line-height: 1.1; }
.kpi--money .kpi-num { font-size: 19px; }
.kpi--alerta .kpi-num { color: var(--rojo); }
.kpi-lbl {
  font-size: 11px; color: var(--texto-suave); font-weight: 700;
  margin-top: 4px; text-transform: uppercase; letter-spacing: .4px;
}

.barra-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.barra-row:last-child { margin-bottom: 0; }
.barra-lbl { width: 38%; color: var(--texto); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barra-track { flex: 1; height: 8px; background: var(--gris-bg); border-radius: 999px; overflow: hidden; }
.barra-fill { display: block; height: 100%; background: var(--orange); border-radius: 999px; }
.barra-val { min-width: 48px; text-align: right; color: var(--texto-suave); font-weight: 700; font-size: 12px; white-space: nowrap; }

.fecha-badge { flex-shrink: 0; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.fecha-badge--vencido { background: var(--rojo-bg);  color: var(--rojo); }
.fecha-badge--proximo { background: var(--ambar-bg); color: var(--ambar); }
.fecha-badge--ok      { background: var(--verde-bg); color: var(--verde); }

/* Las listas del dashboard sí muestran todo su contenido */
#pendientes, #ultimas { max-height: none; }

/* ===== Órdenes de Trabajo ===== */
.ot-cab { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }

/* ===== Tabla de materiales / repuestos ===== */
.mat-tabla { border: 1px solid var(--gris-linea); border-radius: 10px; overflow: hidden; }
.mat-head, .mat-row { display: grid; grid-template-columns: 1fr 46px 84px 30px; gap: 6px; align-items: center; padding: 6px 8px; }
.mat-head { background: var(--azul-claro); font-size: 11px; font-weight: 700; color: var(--azul); text-transform: uppercase; letter-spacing: .3px; }
.mat-row { border-top: 1px solid var(--gris-linea); }
.mat-row input { padding: 8px 8px; font-size: 14px; }
.mat-quitar { width: 28px; height: 28px; border: none; border-radius: 6px; background: var(--rojo-bg); color: var(--rojo); font-size: 12px; font-weight: 700; cursor: pointer; }
.mat-quitar:hover { background: #F8D7D2; }

/* ===== Botón "Mejorar redacción" (IA) ===== */
.btn-mejorar {
  margin-top: 6px; font: inherit; font-size: 12px; font-weight: 700;
  color: var(--acento); background: var(--acento-bg);
  border: 1px solid #F3D5B5; border-radius: 8px; padding: 6px 10px; cursor: pointer;
  transition: background .15s;
}
.btn-mejorar:hover { background: #FFE7CC; }
.btn-mejorar:disabled { opacity: .6; cursor: progress; }

/* ===== Banner de edición de intervención ===== */
.edit-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
  background: var(--azul-claro); border: 1px solid #C5D6F2;
}
.edit-banner span { font-weight: 700; color: var(--azul); font-size: 13px; }

/* ===== Informes agrupados por empresa ===== */
.lista-grupo { margin-bottom: 14px; }
.grupo-cab {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 12px; background: var(--azul); border-radius: 10px 10px 0 0;
}
.grupo-cab strong { color: #fff; font-size: 13px; font-weight: 700; }
.grupo-cab small { color: #C8D4E4; font-size: 12px; font-weight: 600; white-space: nowrap; }
#lista .resultados { max-height: none; border-radius: 0 0 10px 10px; border-top: none; }

/* ===== Sesión: botón Salir en el encabezado ===== */
.header-right { display: flex; align-items: center; gap: 10px; }
.btn-salir {
  font: inherit; font-weight: 700; font-size: 13px;
  color: var(--navy); background: transparent;
  border: 1px solid var(--gris-linea); border-radius: 999px;
  padding: 6px 12px; cursor: pointer;
}
.btn-salir:hover { background: var(--gris-bg); }

/* ===== Pantalla de login ===== */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--gris-bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--blanco);
  border: 1px solid var(--gris-linea); border-top: 4px solid var(--orange);
  border-radius: 16px; box-shadow: 0 8px 30px rgba(0,31,63,.10);
  padding: 28px 24px; text-align: center;
}
.login-logo { height: 56px; width: auto; margin: 4px auto 8px; display: block; }
.login-title { margin: 4px 0 18px; font-size: 18px; color: var(--navy); }
.login-card form { text-align: left; }
.login-error {
  margin: 0 0 12px; padding: 10px 12px; border-radius: 10px;
  background: var(--rojo-bg); color: var(--rojo); font-size: 14px; border: 1px solid #F3C0BB;
}
.login-hint { margin: 16px 0 0; font-size: 12px; color: var(--texto-suave); text-align: center; }

@media (max-width: 420px) {
  .fila { flex-direction: column; gap: 0; }
  .fila .campo { margin-bottom: 14px; }
}

/* ===== Agenda de OT: toggle Lista / Calendario ===== */
.agenda-toggle { display: flex; gap: 6px; }
.btn-cambiar.actual {
  background: var(--navy); color: var(--blanco); border-color: var(--navy);
}

/* ===== Calendario mensual ===== */
.cal-nav {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  margin: 6px 0 12px;
}
.cal-nav strong { color: var(--navy); font-size: 15px; min-width: 150px; text-align: center; }
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
}
.cal-dow {
  text-align: center; font-size: 11px; font-weight: 700; color: var(--texto-suave);
  text-transform: uppercase; padding: 4px 0;
}
.cal-cell {
  min-height: 70px; border: 1px solid var(--gris-linea); border-radius: 8px;
  padding: 3px; background: var(--blanco); overflow: hidden;
}
.cal-cell.cal-empty { background: transparent; border: none; }
.cal-cell.cal-hoy { border-color: var(--orange); box-shadow: 0 0 0 1px var(--orange) inset; }
.cal-num { font-size: 11px; font-weight: 700; color: var(--texto-suave); margin-bottom: 2px; }
.cal-chip {
  display: block; font-size: 10px; font-weight: 700; line-height: 1.3;
  padding: 1px 4px; margin-bottom: 2px; border-radius: 4px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-chip--Alta  { background: var(--rojo-bg);  color: var(--rojo); }
.cal-chip--Media { background: var(--ambar-bg); color: var(--ambar); }
.cal-chip--Baja  { background: var(--verde-bg); color: var(--verde); }
.cal-mas { font-size: 10px; color: var(--texto-suave); font-weight: 700; padding-left: 4px; }

@media (max-width: 420px) {
  .cal-cell { min-height: 54px; }
  .cal-chip { font-size: 9px; }
}
