/* Contratos PE - hoja de estilos propia (sin dependencias externas; compatible con CSP estricta) */
:root {
  --fondo: #f5f6f8;
  --panel: #ffffff;
  --texto: #1f2430;
  --suave: #5d6475;
  --borde: #dde1e8;
  --marca: #1c4e80;
  --marca-oscura: #143a60;
  --ok: #1e7b4a;
  --ok-fondo: #e6f4ec;
  --aviso: #8a5a00;
  --aviso-fondo: #fdf3dc;
  --error: #b42318;
  --error-fondo: #fdecea;
  --info: #1c4e80;
  --info-fondo: #e8f0f9;
  --neutro-fondo: #eef0f4;
  --radio: 8px;
  --sombra: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--texto);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--fondo); font-size: 14px; line-height: 1.45; }
a { color: var(--marca); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.subtitulo { color: var(--suave); margin: 0 0 20px; }
.oculto { display: none !important; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 13px; }
.suave { color: var(--suave); }

/* Estructura */
.barra {
  background: var(--marca); color: #fff; display: flex; align-items: center; gap: 16px;
  padding: 0 20px; height: 52px; position: sticky; top: 0; z-index: 10;
}
.barra .marca { font-weight: 600; font-size: 16px; color: #fff; white-space: nowrap; }
.barra .espacio { flex: 1; }
.barra select { max-width: 380px; background: var(--marca-oscura); color: #fff; border: 1px solid #3e6b98; border-radius: 6px; padding: 5px 8px; }
.barra .usuario { font-size: 13px; opacity: 0.9; }
.barra button { background: transparent; color: #fff; border: 1px solid #5d86b0; }
.contenedor { display: flex; min-height: calc(100vh - 52px); }
.menu { width: 210px; background: var(--panel); border-right: 1px solid var(--borde); padding: 16px 10px; flex-shrink: 0; }
.menu a { display: block; padding: 8px 12px; border-radius: 6px; color: var(--texto); margin-bottom: 2px; }
.menu a:hover { background: var(--neutro-fondo); text-decoration: none; }
.menu a.activo { background: var(--info-fondo); color: var(--marca); font-weight: 600; }
.menu .grupo { font-size: 11px; text-transform: uppercase; color: var(--suave); margin: 16px 12px 6px; letter-spacing: 0.04em; }
main { flex: 1; padding: 24px 28px; max-width: 1280px; }

/* Paneles y tarjetas */
.panel { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--sombra); }
.tarjetas { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tarjeta { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px 16px; box-shadow: var(--sombra); }
.tarjeta .valor { font-size: 26px; font-weight: 600; }
.tarjeta .etiqueta { color: var(--suave); font-size: 12px; }
/* Totales de la grilla de RxH: una fila por moneda (nunca se suman PEN y USD) */
.totales-grilla { display: grid; grid-template-columns: minmax(110px, 0.6fr) repeat(3, minmax(150px, 1fr)); gap: 10px; margin-bottom: 10px; }
.totales-grilla .tarjeta { padding: 10px 14px; box-shadow: none; }
.totales-grilla .valor { font-size: 19px; font-variant-numeric: tabular-nums; }
@media (max-width: 760px) { .totales-grilla { grid-template-columns: repeat(2, 1fr); } }
.tarjeta.alerta .valor { color: var(--error); }
.cabecera { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.acciones { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tablas */
.tabla-envoltura { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--borde); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--suave); font-weight: 600; background: #fafbfc; }
tbody tr:hover { background: #fafbfd; }
.vacio { color: var(--suave); padding: 18px; text-align: center; }
dl.datos { display: grid; grid-template-columns: 190px 1fr; gap: 6px 16px; margin: 0; }
dl.datos dt { color: var(--suave); }
dl.datos dd { margin: 0; }

/* Estados */
.estado { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.estado.ok { background: var(--ok-fondo); color: var(--ok); }
.estado.aviso { background: var(--aviso-fondo); color: var(--aviso); }
.estado.error { background: var(--error-fondo); color: var(--error); }
.estado.info { background: var(--info-fondo); color: var(--info); }
.estado.neutro { background: var(--neutro-fondo); color: var(--suave); }
.motivo { margin: 2px 0; font-size: 13px; }
.motivo.error { color: var(--error); }
.motivo.aviso { color: var(--aviso); }
.motivo.info { color: var(--info); }

/* Formularios */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.campo { margin-bottom: 14px; }
.campo .ayuda { color: var(--suave); font-size: 12px; font-weight: 400; margin-top: 3px; }
input, select, textarea {
  width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--borde); border-radius: 6px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0e6; border-color: var(--marca); }
textarea { min-height: 80px; resize: vertical; }
.fila { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.filtros { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filtros .campo { margin-bottom: 0; min-width: 160px; }
/* Combo de selección múltiple (desplegable con casillas) */
.multi { position: relative; }
.multi > summary {
  list-style: none; cursor: pointer; padding: 8px 28px 8px 10px; border: 1px solid var(--borde); border-radius: 6px;
  background: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative;
}
.multi > summary::-webkit-details-marker { display: none; }
.multi > summary::after { content: "▾"; position: absolute; right: 10px; color: var(--suave); }
.multi[open] > summary { outline: 2px solid #9cc0e6; border-color: var(--marca); }
.multi .opciones {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 100%; max-height: 280px; overflow-y: auto;
  background: #fff; border: 1px solid var(--borde); border-radius: 6px; box-shadow: var(--sombra); padding: 6px;
}
.multi .opciones label { display: flex; gap: 8px; align-items: center; font-weight: 400; padding: 4px 6px; border-radius: 4px; cursor: pointer; margin: 0; white-space: nowrap; }
.multi .opciones label:hover { background: var(--fondo); }
.multi .opciones input { width: auto; }
.multi .opciones .pie { display: flex; justify-content: space-between; gap: 6px; border-top: 1px solid var(--borde); margin-top: 4px; padding-top: 6px; }
button, .boton {
  font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--borde); background: #fff; cursor: pointer;
  color: var(--texto); display: inline-block;
}
button:hover, .boton:hover { background: var(--neutro-fondo); text-decoration: none; }
button.primario, .boton.primario { background: var(--marca); border-color: var(--marca); color: #fff; }
button.primario:hover, .boton.primario:hover { background: var(--marca-oscura); }
button.peligro { color: var(--error); border-color: #f1b5ae; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.chico, .boton.chico { padding: 3px 9px; font-size: 12px; }

/* Diálogos y mensajes */
dialog { border: none; border-radius: 10px; padding: 0; width: min(560px, 94vw); max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25); }
dialog::backdrop { background: rgba(15, 23, 42, 0.45); }
dialog form { padding: 20px 22px; }
dialog h2 { margin-bottom: 16px; }
dialog .pie { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.error-form { color: var(--error); background: var(--error-fondo); padding: 8px 10px; border-radius: 6px; margin-bottom: 12px; }
.clave-temporal { font-family: Consolas, monospace; font-size: 20px; background: var(--aviso-fondo); padding: 10px; border-radius: 6px; text-align: center; letter-spacing: 1px; }
#mensajes { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.mensaje { padding: 10px 14px; border-radius: 8px; box-shadow: var(--sombra); background: var(--panel); border-left: 4px solid var(--marca); max-width: 380px; }
.mensaje.ok { border-left-color: var(--ok); }
.mensaje.error { border-left-color: var(--error); }

/* Firmas */
img.firma { max-width: 320px; max-height: 110px; border: 1px dashed var(--borde); border-radius: 6px; padding: 6px; background: #fff; display: block; margin: 8px 0; }
.declaracion { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; background: var(--info-fondo); padding: 10px 12px; border-radius: 6px; margin: 10px 0; }
.declaracion input { width: auto; margin-top: 3px; }

/* Carga */
.zona-carga { border: 2px dashed #b8c2d1; border-radius: var(--radio); padding: 28px; text-align: center; background: #fbfcfe; cursor: pointer; }
.zona-carga.sobre { border-color: var(--marca); background: var(--info-fondo); }
.lista-archivos { margin: 12px 0 0; padding: 0; list-style: none; text-align: left; }
.lista-archivos li { padding: 4px 0; border-bottom: 1px solid var(--borde); display: flex; justify-content: space-between; }

/* Ingreso */
.ingreso { max-width: 380px; margin: 9vh auto; }
.ingreso .panel { padding: 26px 28px; }
.ingreso h1 { margin-bottom: 18px; }

@media (max-width: 800px) {
  .contenedor { flex-direction: column; }
  .menu { width: auto; border-right: none; border-bottom: 1px solid var(--borde); display: flex; flex-wrap: wrap; gap: 4px; }
  .menu .grupo { display: none; }
  main { padding: 16px; }
  dl.datos { grid-template-columns: 1fr; }
}
